Add/update tests.
[eruntime.git] / tests / test-version.c
blob2499743bceab163c287ec16dfb1a083c2f588c52
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #include "eruntime/version.h"
7 static int t_eruntime_get_version (void);
8 static int t_eruntime_compare_versions (void);
10 typedef int (*test_case_func) (void);
12 typedef struct _test_case_struct
14 const char *name;
15 const char *desc;
16 test_case_func func;
18 } test_case_t;
20 /* {{{ static test_case_t version_tests[] = { ... } */
21 static test_case_t version_tests[] =
24 "eruntime_get_version",
25 "function eruntime_get_version()",
26 t_eruntime_get_version
29 "eruntime_compare_versions",
30 "function t_eruntime_compare_versions()",
31 t_eruntime_compare_versions,
34 {NULL, NULL, NULL},
36 /* }}} */
38 /* {{{ int main() */
39 int
40 main (void)
42 test_case_t *tc = NULL;
43 int ret;
45 setbuf(stdout, NULL);
46 setbuf(stderr, NULL);
48 for (tc = version_tests; tc->name; ++tc)
50 printf("Testing %s... ", tc->desc);
51 ret = tc->func();
53 if (ret == EXIT_SUCCESS)
54 fputs("success\n", stdout);
55 else
56 fprintf(stderr, "\nTest '%s' failed\n", tc->name);
59 return EXIT_SUCCESS;
61 /* }}} */
63 /* {{{ static int t_eruntime_get_version() */
64 static int
65 t_eruntime_get_version (void)
67 version_spec_t ev;
69 if (eruntime_get_version(&ev) < 0)
71 fprintf(stderr, "eruntime_get_version() failed\n");
72 return EXIT_FAILURE;
75 return EXIT_SUCCESS;
77 /* }}} */
79 /* {{{ static int t_eruntime_compare_versions() */
80 static int
81 t_eruntime_compare_versions (void)
83 version_spec_t ev, ev_copy;
84 int sort_order;
86 if (eruntime_get_version(&ev) < 0)
88 fprintf(stderr, "eruntime_get_version() failed\n");
89 return EXIT_FAILURE;
92 memcpy(&ev_copy, &ev, sizeof(ev));
93 sort_order = eruntime_compare_versions(&ev, &ev_copy);
94 if (sort_order != 0)
96 fprintf(stderr, "\n\n"
97 "sort order: %d\n"
98 "expecting : 0\n",
99 (int) sort_order);
100 return EXIT_FAILURE;
103 return EXIT_SUCCESS;
105 /* }}} */
108 * vim: ts=8 sw=8 noet fdm=marker tw=80 :