Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief Tests for I/O bindings
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : *
8 : */
9 :
10 : #include <stdio.h>
11 : #include <stdlib.h>
12 : #include <string.h>
13 :
14 : #include <tests.h>
15 :
16 : #include "test.h"
17 : #include <kdbio.h>
18 : #include <kdbioprivate.h>
19 : #include <kdbiotest.h>
20 :
21 6 : static void test_timing (void)
22 : {
23 : struct timespec start;
24 6 : exit_if_fail (elektraIoTestSuiteUtilGetCurrentTime (&start) != 0, "could not measure time; aborting test-suite");
25 6 : }
26 :
27 6 : static void test_basics (ElektraIoInterface * wrapper)
28 : {
29 6 : printf ("test basics\n");
30 :
31 6 : exit_if_fail (wrapper != NULL, "wrapper is null; aborting test-suite");
32 :
33 6 : succeed_if (wrapper->addFd != NULL, "addFd is null");
34 6 : succeed_if (wrapper->updateFd != NULL, "updateFd is null");
35 6 : succeed_if (wrapper->removeFd != NULL, "removeFd is null");
36 :
37 6 : succeed_if (wrapper->addTimer != NULL, "addTimer is null");
38 6 : succeed_if (wrapper->updateTimer != NULL, "updateTimer is null");
39 6 : succeed_if (wrapper->removeTimer != NULL, "removeTimer is null");
40 :
41 6 : succeed_if (wrapper->addIdle != NULL, "addIdle is null");
42 6 : succeed_if (wrapper->updateIdle != NULL, "updateIdle is null");
43 6 : succeed_if (wrapper->removeIdle != NULL, "removeIdle is null");
44 :
45 6 : succeed_if (wrapper->cleanup != NULL, "cleanup is null");
46 :
47 6 : succeed_if (wrapper->cleanup (wrapper), "cleanup did not succeed");
48 6 : }
49 :
50 : /**
51 : * Test all functions and requirements of the I/O binding returned by createBinding.
52 : * Requires the following operations: Idle, Timer, Fd
53 : *
54 : * @param createBinding binding creation function
55 : * @param start starts I/O operations
56 : * @param stop stops I/O operations
57 : */
58 6 : void elektraIoTestSuite (ElektraIoTestSuiteCreateBinding createBinding, ElektraIoTestSuiteStart start, ElektraIoTestSuiteStop stop)
59 : {
60 6 : printf ("BINDING TEST-SUITE\n");
61 6 : printf ("==================\n\n");
62 :
63 6 : test_timing ();
64 :
65 6 : test_basics (createBinding ());
66 :
67 6 : elektraIoTestSuiteIdle (createBinding, start, stop);
68 :
69 6 : elektraIoTestSuiteTimer (createBinding, start, stop);
70 :
71 6 : elektraIoTestSuiteFd (createBinding, start, stop);
72 :
73 6 : elektraIoTestSuiteMix (createBinding, start, stop);
74 6 : }
|