ksgi

Форк
0
/
test-epoch2tms.c 
104 строки · 2.5 Кб
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_ERR
20
# include <err.h>
21
#endif
22

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

36
int
37
main(int argc, char *argv[])
38
{
39
	size_t	 	 i;
40
	time_t	 	 v;
41
	struct tm	*tm;
42
	struct tm	 have, test;
43
	int		 c;
44

45
	for (i = 0; i < 100000; i++) {
46
#if HAVE_ARC4RANDOM
47
		v = (time_t)arc4random();
48
#else
49
		v = (time_t)random();
50
#endif
51
		if ((tm = gmtime(&v)) == NULL) {
52
			warnx("gmtime: %" PRId64, (int64_t)v);
53
			continue;
54
		}
55
		have = *tm;
56
		c = 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);
65
		if (!c)
66
			errx(1, "khttp_epoch2tms");
67
		if (have.tm_sec != test.tm_sec ||
68
		    have.tm_min != test.tm_min ||
69
		    have.tm_hour != test.tm_hour ||
70
		    have.tm_mday != test.tm_mday ||
71
		    have.tm_mon != test.tm_mon ||
72
		    have.tm_year != test.tm_year ||
73
		    have.tm_wday != test.tm_wday ||
74
		    have.tm_yday != test.tm_yday)
75
			errx(1, "khttp_epoch2tms: have "
76
			    "{%d, %d, %d, %d, %d, %d, %d, %d}, want "
77
			    "{%d, %d, %d, %d, %d, %d, %d, %d}",
78
			    have.tm_sec,
79
			    have.tm_min,
80
			    have.tm_hour,
81
			    have.tm_mday,
82
			    have.tm_mon,
83
			    have.tm_year,
84
			    have.tm_wday,
85
			    have.tm_yday,
86
			    test.tm_sec,
87
			    test.tm_min,
88
			    test.tm_hour,
89
			    test.tm_mday,
90
			    test.tm_mon,
91
			    test.tm_year,
92
			    test.tm_wday,
93
			    test.tm_yday);
94
	}
95

96
	/* Handle NULL values. */
97

98
	c = khttp_epoch2tms(0, NULL, NULL, 
99
		NULL, NULL, NULL, NULL, NULL, NULL);
100
	if (!c)
101
		errx(1, "khttp_epoch2tms");
102

103
	return 0;
104
}
105

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.