2 #ifdef LIBREPLACE_CONFIGURE_TEST_STRPTIME
12 #define __STRING(x) #x
15 /* make printf a no-op */
16 #define printf if(0) printf
18 #else /* LIBREPLACE_CONFIGURE_TEST_STRPTIME */
21 #include "system/time.h"
22 #include "replace-test.h"
24 #endif /* LIBREPLACE_CONFIGURE_TEST_STRPTIME */
26 int libreplace_test_strptime(void)
28 const char *s = "20070414101546Z";
32 memset(&t, 0, sizeof(t));
33 memset(&t2, 0, sizeof(t2));
35 printf("test: strptime\n");
37 ret = strptime(s, "%Y%m%d%H%M%S", &t);
39 printf("failure: strptime [\n"
46 printf("failure: strptime [\n"
47 "ret doesn't point to 'Z'\n"
52 ret = strptime(s, "%Y%m%d%H%M%SZ", &t2);
54 printf("failure: strptime [\n"
55 "returned NULL with Z\n"
61 printf("failure: strptime [\n"
62 "ret doesn't point to '\\0'\n"
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" \
73 __STRING(elen), t1.elem, t2.elem); \
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);
88 printf("failure: strptime [\n"
89 "tm_sec: expected: 46, got: %d\n"
96 printf("failure: strptime [\n"
97 "tm_min: expected: 15, got: %d\n"
103 if (t.tm_hour != 10) {
104 printf("failure: strptime [\n"
105 "tm_hour: expected: 10, got: %d\n"
111 if (t.tm_mday != 14) {
112 printf("failure: strptime [\n"
113 "tm_mday: expected: 14, got: %d\n"
120 printf("failure: strptime [\n"
121 "tm_mon: expected: 3, got: %d\n"
127 if (t.tm_year != 107) {
128 printf("failure: strptime [\n"
129 "tm_year: expected: 107, got: %d\n"
135 if (t.tm_wday != 6) { /* saturday */
136 printf("failure: strptime [\n"
137 "tm_wday: expected: 6, got: %d\n"
143 if (t.tm_yday != 103) {
144 printf("failure: strptime [\n"
145 "tm_yday: expected: 103, got: %d\n"
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"
160 printf("success: strptime\n");
165 #ifdef LIBREPLACE_CONFIGURE_TEST_STRPTIME
169 ret = libreplace_test_strptime();
170 if (ret == false) return 1;