int main() { plan(4); ok(1, NULL); ok(1, NULL); /* Tests in the todo region is expected to fail. If they don't, something is strange. */ todo_start("Need to fix these"); ok(0, NULL); ok(0, NULL); todo_end(); return exit_status(); }
int main(int argc, char **argv) { int result; int error = FALSE; char *buffer = NULL; int display_license = FALSE; int display_help = FALSE; int c = 0; struct tm *tm; time_t current_time; time_t test_time; time_t saved_test_time; time_t next_valid_time = 0L; time_t chosen_valid_time = 0L; char datestring[256]; host *temp_host = NULL; hostgroup *temp_hostgroup = NULL; hostsmember *temp_member = NULL; timeperiod *temp_timeperiod = NULL; int is_valid_time = 0; int iterations = 1000; plan_tests(6043); /* reset program variables */ reset_variables(); printf("Reading configuration data...\n"); config_file = strdup("smallconfig/icinga.cfg"); /* read in the configuration files (main config file, resource and object config files) */ result = read_main_config_file(config_file); ok(result == OK, "Read main configuration file okay - if fails, use icinga -v to check"); result = read_all_object_data(config_file); ok(result == OK, "Read all object config files"); result = pre_flight_check(); ok(result == OK, "Preflight check okay"); time(¤t_time); test_time = current_time; saved_test_time = current_time; temp_timeperiod = find_timeperiod("none"); is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "No valid time because time period is empty"); get_next_valid_time(current_time, &next_valid_time, temp_timeperiod); ok((next_valid_time - current_time) <= 2, "Next valid time should be the current_time, but with a 2 second tolerance"); temp_timeperiod = find_timeperiod("24x7"); is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == OK, "Fine because 24x7"); get_next_valid_time(current_time, &next_valid_time, temp_timeperiod); ok(current_time == next_valid_time, "Current time should be the next valid time"); /* 2009-10-25 is the day when clocks go back an hour in Europe. Bug happens during 23:00 to 00:00 */ /* This is 23:01:01 */ saved_test_time = 1256511661; saved_test_time = saved_test_time - (24 * 60 * 60); putenv("TZ=UTC"); tzset(); test_time = saved_test_time; c = 0; while (c < iterations) { is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == OK, "Always OK for 24x7 with TZ=UTC"); chosen_valid_time = 0L; _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); ok(test_time == chosen_valid_time, "get_next_valid_time always returns same time"); test_time += 1800; c++; } putenv("TZ=Europe/London"); tzset(); test_time = saved_test_time; c = 0; while (c < iterations) { is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == OK, "Always OK for 24x7 with TZ=Europe/London"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); ok(test_time == chosen_valid_time, "get_next_valid_time always returns same time, time_t=%lu", test_time); test_time += 1800; c++; } /* 2009-11-01 is the day when clocks go back an hour in America. Bug happens during 23:00 to 00:00 */ /* This is 23:01:01 */ saved_test_time = 1256511661; saved_test_time = saved_test_time - (24 * 60 * 60); putenv("TZ=America/New_York"); tzset(); test_time = saved_test_time; c = 0; while (c < iterations) { is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == OK, "Always OK for 24x7 with TZ=America/New_York"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); ok(test_time == chosen_valid_time, "get_next_valid_time always returns same time, time_t=%lu", test_time); test_time += 1800; c++; } /* Tests around clock change going back for TZ=Europe/London. 1256511661 = Sun Oct 25 23:01:01 2009 */ /* A little trip to Paris*/ putenv("TZ=Europe/Paris"); tzset(); /* Timeperiod exclude tests, from Jean Gabes */ temp_timeperiod = find_timeperiod("Test_exclude"); ok(temp_timeperiod != NULL, "ME: Testing Exclude timeperiod"); test_time = 1278939600; /* printf("Testing at time %s", ctime(&test_time)); */ is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "ME: 12 Jul 2010 15:00:00 - false"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); /* printf("JEAN: Got chosent time at %s", ctime(&chosen_valid_time)); */ todo_start("Bug in exclude"); ok(chosen_valid_time == 1288103400, "ME: Next valid time=Tue Oct 26 16:30:00 2010"); todo_end(); temp_timeperiod = find_timeperiod("Test_exclude2"); ok(temp_timeperiod != NULL, "ME: Testing Exclude timeperiod 2"); test_time = 1278939600; /* printf("Testing at time %s", ctime(&test_time)); */ is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "ME: 12 Jul 2010 15:00:00 - false"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); /* printf("JEAN: Got chosent time at %s", ctime(&chosen_valid_time)); */ todo_start("Bug in exclude 2"); ok(chosen_valid_time == 1279058340, "ME: Next valid time=Tue Jul 13 23:59:00 2010"); todo_end(); temp_timeperiod = find_timeperiod("Test_exclude3"); ok(temp_timeperiod != NULL, "ME: Testing Exclude timeperiod 3"); test_time = 1278939600; /* printf("Testing at time %s", ctime(&test_time)); */ is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "ME: 12 Jul 2010 15:00:00 - false"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); /* printf("JEAN: Got chosent time at %s", ctime(&chosen_valid_time)); */ todo_start("Bug in exclude 3"); ok(chosen_valid_time == 1284474600, "ME: Next valid time=Tue Sep 14 16:30:00 2010"); todo_end(); temp_timeperiod = find_timeperiod("Test_exclude4"); ok(temp_timeperiod != NULL, "ME: Testing Exclude timeperiod 4"); test_time = 1278939600; /* printf("Testing at time %s", ctime(&test_time)); */ is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "ME: 12 Jul 2010 15:00:00 - false"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); /* printf("JEAN: Got chosent time at %s", ctime(&chosen_valid_time)); */ todo_start("Bug in exclude 3"); ok(chosen_valid_time == 1283265000, "ME: Next valid time=Tue Aug 31 16:30:00 2010"); todo_end(); /* Back to New york */ putenv("TZ=America/New_York"); tzset(); temp_timeperiod = find_timeperiod("sunday_only"); ok(temp_timeperiod != NULL, "Testing Sunday 00:00-01:15,03:15-22:00"); putenv("TZ=Europe/London"); tzset(); test_time = 1256421000; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "Sat Oct 24 22:50:00 2009 - false"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == 1256425200, "Next valid time=Sun Oct 25 00:00:00 2009"); test_time = 1256421661; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "Sat Oct 24 23:01:01 2009 - false"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == 1256425200, "Next valid time=Sun Oct 25 00:00:00 2009"); test_time = 1256425400; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == OK, "Sun Oct 25 00:03:20 2009 - true"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == test_time, "Next valid time=Sun Oct 25 00:03:20 2009"); test_time = 1256429700; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == OK, "Sun Oct 25 01:15:00 2009 - true"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == test_time, "Next valid time=Sun Oct 25 01:15:00 2009"); test_time = 1256430400; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "Sun Oct 25 01:26:40 2009 - false"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); todo_start("Is a bug in get_next_valid_time for a time that falls in the DST change hour period"); ok(chosen_valid_time == 1256440500, "Next valid time=Sun Oct 25 03:15:00 2009") || printf("chosen_valid_time=%lu\n", chosen_valid_time); todo_end(); test_time = 1256440500; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == OK, "Sun Oct 25 03:15:00 2009 - true"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == test_time, "Next valid time=Sun Oct 25 03:15:00 2009"); test_time = 1256500000; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == OK, "Sun Oct 25 19:46:40 2009 - true"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == 1256500000, "Next valid time=Sun Oct 25 19:46:40 2009"); test_time = 1256508000; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == OK, "Sun Oct 25 22:00:00 2009 - true"); _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); ok(chosen_valid_time == 1256508000, "Next valid time=Sun Oct 25 22:00:00 2009"); test_time = 1256508001; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "Sun Oct 25 22:00:01 2009 - false"); //_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); _get_next_valid_time_per_timeperiod(test_time, &chosen_valid_time, test_time, temp_timeperiod); ok(chosen_valid_time == 1257033600, "Next valid time=Sun Nov 1 00:00:00 2009"); test_time = 1256513000; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "Sun Oct 25 23:23:20 2009 - false"); //_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); _get_next_valid_time_per_timeperiod(test_time, &chosen_valid_time, test_time, temp_timeperiod); ok(chosen_valid_time == 1257033600, "Next valid time=Sun Nov 1 00:00:00 2009"); temp_timeperiod = find_timeperiod("weekly_complex"); ok(temp_timeperiod != NULL, "Testing complex weekly timeperiod definition"); putenv("TZ=America/New_York"); tzset(); test_time = 1268109420; is_valid_time = check_time_against_period(test_time, temp_timeperiod); ok(is_valid_time == ERROR, "Mon Mar 8 23:37:00 2010 - false"); //_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod); _get_next_valid_time_per_timeperiod(test_time, &chosen_valid_time, test_time, temp_timeperiod); ok(chosen_valid_time == 1268115300, "Next valid time=Tue Mar 9 01:15:00 2010"); cleanup(); my_free(config_file); return exit_status(); }
int main(int argc, char *argv[]) { int p[2]; int stdoutfd; struct obj exp; (void)argc; (void)argv; printf("1..1\n"); fflush(stdout); stderrfd = dup(STDERR_FILENO); if (stderrfd < 0) err(1, "dup of stderr failed"); stdoutfd = dup(STDOUT_FILENO); if (stdoutfd < 0) err(1, "dup of stdout failed"); if (pipe(p) != 0) failmsg("pipe failed"); if (dup2(p[1], STDERR_FILENO) < 0 || dup2(p[1], STDOUT_FILENO) < 0) failmsg("Duplicating file descriptor"); plan_tests(10); expect(p[0], "1..10\n"); ok(1, "msg1"); expect(p[0], "ok 1 - msg1\n"); ok(0, "msg2"); expect(p[0], "not ok 2 - msg2\n" "# Failed test (*test.1.tap.c:main() at line 199)\n"); ok1(true); expect(p[0], "ok 3 - true\n"); ok1(false); expect(p[0], "not ok 4 - false\n" "# Failed test (*test.1.tap.c:main() at line 206)\n"); pass("passed"); expect(p[0], "ok 5 - passed\n"); fail("failed"); expect(p[0], "not ok 6 - failed\n" "# Failed test (*test.1.tap.c:main() at line 213)\n"); skip(2, "skipping %s", "test"); expect(p[0], "ok 7 # skip skipping test\n" "ok 8 # skip skipping test\n"); todo_start("todo"); ok1(false); expect(p[0], "not ok 9 - false # TODO todo\n" "# Failed (TODO) test (*test.1.tap.c:main() at line 222)\n"); ok1(true); expect(p[0], "ok 10 - true # TODO todo\n"); todo_end(); if (exit_status() != 3) failmsg("Expected exit status 3, not %i", exit_status()); is(one_int(), 1, "one_int() returns 1"); expect(p[0], "ok 11 - one_int() returns 1\n"); is(one_int(), 2, "one_int() returns 2"); expect(p[0], "not ok 12 - one_int() returns 2\n" "# Failed test (*test.1.tap.c:main() at line 234)\n" "# got: 1\n" "# expected: 2\n"); is_eq(one_str(), "one", "one_str() returns 'one'"); expect(p[0], "ok 13 - one_str() returns 'one'\n"); is_eq(one_str(), "two", "one_str() returns 'two'"); expect(p[0], "not ok 14 - one_str() returns 'two'\n" "# Failed test (*test.1.tap.c:main() at line 242)\n" "# got: \"one\"\n" "# expected: \"two\"\n"); exp.id = 1; is_cmp(one_obj(), &exp, obj_cmp, obj_to_str, "one_obj() has id 1"); expect(p[0], "ok 15 - one_obj() has id 1\n"); exp.id = 2; is_cmp(one_obj(), &exp, obj_cmp, obj_to_str, "one_obj() has id 2"); expect(p[0], "not ok 16 - one_obj() has id 2\n" "# Failed test (*test.1.tap.c:main() at line 252)\n" "# got: {id=1}\n" "# expected: {id=2}\n"); is_strstr(one_str(), "n", "one_str() contains 'n'"); expect(p[0], "ok 17 - one_str() contains 'n'\n"); is_strstr(one_str(), "w", "one_str() contains 'w'"); expect(p[0], "not ok 18 - one_str() contains 'w'\n" "# Failed test (*test.1.tap.c:main() at line 260)\n" "# got: \"one\"\n" "# expected to contain: \"w\"\n"); #if 0 /* Manually run the atexit command. */ _cleanup(); expect(p[0], "# Looks like you failed 2 tests of 9.\n"); #endif write_all(stdoutfd, "ok 1 - All passed\n", strlen("ok 1 - All passed\n")); _exit(0); }
int main(int argc, char *argv[]) { int p[2]; int stdoutfd; setbuf(stdout, 0); printf("1..1\n"); stderrfd = dup(STDERR_FILENO); if (stderrfd < 0) err(1, "dup of stderr failed"); stdoutfd = dup(STDOUT_FILENO); if (stdoutfd < 0) err(1, "dup of stdout failed"); if (pipe(p) != 0) failmsg("pipe failed"); if (dup2(p[1], STDERR_FILENO) < 0 || dup2(p[1], STDOUT_FILENO) < 0) failmsg("Duplicating file descriptor"); plan_tests(10); expect(p[0], "1..10\n"); ok(1, "msg1"); expect(p[0], "ok 1 - msg1\n"); ok(0, "msg2"); expect(p[0], "not ok 2 - msg2\n" "# Failed test (*test/run.c:main() at line 91)\n"); ok1(true); expect(p[0], "ok 3 - true\n"); ok1(false); expect(p[0], "not ok 4 - false\n" "# Failed test (*test/run.c:main() at line 98)\n"); pass("passed"); expect(p[0], "ok 5 - passed\n"); fail("failed"); expect(p[0], "not ok 6 - failed\n" "# Failed test (*test/run.c:main() at line 105)\n"); skip(2, "skipping %s", "test"); expect(p[0], "ok 7 # skip skipping test\n" "ok 8 # skip skipping test\n"); todo_start("todo"); ok1(false); expect(p[0], "not ok 9 - false # TODO todo\n" "# Failed (TODO) test (*test/run.c:main() at line 114)\n"); ok1(true); expect(p[0], "ok 10 - true # TODO todo\n"); todo_end(); if (exit_status() != 3) failmsg("Expected exit status 3, not %i", exit_status()); #if 0 /* Manually run the atexit command. */ _cleanup(); expect(p[0], "# Looks like you failed 2 tests of 9.\n"); #endif write_all(stdoutfd, "ok 1 - All passed\n", strlen("ok 1 - All passed\n")); exit(0); }