~jamesodhunt/upstart/bug-530779-with-formatting-changes

« back to all changes in this revision

Viewing changes to util/tests/test_initctl.c

  • Committer: Lukáš Nykrýn
  • Date: 2012-02-16 15:45:41 UTC
  • mto: This revision was merged to the branch mainline in revision 1358.
  • Revision ID: lnykryn@redhat.com-20120216154541-f1ngijj35s5dhgmi
Add usage stanza (Petr Lautrbach <plautrba@redhat.com>)

Show diffs side-by-side

added added

removed removed

Lines of Context:
251
251
extern int reload_configuration_action (NihCommand *command, char * const *args);
252
252
extern int version_action              (NihCommand *command, char * const *args);
253
253
extern int log_priority_action         (NihCommand *command, char * const *args);
 
254
extern int usage_action                (NihCommand *command, char * const *args);
254
255
 
255
256
 
256
257
static int my_connect_handler_called = FALSE;
14396
14397
}
14397
14398
 
14398
14399
 
 
14400
void
 
14401
test_usage (void)
 
14402
{
 
14403
        char             dirname[PATH_MAX];
 
14404
        nih_local char  *cmd;
 
14405
        pid_t            upstart_pid = 0;
 
14406
        pid_t            dbus_pid    = 0;
 
14407
        char           **output;
 
14408
        size_t           lines;
 
14409
        FILE            *out;
 
14410
        FILE            *err;
 
14411
        NihCommand       command;
 
14412
        char            *args[2];
 
14413
        int              ret = 0;
 
14414
 
 
14415
        TEST_GROUP ("usage");
 
14416
 
 
14417
        TEST_FILENAME (dirname);
 
14418
        TEST_EQ (mkdir (dirname, 0755), 0);
 
14419
 
 
14420
        /* Use the "secret" interface */
 
14421
        TEST_EQ (setenv ("UPSTART_CONFDIR", dirname, 1), 0);
 
14422
 
 
14423
        TEST_DBUS (dbus_pid);
 
14424
        START_UPSTART (upstart_pid);
 
14425
 
 
14426
        TEST_FEATURE ("no usage");
 
14427
        CREATE_FILE (dirname, "foo.conf",
 
14428
                        "author \"foo\"\n"
 
14429
                        "description \"wibble\"");
 
14430
 
 
14431
        cmd = nih_sprintf (NULL, "%s usage foo 2>&1", INITCTL_BINARY);
 
14432
        TEST_NE_P (cmd, NULL);
 
14433
        RUN_COMMAND (NULL, cmd, &output, &lines);
 
14434
        TEST_EQ_STR (output[0], "Usage: ");
 
14435
        TEST_EQ (lines, 1);
 
14436
        nih_free (output);
 
14437
 
 
14438
        DELETE_FILE (dirname, "foo.conf");
 
14439
 
 
14440
        /*******************************************************************/
 
14441
 
 
14442
        TEST_FEATURE ("with usage");
 
14443
 
 
14444
        CREATE_FILE (dirname, "foo.conf",
 
14445
                        "usage \"this is usage\"");
 
14446
 
 
14447
        cmd = nih_sprintf (NULL, "%s usage foo 2>&1", INITCTL_BINARY);
 
14448
        TEST_NE_P (cmd, NULL);
 
14449
        RUN_COMMAND (NULL, cmd, &output, &lines);
 
14450
        TEST_EQ_STR (output[0], "Usage: this is usage");
 
14451
        TEST_EQ (lines, 1);
 
14452
        nih_free (output);
 
14453
 
 
14454
        DELETE_FILE (dirname, "foo.conf");
 
14455
 
 
14456
        /*******************************************************************/
 
14457
 
 
14458
        TEST_FEATURE ("failed status with usage");
 
14459
 
 
14460
        CREATE_FILE (dirname, "foo.conf",
 
14461
                        "instance $FOO\n"
 
14462
                        "usage \"this is usage\"");
 
14463
 
 
14464
        memset (&command, 0, sizeof command);
 
14465
        args[0] = "foo";
 
14466
        args[1] = NULL;
 
14467
 
 
14468
        out = tmpfile ();
 
14469
        err = tmpfile ();
 
14470
 
 
14471
        TEST_DIVERT_STDOUT (out) {
 
14472
                TEST_DIVERT_STDERR (err) {
 
14473
                        ret = status_action (&command, args);
 
14474
                }
 
14475
        }
 
14476
        rewind (out);
 
14477
        rewind (err);
 
14478
 
 
14479
        TEST_GT (ret, 0);
 
14480
 
 
14481
        TEST_FILE_END (out);
 
14482
        TEST_FILE_RESET (out);
 
14483
 
 
14484
        TEST_FILE_EQ (err, "test: Unknown parameter: FOO\n");
 
14485
        TEST_FILE_EQ (err, "Usage: this is usage\n");
 
14486
        TEST_FILE_END (err);
 
14487
        TEST_FILE_RESET (err);
 
14488
 
 
14489
        DELETE_FILE (dirname, "foo.conf");
 
14490
 
 
14491
 
 
14492
        STOP_UPSTART (upstart_pid);
 
14493
        TEST_EQ (unsetenv ("UPSTART_CONFDIR"), 0);
 
14494
        TEST_DBUS_END (dbus_pid);
 
14495
}
 
14496
 
 
14497
 
14399
14498
/**
14400
14499
 * in_chroot:
14401
14500
 *
14466
14565
        test_reload_configuration_action ();
14467
14566
        test_version_action ();
14468
14567
        test_log_priority_action ();
 
14568
        test_usage ();
14469
14569
 
14470
14570
        if (in_chroot () && !dbus_configured ()) {
14471
14571
                fprintf(stderr, "\n\n"