示例#1
0
int
main (int argc, char** argv)
{
    int i;

    for (i = 0; i < 20; i++)
    {
        Timespec* spec1;
        Timespec spec2;
        gchar* sec_str;
        gchar* nsec_str;

        spec1 = get_random_timespec ();

        sec_str = timespec_sec_to_string (spec1);
        nsec_str = timespec_nsec_to_string (spec1);

        if (!string_to_timespec_secs (sec_str, &spec2))
        {
            failure_args ("string_to_timespec_secs", __FILE__, __LINE__,
                          "string is %s", sec_str);
        }

        else if (!string_to_timespec_nsecs (nsec_str, &spec2))
        {
            failure_args ("string_to_timespec_nsecs", __FILE__, __LINE__,
                          "string is %s", nsec_str);
        }

        else if (spec1->tv_sec != spec2.tv_sec)
        {
            failure_args ("timespec_secs", __FILE__, __LINE__,
                          "not equal ints are %" G_GINT64_FORMAT
                          " and %" G_GINT64_FORMAT "\n",
                          spec1->tv_sec, spec2.tv_sec);
        }

        else if (spec1->tv_nsec != spec2.tv_nsec)
        {
            failure_args ("timespec_nsecs", __FILE__, __LINE__,
                          "not equal ints are %ld and %ld\n",
                          spec1->tv_nsec, spec2.tv_nsec);
        }

        else
        {
            success ("timespec");
        }

        g_free (spec1);
        g_free (sec_str);
        g_free (nsec_str);
    }
    print_test_results ();
    exit (get_rv ());
}
示例#2
0
static void
test_dom_tree_to_timespec(void)
{
    int i;
    for (i = 0; i < 20; i++)
    {
        Timespec *test_spec1;
        Timespec test_spec2;
        xmlNodePtr test_node;

        test_spec1 = get_random_timespec();

        test_node = timespec_to_dom_tree("test-spec", test_spec1);

        test_spec2 = dom_tree_to_timespec(test_node);

        if (!dom_tree_valid_timespec(&test_spec2, (const xmlChar*)"test-spec"))
        {
            failure_args("dom_tree_to_timespec",
                         __FILE__, __LINE__, "NULL return");
            printf("Node looks like:\n");
            xmlElemDump(stdout, NULL, test_node);
            printf("\n");
        }

        else if (timespec_cmp(test_spec1, &test_spec2) == 0)
        {
            success("dom_tree_to_timespec");
        }
        else
        {
            failure("dom_tree_to_timespec");
            printf("Node looks like:\n");
            xmlElemDump(stdout, NULL, test_node);
            printf("\n");
            printf("Secs are %" G_GUINT64_FORMAT " vs %" G_GUINT64_FORMAT " :: ",
                   test_spec1->tv_sec,
                   test_spec2.tv_sec);
            printf("NSecs are %ld vs %ld\n",
                   test_spec1->tv_nsec,
                   test_spec2.tv_nsec);
        }

        g_free(test_spec1);
        xmlFreeNode(test_node);
    }
}
示例#3
0
mychild*
child_create(QofBook *book)
{
    mychild *g;

    g_return_val_if_fail(book, NULL);
    g = g_object_new(GNC_TYPE_MYCHILD, NULL);
    qof_instance_init_data (&g->inst, CHILD_MODULE_NAME, book);
    g->date = *get_random_timespec();
    g->discount = get_random_double();
    g->active = get_random_boolean();
    g->version = get_random_int_in_range(1, 10000);
    g->minor = get_random_int_in_range(100001, 99999999);
    g->flag = get_random_character();
    g->Name = get_random_string();
    g->Amount = get_random_gnc_numeric();
    qof_event_gen(&g->inst, QOF_EVENT_CREATE, NULL);
    return g;
}
示例#4
0
static void
run_test (void)
{
    Timespec ts;
    int i;
    gboolean do_print = FALSE;

    /* Now leaving the 60's:
     *
     * Black Panthers
     * Weather Underground
     * Kent State
     * Evacuation of Vietnam
     * Impeachment
     * Gas Crisis
     * New York Garbage Crisis
     * Stagflation
     * Delapidated Bicentennial
     * Sex Pistols
     * Punk Rock
     *
     * Of course, anything had to be better than the miserable 70's,
     * which explains why Reagan was elected.  Food for thought.
     */
    ts.tv_sec = 10 * 365 * 24 * 3600 + 2 * 24 * 3600;
    ts.tv_nsec = 0;
    check_conversion ("1979-12-31 15:00:00.000000 -0900", ts);
    check_conversion ("1979-12-31 16:00:00.000000 -0800", ts);
    check_conversion ("1979-12-31 17:00:00.000000 -0700", ts);
    check_conversion ("1979-12-31 18:00:00.000000 -0600", ts);
    check_conversion ("1979-12-31 19:00:00.000000 -0500", ts);
    check_conversion ("1979-12-31 20:00:00.000000 -0400", ts);
    check_conversion ("1979-12-31 21:00:00.000000 -0300", ts);
    check_conversion ("1979-12-31 22:00:00.000000 -0200", ts);
    check_conversion ("1979-12-31 23:00:00.000000 -0100", ts);

    check_conversion ("1980-01-01 00:00:00.000000 -0000", ts);
    check_conversion ("1980-01-01 00:00:00.000000 +0000", ts);

    check_conversion ("1980-01-01 01:00:00.000000 +0100", ts);
    check_conversion ("1980-01-01 02:00:00.000000 +0200", ts);
    check_conversion ("1980-01-01 03:00:00.000000 +0300", ts);
    check_conversion ("1980-01-01 04:00:00.000000 +0400", ts);
    check_conversion ("1980-01-01 05:00:00.000000 +0500", ts);
    check_conversion ("1980-01-01 06:00:00.000000 +0600", ts);
    check_conversion ("1980-01-01 07:00:00.000000 +0700", ts);
    check_conversion ("1980-01-01 08:00:00.000000 +0800", ts);

    /* check minute-offsets as well */
    check_conversion ("1980-01-01 08:01:00.000000 +0801", ts);
    check_conversion ("1980-01-01 08:02:00.000000 +0802", ts);
    check_conversion ("1980-01-01 08:03:00.000000 +0803", ts);
    check_conversion ("1980-01-01 08:23:00.000000 +0823", ts);
    check_conversion ("1980-01-01 08:35:00.000000 +0835", ts);
    check_conversion ("1980-01-01 08:47:00.000000 +0847", ts);
    check_conversion ("1980-01-01 08:59:00.000000 +0859", ts);

    check_conversion ("1979-12-31 15:01:00.000000 -0859", ts);
    check_conversion ("1979-12-31 15:02:00.000000 -0858", ts);
    check_conversion ("1979-12-31 15:03:00.000000 -0857", ts);
    check_conversion ("1979-12-31 15:23:00.000000 -0837", ts);
    check_conversion ("1979-12-31 15:45:00.000000 -0815", ts);


    /* The 90's */
    ts.tv_sec = 20 * 365 * 24 * 3600 + 5 * 24 * 3600;
    ts.tv_nsec = 0;
    check_conversion ("1989-12-31 15:00:00.000000 -0900", ts);
    check_conversion ("1989-12-31 16:00:00.000000 -0800", ts);
    check_conversion ("1989-12-31 17:00:00.000000 -0700", ts);
    check_conversion ("1989-12-31 18:00:00.000000 -0600", ts);
    check_conversion ("1989-12-31 19:00:00.000000 -0500", ts);
    check_conversion ("1989-12-31 20:00:00.000000 -0400", ts);
    check_conversion ("1989-12-31 21:00:00.000000 -0300", ts);
    check_conversion ("1989-12-31 22:00:00.000000 -0200", ts);
    check_conversion ("1989-12-31 23:00:00.000000 -0100", ts);

    check_conversion ("1990-01-01 00:00:00.000000 -0000", ts);
    check_conversion ("1990-01-01 00:00:00.000000 +0000", ts);

    check_conversion ("1990-01-01 01:00:00.000000 +0100", ts);
    check_conversion ("1990-01-01 02:00:00.000000 +0200", ts);
    check_conversion ("1990-01-01 03:00:00.000000 +0300", ts);
    check_conversion ("1990-01-01 04:00:00.000000 +0400", ts);
    check_conversion ("1990-01-01 05:00:00.000000 +0500", ts);
    check_conversion ("1990-01-01 06:00:00.000000 +0600", ts);
    check_conversion ("1990-01-01 07:00:00.000000 +0700", ts);
    check_conversion ("1990-01-01 08:00:00.000000 +0800", ts);

    /* check minute-offsets as well */
    check_conversion ("1990-01-01 08:01:00.000000 +0801", ts);
    check_conversion ("1990-01-01 08:02:00.000000 +0802", ts);
    check_conversion ("1990-01-01 08:03:00.000000 +0803", ts);
    check_conversion ("1990-01-01 08:23:00.000000 +0823", ts);
    check_conversion ("1990-01-01 08:35:00.000000 +0835", ts);
    check_conversion ("1990-01-01 08:47:00.000000 +0847", ts);
    check_conversion ("1990-01-01 08:59:00.000000 +0859", ts);

    check_conversion ("1989-12-31 15:01:00.000000 -0859", ts);
    check_conversion ("1989-12-31 15:02:00.000000 -0858", ts);
    check_conversion ("1989-12-31 15:03:00.000000 -0857", ts);
    check_conversion ("1989-12-31 15:23:00.000000 -0837", ts);
    check_conversion ("1989-12-31 15:45:00.000000 -0815", ts);


    /* The naughties */
    ts.tv_sec = 30 * 365 * 24 * 3600 + 7 * 24 * 3600;
    ts.tv_nsec = 0;
    check_conversion ("1999-12-31 15:00:00.000000 -0900", ts);
    check_conversion ("1999-12-31 16:00:00.000000 -0800", ts);
    check_conversion ("1999-12-31 17:00:00.000000 -0700", ts);
    check_conversion ("1999-12-31 18:00:00.000000 -0600", ts);
    check_conversion ("1999-12-31 19:00:00.000000 -0500", ts);
    check_conversion ("1999-12-31 20:00:00.000000 -0400", ts);
    check_conversion ("1999-12-31 21:00:00.000000 -0300", ts);
    check_conversion ("1999-12-31 22:00:00.000000 -0200", ts);
    check_conversion ("1999-12-31 23:00:00.000000 -0100", ts);

    check_conversion ("2000-01-01 00:00:00.000000 -0000", ts);
    check_conversion ("2000-01-01 00:00:00.000000 +0000", ts);

    check_conversion ("2000-01-01 01:00:00.000000 +0100", ts);
    check_conversion ("2000-01-01 02:00:00.000000 +0200", ts);
    check_conversion ("2000-01-01 03:00:00.000000 +0300", ts);
    check_conversion ("2000-01-01 04:00:00.000000 +0400", ts);
    check_conversion ("2000-01-01 05:00:00.000000 +0500", ts);
    check_conversion ("2000-01-01 06:00:00.000000 +0600", ts);
    check_conversion ("2000-01-01 07:00:00.000000 +0700", ts);
    check_conversion ("2000-01-01 08:00:00.000000 +0800", ts);

    /* check minute-offsets as well */
    check_conversion ("2000-01-01 08:01:00.000000 +0801", ts);
    check_conversion ("2000-01-01 08:02:00.000000 +0802", ts);
    check_conversion ("2000-01-01 08:03:00.000000 +0803", ts);
    check_conversion ("2000-01-01 08:23:00.000000 +0823", ts);
    check_conversion ("2000-01-01 08:35:00.000000 +0835", ts);
    check_conversion ("2000-01-01 08:47:00.000000 +0847", ts);
    check_conversion ("2000-01-01 08:59:00.000000 +0859", ts);

    check_conversion ("1999-12-31 15:01:00.000000 -0859", ts);
    check_conversion ("1999-12-31 15:02:00.000000 -0858", ts);
    check_conversion ("1999-12-31 15:03:00.000000 -0857", ts);
    check_conversion ("1999-12-31 15:23:00.000000 -0837", ts);
    check_conversion ("1999-12-31 15:45:00.000000 -0815", ts);


    /* The nows */
    ts.tv_sec = 35 * 365 * 24 * 3600 + 9 * 24 * 3600;
    ts.tv_nsec = 0;
    check_conversion ("2004-12-31 15:00:00.000000 -0900", ts);
    check_conversion ("2004-12-31 16:00:00.000000 -0800", ts);
    check_conversion ("2004-12-31 17:00:00.000000 -0700", ts);
    check_conversion ("2004-12-31 18:00:00.000000 -0600", ts);
    check_conversion ("2004-12-31 19:00:00.000000 -0500", ts);
    check_conversion ("2004-12-31 20:00:00.000000 -0400", ts);
    check_conversion ("2004-12-31 21:00:00.000000 -0300", ts);
    check_conversion ("2004-12-31 22:00:00.000000 -0200", ts);
    check_conversion ("2004-12-31 23:00:00.000000 -0100", ts);

    check_conversion ("2005-01-01 00:00:00.000000 -0000", ts);
    check_conversion ("2005-01-01 00:00:00.000000 +0000", ts);

    check_conversion ("2005-01-01 01:00:00.000000 +0100", ts);
    check_conversion ("2005-01-01 02:00:00.000000 +0200", ts);
    check_conversion ("2005-01-01 03:00:00.000000 +0300", ts);
    check_conversion ("2005-01-01 04:00:00.000000 +0400", ts);
    check_conversion ("2005-01-01 05:00:00.000000 +0500", ts);
    check_conversion ("2005-01-01 06:00:00.000000 +0600", ts);
    check_conversion ("2005-01-01 07:00:00.000000 +0700", ts);
    check_conversion ("2005-01-01 08:00:00.000000 +0800", ts);

    /* check minute-offsets as well */
    check_conversion ("2005-01-01 08:01:00.000000 +0801", ts);
    check_conversion ("2005-01-01 08:02:00.000000 +0802", ts);
    check_conversion ("2005-01-01 08:03:00.000000 +0803", ts);
    check_conversion ("2005-01-01 08:23:00.000000 +0823", ts);
    check_conversion ("2005-01-01 08:35:00.000000 +0835", ts);
    check_conversion ("2005-01-01 08:47:00.000000 +0847", ts);
    check_conversion ("2005-01-01 08:59:00.000000 +0859", ts);

    check_conversion ("2004-12-31 15:01:00.000000 -0859", ts);
    check_conversion ("2004-12-31 15:02:00.000000 -0858", ts);
    check_conversion ("2004-12-31 15:03:00.000000 -0857", ts);
    check_conversion ("2004-12-31 15:23:00.000000 -0837", ts);
    check_conversion ("2004-12-31 15:45:00.000000 -0815", ts);


    /* Various leap-year days and near-leap times. */
    ts = gnc_iso8601_to_timespec_gmt ("1980-02-29 00:00:00.000000 -0000");
    check_time (ts, do_print);

    ts = gnc_iso8601_to_timespec_gmt ("1979-02-28 00:00:00.000000 -0000");
    check_time (ts, do_print);

    ts = gnc_iso8601_to_timespec_gmt ("1990-02-28 00:00:00.000000 -0000");
    check_time (ts, do_print);

    ts = gnc_iso8601_to_timespec_gmt ("2000-02-29 00:00:00.000000 -0000");
    check_time (ts, do_print);

    ts = gnc_iso8601_to_timespec_gmt ("2004-02-29 00:00:00.000000 -0000");
    check_time (ts, do_print);

    ts = gnc_iso8601_to_timespec_gmt ("2008-02-29 00:00:00.000000 -0000");
    check_time (ts, do_print);

    ts = gnc_iso8601_to_timespec_gmt ("2008-02-29 00:01:00.000000 -0000");
    check_time (ts, do_print);

    ts = gnc_iso8601_to_timespec_gmt ("2008-02-29 02:02:00.000000 -0000");
    check_time (ts, do_print);

    ts = gnc_iso8601_to_timespec_gmt ("2008-02-28 23:23:23.000000 -0000");
    check_time (ts, do_print);

    /* Here's a date ten days after the 2038 rollover that should work
       if/when we support it. */
    ts.tv_nsec = 0;
    ts.tv_sec = (long long int) 0x7fffffff + 3600 * 24 * 10;
    check_time(ts, do_print);

    /* Various 'special' times. What makes these so special? */
    ts.tv_sec = 152098136;
    ts.tv_nsec = 0;
    check_time (ts, do_print);

    ts.tv_sec = 1162088421;
    ts.tv_nsec = 12548000;
    check_time (ts, do_print);

    ts.tv_sec = 325659000 - 6500;
    ts.tv_nsec = 0;
    check_time (ts, do_print);

    ts.tv_sec = 1143943200;
    ts.tv_nsec = 0;
    check_time (ts, do_print);

    ts.tv_sec = 1603591171;
    ts.tv_nsec = 595311000;
    check_time (ts, do_print);

    ts.tv_sec = 1738909365;
    ts.tv_nsec = 204102000;
    check_time (ts, do_print);

    ts.tv_sec = 1603591171;
    ts.tv_nsec = 595311000;
    check_time (ts, do_print);

    ts.tv_sec = 1143943200 - 1;
    ts.tv_nsec = 0;
    check_time (ts, do_print);

    ts.tv_sec = 1143943200;
    ts.tv_nsec = 0;
    check_time (ts, do_print);

    ts.tv_sec = 1143943200 + (7 * 60 * 60);
    ts.tv_nsec = 0;
    check_time (ts, do_print);

    ts.tv_sec = 1143943200 + (8 * 60 * 60);
    ts.tv_nsec = 0;
    check_time (ts, do_print);

    ts = *get_random_timespec ();

    for (i = 0; i < 10000; i++)
    {
        ts.tv_sec += 10800;
        if (!check_time (ts, FALSE))
            return;
    }

    for (i = 0; i < 5000; i++)
    {
        ts = *get_random_timespec ();

        if (!check_time (ts, FALSE))
            return;
    }
}