smbd: Use leases_db in lease_match()
[gd/samba-autobuild/.git] / lib / replace / test / strptime.c
1
2 #ifdef LIBREPLACE_CONFIGURE_TEST_STRPTIME
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <time.h>
7
8 #define true 1
9 #define false 0
10
11 #ifndef __STRING
12 #define __STRING(x)    #x
13 #endif
14
15 /* make printf a no-op */
16 #define printf if(0) printf
17
18 #else /* LIBREPLACE_CONFIGURE_TEST_STRPTIME */
19
20 #include "replace.h"
21 #include "system/time.h"
22 #include "replace-test.h"
23
24 #endif /* LIBREPLACE_CONFIGURE_TEST_STRPTIME */
25
26 int libreplace_test_strptime(void)
27 {
28         const char *s = "20070414101546Z";
29         char *ret;
30         struct tm t, t2;
31
32         memset(&t, 0, sizeof(t));
33         memset(&t2, 0, sizeof(t2));
34
35         printf("test: strptime\n");
36
37         ret = strptime(s, "%Y%m%d%H%M%S", &t);
38         if ( ret == NULL ) {
39                 printf("failure: strptime [\n"
40                        "returned NULL\n"
41                        "]\n");
42                 return false;
43         }
44
45         if ( *ret != 'Z' ) {
46                 printf("failure: strptime [\n"
47                        "ret doesn't point to 'Z'\n"
48                        "]\n");
49                 return false;
50         }
51
52         ret = strptime(s, "%Y%m%d%H%M%SZ", &t2);
53         if ( ret == NULL ) {
54                 printf("failure: strptime [\n"
55                        "returned NULL with Z\n"
56                        "]\n");
57                 return false;
58         }
59
60         if ( *ret != '\0' ) {
61                 printf("failure: strptime [\n"
62                        "ret doesn't point to '\\0'\n"
63                        "]\n");
64                 return false;
65         }
66
67 #define CMP_TM_ELEMENT(t1,t2,elem) \
68         if (t1.elem != t2.elem) { \
69                 printf("failure: strptime [\n" \
70                        "result differs if the format string has a 'Z' at the end\n" \
71                        "element: %s %d != %d\n" \
72                        "]\n", \
73                        __STRING(elen), t1.elem, t2.elem); \
74                 return false; \
75         }
76
77         CMP_TM_ELEMENT(t,t2,tm_sec);
78         CMP_TM_ELEMENT(t,t2,tm_min);
79         CMP_TM_ELEMENT(t,t2,tm_hour);
80         CMP_TM_ELEMENT(t,t2,tm_mday);
81         CMP_TM_ELEMENT(t,t2,tm_mon);
82         CMP_TM_ELEMENT(t,t2,tm_year);
83         CMP_TM_ELEMENT(t,t2,tm_wday);
84         CMP_TM_ELEMENT(t,t2,tm_yday);
85         CMP_TM_ELEMENT(t,t2,tm_isdst);
86
87         if (t.tm_sec != 46) {
88                 printf("failure: strptime [\n"
89                        "tm_sec: expected: 46, got: %d\n"
90                        "]\n",
91                        t.tm_sec);
92                 return false;
93         }
94
95         if (t.tm_min != 15) {
96                 printf("failure: strptime [\n"
97                        "tm_min: expected: 15, got: %d\n"
98                        "]\n",
99                        t.tm_min);
100                 return false;
101         }
102
103         if (t.tm_hour != 10) {
104                 printf("failure: strptime [\n"
105                        "tm_hour: expected: 10, got: %d\n"
106                        "]\n",
107                        t.tm_hour);
108                 return false;
109         }
110
111         if (t.tm_mday != 14) {
112                 printf("failure: strptime [\n"
113                        "tm_mday: expected: 14, got: %d\n"
114                        "]\n",
115                        t.tm_mday);
116                 return false;
117         }
118
119         if (t.tm_mon != 3) {
120                 printf("failure: strptime [\n"
121                        "tm_mon: expected: 3, got: %d\n"
122                        "]\n",
123                        t.tm_mon);
124                 return false;
125         }
126
127         if (t.tm_year != 107) {
128                 printf("failure: strptime [\n"
129                        "tm_year: expected: 107, got: %d\n"
130                        "]\n",
131                        t.tm_year);
132                 return false;
133         }
134
135         if (t.tm_wday != 6) { /* saturday */
136                 printf("failure: strptime [\n"
137                        "tm_wday: expected: 6, got: %d\n"
138                        "]\n",
139                        t.tm_wday);
140                 return false;
141         }
142
143         if (t.tm_yday != 103) {
144                 printf("failure: strptime [\n"
145                        "tm_yday: expected: 103, got: %d\n"
146                        "]\n",
147                        t.tm_yday);
148                 return false;
149         }
150
151         /* we don't test this as it depends on the host configuration
152         if (t.tm_isdst != 0) {
153                 printf("failure: strptime [\n"
154                        "tm_isdst: expected: 0, got: %d\n"
155                        "]\n",
156                        t.tm_isdst);
157                 return false;
158         }*/
159
160         printf("success: strptime\n");
161
162         return true;
163 }
164
165 #ifdef LIBREPLACE_CONFIGURE_TEST_STRPTIME
166 int main (void)
167 {
168         int ret;
169         ret = libreplace_test_strptime();
170         if (ret == false) return 1;
171         return 0;
172 }
173 #endif