1 /**
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <stdlib.h>
17 #include <time.h>
18 #include "asctime_data.h"
19 #include "functionalext.h"
20 #include "strptime_data.h"
21
22 static int16_t gBufferSize = 256;
23 static time_t gTime = 1659177614;
24 static int16_t gYearBase = 1900;
25
26 /**
27 * @tc.name : strptime_0100
28 * @tc.desc : according to different time zones, convert a string to a time
29 * type according to a specific time format
30 * @tc.level : Level 0
31 */
strptime_0100(void)32 void strptime_0100(void)
33 {
34 for ( int32_t i = 0; i < (int32_t)(sizeof(test_asctime_data) / sizeof(test_asctime_data[0])); i++) {
35 const char *handlerChar = test_handle_path(test_asctime_data[i].tz);
36 if (!handlerChar) {
37 t_error("strptime_0100 failed: handlerChar is NULL\n");
38 continue;
39 }
40
41 setenv("TZ", handlerChar, 1);
42 tzset();
43 char buffer[gBufferSize];
44 struct tm *timeptr = localtime(&gTime);
45 if (!timeptr) {
46 EXPECT_PTRNE("strptime_0100", timeptr, NULL);
47 return;
48 }
49 size_t cnt = strftime(buffer, sizeof(buffer) - 1, "%c", timeptr);
50 EXPECT_TRUE("strptime_0100", cnt > 0);
51
52 struct tm tmTime = {0};
53 strptime(buffer, "%c", &tmTime);
54 char *result = asctime(&tmTime);
55 if (result == NULL) {
56 EXPECT_FALSE("strptime_0100", result == NULL);
57 return;
58 }
59 result[strlen(result) - 1] = 0x00;
60 EXPECT_STREQ("strptime_0100", test_asctime_data[i].result, result);
61 }
62 }
63
64 /**
65 * @tc.name : strptime_0200
66 * @tc.desc : according to different time zones, convert a string to a time
67 * type according to a specific time format
68 * @tc.level : Level 0
69 */
strptime_0200(void)70 void strptime_0200(void)
71 {
72 for ( int32_t i = 0; i < (int32_t)(sizeof(test_strptime_data)/sizeof(test_strptime_data[0])); i++) {
73 const char *handlerChar = test_handle_path(test_strptime_data[i].tz);
74 if (!handlerChar) {
75 t_error("strptime_0200 failed: handlerChar is NULL\n");
76 continue;
77 }
78
79 setenv("TZ", handlerChar, 1);
80 tzset();
81 char buffer[gBufferSize];
82 struct tm *timeptr = localtime(&gTime);
83 if (!timeptr) {
84 EXPECT_TRUE("strptime_0200", timeptr == NULL);
85 return;
86 }
87 size_t len = strftime(buffer, sizeof(buffer) - 1, "%c %Z%z", timeptr);
88 EXPECT_TRUE("strptime_0200", len > 0);
89 struct tm tmTime = {0};
90 strptime(buffer, "%c %Z%z", &tmTime);
91 char buffResult[gBufferSize];
92
93 int cnt = sprintf(buffResult, "%d-%d-%d %d:%d:%d wday=%d,yday=%d,isdst=%d,gmtoff=%ld,zone=%s",
94 (tmTime.tm_year+gYearBase), tmTime.tm_mon, tmTime.tm_mday, tmTime.tm_hour,
95 tmTime.tm_min, tmTime.tm_sec, tmTime.tm_wday, tmTime.tm_yday, tmTime.tm_isdst,
96 tmTime.tm_gmtoff, tmTime.tm_zone);
97 EXPECT_TRUE("strptime_0200", cnt > 0);
98 EXPECT_STREQ("strptime_0200", test_strptime_data[i].result, buffResult);
99 }
100 }
101
102 /**
103 * @tc.name : strptime_0300
104 * @tc.desc : according to different time zones, convert a string to a time
105 * type according to a specific time format
106 * @tc.level : Level 0
107 */
strptime_0300(void)108 void strptime_0300(void)
109 {
110 char *buffer = "2022-04-10";
111 struct tm tmTime = {0};
112 strptime(buffer, "%F", &tmTime);
113 char buffResult[gBufferSize];
114 int cnt = sprintf(buffResult, "%04d-%02d-%02d",
115 (tmTime.tm_year+gYearBase), tmTime.tm_mon + 1, tmTime.tm_mday);
116 EXPECT_TRUE("strptime_0300", cnt > 0);
117 EXPECT_STREQ("strptime_0300", buffer, buffResult);
118 }
119
120 /**
121 * @tc.name : strptime_0400
122 * @tc.desc : according to different time zones, convert a string to a time
123 * type according to a specific time format
124 * @tc.level : Level 0
125 */
strptime_0400(void)126 void strptime_0400(void)
127 {
128 char *buffer = "23";
129 struct tm tmTime = {0};
130 strptime(buffer, "%g", &tmTime);
131 char buffResult[gBufferSize];
132 int cnt = sprintf(buffResult, "%d", tmTime.tm_year);
133 EXPECT_TRUE("strptime_0400", cnt > 0);
134 EXPECT_STREQ("strptime_0400", buffer, buffResult);
135 }
136
137 /**
138 * @tc.name : strptime_0500
139 * @tc.desc : according to different time zones, convert a string to a time
140 * type according to a specific time format
141 * @tc.level : Level 0
142 */
strptime_0500(void)143 void strptime_0500(void)
144 {
145 const char *buffer = "16";
146 struct tm tmTime = {0};
147 strptime(buffer, " %k", &tmTime);
148 char buffResult[gBufferSize];
149 int cnt = sprintf(buffResult, "%d", tmTime.tm_hour);
150 EXPECT_TRUE("strptime_0500", cnt > 0);
151 EXPECT_STREQ("strptime_0500", buffer, buffResult);
152 }
153
154 /**
155 * @tc.name : strptime_0600
156 * @tc.desc : according to different time zones, convert a string to a time
157 * type according to a specific time format
158 * @tc.level : Level 0
159 */
strptime_0600(void)160 void strptime_0600(void)
161 {
162 const char *buffer = " 4";
163 struct tm tmTime = {0};
164 strptime(buffer, " %l", &tmTime);
165 char buffResult[gBufferSize];
166 int cnt = sprintf(buffResult, "%d", tmTime.tm_hour);
167 EXPECT_TRUE("strptime_0600", cnt > 0);
168 EXPECT_STREQ("strptime_0600", "4", buffResult);
169 }
170
171 /**
172 * @tc.name : strptime_0700
173 * @tc.desc : according to different time zones, convert a string to a time
174 * type according to a specific time format
175 * @tc.level : Level 0
176 */
strptime_0700(void)177 void strptime_0700(void)
178 {
179 const char *buffer = "1659177614";
180 const char *handlerChar = test_handle_path(test_asctime_data[0].tz);
181 if (!handlerChar) {
182 t_error("strptime_0700 failed: handlerChar is NULL\n");
183 return;
184 }
185
186 setenv("TZ", handlerChar, 1);
187 time_t second = 0;
188 struct tm tmTime = {0};
189 strptime(buffer, "%s", &tmTime);
190 second = mktime(&tmTime);
191 char buffResult[gBufferSize];
192 int cnt = sprintf(buffResult, "%lld", second);
193 EXPECT_TRUE("strptime_0700", cnt > 0);
194 EXPECT_STREQ("strptime_0700", buffer, buffResult);
195 }
196
197 /**
198 * @tc.name : strptime_0800
199 * @tc.desc : according to different time zones, convert a string to a time
200 * type according to a specific time format
201 * @tc.level : Level 0
202 */
strptime_0800(void)203 void strptime_0800(void)
204 {
205 const char *buffer = "1";
206 struct tm tmTime = {0};
207 strptime(buffer, "%u", &tmTime);
208 char buffResult[gBufferSize];
209 int cnt = sprintf(buffResult, "%d", tmTime.tm_wday);
210 EXPECT_TRUE("strptime_0800", cnt > 0);
211 EXPECT_STREQ("strptime_0800", buffer, buffResult);
212 }
213
214 /**
215 * @tc.name : strptime_0900
216 * @tc.desc : according to different time zones, convert a string to a time
217 * type according to a specific time format
218 * @tc.level : Level 0
219 */
strptime_0900(void)220 void strptime_0900(void)
221 {
222 const char *buffer = "30-Oct-2021";
223 struct tm tmTime = {0};
224 strptime(buffer, "%v", &tmTime);
225 char buffResult[gBufferSize];
226 int cnt = sprintf(buffResult, "%d-%d-%d",
227 (tmTime.tm_year+gYearBase), tmTime.tm_mon, tmTime.tm_mday);
228 EXPECT_TRUE("strptime_0900", cnt > 0);
229 EXPECT_STREQ("strptime_0900", "2021-9-30", buffResult);
230 }
231
232 /**
233 * @tc.name : strptime_1000
234 * @tc.desc : according to different time zones, convert a string to a time
235 * type according to a specific time format
236 * @tc.level : Level 1
237 */
strptime_1000(void)238 void strptime_1000(void)
239 {
240 const char *buffer = "2021-01-23";
241 struct tm tmTime = {0};
242 char *result = strptime(buffer, "%G", &tmTime);
243 char buffResult[gBufferSize];
244 int cnt = sprintf(buffResult, "%s", result);
245 EXPECT_TRUE("strptime_1000", cnt > 0);
246 EXPECT_STREQ("strptime_1000", "-01-23", buffResult);
247 }
248
249 /**
250 * @tc.name : strptime_1100
251 * @tc.desc : according to different time zones, convert a string to a time
252 * type according to a specific time format
253 * @tc.level : Level 1
254 */
strptime_1100(void)255 void strptime_1100(void)
256 {
257 const char *buffer = "23";
258 struct tm tmTime = {0};
259 strptime(buffer, "%j", &tmTime);
260 char buffResult[gBufferSize];
261 int cnt = sprintf(buffResult, "%d", tmTime.tm_yday);
262 EXPECT_TRUE("strptime_1100", cnt > 0);
263 EXPECT_STREQ("strptime_1100", "22", buffResult);
264 }
265
266 /**
267 * @tc.name : strptime_1200
268 * @tc.desc : according to different time zones, convert a string to a time
269 * type according to a specific time format
270 * @tc.level : Level 0
271 */
strptime_1200(void)272 void strptime_1200(void)
273 {
274 const char *buffer = "am";
275 const char *handlerChar = test_handle_path("Asia/Shanghai");
276 if (!handlerChar) {
277 t_error("strptime_1200 failed: handlerChar is NULL\n");
278 return;
279 }
280
281 setenv("TZ", handlerChar, 1);
282 tzset();
283 struct tm *timeptr = localtime(&gTime);
284 if (!timeptr) {
285 EXPECT_PTRNE("strptime_1200", timeptr, NULL);
286 return;
287 }
288 strptime(buffer, "%P", timeptr);
289 char buffResult[gBufferSize];
290 int cnt = sprintf(buffResult, "%d", timeptr->tm_hour);
291 EXPECT_TRUE("strptime_1200", cnt > 0);
292 EXPECT_STREQ("strptime_1200", "6", buffResult);
293 }
294
295 /**
296 * @tc.name : strptime_1300
297 * @tc.desc : according to different time zones, convert a string to a time
298 * type according to a specific time format
299 * @tc.level : Level 0
300 */
strptime_1300(void)301 void strptime_1300(void)
302 {
303 const char *buffer = "pm";
304 const char *handlerChar = test_handle_path("Asia/Shanghai");
305 if (!handlerChar) {
306 t_error("strptime_1300 failed: handlerChar is NULL\n");
307 return;
308 }
309
310 setenv("TZ", handlerChar, 1);
311 tzset();
312 struct tm *timeptr = localtime(&gTime);
313 if (!timeptr) {
314 EXPECT_PTRNE("strptime_1300", timeptr, NULL);
315 return;
316 }
317 strptime(buffer, "%P", timeptr);
318 char buffResult[gBufferSize];
319 int cnt = sprintf(buffResult, "%d", timeptr->tm_hour);
320 EXPECT_TRUE("strptime_1300", cnt > 0);
321 EXPECT_STREQ("strptime_1300", "18", buffResult);
322 }
323
324 /**
325 * @tc.name : strptime_1400
326 * @tc.desc : according to different time zones, convert a string to a time
327 * type according to a specific time format
328 * @tc.level : Level 0
329 */
strptime_1400(void)330 void strptime_1400(void)
331 {
332 const char *buffer = "30-Oct-2021";
333 struct tm tmTime = {0};
334 char *result = strptime(buffer, "%U", &tmTime);
335 char buffResult[gBufferSize];
336 int cnt = sprintf(buffResult, "%s", result);
337 EXPECT_TRUE("strptime_1400", cnt > 0);
338 EXPECT_STREQ("strptime_1400", "-Oct-2021", buffResult);
339 }
340
341 /**
342 * @tc.name : strptime_1500
343 * @tc.desc : according to different time zones, convert a string to a time
344 * type according to a specific time format
345 * @tc.level : Level 0
346 */
strptime_1500(void)347 void strptime_1500(void)
348 {
349 const char *buffer = "1";
350 struct tm tmTime = {0};
351 char *result = strptime(buffer, "%w", &tmTime);
352 char buffResult[gBufferSize];
353 int cnt = sprintf(buffResult, "%d", tmTime.tm_wday);
354 EXPECT_TRUE("strptime_1500", cnt > 0);
355 EXPECT_STREQ("strptime_1500", "1", buffResult);
356 }
357
358 /**
359 * @tc.name : strptime_1600
360 * @tc.desc : according to different time zones, convert a string to a time
361 * type according to a specific time format
362 * @tc.level : Level 0
363 */
strptime_1600(void)364 void strptime_1600(void)
365 {
366 const char *buffer = "Oct-30-2021";
367 struct tm tmTime = {0};
368 strptime(buffer, "%v", &tmTime);
369 char buffResult[gBufferSize];
370 int cnt = sprintf(buffResult, "%d-%d-%d",
371 (tmTime.tm_year+gYearBase), tmTime.tm_mon, tmTime.tm_mday);
372 EXPECT_TRUE("strptime_1600", cnt > 0);
373 EXPECT_STREQ("strptime_1600", "1900-0-0", buffResult);
374 }
375
376 /**
377 * @tc.name : strptime_1700
378 * @tc.desc : according to different time zones, convert a string to a time
379 * type according to a specific time format
380 * @tc.level : Level 0
381 */
strptime_1700(void)382 void strptime_1700(void)
383 {
384 const char *buffer = "16-Spring";
385 struct tm tmTime = {0};
386 char *result = strptime(buffer, "%V", &tmTime);
387 char buffResult[gBufferSize];
388 int cnt = sprintf(buffResult, "%s", result);
389 EXPECT_TRUE("strptime_1700", cnt > 0);
390 EXPECT_STREQ("strptime_1700", "-Spring", buffResult);
391 }
392
393 /**
394 * @tc.name : strptime_1800
395 * @tc.desc : according to different time zones, convert a string to a time
396 * type according to a specific time format
397 * @tc.level : Level 1
398 */
strptime_1800(void)399 void strptime_1800(void)
400 {
401 const char *buffer = "+03";
402 struct tm tmTime = {0};
403 char *result = strptime(buffer, "%Z", &tmTime);
404 char buffResult[gBufferSize];
405 int cnt = sprintf(buffResult, "%s", tmTime.__tm_zone);
406 EXPECT_TRUE("strptime_1800", cnt > 0);
407 EXPECT_STREQ("strptime_1800", "+03", buffResult);
408 }
409
410 /**
411 * @tc.name : strptime_1900
412 * @tc.desc : according to different time zones, convert a string to a time
413 * type according to a specific time format
414 * @tc.level : Level 1
415 */
strptime_1900(void)416 void strptime_1900(void)
417 {
418 const char *buffer = "-03";
419 struct tm tmTime = {0};
420 char *result = strptime(buffer, "%Z", &tmTime);
421 char buffResult[gBufferSize];
422 int cnt = sprintf(buffResult, "%s", tmTime.__tm_zone);
423 EXPECT_TRUE("strptime_1900", cnt > 0);
424 EXPECT_STREQ("strptime_1900", "-03", buffResult);
425 }
426
427 /**
428 * @tc.name : strptime_2000
429 * @tc.desc : according to different time zones, convert a string to a time
430 * type according to a specific time format
431 * @tc.level : Level 2
432 */
strptime_2000(void)433 void strptime_2000(void)
434 {
435 const char *buffer = "Oct-30-2021";
436 struct tm tmTime = {0};
437 char *result = strptime(buffer, "test", &tmTime);
438 EXPECT_FALSE("strptime_2000", result);
439 }
440
441 /**
442 * @tc.name : strptime_2100
443 * @tc.desc : according to different time zones, convert a string to a time
444 * type according to a specific time format
445 * @tc.level : Level 1
446 */
strptime_2100(void)447 void strptime_2100(void)
448 {
449 const char *buffer = "2022-4-10";
450 struct tm tmTime = {0};
451 char *result = strptime(buffer, "%+2F", &tmTime);
452 char buffResult[gBufferSize];
453 int cnt = sprintf(buffResult, "%d", tmTime.tm_mday);
454 EXPECT_TRUE("strptime_2100", cnt > 0);
455 EXPECT_STREQ("strptime_2100", "10", buffResult);
456 }
457
458 /**
459 * @tc.name : strptime_2200
460 * @tc.desc : according to different time zones, convert a string to a time
461 * type according to a specific time format
462 * @tc.level : Level 2
463 */
strptime_2200(void)464 void strptime_2200(void)
465 {
466 const char *buffer = "";
467 struct tm tmTime = {0};
468 char *result = strptime(buffer, "%c", &tmTime);
469 EXPECT_FALSE("strptime_2200", result);
470 }
471
472 /**
473 * @tc.name : strptime_2300
474 * @tc.desc : according to different time zones, convert a string to a time
475 * type according to a specific time format
476 * @tc.level : Level 1
477 */
strptime_2300(void)478 void strptime_2300(void)
479 {
480 const char *buffer = "2022";
481 struct tm tmTime = {0};
482 char *result = strptime(buffer, "%C", &tmTime);
483 char buffResult[gBufferSize];
484 int cnt = sprintf(buffResult, "%s", result);
485 EXPECT_TRUE("strptime_2300", cnt > 0);
486 EXPECT_STREQ("strptime_2300", "22", buffResult);
487 }
488
489 /**
490 * @tc.name : strptime_2400
491 * @tc.desc : according to different time zones, convert a string to a time
492 * type according to a specific time format
493 * @tc.level : Level 2
494 */
strptime_2400(void)495 void strptime_2400(void)
496 {
497 const char *buffer = "";
498 struct tm tmTime = {0};
499 char *result = strptime(buffer, "%D", &tmTime);
500 EXPECT_FALSE("strptime_2400", result);
501 }
502
503 /**
504 * @tc.name : strptime_2500
505 * @tc.desc : according to different time zones, convert a string to a time
506 * type according to a specific time format
507 * @tc.level : Level 2
508 */
strptime_2500(void)509 void strptime_2500(void)
510 {
511 const char *buffer = "";
512 struct tm tmTime = {0};
513 char *result = strptime(buffer, "%F", &tmTime);
514 EXPECT_FALSE("strptime_2500", result);
515 }
516
517 /**
518 * @tc.name : strptime_2600
519 * @tc.desc : according to different time zones, convert a string to a time
520 * type according to a specific time format
521 * @tc.level : Level 1
522 */
strptime_2600(void)523 void strptime_2600(void)
524 {
525 const char *buffer = " 1";
526 struct tm tmTime = {0};
527 char *result = strptime(buffer, "%n%t", &tmTime);
528 char buffResult[gBufferSize];
529 int cnt = sprintf(buffResult, "%s", result);
530 EXPECT_TRUE("strptime_2600", cnt > 0);
531 EXPECT_STREQ("strptime_2600", "1", buffResult);
532 }
533
534 /**
535 * @tc.name : strptime_2700
536 * @tc.desc : according to different time zones, convert a string to a time
537 * type according to a specific time format
538 * @tc.level : Level 1
539 */
strptime_2700(void)540 void strptime_2700(void)
541 {
542 const char *buffer = "08:38:20";
543 struct tm tmTime = {0};
544 char *result = strptime(buffer, "%r", &tmTime);
545 char buffResult[gBufferSize];
546 int cnt = sprintf(buffResult, "%d:%d:%d", tmTime.tm_hour, tmTime.tm_min, tmTime.tm_sec);
547 EXPECT_TRUE("strptime_2700", cnt > 0);
548 EXPECT_STREQ("strptime_2700", "8:38:20", buffResult);
549 }
550
551 /**
552 * @tc.name : strptime_2800
553 * @tc.desc : according to different time zones, convert a string to a time
554 * type according to a specific time format
555 * @tc.level : Level 2
556 */
strptime_2800(void)557 void strptime_2800(void)
558 {
559 const char *buffer = "";
560 struct tm tmTime = {0};
561 char *result = strptime(buffer, "%r", &tmTime);
562 EXPECT_FALSE("strptime_2800", result);
563 }
564
565 /**
566 * @tc.name : strptime_2900
567 * @tc.desc : according to different time zones, convert a string to a time
568 * type according to a specific time format
569 * @tc.level : Level 2
570 */
strptime_2900(void)571 void strptime_2900(void)
572 {
573 const char *buffer = "";
574 struct tm tmTime = {0};
575 char *result = strptime(buffer, "%R", &tmTime);
576 EXPECT_FALSE("strptime_2900", result);
577 }
578
579 /**
580 * @tc.name : strptime_3000
581 * @tc.desc : according to different time zones, convert a string to a time
582 * type according to a specific time format
583 * @tc.level : Level 2
584 */
strptime_3000(void)585 void strptime_3000(void)
586 {
587 const char *buffer = "+1";
588 struct tm tmTime = {0};
589 char *result = strptime(buffer, "%s", &tmTime);
590 EXPECT_FALSE("strptime_3000", result);
591 }
592
593 /**
594 * @tc.name : strptime_3100
595 * @tc.desc : according to different time zones, convert a string to a time
596 * type according to a specific time format
597 * @tc.level : Level 2
598 */
strptime_3100(void)599 void strptime_3100(void)
600 {
601 const char *buffer = "";
602 struct tm tmTime = {0};
603 char *result = strptime(buffer, "%T", &tmTime);
604 EXPECT_FALSE("strptime_3100", result);
605 }
606
607 /**
608 * @tc.name : strptime_3200
609 * @tc.desc : according to different time zones, convert a string to a time
610 * type according to a specific time format
611 * @tc.level : Level 2
612 */
strptime_3200(void)613 void strptime_3200(void)
614 {
615 const char *buffer = "";
616 struct tm tmTime = {0};
617 char *result = strptime(buffer, "%u", &tmTime);
618 EXPECT_FALSE("strptime_3200", result);
619 }
620
621 /**
622 * @tc.name : strptime_3300
623 * @tc.desc : according to different time zones, convert a string to a time
624 * type according to a specific time format
625 * @tc.level : Level 2
626 */
strptime_3300(void)627 void strptime_3300(void)
628 {
629 const char *buffer = "";
630 struct tm tmTime = {0};
631 char *result = strptime(buffer, "%V", &tmTime);
632 EXPECT_FALSE("strptime_3300", result);
633 }
634
635 /**
636 * @tc.name : strptime_3400
637 * @tc.desc : according to different time zones, convert a string to a time
638 * type according to a specific time format
639 * @tc.level : Level 1
640 */
strptime_3400(void)641 void strptime_3400(void)
642 {
643 const char *buffer = "04/10/22";
644 struct tm tmTime = {0};
645 char *result = strptime(buffer, "%x", &tmTime);
646 char buffResult[gBufferSize];
647 int cnt = sprintf(buffResult, "%d/%d/%d", (tmTime.tm_mon + 1), tmTime.tm_mday, (tmTime.tm_year + gYearBase));
648 EXPECT_TRUE("strptime_3400", cnt > 0);
649 EXPECT_STREQ("strptime_3400", "4/10/2022", buffResult);
650 }
651
652 /**
653 * @tc.name : strptime_3500
654 * @tc.desc : according to different time zones, convert a string to a time
655 * type according to a specific time format
656 * @tc.level : Level 2
657 */
strptime_3500(void)658 void strptime_3500(void)
659 {
660 const char *buffer = "";
661 struct tm tmTime = {0};
662 char *result = strptime(buffer, "%x", &tmTime);
663 EXPECT_FALSE("strptime_3500", result);
664 }
665
666 /**
667 * @tc.name : strptime_3600
668 * @tc.desc : according to different time zones, convert a string to a time
669 * type according to a specific time format
670 * @tc.level : Level 1
671 */
strptime_3600(void)672 void strptime_3600(void)
673 {
674 const char *buffer = "08:10:20";
675 struct tm tmTime = {0};
676 char *result = strptime(buffer, "%X", &tmTime);
677 char buffResult[gBufferSize];
678 int cnt = sprintf(buffResult, "%d:%d:%d", tmTime.tm_hour, tmTime.tm_min, tmTime.tm_sec);
679 EXPECT_TRUE("strptime_3600", cnt > 0);
680 EXPECT_STREQ("strptime_3600", "8:10:20", buffResult);
681 }
682
683 /**
684 * @tc.name : strptime_3700
685 * @tc.desc : according to different time zones, convert a string to a time
686 * type according to a specific time format
687 * @tc.level : Level 2
688 */
strptime_3700(void)689 void strptime_3700(void)
690 {
691 const char *buffer = "";
692 struct tm tmTime = {0};
693 char *result = strptime(buffer, "%X", &tmTime);
694 EXPECT_FALSE("strptime_3700", result);
695 }
696
697 /**
698 * @tc.name : strptime_3800
699 * @tc.desc : according to different time zones, convert a string to a time
700 * type according to a specific time format
701 * @tc.level : Level 2
702 */
strptime_3800(void)703 void strptime_3800(void)
704 {
705 const char *buffer = "";
706 struct tm tmTime = {0};
707 char *result = strptime(buffer, "%%", &tmTime);
708 EXPECT_FALSE("strptime_3800", result);
709 }
710
711 /**
712 * @tc.name : strptime_3900
713 * @tc.desc : according to different time zones, convert a string to a time
714 * type according to a specific time format
715 * @tc.level : Level 2
716 */
strptime_3900(void)717 void strptime_3900(void)
718 {
719 const char *buffer = "";
720 struct tm tmTime = {0};
721 char *result = strptime(buffer, "%&", &tmTime);
722 EXPECT_FALSE("strptime_3900", result);
723 }
724
main(void)725 int main(void)
726 {
727 strptime_0100();
728 strptime_0200();
729 strptime_0300();
730 strptime_0400();
731 strptime_0500();
732 strptime_0600();
733 strptime_0700();
734 strptime_0800();
735 strptime_0900();
736 strptime_1000();
737 strptime_1100();
738 strptime_1200();
739 strptime_1300();
740 strptime_1400();
741 strptime_1500();
742 strptime_1600();
743 strptime_1700();
744 strptime_1800();
745 strptime_1900();
746 strptime_2000();
747 strptime_2100();
748 strptime_2200();
749 strptime_2300();
750 strptime_2400();
751 strptime_2500();
752 strptime_2600();
753 strptime_2700();
754 strptime_2800();
755 strptime_2900();
756 strptime_3000();
757 strptime_3100();
758 strptime_3200();
759 strptime_3300();
760 strptime_3400();
761 strptime_3500();
762 strptime_3600();
763 strptime_3700();
764 strptime_3800();
765 strptime_3900();
766 return t_status;
767 }