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"
23 #endif /* LIBREPLACE_CONFIGURE_TEST_STRPTIME */
25 int libreplace_test_strptime(void)
27 const char *s
= "20070414101546Z";
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
);
38 printf("failure: strptime [\n"
45 printf("failure: strptime [\n"
46 "ret doesn't point to 'Z'\n"
51 ret
= strptime(s
, "%Y%m%d%H%M%SZ", &t2
);
53 printf("failure: strptime [\n"
54 "returned NULL with Z\n"
60 printf("failure: strptime [\n"
61 "ret doesn't point to '\\0'\n"
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" \
72 __STRING(elen), t1.elem, t2.elem); \
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
);
87 printf("failure: strptime [\n"
88 "tm_sec: expected: 46, got: %d\n"
95 printf("failure: strptime [\n"
96 "tm_min: expected: 15, got: %d\n"
102 if (t
.tm_hour
!= 10) {
103 printf("failure: strptime [\n"
104 "tm_hour: expected: 10, got: %d\n"
110 if (t
.tm_mday
!= 14) {
111 printf("failure: strptime [\n"
112 "tm_mday: expected: 14, got: %d\n"
119 printf("failure: strptime [\n"
120 "tm_mon: expected: 3, got: %d\n"
126 if (t
.tm_year
!= 107) {
127 printf("failure: strptime [\n"
128 "tm_year: expected: 107, got: %d\n"
134 if (t
.tm_wday
!= 6) { /* saturday */
135 printf("failure: strptime [\n"
136 "tm_wday: expected: 6, got: %d\n"
142 if (t
.tm_yday
!= 103) {
143 printf("failure: strptime [\n"
144 "tm_yday: expected: 103, got: %d\n"
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"
159 printf("success: strptime\n");
164 #ifdef LIBREPLACE_CONFIGURE_TEST_STRPTIME
168 ret
= libreplace_test_strptime();
169 if (ret
== false) return 1;