Esempio n. 1
0
int 
main() {
    int i, ntests;

    ntests = sizeof(tests) / sizeof(*tests);
    for (i = 0; i < ntests; i++) {
        const struct test t = tests[i];

        {
            dt_t src = dt_from_ywd(t.y, t.w, t.d);
            dt_t got = dt_end_of_week(src, t.dow);
            dt_t exp = dt_from_ywd(t.ey, t.ew, t.ed);
            cmp_ok(got, "==", exp, "dt_end_of_week(%d, %d)", src, t.dow);
        }

        {
            dt_t src = dt_from_ywd(t.y, t.w, t.d);
            dt_t dt1 = dt_end_of_week(src, t.dow);
            dt_t dt2 = dt_start_of_week(src, t.dow) + 6;
            cmp_ok(dt1, "==", dt2, "dt_end_of_week(%d, %d) == dt_start_of_week(%d, %d) + 6", 
              src, t.dow, src, t.dow);
        }

    }
    done_testing();
}
Esempio n. 2
0
int main (int argc, char **argv)
{
    flux_t h;
    heartbeat_t *hb;
    flux_msg_handler_t *w;

    plan (18);

    check_codec ();

    (void)setenv ("FLUX_CONNECTOR_PATH", CONNECTOR_PATH, 0);
    ok ((h = flux_open ("loop://", 0)) != NULL,
        "opened loop connector");
    if (!h)
        BAIL_OUT ("can't continue without loop handle");
    flux_fatal_set (h, fatal_err, NULL);

    ok ((hb = heartbeat_create ()) != NULL,
        "heartbeat_create works");

    heartbeat_set_flux (hb, h);

    ok (heartbeat_get_rate (hb) == 2.,
        "heartbeat_get_rate returns default of 2s");
    errno = 0;
    ok (heartbeat_set_rate (hb, -1) < 1 && errno == EINVAL,
        "heartbeat_set_rate -1 fails with EINVAL");
    errno = 0;
    ok (heartbeat_set_rate (hb, 1000000) < 1 && errno == EINVAL,
        "heartbeat_set_rate 1000000 fails with EINVAL");
    ok (heartbeat_set_ratestr (hb, "250ms") == 0,
        "heartbeat_set_ratestr 250ms works");
    ok (heartbeat_get_rate (hb) == 0.250,
        "heartbeat_get_rate returns what was set");
    ok (heartbeat_set_rate (hb, 0.1) == 0,
        "heartbeat_set_rate 0.1 works");
    ok (heartbeat_get_rate (hb) == 0.1,
        "heartbeat_get_rate returns what was set");

    ok (heartbeat_get_epoch (hb) == 0,
        "heartbeat_get_epoch works, default is zero");

    w = flux_msg_handler_create (h, FLUX_MATCH_EVENT, heartbeat_event_cb, hb);
    ok (w != NULL,
        "created event watcher");
    flux_msg_handler_start (w);

    ok (heartbeat_start (hb) == 0,
        "heartbeat_start works");

    ok (flux_reactor_run (flux_get_reactor (h), 0) == 0,
        "flux reactor exited normally");

    heartbeat_destroy (hb);
    flux_msg_handler_destroy (w);
    flux_close (h);

    done_testing ();
    return 0;
}
Esempio n. 3
0
void _subtest(char *name, void *(*func)(void), const char *file, uint line)
{
    uint subtestp;

    // Push tests status stack
    if (++current == SUBTEST_MAX_DEPTH) {
        bail("Too deep subtest nesting. You can change macro SUBTEST_MAX_DEPTH to change this value.");
    }

    plan(-1);
    func();
    
    done_testing(-1);

    // Pop tests status stack
    subtestp = current--;

    assert(current >= 0);

    if (tests[subtestp].run == 0) {
        _fail(file, line, "No tests run for subtest \"%s\"", name);
    } else {
        __ok((tests[subtestp].run == tests[subtestp].pass), 0, file, line, name, NULL);
    }
}
Esempio n. 4
0
int
main() {
    int i, ntests;

    ntests = sizeof(tests) / sizeof(*tests);
    for (i = 0; i < ntests; i++) {
        const struct test t = tests[i];

        {
            dt_t src = dt_from_yd(t.y, t.d);
            dt_t got = dt_add_years(src, t.delta, t.adjust);
            dt_t exp = dt_from_yd(t.ey, t.ed);
            cmp_ok(got, "==", exp, "dt_add_years(%d (%.4d-%.3d), %d, %d)",
              src, t.y, t.d, t.delta, t.adjust);
        }

        if (t.adjust != DT_EXCESS) {
            dt_t dt1 = dt_from_yd(t.y, t.d);
            dt_t dt2 = dt_add_years(dt1, t.delta, t.adjust);
            int got = dt_delta_years(dt1, dt2, 0);
            cmp_ok(got, "==", t.delta, "dt_delta_years(%d, %d, false)", dt1, dt2);
        }
    }
    done_testing();
}
Esempio n. 5
0
// Test driver
int main(void) {
    plan(1);
    ok(1, "ok works");

    done_testing();
    return 0;
}
Esempio n. 6
0
int
main() {
    int ntests, nholidays;
    int i;
    dt_t holidays[20];

    nholidays = sizeof(days) / sizeof(*days);
    for (i = 0; i < nholidays; i++) {
        const struct ymd date = days[i];
        holidays[i] = dt_from_ymd(date.y, date.m, date.d);
    }

    ntests = sizeof(tests) / sizeof(*tests);
    for (i = 0; i < ntests; i++) {
        const struct test t = tests[i];

        {
            dt_t src = dt_from_ymd(t.y, t.m, t.d);
            dt_t got = dt_add_workdays(src, t.delta, holidays, nholidays);
            dt_t exp = dt_from_ymd(t.ey, t.em, t.ed);
            cmp_ok(got, "==", exp, "dt_add_workdays(%.4d-%.2d-%.2d, %d)", 
              src, t.y, t.m, t.d, t.delta);
        }
    }
    done_testing();
}
Esempio n. 7
0
int main()
{
	plan (NO_PLAN);
	sha256_test ();
	done_testing ();
	return(0);
}
Esempio n. 8
0
int main (int argc, char *argv[])
{
    flux_t *h;

    plan (NO_PLAN);

    (void)setenv ("FLUX_CONNECTOR_PATH",
                  flux_conf_get ("connector_path", CONF_FLAG_INTREE), 0);
    ok ((h = flux_open ("loop://", 0)) != NULL,
        "opened loop connector");
    if (!h)
        BAIL_OUT ("can't continue without loop handle");

    flux_attr_set_cacheonly (h, "rank", "0");
    flux_attr_set_cacheonly (h, "tbon.level", "0");
    flux_attr_set_cacheonly (h, "tbon.maxlevel", "0");

    test_nopolicy (h); // 6
    test_hwm (h); // 37
    test_timed(h); // 18

    flux_close (h);
    done_testing();
    return (0);
}
Esempio n. 9
0
int 
main() {
    int i, ntests;

    ntests = sizeof(good) / sizeof(*good);
    for (i = 0; i < ntests; i++) {
        const struct good_t t = good[i];

        {
            dt_t got = 0, exp = 0;
            size_t glen;

            glen = dt_parse_iso_date(t.str, strlen(t.str), &got);
            ok(glen == t.elen, "dt_parse_iso_date(%s) size_t: %d", t.str, (int)glen);
            exp = dt_from_ymd(t.ey, t.em, t.ed);
            cmp_ok(got, "==", exp, "dt_parse_iso_date(%s)", t.str);
        }
    }

    ntests = sizeof(bad) / sizeof(*bad);
    for (i = 0; i < ntests; i++) {
        const struct bad_t t = bad[i];

        {
            dt_t got = 0;
            size_t glen;

            glen = dt_parse_iso_date(t.str, strlen(t.str), &got);
            ok(glen == 0, "dt_parse_iso_date(%s) size_t: %d", t.str, (int)glen);
        }
    }
    done_testing();
}
Esempio n. 10
0
int main(void)
{
    in_addrX ipnum;
    struct stat sstat;
    char *fname = get_test_db_fname();
    int err = stat(fname, &sstat);
    ok(err == 0, "%s exists", fname);

    MMDB_s *mmdb = MMDB_open(fname, MMDB_MODE_MEMORY_CACHE);
    ok(mmdb != NULL, "MMDB_open successful");
    if (mmdb) {

        MMDB_root_entry_s root = {.entry.mmdb = mmdb };
        char *ipstr = "24.24.24.24";
        ip_to_num(mmdb, ipstr, &ipnum);
        err = MMDB_lookup_by_ipnum_128(ipnum.v6, &root);
        ok(err == MMDB_SUCCESS, "Search for %s SUCCESSFUL", ipstr);
        ok(root.entry.offset > 0, "Found something %s good", ipstr);
        MMDB_decode_all_s *decode_all;
        int err = MMDB_get_tree(&root.entry, &decode_all);
        if (err == MMDB_SUCCESS) {
            if (decode_all != NULL)
                MMDB_dump(mmdb, decode_all, 0);
            MMDB_free_decode_all(decode_all);
        }
    }
    done_testing();
}
Esempio n. 11
0
int main () {
  carp_bool status;
  carp_ht h;
  carp_ht_entry *res;
  const char *key = "mykey";
  const char *badkey = "badkey";
  carp_value value = 17;

  plan(NO_PLAN);

  carp_ht_init(&h, 10);

  status = carp_ht_del(&h, key);
  ok(status == 1, "Delete fails with empty table.");

  status = carp_ht_set(&h, key, value);
  ok(status == 0, "Set returns successfully.");

  res = carp_ht_get(&h, key);
  ok(res->value == value && !strcmp(key, res->key), \
     "Gets correct struct back.");

  res = carp_ht_get(&h, badkey);
  ok(res == NULL, "Bad key gives null response.");

  carp_ht_cleanup(&h);

  done_testing();
}
Esempio n. 12
0
int 
main() {
    int i, ntests;

    ntests = sizeof(good) / sizeof(*good);
    for (i = 0; i < ntests; i++) {
        const struct good_t t = good[i];

        {
            int offset = 0;
            size_t glen;

            glen = dt_parse_iso_zone_lenient(t.str, strlen(t.str), &offset);
            ok(glen == t.elen, "dt_parse_iso_zone_lenient(%s) size_t: %d", t.str, (int)glen);
            cmp_ok(offset, "==", t.offset, "dt_parse_iso_zone_lenient(%s)", t.str);
        }
    }

    ntests = sizeof(bad) / sizeof(*bad);
    for (i = 0; i < ntests; i++) {
        const struct bad_t t = bad[i];

        {
            int offset = 0;
            size_t glen;

            glen = dt_parse_iso_zone_lenient(t.str, strlen(t.str), &offset);
            ok(glen == 0, "dt_parse_iso_zone_lenient(%s) size_t: %d", t.str, (int)glen);
        }
    }
    done_testing();
}
Esempio n. 13
0
int 
main() {
    int i, ntests;

    ntests = sizeof(tests) / sizeof(*tests);
    for (i = 0; i < ntests; i++) {
        const struct test t = tests[i];

        {
            dt_t src = dt_from_ymd(t.y, t.m, t.d);
            dt_t got = dt_start_of_month(src, t.delta);
            dt_t exp = dt_from_ymd(t.ey, t.em, t.ed);
            cmp_ok(got, "==", exp, "dt_start_of_month(%d (%.4d-%.2d-%.2d), %d)", 
              src, t.y, t.m, t.d, t.delta);
        }

        {
            dt_t src = dt_from_ymd(t.y, t.m, t.d);
            dt_t dt1 = dt_start_of_month(src, t.delta);
            dt_t dt2 = dt_end_of_month(src, t.delta - 1) + 1;
            cmp_ok(dt1, "==", dt2, "dt_start_of_month(%d, %d) == dt_end_of_month(%d, %d - 1) + 1",
              src, t.y, src, t.y);
        }

        {
            dt_t dt1 = dt_from_ymd(t.y, t.m, t.d);
            dt_t dt2 = dt_start_of_month(dt1, t.delta);
            int got = dt_delta_months(dt1, dt2, 0);
            cmp_ok(got, "==", t.delta, "dt_delta_months(%d, %d, false)", dt1, dt2);
        }
    }
    done_testing();
}
Esempio n. 14
0
int main () {
  carp_value val = 127;
  carp_value code[] = {CARP_I(LOADR), CARP_R0, val,

		       CARP_I(MOV), CARP_R1, CARP_R0,

		       CARP_I(MOV), CARP_R2, CARP_R0,
		       CARP_I(INCR), CARP_R2,

		       CARP_I(MOV), CARP_R3, CARP_R0,
		       CARP_I(DECR), CARP_R3,

		       CARP_I(HALT), EXIT_SUCCESS};

  carp_vm_init(&m, 1, 0);
  carp_vm_load(&m, code, sizeof(code)/sizeof(*code));
  carp_vm_run(&m);
  carp_vm_cleanup(&m);

  plan(NO_PLAN);

  ok(m.regs[CARP_R0] == val, "Set register successfully.");
  ok(m.regs[CARP_R1] == val, "Moved register successfully.");
  ok(m.regs[CARP_R2] == val + 1, "Incremented register successfully.");
  ok(m.regs[CARP_R3] == val - 1, "Decremented register successfully.");

  done_testing();
}
Esempio n. 15
0
int 
main() {
    int i, ntests;

    ntests = sizeof(tests) / sizeof(*tests);
    for (i = 0; i < ntests; i++) {
        const struct test t = tests[i];

        {
            dt_t got = dt_from_nth_weekday_in_year(t.y, t.nth);
            dt_t exp = dt_from_yd(t.ey, t.ed);
            cmp_ok(got, "==", exp, "dt_from_nth_weekday_in_year(%d, %d)", t.y, t.nth);
        }

        {
            dt_t src = dt_from_yd(t.y, 1);
            dt_t got = dt_nth_weekday_in_year(src, t.nth);
            dt_t exp = dt_from_yd(t.ey, t.ed);
            cmp_ok(got, "==", exp, "dt_nth_weekday_in_year(%d, %d)", src, t.nth);
        }

        {
            dt_t src = dt_from_nth_weekday_in_year(t.y, t.nth);
            int  got = dt_weekday_in_year(src, t.nth < 0);
            cmp_ok(got, "==", t.nth, "dt_weekday_in_year(%d, %s)", src, (t.nth < 0 ? "true" : "false"));
        }

    }
    done_testing();
}
Esempio n. 16
0
int main(void) {
  test_field();
  test_schedule_get();
  test_schedule_set();
  test_schedule_valid();
  done_testing();
  return 0;
}
Esempio n. 17
0
/***
 * Test driver
 ***/
int main(void) {
	test_pktgen_rnd_bits_init();
	test_pktgen_set_random_bitfield();
	test_pktgen_rnd_bits_apply();

    done_testing();
    return 0;
}
Esempio n. 18
0
int main(void)
{
    const char *version = TMMDB_lib_version();
    ok(version != NULL, "TMMDB_lib_version exists");
    if (version)
        ok(strcmp(version, PACKAGE_VERSION) == 0,
           "version is " PACKAGE_VERSION);
    done_testing();
}
Esempio n. 19
0
int main(int argc, char **argv)
{
    subtest("request", test_request);
    subtest("response", test_response);
    subtest("headers", test_headers);
    subtest("chunked", test_chunked);
    subtest("chunked-consume-trailer", test_chunked_consume_trailer);
    return done_testing();
}
Esempio n. 20
0
int main()
{
    plan(1);

    int i;
    scanf("%d", &i);
    is_eq(i, 7);

    done_testing();
}
Esempio n. 21
0
int main(int argc, const char *argv[])
{
  plan(NO_PLAN);

  test();

  done_testing();

  return 0;
}
Esempio n. 22
0
int main (int argc, char *argv[])
{

    plan (NO_PLAN);

    errors ();

    done_testing();
    return (0);
}
Esempio n. 23
0
int main() {
  bench_ansicolor = getenv("ANSICOLOR") != NULL;
  ansicolor(bench_ansicolor);
  plan(2);

  bench_math();
  bench_iterator();
  bench_particle();

  done_testing();
}
Esempio n. 24
0
int main (int argc, char *argv[])
{
    plan (24);

    test_helpers (); // 9
    test_lsmod_codec (); // 11
    test_rmmod_codec (); // 2
    test_insmod_codec (); // 2

    done_testing ();
}
Esempio n. 25
0
int main (int argc, char *argv[])
{
    plan (27);

    test_libev_timer (); // 5
    test_libev_io (); // 3
    test_zmq_events (); // 11
    test_ev_zmq (); // 6
    test_ev_zlist (); // 2

    done_testing ();
}
Esempio n. 26
0
int main(void)
{
    video_init();
    camera_init();
    tilemap_init();
    plan(4);
    test_basic_output();
    todo();
    note("exercise file reading");
    end_todo;
    done_testing();
}
Esempio n. 27
0
int main (int argc, char *argv[])
{

    plan (NO_PLAN);

    test_readback (33);
    test_readback (8192); // more than internal chunk size

    test_badargs ();

    done_testing ();
}
Esempio n. 28
0
/*
 * These is a test of the resrc library.  The test uses two methods
 * for generating a resrc object.  The first loads an RDL-formatted
 * resource identified by the TESTRESRC_INPUT_FILE environment
 * variable.  The second option generates a resrc object from the node
 * it is running on using the hwloc library.  The test then conducts a
 * number of resrc library operations on each of these resrc objects.
 */
int main (int argc, char *argv[])
{
    int rc1 = 1, rc2 = 1;

    plan (27 + num_temporal_allocation_tests);
    test_temporal_allocation ();
    rc1 = test_using_reader_rdl ();
    rc2 = test_using_reader_hwloc ();
    /* plance holder for testing with other reader types */
    done_testing ();

    return (rc1 | rc2);
}
Esempio n. 29
0
int main () {
    plan(9);
    cmp_ok(420, ">", 666);
    cmp_ok(23, "==", 55, "the number 23 is definitely 55");
    cmp_ok(23, "==", 55);
    cmp_ok(23, "!=", 55);
    cmp_ok(23, "frob", 55);
    cmp_ok(23, "<=", 55);
    cmp_ok(55, "+", -55);
    cmp_ok(23, "%", 5);
    cmp_ok(55, "%", 5);
    done_testing();
}
Esempio n. 30
0
int main (int argc, char *argv[])
{
    flux_t *h;
    flux_msg_t *msg;
    const char *topic;
    const char *reason;
    int flags;

    plan (NO_PLAN);

    if (!(h = loopback_create (0)))
        BAIL_OUT ("loopback_create failed");

    /* Send request
     */
    ok (flux_panic (h, 0, 0, "fubar") == 0,
        "flux_panic works");

    /* Receive request on the loopback
     */
    msg = flux_recv (h, FLUX_MATCH_ANY, 0);
    ok (msg != NULL,
        "flux_recv received message on loop");
    ok (flux_request_unpack (msg, &topic, "{s:s s:i}",
                             "reason", &reason, "flags", &flags) == 0,
        "flux_request_unpack worked on panic request");
    ok (topic != NULL && !strcmp (topic, "cmb.panic"),
        "topic string is correct");
    ok (!strcmp (reason, "fubar"),
        "reason is correct");
    ok (flags == 0,
        "flags is correct");
    flux_msg_destroy (msg);

    /* invalid arguments
     */
    errno = 0;
    ok (flux_panic (NULL, 0, 0, "foo") < 0 && errno == EINVAL,
        "flux_panic h=NULL fails with EINVAL");
    errno = 0;
    ok (flux_panic (h, 0, 1, "foo") < 0 && errno == EINVAL,
        "flux_panic flags=1 fails with EINVAL");
    errno = 0;
    ok (flux_panic (h, 0, 0, NULL) < 0 && errno == EINVAL,
        "flux_panic reason=NULL fails with EINVAL");

    flux_close (h);

    done_testing();
    return (0);
}