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