mirror of
https://github.com/bdnugget/kcgi.git
synced 2026-11-07 05:47:27 +00:00
Write tests for new functions khttp_epoch2xxx, move existing tests to
deprecated test file.
This commit is contained in:
1 parent
35d192dfec
commit
ff869b7beb
5 files changed
+272
-1
No files matched your search
@@ -188,10 +188,13 @@ REGRESS = regress/test-abort-validator \
|
||||
regress/test-basic-curl \
|
||||
regress/test-bigfile \
|
||||
regress/test-buf \
|
||||
regress/test-datetime \
|
||||
regress/test-datetime-deprecated \
|
||||
regress/test-digest \
|
||||
regress/test-digest-auth-int \
|
||||
regress/test-digest-auth-int-bad \
|
||||
regress/test-epoch2str \
|
||||
regress/test-epoch2tms \
|
||||
regress/test-epoch2ustr \
|
||||
regress/test-fcgi-abort-validator \
|
||||
regress/test-fcgi-bigfile \
|
||||
regress/test-fcgi-file-get \
|
||||
|
||||
File renamed without changes.
@@ -0,0 +1,90 @@
|
||||
/* $Id$ */
|
||||
/*
|
||||
* Copyright (c) 2016, 2020 Kristaps Dzonsons <kristaps@bsd.lv>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
#include "../config.h"
|
||||
|
||||
#if HAVE_ERR
|
||||
# include <err.h>
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include "../kcgi.h"
|
||||
#include "regress.h"
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
size_t i;
|
||||
time_t v;
|
||||
struct tm *tm;
|
||||
char buf[64], testbuf[64];
|
||||
|
||||
/*
|
||||
* Test a lot of positive and negative numbers.
|
||||
* We want the full range of time_t to work.
|
||||
*/
|
||||
|
||||
for (i = 0; i < 100000; i++) {
|
||||
#if HAVE_ARC4RANDOM
|
||||
v = (int32_t)arc4random();
|
||||
#else
|
||||
v = (int32_t)(random() + random());
|
||||
#endif
|
||||
tm = gmtime(&v);
|
||||
strftime(buf, sizeof(buf), "%a, %d %b %Y %T GMT", tm);
|
||||
khttp_epoch2str(v, testbuf, sizeof(testbuf));
|
||||
if (strcmp(buf, testbuf))
|
||||
errx(1, "khttp_epoch2str: "
|
||||
"have %s, want %s", testbuf, buf);
|
||||
}
|
||||
|
||||
/* Truncate test. */
|
||||
|
||||
v = 10000; /* whatever */
|
||||
tm = gmtime(&v);
|
||||
strftime(buf, sizeof(buf), "%a, %d %b %Y %T GMT", tm);
|
||||
khttp_epoch2str(v, testbuf, 10);
|
||||
if (strlen(testbuf) != 9)
|
||||
errx(1, "khttp_epoch2str: bad string length");
|
||||
if (strncmp(buf, testbuf, 9))
|
||||
errx(1, "khttp_epoch2str: have %s, "
|
||||
"want %s", testbuf, buf);
|
||||
|
||||
/* Truncate to zero test. */
|
||||
|
||||
tm = gmtime(&v);
|
||||
strftime(buf, sizeof(buf), "%a, %d %b %Y %T GMT", tm);
|
||||
khttp_epoch2str(v, testbuf, 1);
|
||||
if (strlen(testbuf) != 0)
|
||||
errx(1, "khttp_epoch2str: bad string length");
|
||||
|
||||
/* No NULL or zero-length values. */
|
||||
|
||||
if (khttp_epoch2str(v, NULL, 1) != NULL)
|
||||
errx(1, "khttp_epoch2str: should return NULL");
|
||||
if (khttp_epoch2str(v, testbuf, 0) != NULL)
|
||||
errx(1, "khttp_epoch2str: should return NULL");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/* $Id$ */
|
||||
/*
|
||||
* Copyright (c) 2020 Kristaps Dzonsons <kristaps@bsd.lv>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
#include "../config.h"
|
||||
|
||||
#if HAVE_ERR
|
||||
# include <err.h>
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include "../kcgi.h"
|
||||
#include "regress.h"
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
size_t i;
|
||||
time_t v;
|
||||
struct tm *tm;
|
||||
struct tm have, test;
|
||||
int c;
|
||||
|
||||
/*
|
||||
* Test a lot of positive and negative numbers.
|
||||
* We want the full range of time_t to work.
|
||||
*/
|
||||
|
||||
for (i = 0; i < 100000; i++) {
|
||||
#if HAVE_ARC4RANDOM
|
||||
v = (int32_t)arc4random();
|
||||
#else
|
||||
v = (int32_t)(random() + random());
|
||||
#endif
|
||||
if ((tm = gmtime(&v)) == NULL)
|
||||
err(1, "gmtime");
|
||||
have = *tm;
|
||||
c = khttp_epoch2tms(v,
|
||||
&test.tm_sec,
|
||||
&test.tm_min,
|
||||
&test.tm_hour,
|
||||
&test.tm_mday,
|
||||
&test.tm_mon,
|
||||
&test.tm_year,
|
||||
&test.tm_wday,
|
||||
&test.tm_yday);
|
||||
if (!c)
|
||||
errx(1, "khttp_epoch2tms");
|
||||
if (have.tm_sec != test.tm_sec ||
|
||||
have.tm_min != test.tm_min ||
|
||||
have.tm_hour != test.tm_hour ||
|
||||
have.tm_mday != test.tm_mday ||
|
||||
have.tm_mon != test.tm_mon ||
|
||||
have.tm_year != test.tm_year ||
|
||||
have.tm_wday != test.tm_wday ||
|
||||
have.tm_yday != test.tm_yday)
|
||||
errx(1, "khttp_epoch2tms: mismatch");
|
||||
}
|
||||
|
||||
/* Handle NULL values. */
|
||||
|
||||
c = khttp_epoch2tms(0, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
if (!c)
|
||||
errx(1, "khttp_epoch2tms");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/* $Id$ */
|
||||
/*
|
||||
* Copyright (c) 2016, 2020 Kristaps Dzonsons <kristaps@bsd.lv>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
#include "../config.h"
|
||||
|
||||
#if HAVE_ERR
|
||||
# include <err.h>
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include "../kcgi.h"
|
||||
#include "regress.h"
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
size_t i;
|
||||
time_t v;
|
||||
struct tm *tm;
|
||||
char buf[64], testbuf[64];
|
||||
|
||||
/*
|
||||
* Test a lot of positive and negative numbers.
|
||||
* We want the full range of time_t to work.
|
||||
*/
|
||||
|
||||
for (i = 0; i < 100000; i++) {
|
||||
#if HAVE_ARC4RANDOM
|
||||
v = (int32_t)arc4random();
|
||||
#else
|
||||
v = (int32_t)(random() + random());
|
||||
#endif
|
||||
tm = gmtime(&v);
|
||||
strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", tm);
|
||||
khttp_epoch2ustr(v, testbuf, sizeof(testbuf));
|
||||
if (strcmp(buf, testbuf))
|
||||
errx(1, "khttp_epoch2ustr: "
|
||||
"have %s, want %s", testbuf, buf);
|
||||
}
|
||||
|
||||
/* Truncate test. */
|
||||
|
||||
v = 10000; /* whatever */
|
||||
tm = gmtime(&v);
|
||||
strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", tm);
|
||||
khttp_epoch2ustr(v, testbuf, 10);
|
||||
if (strlen(testbuf) != 9)
|
||||
errx(1, "khttp_epoch2ustr: bad string length");
|
||||
if (strncmp(buf, testbuf, 9))
|
||||
errx(1, "khttp_epoch2ustr: have %s, "
|
||||
"want %s", testbuf, buf);
|
||||
|
||||
/* Truncate to zero test. */
|
||||
|
||||
tm = gmtime(&v);
|
||||
strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", tm);
|
||||
khttp_epoch2ustr(v, testbuf, 1);
|
||||
if (strlen(testbuf) != 0)
|
||||
errx(1, "khttp_epoch2ustr: bad string length");
|
||||
|
||||
/* No NULL or zero-length values. */
|
||||
|
||||
if (khttp_epoch2ustr(v, NULL, 1) != NULL)
|
||||
errx(1, "khttp_epoch2ustr: should return NULL");
|
||||
if (khttp_epoch2ustr(v, testbuf, 0) != NULL)
|
||||
errx(1, "khttp_epoch2ustr: should return NULL");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user