35 assert_date_expression(
const xmlNode *xml,
const char *now_s,
36 const char *next_change_s,
const char *reference_s,
41 bool check_next_change = (next_change_s != NULL) && (reference_s != NULL);
43 if (check_next_change) {
52 if (check_next_change) {
61 #define EXPR_LT_VALID \ 62 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 63 PCMK_XA_OPERATION "='" PCMK_VALUE_LT "' " \ 64 PCMK_XA_END "='2024-02-01 15:00:00' />" 67 null_invalid(
void **state)
81 null_next_change_ok(
void **state)
89 #define EXPR_ID_MISSING \ 90 "<" PCMK_XE_DATE_EXPRESSION " " \ 91 PCMK_XA_OPERATION "='" PCMK_VALUE_LT "' " \ 92 PCMK_XA_END "='2024-02-01 15:00:00' />" 95 id_missing(
void **state)
104 #define EXPR_OP_INVALID \ 105 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 106 PCMK_XA_OPERATION "='not-a-choice' />" 109 op_invalid(
void **state)
117 #define EXPR_LT_MISSING_END \ 118 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 119 PCMK_XA_OPERATION "='" PCMK_VALUE_LT "' />" 122 lt_missing_end(
void **state)
130 #define EXPR_LT_INVALID_END \ 131 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 132 PCMK_XA_OPERATION "='" PCMK_VALUE_LT "' " \ 133 PCMK_XA_END "='not-a-datetime' />" 136 lt_invalid_end(
void **state)
145 lt_valid(
void **state)
150 assert_date_expression(xml,
"2023-01-01 05:00:00",
"2024-02-01 10:00:00",
154 assert_date_expression(xml,
"2024-02-01 14:59:59",
"2024-02-01 18:00:00",
158 assert_date_expression(xml,
"2024-02-01 15:00:00",
"2024-02-01 20:00:00",
162 assert_date_expression(xml,
"2024-03-01 12:00:00",
"2024-02-01 20:00:00",
168 #define EXPR_GT_MISSING_START \ 169 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 170 PCMK_XA_OPERATION "='" PCMK_VALUE_GT "' />" 173 gt_missing_start(
void **state)
181 #define EXPR_GT_INVALID_START \ 182 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 183 PCMK_XA_OPERATION "='" PCMK_VALUE_GT "' " \ 184 PCMK_XA_START "='not-a-datetime' />" 187 gt_invalid_start(
void **state)
195 #define EXPR_GT_VALID \ 196 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 197 PCMK_XA_OPERATION "='" PCMK_VALUE_GT "' " \ 198 PCMK_XA_START "='2024-02-01 12:00:00' />" 201 gt_valid(
void **state)
206 assert_date_expression(xml,
"2024-01-01 04:30:05",
"2024-01-01 11:00:00",
210 assert_date_expression(xml,
"2024-02-01 11:59:59",
"2024-02-01 18:00:00",
214 assert_date_expression(xml,
"2024-02-01 12:00:00",
"2024-02-01 18:00:00",
218 assert_date_expression(xml,
"2024-02-01 12:00:01",
"2024-02-01 18:00:00",
222 assert_date_expression(xml,
"2024-03-01 05:03:11",
"2024-04-04 04:04:04",
228 #define EXPR_RANGE_MISSING \ 229 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 230 PCMK_XA_OPERATION "='" PCMK_VALUE_IN_RANGE "' />" 233 range_missing(
void **state)
245 #define EXPR_RANGE_INVALID_START_INVALID_END \ 246 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 247 PCMK_XA_OPERATION "='" PCMK_VALUE_IN_RANGE "' " \ 248 PCMK_XA_START "='not-a-date' " \ 249 PCMK_XA_END "='not-a-date' />" 252 range_invalid_start_invalid_end(
void **state)
260 #define EXPR_RANGE_INVALID_START_ONLY \ 261 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 262 PCMK_XA_OPERATION "='" PCMK_VALUE_IN_RANGE "' " \ 263 PCMK_XA_START "='not-a-date' />" 266 range_invalid_start_only(
void **state)
274 #define EXPR_RANGE_VALID_START_ONLY \ 275 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 276 PCMK_XA_OPERATION "='" PCMK_VALUE_IN_RANGE "' " \ 277 PCMK_XA_START "='2024-02-01 12:00:00' />" 280 range_valid_start_only(
void **state)
285 assert_date_expression(xml,
"2024-01-01 04:30:05",
"2024-01-01 11:00:00",
289 assert_date_expression(xml,
"2024-02-01 11:59:59",
"2024-02-01 18:00:00",
293 assert_date_expression(xml,
"2024-02-01 12:00:00",
"2024-02-01 18:00:00",
297 assert_date_expression(xml,
"2024-03-01 05:03:11",
"2024-04-04 04:04:04",
303 #define EXPR_RANGE_INVALID_END_ONLY \ 304 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 305 PCMK_XA_OPERATION "='" PCMK_VALUE_IN_RANGE "' " \ 306 PCMK_XA_END "='not-a-date' />" 309 range_invalid_end_only(
void **state)
317 #define EXPR_RANGE_VALID_END_ONLY \ 318 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 319 PCMK_XA_OPERATION "='" PCMK_VALUE_IN_RANGE "' " \ 320 PCMK_XA_END "='2024-02-01 15:00:00' />" 323 range_valid_end_only(
void **state)
328 assert_date_expression(xml,
"2024-01-01 04:30:05",
"2024-01-01 11:00:00",
332 assert_date_expression(xml,
"2024-02-01 14:59:59",
"2024-02-01 18:00:00",
336 assert_date_expression(xml,
"2024-02-01 15:00:00",
"2024-02-01 18:00:00",
340 assert_date_expression(xml,
"2024-02-01 15:00:01",
"2024-04-04 04:04:04",
346 #define EXPR_RANGE_VALID_START_INVALID_END \ 347 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 348 PCMK_XA_OPERATION "='" PCMK_VALUE_IN_RANGE "' " \ 349 PCMK_XA_START "='2024-02-01 12:00:00' " \ 350 PCMK_XA_END "='not-a-date' />" 353 range_valid_start_invalid_end(
void **state)
359 assert_date_expression(xml,
"2024-01-01 04:30:05",
"2024-01-01 11:00:00",
363 assert_date_expression(xml,
"2024-02-01 11:59:59",
"2024-02-01 18:00:00",
367 assert_date_expression(xml,
"2024-02-01 12:00:00",
"2024-02-01 18:00:00",
371 assert_date_expression(xml,
"2024-03-01 05:03:11",
"2024-04-04 04:04:04",
377 #define EXPR_RANGE_INVALID_START_VALID_END \ 378 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 379 PCMK_XA_OPERATION "='" PCMK_VALUE_IN_RANGE "' " \ 380 PCMK_XA_START "='not-a-date' " \ 381 PCMK_XA_END "='2024-02-01 15:00:00' />" 384 range_invalid_start_valid_end(
void **state)
390 assert_date_expression(xml,
"2024-01-01 04:30:05",
"2024-01-01 11:00:00",
394 assert_date_expression(xml,
"2024-02-01 14:59:59",
"2024-02-01 18:00:00",
398 assert_date_expression(xml,
"2024-02-01 15:00:00",
"2024-02-01 18:00:00",
402 assert_date_expression(xml,
"2024-02-01 15:00:01",
"2024-04-04 04:04:04",
408 #define EXPR_RANGE_VALID_START_VALID_END \ 409 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 410 PCMK_XA_OPERATION "='" PCMK_VALUE_IN_RANGE "' " \ 411 PCMK_XA_START "='2024-02-01 12:00:00' " \ 412 PCMK_XA_END "='2024-02-01 15:00:00' />" 415 range_valid_start_valid_end(
void **state)
420 assert_date_expression(xml,
"2024-01-01 04:30:05",
"2024-01-01 11:00:00",
424 assert_date_expression(xml,
"2024-02-01 11:59:59",
"2024-02-01 14:00:00",
428 assert_date_expression(xml,
"2024-02-01 12:00:00",
"2024-02-01 14:30:00",
432 assert_date_expression(xml,
"2024-02-01 14:03:11",
"2024-04-04 04:04:04",
436 assert_date_expression(xml,
"2024-02-01 15:00:00",
"2028-04-04 04:04:04",
440 assert_date_expression(xml,
"2024-02-01 15:00:01",
"2028-04-04 04:04:04",
446 #define EXPR_RANGE_VALID_START_INVALID_DURATION \ 447 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 448 PCMK_XA_OPERATION "='" PCMK_VALUE_IN_RANGE "' " \ 449 PCMK_XA_START "='2024-02-01 12:00:00'>" \ 450 "<" PCMK_XE_DURATION " " PCMK_XA_ID "='d' " \ 451 PCMK_XA_HOURS "='not-a-number' />" \ 452 "</" PCMK_XE_DATE_EXPRESSION ">" 455 range_valid_start_invalid_duration(
void **state)
461 assert_date_expression(xml,
"2024-02-01 04:30:05",
"2024-01-01 11:00:00",
465 assert_date_expression(xml,
"2024-02-01 11:59:59",
"2024-02-01 18:00:00",
469 assert_date_expression(xml,
"2024-02-01 12:00:00",
"2024-02-01 14:30:00",
473 assert_date_expression(xml,
"2024-02-01 12:00:01",
"2024-02-01 14:30:00",
479 #define EXPR_RANGE_VALID_START_VALID_DURATION \ 480 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 481 PCMK_XA_OPERATION "='" PCMK_VALUE_IN_RANGE "' " \ 482 PCMK_XA_START "='2024-02-01 12:00:00'>" \ 483 "<" PCMK_XE_DURATION " " PCMK_XA_ID "='d' " \ 484 PCMK_XA_HOURS "='3' />" \ 485 "</" PCMK_XE_DATE_EXPRESSION ">" 488 range_valid_start_valid_duration(
void **state)
493 assert_date_expression(xml,
"2024-01-01 04:30:05",
"2024-01-01 11:00:00",
497 assert_date_expression(xml,
"2024-02-01 11:59:59",
"2024-02-01 14:00:00",
501 assert_date_expression(xml,
"2024-02-01 12:00:00",
"2024-02-01 14:30:00",
505 assert_date_expression(xml,
"2024-02-01 14:03:11",
"2024-04-04 04:04:04",
509 assert_date_expression(xml,
"2024-02-01 15:00:00",
"2028-04-04 04:04:04",
513 assert_date_expression(xml,
"2024-02-01 15:00:01",
"2028-04-04 04:04:04",
519 #define EXPR_RANGE_VALID_START_DURATION_MISSING_ID \ 520 "<" PCMK_XE_DATE_EXPRESSION " " \ 521 PCMK_XA_OPERATION "='" PCMK_VALUE_IN_RANGE "' " \ 522 PCMK_XA_START "='2024-02-01 12:00:00'>" \ 523 "<" PCMK_XE_DURATION " " PCMK_XA_ID "='d' " \ 524 PCMK_XA_HOURS "='3' />" \ 525 "</" PCMK_XE_DATE_EXPRESSION ">" 528 range_valid_start_duration_missing_id(
void **state)
531 xmlNodePtr xml = NULL;
536 assert_date_expression(xml,
"2024-01-01 04:30:05",
"2024-01-01 11:00:00",
540 assert_date_expression(xml,
"2024-02-01 11:59:59",
"2024-02-01 14:00:00",
544 assert_date_expression(xml,
"2024-02-01 12:00:00",
"2024-02-01 14:30:00",
548 assert_date_expression(xml,
"2024-02-01 14:03:11",
"2024-04-04 04:04:04",
552 assert_date_expression(xml,
"2024-02-01 15:00:00",
"2028-04-04 04:04:04",
556 assert_date_expression(xml,
"2024-02-01 15:00:01",
"2028-04-04 04:04:04",
562 #define EXPR_SPEC_MISSING \ 563 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 564 PCMK_XA_OPERATION "='" PCMK_VALUE_DATE_SPEC "' />" 567 spec_missing(
void **state)
575 #define EXPR_SPEC_INVALID \ 576 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 577 PCMK_XA_OPERATION "='" PCMK_VALUE_DATE_SPEC "'>" \ 578 "<" PCMK_XE_DATE_SPEC " " PCMK_XA_ID "='s' " \ 579 PCMK_XA_MONTHS "='not-a-number'/>" \ 580 "</" PCMK_XE_DATE_EXPRESSION ">" 583 spec_invalid(
void **state)
588 assert_date_expression(xml,
"2024-01-01", NULL, NULL,
pcmk_rc_ok);
592 #define EXPR_SPEC_VALID \ 593 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 594 PCMK_XA_OPERATION "='" PCMK_VALUE_DATE_SPEC "'>" \ 595 "<" PCMK_XE_DATE_SPEC " " PCMK_XA_ID "='s' " \ 596 PCMK_XA_MONTHS "='2'/>" \ 597 "</" PCMK_XE_DATE_EXPRESSION ">" 600 spec_valid(
void **state)
606 assert_date_expression(xml,
"2024-01-01 23:59:59", NULL, NULL,
610 assert_date_expression(xml,
"2024-02-01 00:00:00", NULL, NULL,
pcmk_rc_ok);
613 assert_date_expression(xml,
"2024-02-22 22:22:22", NULL, NULL,
pcmk_rc_ok);
616 assert_date_expression(xml,
"2024-02-29 23:59:59", NULL, NULL,
pcmk_rc_ok);
619 assert_date_expression(xml,
"2024-03-01 00:00:00", NULL, NULL,
625 #define EXPR_SPEC_MISSING_ID \ 626 "<" PCMK_XE_DATE_EXPRESSION " " PCMK_XA_ID "='e' " \ 627 PCMK_XA_OPERATION "='" PCMK_VALUE_DATE_SPEC "'>" \ 628 "<" PCMK_XE_DATE_SPEC " " \ 629 PCMK_XA_MONTHS "='2'/>" \ 630 "</" PCMK_XE_DATE_EXPRESSION ">" 633 spec_missing_id(
void **state)
639 assert_date_expression(xml,
"2024-01-01 23:59:59", NULL, NULL,
643 assert_date_expression(xml,
"2024-02-01 00:00:00", NULL, NULL,
pcmk_rc_ok);
646 assert_date_expression(xml,
"2024-02-22 22:22:22", NULL, NULL,
pcmk_rc_ok);
649 assert_date_expression(xml,
"2024-02-29 23:59:59", NULL, NULL,
pcmk_rc_ok);
652 assert_date_expression(xml,
"2024-03-01 00:00:00", NULL, NULL,
659 cmocka_unit_test(null_invalid),
660 cmocka_unit_test(null_next_change_ok),
661 cmocka_unit_test(id_missing),
662 cmocka_unit_test(op_invalid),
663 cmocka_unit_test(lt_missing_end),
664 cmocka_unit_test(lt_invalid_end),
665 cmocka_unit_test(lt_valid),
666 cmocka_unit_test(gt_missing_start),
667 cmocka_unit_test(gt_invalid_start),
668 cmocka_unit_test(gt_valid),
669 cmocka_unit_test(range_missing),
670 cmocka_unit_test(range_invalid_start_invalid_end),
671 cmocka_unit_test(range_invalid_start_only),
672 cmocka_unit_test(range_valid_start_only),
673 cmocka_unit_test(range_invalid_end_only),
674 cmocka_unit_test(range_valid_end_only),
675 cmocka_unit_test(range_valid_start_invalid_end),
676 cmocka_unit_test(range_invalid_start_valid_end),
677 cmocka_unit_test(range_valid_start_valid_end),
678 cmocka_unit_test(range_valid_start_invalid_duration),
679 cmocka_unit_test(range_valid_start_valid_duration),
680 cmocka_unit_test(range_valid_start_duration_missing_id),
681 cmocka_unit_test(spec_missing),
682 cmocka_unit_test(spec_invalid),
683 cmocka_unit_test(spec_valid),
684 cmocka_unit_test(spec_missing_id))
#define EXPR_RANGE_INVALID_START_VALID_END
#define EXPR_RANGE_MISSING
struct crm_time_s crm_time_t
#define EXPR_GT_MISSING_START
#define EXPR_SPEC_MISSING_ID
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
#define EXPR_SPEC_MISSING
#define EXPR_LT_INVALID_END
#define EXPR_RANGE_VALID_START_DURATION_MISSING_ID
#define EXPR_RANGE_VALID_START_INVALID_END
int pcmk__xml_test_setup_group(void **state)
Wrappers for and extensions to libxml2.
#define EXPR_RANGE_VALID_START_VALID_DURATION
#define EXPR_SPEC_INVALID
#define EXPR_RANGE_VALID_END_ONLY
void free_xml(xmlNode *child)
xmlNode * pcmk__xml_parse(const char *input)
int crm_time_compare(const crm_time_t *a, const crm_time_t *b)
#define EXPR_RANGE_VALID_START_VALID_END
#define EXPR_GT_INVALID_START
#define EXPR_RANGE_VALID_START_INVALID_DURATION
#define EXPR_RANGE_INVALID_END_ONLY
#define EXPR_RANGE_INVALID_START_ONLY
#define EXPR_RANGE_VALID_START_ONLY
crm_time_t * crm_time_new(const char *string)
#define EXPR_LT_MISSING_END
int pcmk__evaluate_date_expression(const xmlNode *date_expression, const crm_time_t *now, crm_time_t *next_change)
#define EXPR_RANGE_INVALID_START_INVALID_END
void crm_time_free(crm_time_t *dt)