1326
test_operator_serialisation (void)
1328
JobClass *job = NULL;
1329
EventOperator *oper1, *oper2;
1333
struct test_operator {
1338
struct test_operator test_operators[] = {
1339
{ "with simple operator", "started JOB=second_test\n" },
1340
{ "with or operator", "runlevel [23] or not-container" },
1341
{ "with and operator", "(local-filesystems and net-device-up)" },
1342
{ "with complex operator", "runlevel [23] and (\n"
1343
"not-container or\n"
1344
"container CONTAINER=lxc or\n"
1345
"container CONTAINER=lxc-libvirt)" },
1348
struct test_operator *test;
1350
/* Check correct serialisation/deserialisation of complex
1351
* operators, to be sure that we can generate a correct round-trip
1354
TEST_FUNCTION ("event_operator_serialisation");
1360
job = job_class_new (NULL, "operator_test", NULL);
1362
for (test = test_operators; test && test->value; test++)
1364
TEST_FEATURE (test->description);
1366
oper1 = parse_on_simple (job, "start", test->value);
1367
/* Ideally we would exercise allocation here,
1368
* but NIH_MUST is being used.
1370
oper1_string = event_operator_collapse (oper1);
1371
nih_message ("oper1_string: '%s' (from '%s')", oper1_string, test->value);
1373
oper2 = parse_on_simple (job, "start", oper1_string);
1375
oper2_string = event_operator_collapse (oper2);
1376
nih_message ("oper2_string: '%s' (from '%s')", oper2_string, oper1_string);
1379
char *str = "(((runlevel [23] and not-container) or container CONTAINER=lxc) or container CONTAINER=lxc-libvirt)";
1380
EventOperator *oper3;
1383
oper3 = parse_on_simple (job, "start", str);
1385
oper3_string = event_operator_collapse (oper3);
1386
nih_message ("oper3_string: '%s' (from '%s')", oper3_string, str);
1389
char *str = "runlevel [23] and not-container or container CONTAINER=lxc or container CONTAINER=lxc-libvirt";
1390
EventOperator *oper4;
1393
oper4 = parse_on_simple (job, "start", str);
1395
oper4_string = event_operator_collapse (oper4);
1396
nih_message ("oper4_string: '%s' (from '%s')", oper4_string, str);
1399
TEST_EQ (oper1->value, oper2->value);
1400
TEST_EQ (oper1->type, oper2->type);
1401
if (oper1->name || oper2->name) {
1402
TEST_EQ_STR (oper1->name, oper2->name);
1405
/* We don't get to use the macros here because we need to
1406
* walk both trees in tandem */
1407
for (NihTree *iter1 = nih_tree_next (&oper1->node, NULL),
1408
*iter2 = nih_tree_next (&oper2->node, NULL);
1409
iter1 != NULL && iter2 != NULL;
1410
iter1 = nih_tree_next (&oper1->node, iter1),
1411
iter2 = nih_tree_next (&oper2->node, iter2))
1413
EventOperator *oper1_sub = (EventOperator *)iter1;
1414
EventOperator *oper2_sub = (EventOperator *)iter2;
1416
TEST_EQ (oper1_sub->value, oper2_sub->value);
1417
TEST_EQ (oper1_sub->type, oper2_sub->type);
1418
if (oper1_sub->name || oper2_sub->name) {
1419
TEST_EQ_STR (oper1_sub->name, oper2_sub->name);
1325
1427
main (int argc,