release 0.1.15
[liba.git] / test / version.h
blob4ebe733dffc55bbaf3a61476f6c7394dce99c9fd
1 #define MAIN(x) version##x
2 #include "test.h"
3 #include "a/version.h"
5 int main(int argc, char *argv[]) // NOLINT(misc-definitions-in-headers)
7 #if defined(__cplusplus)
8 a::version v000 = A_VERSION_0();
9 a::version v100 = A_VERSION_1(1);
10 a::version v010 = A_VERSION_2(0, 1);
11 a::version v001 = A_VERSION_3(0, 0, 1);
12 v010.parse(".1");
14 TEST_BUG(v000 == v000);
15 TEST_BUG(v000 != v001);
17 TEST_BUG(v000 < v001);
18 TEST_BUG(v001 < v010);
19 TEST_BUG(v010 < v100);
21 TEST_BUG(v001 > v000);
22 TEST_BUG(v010 > v001);
23 TEST_BUG(v100 > v010);
25 TEST_BUG(v000 <= v001);
26 TEST_BUG(v001 <= v001);
27 TEST_BUG(v001 <= v010);
28 TEST_BUG(v010 <= v010);
29 TEST_BUG(v010 <= v100);
30 TEST_BUG(v100 <= v100);
32 TEST_BUG(v001 >= v000);
33 TEST_BUG(v001 >= v001);
34 TEST_BUG(v010 >= v001);
35 TEST_BUG(v010 >= v010);
36 TEST_BUG(v100 >= v010);
37 TEST_BUG(v100 >= v100);
39 #else /* !__cplusplus */
40 a_version v000 = A_VERSION_0();
41 a_version v100 = A_VERSION_1(1);
42 a_version v010 = A_VERSION_2(0, 1);
43 a_version v001 = A_VERSION_3(0, 0, 1);
45 TEST_BUG(a_version_eq(&v000, &v000));
46 TEST_BUG(a_version_ne(&v000, &v001));
48 TEST_BUG(a_version_lt(&v000, &v001));
49 TEST_BUG(a_version_lt(&v001, &v010));
50 TEST_BUG(a_version_lt(&v010, &v100));
52 TEST_BUG(a_version_gt(&v001, &v000));
53 TEST_BUG(a_version_gt(&v010, &v001));
54 TEST_BUG(a_version_gt(&v100, &v010));
56 TEST_BUG(a_version_le(&v000, &v001));
57 TEST_BUG(a_version_le(&v001, &v001));
58 TEST_BUG(a_version_le(&v001, &v010));
59 TEST_BUG(a_version_le(&v010, &v010));
60 TEST_BUG(a_version_le(&v010, &v100));
61 TEST_BUG(a_version_le(&v100, &v100));
63 TEST_BUG(a_version_ge(&v001, &v000));
64 TEST_BUG(a_version_ge(&v001, &v001));
65 TEST_BUG(a_version_ge(&v010, &v001));
66 TEST_BUG(a_version_ge(&v010, &v010));
67 TEST_BUG(a_version_ge(&v100, &v010));
68 TEST_BUG(a_version_ge(&v100, &v100));
70 TEST_BUG(a_version_cmp(&v010, &v100) < 0);
71 TEST_BUG(a_version_cmp(&v001, &v010) < 0);
72 TEST_BUG(a_version_cmp(&v000, &v001) < 0);
73 TEST_BUG(a_version_cmp(&v100, &v010) > 0);
74 TEST_BUG(a_version_cmp(&v010, &v001) > 0);
75 TEST_BUG(a_version_cmp(&v001, &v000) > 0);
76 TEST_BUG(a_version_cmp(&v000, &v000) == 0);
77 #endif /* __cplusplus */
78 #if defined(__cplusplus) && (__cplusplus > 201100L)
79 A_BUILD_ASSERT(std::is_pod<a_version>::value);
80 #endif /* __cplusplus */
81 for (int i = 0; i < argc; ++i)
83 char str[48];
84 a_version ctx = A_VERSION_0();
85 a_version_parse(&ctx, argv[i]);
86 a_version_tostr(&ctx, str, sizeof(str));
87 debug("parse \"%s\" -> %s\n", argv[i], str);
89 printf("%s\n", A_FUNC);
90 debug("version %u.%u.%u+%" PRIu32 "\n", a_version_major, a_version_minor, a_version_patch, a_version_tweak);
91 TEST_BUG(A_VERSION_CHECK() == 0);
92 return 0;