Пример #1
0
/*
 * Seen in the wild, generated by Apple Mail: a date
 * which is a valid UNIX time_t because it's in the first
 * hour of 1970 in UTC, but expressed in a timezone which
 * makes it be in the last day of 1969.  This is weird
 * and probably technically valid but does not need to
 * be supported, but we do need to fail gracefully.
 */
static void test_zerohour(void)
{
    static const char DATETIME_NY[] = "Wed, 31 Dec 1969 19:36:29 -0500";
    static const char DATETIME_MEL[] = " 1-Jan-1970 11:36:29 +1100";
    static const time_t TIMET = 2189;
    time_t t;
    int r;
    char buf[RFC3501_DATETIME_MAX+1];

    t = UNINIT_TIMET;
    r = time_from_rfc822(DATETIME_NY, &t);
    CU_ASSERT_EQUAL(r, -1);
    CU_ASSERT_EQUAL(t, UNINIT_TIMET);  /* fail gracefully */

    push_tz(TZ_UTC);
    t = UNINIT_TIMET;
    r = time_from_rfc822(DATETIME_NY, &t);
    CU_ASSERT_EQUAL(r, -1);
    CU_ASSERT_EQUAL(t, UNINIT_TIMET);  /* fail gracefully */
    pop_tz();

    push_tz(TZ_NEWYORK);
    t = UNINIT_TIMET;
    r = time_from_rfc822(DATETIME_NY, &t);
    CU_ASSERT_EQUAL(r, -1);
    CU_ASSERT_EQUAL(t, UNINIT_TIMET);  /* fail gracefully */
    pop_tz();

    memset(buf, 0, sizeof(buf));
    time_to_rfc3501(TIMET, buf, sizeof(buf));
    CU_ASSERT_STRING_EQUAL(buf, DATETIME_MEL);
}
Пример #2
0
/*
 * Test time_to_rfc822()
 */
static void test_gen_rfc822(void)
{
    static const char DATETIME_MEL[] = "Fri, 26 Nov 2010 14:22:02 +1100";
    static const char DATETIME_UTC[] = "Fri, 26 Nov 2010 03:22:02 +0000";
    static const char DATETIME_NYC[] = "Thu, 25 Nov 2010 22:22:02 -0500";
    static const time_t TIMET = 1290741722;
    int r;
    char buf[RFC822_DATETIME_MAX+1];

    memset(buf, 0x45, sizeof(buf));
    r = time_to_rfc822(TIMET, buf, sizeof(buf));
    CU_ASSERT_EQUAL(r, 31);
    CU_ASSERT_STRING_EQUAL(buf, DATETIME_MEL);

    push_tz(TZ_UTC);
    memset(buf, 0x45, sizeof(buf));
    r = time_to_rfc822(TIMET, buf, sizeof(buf));
    CU_ASSERT_EQUAL(r, 31);
    CU_ASSERT_STRING_EQUAL(buf, DATETIME_UTC);
    pop_tz();

    push_tz(TZ_NEWYORK);
    memset(buf, 0x45, sizeof(buf));
    r = time_to_rfc822(TIMET, buf, sizeof(buf));
    CU_ASSERT_EQUAL(r, 31);
    CU_ASSERT_STRING_EQUAL(buf, DATETIME_NYC);
    pop_tz();
}
Пример #3
0
/*
 * Test time_from_rfc822()
 */
static void test_parse_rfc822(void)
{
    static const char DATETIME[] = "Tue, 16 Nov 2010 12:46:49 +1100";
    static const time_t TIMET = 1289872009;
    time_t t;
    int r;

    /*
     * Convert the datetime string into a time_t, which is always
     * expressed in UTC regardless of the current timezone.
     */
    t = UNINIT_TIMET;
    r = time_from_rfc822(DATETIME, &t);
    CU_ASSERT_EQUAL(r, 31);
    CU_ASSERT_EQUAL(t, TIMET);

    push_tz(TZ_UTC);
    t = UNINIT_TIMET;
    r = time_from_rfc822(DATETIME, &t);
    CU_ASSERT_EQUAL(r, 31);
    CU_ASSERT_EQUAL(t, TIMET);
    pop_tz();

    push_tz(TZ_NEWYORK);
    t = UNINIT_TIMET;
    r = time_from_rfc822(DATETIME, &t);
    CU_ASSERT_EQUAL(r, 31);
    CU_ASSERT_EQUAL(t, TIMET);
    pop_tz();
}
Пример #4
0
static int tear_down(void)
{
    pop_tz();
    if (n_tz_stack != 1)
	return -1;
    return 0;
}
Пример #5
0
void restore_tz(void)
{
    while (n_tz_stack > 1)
	pop_tz();
}