20 assert_add_days(
const char *orig_date_time,
int days,
21 const char *expected_date_time)
26 assert_non_null(orig);
27 assert_non_null(expected);
37 invalid_argument(
void **state)
43 positive_same_year(
void **state)
45 assert_add_days(
"2024-01-01 00:30:00 +01:00", 1,
46 "2024-01-02 00:30:00 +01:00");
48 assert_add_days(
"2024-01-31 01:40:50 +02:00", 1,
49 "2024-02-01 01:40:50 +02:00");
51 assert_add_days(
"2024-02-28 11:45:11 +03:00", 1,
52 "2024-02-29 11:45:11 +03:00");
54 assert_add_days(
"2024-02-28 12:59:59 -03:00", 2,
55 "2024-03-01 12:59:59 -03:00");
57 assert_add_days(
"2024-01-01 00:00:00 +00:00", 365,
58 "2024-12-31 00:00:00 +00:00");
60 assert_add_days(
"2025-01-01 23:00:00 +00:00", 364,
61 "2025-12-31 23:00:00 +00:00");
65 negative_same_year(
void **state)
67 assert_add_days(
"2024-01-02 00:30:00 +01:00", -1,
68 "2024-01-01 00:30:00 +01:00");
70 assert_add_days(
"2024-02-01 01:40:50 +02:00", -1,
71 "2024-01-31 01:40:50 +02:00");
73 assert_add_days(
"2024-03-01 11:45:11 +03:00", -1,
74 "2024-02-29 11:45:11 +03:00");
76 assert_add_days(
"2024-03-01 12:59:59 -03:00", -2,
77 "2024-02-28 12:59:59 -03:00");
79 assert_add_days(
"2024-12-31 00:00:00 +00:00", -365,
80 "2024-01-01 00:00:00 +00:00");
82 assert_add_days(
"2025-12-31 23:00:00 +00:00", -364,
83 "2025-01-01 23:00:00 +00:00");
87 positive_year_changes(
void **state)
90 assert_add_days(
"2023-01-01 00:40:20 +02:00", 365,
91 "2024-01-01 00:40:20 +02:00");
94 assert_add_days(
"2023-01-01 00:40:20 +02:00", 426,
95 "2024-03-02 00:40:20 +02:00");
98 assert_add_days(
"2023-03-02 00:40:20 +02:00", 325,
99 "2024-01-21 00:40:20 +02:00");
102 assert_add_days(
"2023-03-02 00:40:20 +02:00", 385,
103 "2024-03-21 00:40:20 +02:00");
106 assert_add_days(
"2024-01-01 00:40:20 +02:00", 366,
107 "2025-01-01 00:40:20 +02:00");
110 assert_add_days(
"2024-01-01 00:40:20 +02:00", 430,
111 "2025-03-06 00:40:20 +02:00");
114 assert_add_days(
"2024-12-31 09:41:23 +06:00", 1,
115 "2025-01-01 09:41:23 +06:00");
118 assert_add_days(
"2024-12-31 09:41:23 +06:00", 90,
119 "2025-03-31 09:41:23 +06:00");
122 assert_add_days(
"2025-01-01 01:00:00 -02:00", 366,
123 "2026-01-02 01:00:00 -02:00");
126 assert_add_days(
"2025-01-01 00:00:00 +00:00", 1500,
127 "2029-02-09 00:00:00 +00:00");
130 assert_add_days(
"2025-01-01 00:00:00 +00:00", 28000,
131 "2101-08-31 00:00:00 +00:00");
134 assert_add_days(
"2025-01-01 00:00:00 +00:00", 150000,
135 "2435-09-09 00:00:00 +00:00");
139 negative_year_changes(
void **state)
142 assert_add_days(
"2025-01-01 00:40:20 +02:00", -366,
143 "2024-01-01 00:40:20 +02:00");
146 assert_add_days(
"2025-01-01 00:40:20 +02:00", -300,
147 "2024-03-07 00:40:20 +02:00");
150 assert_add_days(
"2024-01-01 00:40:20 +02:00", -365,
151 "2023-01-01 00:40:20 +02:00");
154 assert_add_days(
"2024-01-01 00:40:20 +02:00", -1,
155 "2023-12-31 00:40:20 +02:00");
158 assert_add_days(
"1990-01-01 00:00:00 +00:00", -2000,
159 "1984-07-11 00:00:00 +00:00");
162 assert_add_days(
"1990-01-01 00:00:00 +00:00", -33000,
163 "1899-08-26 00:00:00 +00:00");
166 assert_add_days(
"1990-01-01 00:00:00 +00:00", -150000,
167 "1579-04-26 00:00:00 +00:00");
171 year_out_of_range(
void **state)
173 char *orig_datetime = NULL;
174 char *expected_datetime = NULL;
179 assert_add_days(orig_datetime, 400, expected_datetime);
181 free(expected_datetime);
184 assert_add_days(
"01-02-01 00:00:00 +00:00", -40,
185 "01-01-01 00:00:00 +00:00");
189 cmocka_unit_test(invalid_argument),
190 cmocka_unit_test(positive_same_year),
191 cmocka_unit_test(negative_same_year),
192 cmocka_unit_test(positive_year_changes),
193 cmocka_unit_test(negative_year_changes),
194 cmocka_unit_test(year_out_of_range));
PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(invalid_argument), cmocka_unit_test(positive_same_year), cmocka_unit_test(negative_same_year), cmocka_unit_test(positive_year_changes), cmocka_unit_test(negative_year_changes), cmocka_unit_test(year_out_of_range))
struct crm_time_s crm_time_t
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
#define pcmk__assert_asserts(stmt)
int crm_time_compare(const crm_time_t *a, const crm_time_t *b)
crm_time_t * crm_time_new(const char *string)
void crm_time_add_days(crm_time_t *dt, int value)
Add days to a date/time.
void crm_time_free(crm_time_t *dt)