関数 | |
int | libreplace_test_strptime (void) |
int | main (void) |
int libreplace_test_strptime | ( | void | ) |
strptime.c の 25 行で定義されています。
参照先 printf().
参照元 main()・test_strptime().
00026 { 00027 const char *s = "20070414101546Z"; 00028 char *ret; 00029 struct tm t, t2; 00030 00031 memset(&t, 0, sizeof(t)); 00032 memset(&t2, 0, sizeof(t2)); 00033 00034 printf("test: strptime\n"); 00035 00036 ret = strptime(s, "%Y%m%d%H%M%S", &t); 00037 if ( ret == NULL ) { 00038 printf("failure: strptime [\n" 00039 "returned NULL\n" 00040 "]\n"); 00041 return false; 00042 } 00043 00044 if ( *ret != 'Z' ) { 00045 printf("failure: strptime [\n" 00046 "ret doesn't point to 'Z'\n" 00047 "]\n"); 00048 return false; 00049 } 00050 00051 ret = strptime(s, "%Y%m%d%H%M%SZ", &t2); 00052 if ( ret == NULL ) { 00053 printf("failure: strptime [\n" 00054 "returned NULL with Z\n" 00055 "]\n"); 00056 return false; 00057 } 00058 00059 if ( *ret != '\0' ) { 00060 printf("failure: strptime [\n" 00061 "ret doesn't point to '\\0'\n" 00062 "]\n"); 00063 return false; 00064 } 00065 00066 #define CMP_TM_ELEMENT(t1,t2,elem) \ 00067 if (t1.elem != t2.elem) { \ 00068 printf("failure: strptime [\n" \ 00069 "result differs if the format string has a 'Z' at the end\n" \ 00070 "element: %s %d != %d\n" \ 00071 "]\n", \ 00072 __STRING(elen), t1.elem, t2.elem); \ 00073 return false; \ 00074 } 00075 00076 CMP_TM_ELEMENT(t,t2,tm_sec); 00077 CMP_TM_ELEMENT(t,t2,tm_min); 00078 CMP_TM_ELEMENT(t,t2,tm_hour); 00079 CMP_TM_ELEMENT(t,t2,tm_mday); 00080 CMP_TM_ELEMENT(t,t2,tm_mon); 00081 CMP_TM_ELEMENT(t,t2,tm_year); 00082 CMP_TM_ELEMENT(t,t2,tm_wday); 00083 CMP_TM_ELEMENT(t,t2,tm_yday); 00084 CMP_TM_ELEMENT(t,t2,tm_isdst); 00085 00086 if (t.tm_sec != 46) { 00087 printf("failure: strptime [\n" 00088 "tm_sec: expected: 46, got: %d\n" 00089 "]\n", 00090 t.tm_sec); 00091 return false; 00092 } 00093 00094 if (t.tm_min != 15) { 00095 printf("failure: strptime [\n" 00096 "tm_min: expected: 15, got: %d\n" 00097 "]\n", 00098 t.tm_min); 00099 return false; 00100 } 00101 00102 if (t.tm_hour != 10) { 00103 printf("failure: strptime [\n" 00104 "tm_hour: expected: 10, got: %d\n" 00105 "]\n", 00106 t.tm_hour); 00107 return false; 00108 } 00109 00110 if (t.tm_mday != 14) { 00111 printf("failure: strptime [\n" 00112 "tm_mday: expected: 14, got: %d\n" 00113 "]\n", 00114 t.tm_mday); 00115 return false; 00116 } 00117 00118 if (t.tm_mon != 3) { 00119 printf("failure: strptime [\n" 00120 "tm_mon: expected: 3, got: %d\n" 00121 "]\n", 00122 t.tm_mon); 00123 return false; 00124 } 00125 00126 if (t.tm_year != 107) { 00127 printf("failure: strptime [\n" 00128 "tm_year: expected: 107, got: %d\n" 00129 "]\n", 00130 t.tm_year); 00131 return false; 00132 } 00133 00134 if (t.tm_wday != 6) { /* saturday */ 00135 printf("failure: strptime [\n" 00136 "tm_wday: expected: 6, got: %d\n" 00137 "]\n", 00138 t.tm_wday); 00139 return false; 00140 } 00141 00142 if (t.tm_yday != 103) { 00143 printf("failure: strptime [\n" 00144 "tm_yday: expected: 103, got: %d\n" 00145 "]\n", 00146 t.tm_yday); 00147 return false; 00148 } 00149 00150 /* we don't test this as it depends on the host configuration 00151 if (t.tm_isdst != 0) { 00152 printf("failure: strptime [\n" 00153 "tm_isdst: expected: 0, got: %d\n" 00154 "]\n", 00155 t.tm_isdst); 00156 return false; 00157 }*/ 00158 00159 printf("success: strptime\n"); 00160 00161 return true; 00162 }
int main | ( | void | ) |
strptime.c の 165 行で定義されています。
参照先 libreplace_test_strptime().
00166 { 00167 int ret; 00168 ret = libreplace_test_strptime(); 00169 if (ret == false) return 1; 00170 return 0; 00171 }