pacemaker  2.1.9-49aab99839
Scalable High-Availability cluster resource manager
pcmk__set_time_if_earlier_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2024 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU General Public License version 2
7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
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  // Should do nothing (just checking it doesn't assert or crash)
24  pcmk__set_time_if_earlier(NULL, NULL);
26 
27  // Shouldn't assert, crash, or change target
29  assert_int_equal(crm_time_compare(target, target_copy), 0);
30 
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");
40 
42  assert_int_equal(crm_time_compare(target, source), 0);
43 
44  crm_time_free(source);
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 
55  assert_int_equal(crm_time_compare(target, source), 0);
56 
57  crm_time_free(source);
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 
69  assert_int_equal(crm_time_compare(target, target_copy), 0);
70 
71  crm_time_free(source);
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))
crm_time_t * crm_time_new_undefined(void)
Allocate memory for an uninitialized time object.
Definition: iso8601.c:129
struct crm_time_s crm_time_t
Definition: iso8601.h:32
crm_time_t * pcmk_copy_time(const crm_time_t *source)
Definition: iso8601.c:1471
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
ISO_8601 Date handling.
int crm_time_compare(const crm_time_t *a, const crm_time_t *b)
Definition: iso8601.c:1736
const char * target
Definition: pcmk_fence.c:29
G_GNUC_INTERNAL void pcmk__set_time_if_earlier(crm_time_t *target, const crm_time_t *source)
Definition: iso8601.c:1461
crm_time_t * crm_time_new(const char *string)
Definition: iso8601.c:112
void crm_time_free(crm_time_t *dt)
Definition: iso8601.c:150