<sys/socket.h>: turn off MSG_NOSIGNAL
[minix3.git] / tests / lib / libutil / t_parsedate.c
blobec035a6dfaf6f3b02a43eae7394c6beaf45fe183
1 /* $NetBSD: t_parsedate.c,v 1.7 2013/01/19 15:21:43 apb Exp $ */
2 /*-
3 * Copyright (c) 2010 The NetBSD Foundation, Inc.
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: t_parsedate.c,v 1.7 2013/01/19 15:21:43 apb Exp $");
34 #include <atf-c.h>
35 #include <errno.h>
36 #include <stdlib.h>
37 #include <time.h>
38 #include <util.h>
40 ATF_TC(dates);
42 ATF_TC_HEAD(dates, tc)
44 atf_tc_set_md_var(tc, "descr", "Test unambiguous dates"
45 " (PR lib/44255)");
48 ATF_TC_BODY(dates, tc)
51 ATF_CHECK(parsedate("69-09-10", NULL, NULL) != -1);
52 ATF_CHECK(parsedate("2006-11-17", NULL, NULL) != -1);
53 ATF_CHECK(parsedate("10/1/2000", NULL, NULL) != -1);
54 ATF_CHECK(parsedate("20 Jun 1994", NULL, NULL) != -1);
55 ATF_CHECK(parsedate("23jun2001", NULL, NULL) != -1);
56 ATF_CHECK(parsedate("1-sep-06", NULL, NULL) != -1);
57 ATF_CHECK(parsedate("1/11", NULL, NULL) != -1);
58 ATF_CHECK(parsedate("1500-01-02", NULL, NULL) != -1);
59 ATF_CHECK(parsedate("9999-12-21", NULL, NULL) != -1);
62 ATF_TC(times);
64 ATF_TC_HEAD(times, tc)
66 atf_tc_set_md_var(tc, "descr", "Test times"
67 " (PR lib/44255)");
70 ATF_TC_BODY(times, tc)
73 ATF_CHECK(parsedate("10:01", NULL, NULL) != -1);
74 ATF_CHECK(parsedate("10:12pm", NULL, NULL) != -1);
75 ATF_CHECK(parsedate("12:11:01.000012", NULL, NULL) != -1);
76 ATF_CHECK(parsedate("12:21-0500", NULL, NULL) != -1);
79 ATF_TC(relative);
81 ATF_TC_HEAD(relative, tc)
83 atf_tc_set_md_var(tc, "descr", "Test relative items"
84 " (PR lib/44255)");
87 ATF_TC_BODY(relative, tc)
90 ATF_CHECK(parsedate("-1 month", NULL, NULL) != -1);
91 ATF_CHECK(parsedate("last friday", NULL, NULL) != -1);
92 ATF_CHECK(parsedate("one week ago", NULL, NULL) != -1);
93 ATF_CHECK(parsedate("this thursday", NULL, NULL) != -1);
94 ATF_CHECK(parsedate("next sunday", NULL, NULL) != -1);
95 ATF_CHECK(parsedate("+2 years", NULL, NULL) != -1);
98 ATF_TC(atsecs);
100 ATF_TC_HEAD(atsecs, tc)
102 atf_tc_set_md_var(tc, "descr", "Test seconds past the epoch");
105 ATF_TC_BODY(atsecs, tc)
107 int tzoff;
109 /* "@0" -> (time_t)0, regardless of timezone */
110 ATF_CHECK(parsedate("@0", NULL, NULL) == (time_t)0);
111 putenv(__UNCONST("TZ=Europe/Berlin"));
112 tzset();
113 ATF_CHECK(parsedate("@0", NULL, NULL) == (time_t)0);
114 putenv(__UNCONST("TZ=America/New_York"));
115 tzset();
116 ATF_CHECK(parsedate("@0", NULL, NULL) == (time_t)0);
117 tzoff = 0;
118 ATF_CHECK(parsedate("@0", NULL, &tzoff) == (time_t)0);
119 tzoff = 3600;
120 ATF_CHECK(parsedate("@0", NULL, &tzoff) == (time_t)0);
121 tzoff = -3600;
122 ATF_CHECK(parsedate("@0", NULL, &tzoff) == (time_t)0);
124 /* -1 or other negative numbers are not errors */
125 errno = 0;
126 ATF_CHECK(parsedate("@-1", NULL, &tzoff) == (time_t)-1 && errno == 0);
127 ATF_CHECK(parsedate("@-2", NULL, &tzoff) == (time_t)-2 && errno == 0);
129 /* junk is an error */
130 errno = 0;
131 ATF_CHECK(parsedate("@junk", NULL, NULL) == (time_t)-1 && errno != 0);
134 ATF_TP_ADD_TCS(tp)
136 ATF_TP_ADD_TC(tp, dates);
137 ATF_TP_ADD_TC(tp, times);
138 ATF_TP_ADD_TC(tp, relative);
139 ATF_TP_ADD_TC(tp, atsecs);
141 return atf_no_error();