1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-08-16 11:21:57 +03:00

Improve unit tests

This commit is contained in:
bel
2016-04-01 21:57:51 +02:00
parent bd9c20e04f
commit 7b51e4ce60
3 changed files with 66 additions and 8 deletions

View File

@@ -536,10 +536,51 @@ END_TEST
START_TEST(test_parse_date_string)
{
ck_assert_uint_eq((unsigned long)parse_date_string("1/Jan/1970 00:01:02"), 62ul);
ck_assert_uint_eq((unsigned long)parse_date_string("1 Jan 1970 00:02:03"), 123ul);
ck_assert_uint_eq((unsigned long)parse_date_string("1-Jan-1970 00:03:04"), 184ul);
ck_assert_uint_eq((unsigned long)parse_date_string("Xyz, 1 Jan 1970 00:04:05"), 245ul);
time_t now = time(0);
struct tm *tm = gmtime(&now);
char date[64] = {0};
unsigned long i;
ck_assert_uint_eq((unsigned long)parse_date_string("1/Jan/1970 00:01:02"),
62ul);
ck_assert_uint_eq((unsigned long)parse_date_string("1 Jan 1970 00:02:03"),
123ul);
ck_assert_uint_eq((unsigned long)parse_date_string("1-Jan-1970 00:03:04"),
184ul);
ck_assert_uint_eq((unsigned long)parse_date_string(
"Xyz, 1 Jan 1970 00:04:05"),
245ul);
gmt_time_string(date, sizeof(date), &now);
ck_assert_uint_eq((uintmax_t)parse_date_string(date), (uintmax_t)now);
sprintf(date,
"%02u %s %04u %02u:%02u:%02u",
tm->tm_mday,
month_names[tm->tm_mon],
tm->tm_year + 1900,
tm->tm_hour,
tm->tm_min,
tm->tm_sec);
ck_assert_uint_eq((uintmax_t)parse_date_string(date), (uintmax_t)now);
for (i = 2ul; i < 0x8000000ul; i += i / 2) {
now = (time_t)i;
gmt_time_string(date, sizeof(date), &now);
ck_assert_uint_eq((uintmax_t)parse_date_string(date), (uintmax_t)now);
tm = gmtime(&now);
sprintf(date,
"%02u-%s-%04u %02u:%02u:%02u",
tm->tm_mday,
month_names[tm->tm_mon],
tm->tm_year + 1900,
tm->tm_hour,
tm->tm_min,
tm->tm_sec);
ck_assert_uint_eq((uintmax_t)parse_date_string(date), (uintmax_t)now);
}
}
END_TEST
@@ -590,3 +631,16 @@ make_private_suite(void)
return suite;
}
#ifdef REPLACE_CHECK_FOR_LOCAL_DEBUGGING
/* Used to debug test cases without using the check framework */
void
main(void)
{
test_alloc_vprintf(0);
test_parse_date_string(0);
}
#endif