|
@@ -0,0 +1,115 @@
|
|
1
|
+#include <check.h>
|
|
2
|
+#include <stdio.h>
|
|
3
|
+
|
|
4
|
+#include "ttail_check.h"
|
|
5
|
+#include "ttail.h"
|
|
6
|
+#include "ttail_init.h"
|
|
7
|
+#include "ttail_search.h"
|
|
8
|
+
|
|
9
|
+#define TTAIL_TM_CMP_INIT \
|
|
10
|
+struct tm a, b;\
|
|
11
|
+int ret;\
|
|
12
|
+ttail_tm_init(&a);\
|
|
13
|
+ttail_tm_init(&b);\
|
|
14
|
+
|
|
15
|
+START_TEST (test_tm_cmp_init)
|
|
16
|
+{
|
|
17
|
+ TTAIL_TM_CMP_INIT
|
|
18
|
+ ret = ttail_tm_cmp(&a, &b);
|
|
19
|
+ ck_assert_int_eq(ret, 0);
|
|
20
|
+}
|
|
21
|
+END_TEST
|
|
22
|
+
|
|
23
|
+START_TEST (test_tm_cmp_field_priority)
|
|
24
|
+{
|
|
25
|
+ TTAIL_TM_CMP_INIT
|
|
26
|
+ a.tm_sec = 42;
|
|
27
|
+ b.tm_sec = 41;
|
|
28
|
+ ret = ttail_tm_cmp(&a, &b);
|
|
29
|
+ ck_assert_int_gt(ret, 0);
|
|
30
|
+ a.tm_min = 41;
|
|
31
|
+ b.tm_min = 42;
|
|
32
|
+ ret = ttail_tm_cmp(&a, &b);
|
|
33
|
+ ck_assert_int_lt(ret, 0);
|
|
34
|
+ a.tm_hour = 42;
|
|
35
|
+ b.tm_hour = 41;
|
|
36
|
+ ret = ttail_tm_cmp(&a, &b);
|
|
37
|
+ ck_assert_int_gt(ret, 0);
|
|
38
|
+ a.tm_mday = 21;
|
|
39
|
+ b.tm_mday = 22;
|
|
40
|
+ ret = ttail_tm_cmp(&a, &b);
|
|
41
|
+ ck_assert_int_lt(ret, 0);
|
|
42
|
+ a.tm_mon = 10;
|
|
43
|
+ b.tm_mon = 9;
|
|
44
|
+ ret = ttail_tm_cmp(&a, &b);
|
|
45
|
+ ck_assert_int_gt(ret, 0);
|
|
46
|
+ a.tm_year = 14;
|
|
47
|
+ b.tm_year = 15;
|
|
48
|
+ ret = ttail_tm_cmp(&a, &b);
|
|
49
|
+ ck_assert_int_lt(ret, 0);
|
|
50
|
+}
|
|
51
|
+END_TEST
|
|
52
|
+
|
|
53
|
+START_TEST (test_tm_cmp_empty_fields1)
|
|
54
|
+{
|
|
55
|
+ TTAIL_TM_CMP_INIT
|
|
56
|
+ a.tm_sec = 42;
|
|
57
|
+ b.tm_min = 41;
|
|
58
|
+ a.tm_hour = 1;
|
|
59
|
+ b.tm_hour = 1;
|
|
60
|
+ ret = ttail_tm_cmp(&a, &b);
|
|
61
|
+ ck_assert_int_eq(ret, 0);
|
|
62
|
+}
|
|
63
|
+END_TEST
|
|
64
|
+
|
|
65
|
+START_TEST (test_tm_cmp_empty_fields2)
|
|
66
|
+{
|
|
67
|
+ TTAIL_TM_CMP_INIT
|
|
68
|
+ a.tm_sec = 42;
|
|
69
|
+ b.tm_min = 41;
|
|
70
|
+ b.tm_hour = 1;
|
|
71
|
+ b.tm_mday = 6;
|
|
72
|
+ b.tm_mon = 7;
|
|
73
|
+ b.tm_year = 15;
|
|
74
|
+ ret = ttail_tm_cmp(&a, &b);
|
|
75
|
+ ck_assert_int_eq(ret, 0);
|
|
76
|
+}
|
|
77
|
+END_TEST
|
|
78
|
+
|
|
79
|
+START_TEST (test_tm_cmp_empty_fields3)
|
|
80
|
+{
|
|
81
|
+ TTAIL_TM_CMP_INIT
|
|
82
|
+ a.tm_sec = 42;
|
|
83
|
+ b.tm_sec = 55;
|
|
84
|
+ b.tm_min = 41;
|
|
85
|
+ b.tm_hour = 1;
|
|
86
|
+ b.tm_mday = 6;
|
|
87
|
+ b.tm_mon = 7;
|
|
88
|
+ b.tm_year = 15;
|
|
89
|
+ ret = ttail_tm_cmp(&a, &b);
|
|
90
|
+ ck_assert_int_lt(ret, 0);
|
|
91
|
+}
|
|
92
|
+END_TEST
|
|
93
|
+
|
|
94
|
+START_TEST (test_tm_cmp_empty_fields4)
|
|
95
|
+{
|
|
96
|
+ TTAIL_TM_CMP_INIT
|
|
97
|
+ b.tm_sec = 42;
|
|
98
|
+ a.tm_min = 41;
|
|
99
|
+ a.tm_hour = 1;
|
|
100
|
+ a.tm_mday = 6;
|
|
101
|
+ a.tm_mon = 7;
|
|
102
|
+ a.tm_year = 15;
|
|
103
|
+ ret = ttail_tm_cmp(&a, &b);
|
|
104
|
+ ck_assert_int_eq(ret, 0);
|
|
105
|
+}
|
|
106
|
+END_TEST
|
|
107
|
+
|
|
108
|
+TTAIL_CHECK_START("ttail search functions checks", "ttail_tm_cmp() checks")
|
|
109
|
+ TTAIL_ADD_TEST(test_tm_cmp_init);
|
|
110
|
+ TTAIL_ADD_TEST(test_tm_cmp_field_priority);
|
|
111
|
+ TTAIL_ADD_TEST(test_tm_cmp_empty_fields1);
|
|
112
|
+ TTAIL_ADD_TEST(test_tm_cmp_empty_fields2);
|
|
113
|
+ TTAIL_ADD_TEST(test_tm_cmp_empty_fields3);
|
|
114
|
+ TTAIL_ADD_TEST(test_tm_cmp_empty_fields4);
|
|
115
|
+TTAIL_CHECK_END
|