This source file includes following definitions.
- null_ok
- target_undefined
- source_earlier
- source_later
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/unittest_internal.h>
13
14 #include <crm/common/iso8601.h>
15 #include "../../crmcommon_private.h"
16
17 static void
18 null_ok(void **state)
19 {
20 crm_time_t *target = crm_time_new("2024-01-01 00:30:00 +01:00");
21 crm_time_t *target_copy = pcmk_copy_time(target);
22
23
24 pcmk__set_time_if_earlier(NULL, NULL);
25 pcmk__set_time_if_earlier(NULL, target);
26
27
28 pcmk__set_time_if_earlier(target, NULL);
29 assert_int_equal(crm_time_compare(target, target_copy), 0);
30
31 crm_time_free(target);
32 crm_time_free(target_copy);
33 }
34
35 static void
36 target_undefined(void **state)
37 {
38 crm_time_t *source = crm_time_new("2024-01-01 00:29:59 +01:00");
39 crm_time_t *target = crm_time_new_undefined();
40
41 pcmk__set_time_if_earlier(target, source);
42 assert_int_equal(crm_time_compare(target, source), 0);
43
44 crm_time_free(source);
45 crm_time_free(target);
46 }
47
48 static void
49 source_earlier(void **state)
50 {
51 crm_time_t *source = crm_time_new("2024-01-01 00:29:59 +01:00");
52 crm_time_t *target = crm_time_new("2024-01-01 00:30:00 +01:00");
53
54 pcmk__set_time_if_earlier(target, source);
55 assert_int_equal(crm_time_compare(target, source), 0);
56
57 crm_time_free(source);
58 crm_time_free(target);
59 }
60
61 static void
62 source_later(void **state)
63 {
64 crm_time_t *source = crm_time_new("2024-01-01 00:31:00 +01:00");
65 crm_time_t *target = crm_time_new("2024-01-01 00:30:00 +01:00");
66 crm_time_t *target_copy = pcmk_copy_time(target);
67
68 pcmk__set_time_if_earlier(target, source);
69 assert_int_equal(crm_time_compare(target, target_copy), 0);
70
71 crm_time_free(source);
72 crm_time_free(target);
73 crm_time_free(target_copy);
74 }
75
76 PCMK__UNIT_TEST(NULL, NULL,
77 cmocka_unit_test(null_ok),
78 cmocka_unit_test(target_undefined),
79 cmocka_unit_test(source_earlier),
80 cmocka_unit_test(source_later))