3236
test_get_start_on (void)
3238
NihDBusMessage *message = NULL;
3239
JobClass *class = NULL;
3240
EventOperator *oper = NULL;
3241
EventOperator *and_oper = NULL;
3246
TEST_FUNCTION ("job_class_get_start_on");
3248
/* Check that the job's start_on tree is returned as a flattened
3249
* array of string arrays, as a child of the message.
3251
TEST_FEATURE ("with event tree");
3257
class = job_class_new (NULL, "test");
3259
class->start_on = event_operator_new (
3260
class, EVENT_OR, NULL, NULL);
3262
and_oper = event_operator_new (
3263
class, EVENT_AND, NULL, NULL);
3264
nih_tree_add (&class->start_on->node, &and_oper->node,
3267
oper = event_operator_new (
3268
class->start_on, EVENT_MATCH, "foo", NULL);
3269
oper->env = nih_str_array_new (oper);
3270
NIH_MUST (nih_str_array_add (&oper->env, oper, NULL, "omnomnom"));
3271
NIH_MUST (nih_str_array_add (&oper->env, oper, NULL, "ABER=crombie"));
3272
NIH_MUST (nih_str_array_add (&oper->env, oper, NULL, "HOBBIT=frodo"));
3274
nih_tree_add (&class->start_on->node, &oper->node,
3277
oper = event_operator_new (
3278
class->start_on, EVENT_MATCH, "wibble", NULL);
3279
nih_tree_add (&and_oper->node, &oper->node,
3282
oper = event_operator_new (
3283
class->start_on, EVENT_MATCH, "wobble", NULL);
3284
nih_tree_add (&and_oper->node, &oper->node,
3287
message = nih_new (NULL, NihDBusMessage);
3288
message->connection = NULL;
3289
message->message = NULL;
3294
ret = job_class_get_start_on (class, message, &start_on);
3296
if (test_alloc_failed) {
3299
error = nih_error_get ();
3300
TEST_EQ (error->number, ENOMEM);
3310
TEST_ALLOC_PARENT (start_on, message);
3311
TEST_ALLOC_SIZE (start_on, sizeof (char **) * 6);
3313
TEST_ALLOC_SIZE (start_on[0], sizeof (char *) * 2);
3314
TEST_EQ_STR (start_on[0][0], "wibble");
3315
TEST_EQ_P (start_on[0][1], NULL);
3317
TEST_ALLOC_SIZE (start_on[1], sizeof (char *) * 2);
3318
TEST_EQ_STR (start_on[1][0], "wobble");
3319
TEST_EQ_P (start_on[1][1], NULL);
3321
TEST_ALLOC_SIZE (start_on[2], sizeof (char *) * 2);
3322
TEST_EQ_STR (start_on[2][0], "/AND");
3323
TEST_EQ_P (start_on[2][1], NULL);
3325
TEST_ALLOC_SIZE (start_on[3], sizeof (char *) * 5);
3326
TEST_EQ_STR (start_on[3][0], "foo");
3327
TEST_EQ_STR (start_on[3][1], "omnomnom");
3328
TEST_EQ_STR (start_on[3][2], "ABER=crombie");
3329
TEST_EQ_STR (start_on[3][3], "HOBBIT=frodo");
3330
TEST_EQ_P (start_on[3][4], NULL);
3332
TEST_ALLOC_SIZE (start_on[4], sizeof (char *) * 2);
3333
TEST_EQ_STR (start_on[4][0], "/OR");
3334
TEST_EQ_P (start_on[4][1], NULL);
3336
TEST_EQ_P (start_on[5], NULL);
3343
/* Check that an empty array is returned when the job has no
3344
* start_on operator tree.
3346
TEST_FEATURE ("with no events");
3352
class = job_class_new (NULL, "test");
3354
message = nih_new (NULL, NihDBusMessage);
3355
message->connection = NULL;
3356
message->message = NULL;
3361
ret = job_class_get_start_on (class, message, &start_on);
3363
if (test_alloc_failed) {
3366
error = nih_error_get ();
3367
TEST_EQ (error->number, ENOMEM);
3377
TEST_ALLOC_PARENT (start_on, message);
3378
TEST_ALLOC_SIZE (start_on, sizeof (char **));
3379
TEST_EQ_P (start_on[0], NULL);
3387
test_get_stop_on (void)
3389
NihDBusMessage *message = NULL;
3390
JobClass *class = NULL;
3391
EventOperator *oper = NULL;
3392
EventOperator *and_oper = NULL;
3397
TEST_FUNCTION ("job_class_get_stop_on");
3399
/* Check that the job's stop_on tree is returned as a flattened
3400
* array of string arrays, as a child of the message.
3402
TEST_FEATURE ("with event tree");
3408
class = job_class_new (NULL, "test");
3410
class->stop_on = event_operator_new (
3411
class, EVENT_OR, NULL, NULL);
3413
and_oper = event_operator_new (
3414
class, EVENT_AND, NULL, NULL);
3415
nih_tree_add (&class->stop_on->node, &and_oper->node,
3418
oper = event_operator_new (
3419
class->stop_on, EVENT_MATCH, "foo", NULL);
3420
oper->env = nih_str_array_new (oper);
3421
NIH_MUST (nih_str_array_add (&oper->env, oper, NULL, "omnomnom"));
3422
NIH_MUST (nih_str_array_add (&oper->env, oper, NULL, "ABER=crombie"));
3423
NIH_MUST (nih_str_array_add (&oper->env, oper, NULL, "HOBBIT=frodo"));
3425
nih_tree_add (&class->stop_on->node, &oper->node,
3428
oper = event_operator_new (
3429
class->stop_on, EVENT_MATCH, "wibble", NULL);
3430
nih_tree_add (&and_oper->node, &oper->node,
3433
oper = event_operator_new (
3434
class->stop_on, EVENT_MATCH, "wobble", NULL);
3435
nih_tree_add (&and_oper->node, &oper->node,
3438
message = nih_new (NULL, NihDBusMessage);
3439
message->connection = NULL;
3440
message->message = NULL;
3445
ret = job_class_get_stop_on (class, message, &stop_on);
3447
if (test_alloc_failed) {
3450
error = nih_error_get ();
3451
TEST_EQ (error->number, ENOMEM);
3461
TEST_ALLOC_PARENT (stop_on, message);
3462
TEST_ALLOC_SIZE (stop_on, sizeof (char **) * 6);
3464
TEST_ALLOC_SIZE (stop_on[0], sizeof (char *) * 2);
3465
TEST_EQ_STR (stop_on[0][0], "wibble");
3466
TEST_EQ_P (stop_on[0][1], NULL);
3468
TEST_ALLOC_SIZE (stop_on[1], sizeof (char *) * 2);
3469
TEST_EQ_STR (stop_on[1][0], "wobble");
3470
TEST_EQ_P (stop_on[1][1], NULL);
3472
TEST_ALLOC_SIZE (stop_on[2], sizeof (char *) * 2);
3473
TEST_EQ_STR (stop_on[2][0], "/AND");
3474
TEST_EQ_P (stop_on[2][1], NULL);
3476
TEST_ALLOC_SIZE (stop_on[3], sizeof (char *) * 5);
3477
TEST_EQ_STR (stop_on[3][0], "foo");
3478
TEST_EQ_STR (stop_on[3][1], "omnomnom");
3479
TEST_EQ_STR (stop_on[3][2], "ABER=crombie");
3480
TEST_EQ_STR (stop_on[3][3], "HOBBIT=frodo");
3481
TEST_EQ_P (stop_on[3][4], NULL);
3483
TEST_ALLOC_SIZE (stop_on[4], sizeof (char *) * 2);
3484
TEST_EQ_STR (stop_on[4][0], "/OR");
3485
TEST_EQ_P (stop_on[4][1], NULL);
3487
TEST_EQ_P (stop_on[5], NULL);
3494
/* Check that an empty array is returned when the job has no
3495
* stop_on operator tree.
3497
TEST_FEATURE ("with no events");
3503
class = job_class_new (NULL, "test");
3505
message = nih_new (NULL, NihDBusMessage);
3506
message->connection = NULL;
3507
message->message = NULL;
3512
ret = job_class_get_stop_on (class, message, &stop_on);
3514
if (test_alloc_failed) {
3517
error = nih_error_get ();
3518
TEST_EQ (error->number, ENOMEM);
3528
TEST_ALLOC_PARENT (stop_on, message);
3529
TEST_ALLOC_SIZE (stop_on, sizeof (char **));
3530
TEST_EQ_P (stop_on[0], NULL);
3538
test_get_emits (void)
3540
NihDBusMessage *message = NULL;
3541
JobClass *class = NULL;
3546
TEST_FUNCTION ("job_class_get_emits");
3548
/* Check that an array of strings is returned from the property
3549
* as a child of the message when the job declares that it emits
3552
TEST_FEATURE ("with events");
3558
class = job_class_new (NULL, "test");
3559
class->emits = nih_str_array_new (class);
3561
NIH_MUST (nih_str_array_add (&class->emits, class, NULL, "foo"));
3562
NIH_MUST (nih_str_array_add (&class->emits, class, NULL, "bar"));
3563
NIH_MUST (nih_str_array_add (&class->emits, class, NULL, "baz"));
3565
message = nih_new (NULL, NihDBusMessage);
3566
message->connection = NULL;
3567
message->message = NULL;
3572
ret = job_class_get_emits (class, message, &emits);
3574
if (test_alloc_failed) {
3577
error = nih_error_get ();
3578
TEST_EQ (error->number, ENOMEM);
3588
TEST_ALLOC_PARENT (emits, message);
3589
TEST_ALLOC_SIZE (emits, sizeof (char *) * 4);
3590
TEST_EQ_STR (emits[0], "foo");
3591
TEST_EQ_STR (emits[1], "bar");
3592
TEST_EQ_STR (emits[2], "baz");
3593
TEST_EQ_P (emits[3], NULL);
3600
/* Check that an empty array is returned from the property
3601
* as a child of the message when the job doesn't declare
3602
* any particular emitted events.
3604
TEST_FEATURE ("with no events");
3610
class = job_class_new (NULL, "test");
3612
message = nih_new (NULL, NihDBusMessage);
3613
message->connection = NULL;
3614
message->message = NULL;
3619
ret = job_class_get_emits (class, message, &emits);
3621
if (test_alloc_failed) {
3624
error = nih_error_get ();
3625
TEST_EQ (error->number, ENOMEM);
3635
TEST_ALLOC_PARENT (emits, message);
3636
TEST_ALLOC_SIZE (emits, sizeof (char *));
3637
TEST_EQ_P (emits[0], NULL);
3237
3646
main (int argc,