~vorlon/ubuntu/raring/upstart/lp.1199778

« back to all changes in this revision

Viewing changes to init/tests/test_control.c

  • Committer: Scott James Remnant
  • Date: 2008-04-29 23:03:00 UTC
  • Revision ID: scott@netsplit.com-20080429230300-q31h4w9fgm93n7u9
* init/control.c (control_job_config_path, control_job_path)
(control_path_append): Drop these functions (replaced by the more
generic nih_dbus_path() function)
* init/control.h: Make CONTROL_ROOT public, and drop other prototypes.
* init/tests/test_control.c (test_job_config_path)
(test_job_path): Drop tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
420
420
}
421
421
 
422
422
 
423
 
void
424
 
test_job_config_path (void)
425
 
{
426
 
        char *path;
427
 
 
428
 
        TEST_FUNCTION ("control_job_config_path");
429
 
 
430
 
        /* Check that the path for an ordinary name can be returned as
431
 
         * we'd expect.
432
 
         */
433
 
        TEST_FEATURE ("with ordinary name");
434
 
        TEST_ALLOC_FAIL {
435
 
                path = control_job_config_path (NULL, "foo");
436
 
 
437
 
                if (test_alloc_failed) {
438
 
                        TEST_EQ_P (path, NULL);
439
 
 
440
 
                        continue;
441
 
                }
442
 
 
443
 
                TEST_EQ_STR (path, "/com/ubuntu/Upstart/jobs/foo");
444
 
 
445
 
                nih_free (path);
446
 
        }
447
 
 
448
 
 
449
 
        /* Check that the path of a job name that requires escaping is
450
 
         * escaped using the _xx notation.
451
 
         */
452
 
        TEST_FEATURE ("with name that requires escaping");
453
 
        TEST_ALLOC_FAIL {
454
 
                path = control_job_config_path (NULL, "foo/bar.baz");
455
 
 
456
 
                if (test_alloc_failed) {
457
 
                        TEST_EQ_P (path, NULL);
458
 
 
459
 
                        continue;
460
 
                }
461
 
 
462
 
                TEST_EQ_STR (path, "/com/ubuntu/Upstart/jobs/foo_2fbar_2ebaz");
463
 
 
464
 
                nih_free (path);
465
 
        }
466
 
 
467
 
 
468
 
        /* Check that the path of a job name that contains an underscore has
469
 
         * that escaped to ensure uniqueness with other escaped paths.
470
 
         */
471
 
        TEST_FEATURE ("with underscore in name");
472
 
        TEST_ALLOC_FAIL {
473
 
                path = control_job_config_path (NULL, "foo_bar");
474
 
 
475
 
                if (test_alloc_failed) {
476
 
                        TEST_EQ_P (path, NULL);
477
 
 
478
 
                        continue;
479
 
                }
480
 
 
481
 
                TEST_EQ_STR (path, "/com/ubuntu/Upstart/jobs/foo_5fbar");
482
 
 
483
 
                nih_free (path);
484
 
        }
485
 
}
486
 
 
487
 
void
488
 
test_job_path (void)
489
 
{
490
 
        char *path;
491
 
 
492
 
        TEST_FUNCTION ("control_job_path");
493
 
 
494
 
        /* Check that the path for ordinary names can be returned as we'd
495
 
         * expect.
496
 
         */
497
 
        TEST_FEATURE ("with ordinary names");
498
 
        TEST_ALLOC_FAIL {
499
 
                path = control_job_path (NULL, "foo", "bar");
500
 
 
501
 
                if (test_alloc_failed) {
502
 
                        TEST_EQ_P (path, NULL);
503
 
 
504
 
                        continue;
505
 
                }
506
 
 
507
 
                TEST_EQ_STR (path, "/com/ubuntu/Upstart/jobs/foo/bar");
508
 
 
509
 
                nih_free (path);
510
 
        }
511
 
 
512
 
 
513
 
        /* Check that the job instance name may be NULL and will be
514
 
         * substituted for the name "active" (which is safe since these jobs
515
 
         * will never have more than one instance).
516
 
         */
517
 
        TEST_FEATURE ("with instance-less job");
518
 
        TEST_ALLOC_FAIL {
519
 
                path = control_job_path (NULL, "foo", NULL);
520
 
 
521
 
                if (test_alloc_failed) {
522
 
                        TEST_EQ_P (path, NULL);
523
 
 
524
 
                        continue;
525
 
                }
526
 
 
527
 
                TEST_EQ_STR (path, "/com/ubuntu/Upstart/jobs/foo/active");
528
 
 
529
 
                nih_free (path);
530
 
        }
531
 
 
532
 
 
533
 
        /* Check that the path of a job config name that requires escaping is
534
 
         * escaped using the _xx notation.
535
 
         */
536
 
        TEST_FEATURE ("with config name that requires escaping");
537
 
        TEST_ALLOC_FAIL {
538
 
                path = control_job_path (NULL, "foo/bar.baz", "frodo");
539
 
 
540
 
                if (test_alloc_failed) {
541
 
                        TEST_EQ_P (path, NULL);
542
 
 
543
 
                        continue;
544
 
                }
545
 
 
546
 
                TEST_EQ_STR (path,
547
 
                             "/com/ubuntu/Upstart/jobs/foo_2fbar_2ebaz/frodo");
548
 
 
549
 
                nih_free (path);
550
 
        }
551
 
 
552
 
 
553
 
        /* Check that the path of a job instance name that requires escaping
554
 
         * is escaped using the _xx notation.
555
 
         */
556
 
        TEST_FEATURE ("with instance name that requires escaping");
557
 
        TEST_ALLOC_FAIL {
558
 
                path = control_job_path (NULL, "foo", "frodo+baggins");
559
 
 
560
 
                if (test_alloc_failed) {
561
 
                        TEST_EQ_P (path, NULL);
562
 
 
563
 
                        continue;
564
 
                }
565
 
 
566
 
                TEST_EQ_STR (path,
567
 
                             "/com/ubuntu/Upstart/jobs/foo/frodo_2bbaggins");
568
 
 
569
 
                nih_free (path);
570
 
        }
571
 
 
572
 
 
573
 
        /* Check that the paths of a job config and instance name that
574
 
         * require escaping are using the _xx notation.
575
 
         */
576
 
        TEST_FEATURE ("with both names requiring escaping");
577
 
        TEST_ALLOC_FAIL {
578
 
                path = control_job_path (NULL, "foo/bar.baz", "frodo+baggins");
579
 
 
580
 
                if (test_alloc_failed) {
581
 
                        TEST_EQ_P (path, NULL);
582
 
 
583
 
                        continue;
584
 
                }
585
 
 
586
 
                TEST_EQ_STR (path,
587
 
                             "/com/ubuntu/Upstart/jobs/foo_2fbar_2ebaz/"
588
 
                             "frodo_2bbaggins");
589
 
 
590
 
                nih_free (path);
591
 
        }
592
 
 
593
 
 
594
 
        /* Check that the path of a job config name that contains an
595
 
         * underscore has that escaped to ensure uniqueness with other
596
 
         * escaped paths.
597
 
         */
598
 
        TEST_FEATURE ("with underscore in config name");
599
 
        TEST_ALLOC_FAIL {
600
 
                path = control_job_path (NULL, "foo_bar", "frodo");
601
 
 
602
 
                if (test_alloc_failed) {
603
 
                        TEST_EQ_P (path, NULL);
604
 
 
605
 
                        continue;
606
 
                }
607
 
 
608
 
                TEST_EQ_STR (path, "/com/ubuntu/Upstart/jobs/foo_5fbar/frodo");
609
 
 
610
 
                nih_free (path);
611
 
        }
612
 
 
613
 
 
614
 
        /* Check that the path of a job instance name that contains an
615
 
         * underscore has that escaped to ensure uniqueness with other
616
 
         * escaped paths.
617
 
         */
618
 
        TEST_FEATURE ("with underscore in instance name");
619
 
        TEST_ALLOC_FAIL {
620
 
                path = control_job_path (NULL, "foo", "frodo_baggins");
621
 
 
622
 
                if (test_alloc_failed) {
623
 
                        TEST_EQ_P (path, NULL);
624
 
 
625
 
                        continue;
626
 
                }
627
 
 
628
 
                TEST_EQ_STR (path,
629
 
                             "/com/ubuntu/Upstart/jobs/foo/frodo_5fbaggins");
630
 
 
631
 
                nih_free (path);
632
 
        }
633
 
 
634
 
 
635
 
        /* Check that the path of job config and instance names that contain
636
 
         * underscores have that escaped to ensure uniqueness with other
637
 
         * escaped paths.
638
 
         */
639
 
        TEST_FEATURE ("with underscore in both names");
640
 
        TEST_ALLOC_FAIL {
641
 
                path = control_job_path (NULL, "foo_bar", "frodo_baggins");
642
 
 
643
 
                if (test_alloc_failed) {
644
 
                        TEST_EQ_P (path, NULL);
645
 
 
646
 
                        continue;
647
 
                }
648
 
 
649
 
                TEST_EQ_STR (path,
650
 
                             "/com/ubuntu/Upstart/jobs/foo_5fbar/"
651
 
                             "frodo_5fbaggins");
652
 
 
653
 
                nih_free (path);
654
 
        }
655
 
}
656
 
 
657
 
 
658
423
int
659
424
main (int   argc,
660
425
      char *argv[])
663
428
        test_bus_disconnected ();
664
429
        test_bus_close ();
665
430
 
666
 
        test_job_config_path ();
667
 
        test_job_path ();
668
 
 
669
431
        return 0;
670
432
}