This source file includes following definitions.
- assert_add_years
- invalid_argument
- add_positive
- add_negative
- out_of_range
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdio.h>
13 #include <limits.h>
14
15 #include <crm/common/unittest_internal.h>
16
17 #include <crm/common/iso8601.h>
18
19 static void
20 assert_add_years(const char *orig_date_time, int years,
21 const char *expected_date_time)
22 {
23 crm_time_t *orig = crm_time_new(orig_date_time);
24 crm_time_t *expected = crm_time_new(expected_date_time);
25
26 assert_non_null(orig);
27 assert_non_null(expected);
28
29 crm_time_add_years(orig, years);
30 assert_int_equal(crm_time_compare(orig, expected), 0);
31
32 crm_time_free(orig);
33 crm_time_free(expected);
34 }
35
36 static void
37 invalid_argument(void **state)
38 {
39 pcmk__assert_asserts(crm_time_add_years(NULL, 1));
40 }
41
42 static void
43 add_positive(void **state)
44 {
45 assert_add_years("2024-01-01 00:30:00 +01:00", 1,
46 "2025-01-01 00:30:00 +01:00");
47
48 assert_add_years("2024-12-31 01:40:50 +02:00", 1000,
49 "3024-12-31 01:40:50 +02:00");
50 }
51
52 static void
53 add_negative(void **state)
54 {
55 assert_add_years("2024-01-01 00:30:00 +01:00", -1,
56 "2023-01-01 00:30:00 +01:00");
57
58 assert_add_years("2024-12-31 01:40:50 +02:00", -1000,
59 "1024-12-31 01:40:50 +02:00");
60 }
61
62 static void
63 out_of_range(void **state)
64 {
65 char *expected_datetime = NULL;
66
67 expected_datetime = crm_strdup_printf("%d-01-01 00:00:00 +00:00", INT_MAX);
68 assert_add_years("2024-01-01 00:00:00 +00:00", INT_MAX, expected_datetime);
69 free(expected_datetime);
70
71 assert_add_years("2024-01-01 00:00:00 +00:00", -3000,
72 "01-01-01 00:00:00 +00:00");
73 }
74
75 PCMK__UNIT_TEST(NULL, NULL,
76 cmocka_unit_test(invalid_argument),
77 cmocka_unit_test(add_positive),
78 cmocka_unit_test(add_negative),
79 cmocka_unit_test(out_of_range));