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
21 static time_t gTime = 1659177614;
22 static int16_t gBufferSize = 256;
23
24 // static const char *test_handle_path(const char *tz)
25 // {
26 // const char *p = tz;
27 // if (tz) {
28 // #ifdef TIME_ZONE_SUB_TAG
29 // char *str = strrchr(tz, TIME_ZONE_SUB_TAG);
30 // if (str) {
31 // p = ++str;
32 // }
33 // #endif
34 // }
35 // }
36
37 /**
38 * @tc.name : asctime_r_0100
39 * @tc.desc : according to different time zones, take an argument representing broken-down time,
40 * which is a representation separated into year, month, day, and so on
41 * @tc.level : Level 0
42 */
asctime_r_0100(void)43 void asctime_r_0100(void)
44 {
45 for (int32_t i = 0; i < (int32_t)(sizeof(test_asctime_data) / sizeof(test_asctime_data[0])); i++) {
46 const char *handlerChar = test_handle_path(test_asctime_data[i].tz);
47 if (!handlerChar) {
48 t_error("asctime_r_0100 failed: handlerChar is NULL\n");
49 continue;
50 }
51 setenv("TZ", handlerChar, 1);
52 tzset();
53 struct tm *timeptr = localtime(&gTime);
54 if (!timeptr) {
55 EXPECT_PTRNE("asctime_r_0100", timeptr, NULL);
56 return;
57 }
58 char s[gBufferSize];
59 char *returnStr = asctime_r(timeptr, s);
60 if (returnStr == NULL) {
61 EXPECT_FALSE("asctime_r_0100", returnStr == NULL);
62 return;
63 }
64
65 returnStr[strlen(returnStr) - 1] = 0x00;
66 EXPECT_STREQ("asctime_r_0100", test_asctime_data[i].result, returnStr);
67 }
68 }
69
main(void)70 int main(void)
71 {
72 asctime_r_0100();
73 return t_status;
74 }