ksgi
1/* $Id$ */
2/*
3* Copyright (c) 2020 Kristaps Dzonsons <kristaps@bsd.lv>
4*
5* Permission to use, copy, modify, and distribute this software for any
6* purpose with or without fee is hereby granted, provided that the above
7* copyright notice and this permission notice appear in all copies.
8*
9* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*/
17#include "../config.h"18
19#if HAVE_ERR20# include <err.h>21#endif22
23#include <inttypes.h>24#include <stdarg.h>25#include <stdint.h>26#include <stdlib.h>27#include <string.h>28#include <time.h>29#include <unistd.h>30
31#include <curl/curl.h>32
33#include "../kcgi.h"34#include "regress.h"35
36int
37main(int argc, char *argv[])38{
39size_t i;40time_t v;41struct tm *tm;42struct tm have, test;43int c;44
45for (i = 0; i < 100000; i++) {46#if HAVE_ARC4RANDOM47v = (time_t)arc4random();48#else49v = (time_t)random();50#endif51if ((tm = gmtime(&v)) == NULL) {52warnx("gmtime: %" PRId64, (int64_t)v);53continue;54}55have = *tm;56c = khttp_epoch2tms(v,57&test.tm_sec,58&test.tm_min,59&test.tm_hour,60&test.tm_mday,61&test.tm_mon,62&test.tm_year,63&test.tm_wday,64&test.tm_yday);65if (!c)66errx(1, "khttp_epoch2tms");67if (have.tm_sec != test.tm_sec ||68have.tm_min != test.tm_min ||69have.tm_hour != test.tm_hour ||70have.tm_mday != test.tm_mday ||71have.tm_mon != test.tm_mon ||72have.tm_year != test.tm_year ||73have.tm_wday != test.tm_wday ||74have.tm_yday != test.tm_yday)75errx(1, "khttp_epoch2tms: have "76"{%d, %d, %d, %d, %d, %d, %d, %d}, want "77"{%d, %d, %d, %d, %d, %d, %d, %d}",78have.tm_sec,79have.tm_min,80have.tm_hour,81have.tm_mday,82have.tm_mon,83have.tm_year,84have.tm_wday,85have.tm_yday,86test.tm_sec,87test.tm_min,88test.tm_hour,89test.tm_mday,90test.tm_mon,91test.tm_year,92test.tm_wday,93test.tm_yday);94}95
96/* Handle NULL values. */97
98c = khttp_epoch2tms(0, NULL, NULL,99NULL, NULL, NULL, NULL, NULL, NULL);100if (!c)101errx(1, "khttp_epoch2tms");102
103return 0;104}
105