mirror of
https://github.com/lammertb/libhttp.git
synced 2025-08-10 14:23:00 +03:00
Improve unit tests
This commit is contained in:
@@ -4175,7 +4175,7 @@ static int
|
|||||||
alloc_vprintf2(char **buf, const char *fmt, va_list ap)
|
alloc_vprintf2(char **buf, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
va_list ap_copy;
|
va_list ap_copy;
|
||||||
size_t size = MG_BUF_LEN;
|
size_t size = MG_BUF_LEN / 4;
|
||||||
int len = -1;
|
int len = -1;
|
||||||
|
|
||||||
*buf = NULL;
|
*buf = NULL;
|
||||||
@@ -4183,14 +4183,17 @@ alloc_vprintf2(char **buf, const char *fmt, va_list ap)
|
|||||||
if (*buf) {
|
if (*buf) {
|
||||||
mg_free(*buf);
|
mg_free(*buf);
|
||||||
}
|
}
|
||||||
*buf = (char *)mg_malloc(size *= 4);
|
|
||||||
|
size *= 4;
|
||||||
|
*buf = (char *)mg_malloc(size);
|
||||||
if (!*buf) {
|
if (!*buf) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
va_copy(ap_copy, ap);
|
va_copy(ap_copy, ap);
|
||||||
len = vsnprintf_impl(*buf, size - 1, fmt, ap_copy);
|
len = vsnprintf_impl(*buf, size - 1, fmt, ap_copy);
|
||||||
va_end(ap_copy);
|
va_end(ap_copy);
|
||||||
*buf[size - 1] = 0;
|
(*buf)[size - 1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
|
@@ -536,10 +536,51 @@ END_TEST
|
|||||||
|
|
||||||
START_TEST(test_parse_date_string)
|
START_TEST(test_parse_date_string)
|
||||||
{
|
{
|
||||||
ck_assert_uint_eq((unsigned long)parse_date_string("1/Jan/1970 00:01:02"), 62ul);
|
time_t now = time(0);
|
||||||
ck_assert_uint_eq((unsigned long)parse_date_string("1 Jan 1970 00:02:03"), 123ul);
|
struct tm *tm = gmtime(&now);
|
||||||
ck_assert_uint_eq((unsigned long)parse_date_string("1-Jan-1970 00:03:04"), 184ul);
|
char date[64] = {0};
|
||||||
ck_assert_uint_eq((unsigned long)parse_date_string("Xyz, 1 Jan 1970 00:04:05"), 245ul);
|
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
|
END_TEST
|
||||||
|
|
||||||
@@ -590,3 +631,16 @@ make_private_suite(void)
|
|||||||
|
|
||||||
return suite;
|
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
|
||||||
|
@@ -1495,8 +1495,9 @@ make_public_server_suite(void)
|
|||||||
static int chk_ok = 0;
|
static int chk_ok = 0;
|
||||||
static int chk_failed = 0;
|
static int chk_failed = 0;
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
main(void)
|
xmain(void)
|
||||||
{
|
{
|
||||||
test_the_test_environment(0);
|
test_the_test_environment(0);
|
||||||
test_threading(0);
|
test_threading(0);
|
||||||
|
Reference in New Issue
Block a user