• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23 /**
24  * @tc.name      : asctime_0100
25  * @tc.desc      : according to different time zones, take an argument representing broken-down time,
26  * which is a representation separated into year, month, day, and so on
27  * @tc.level     : Level 0
28  */
asctime_0100(void)29 void asctime_0100(void)
30 {
31     for (int32_t i = 0; i < (int32_t)(sizeof(test_asctime_data) / sizeof(test_asctime_data[0])); i++) {
32         const char *handlerChar = test_handle_path(test_asctime_data[i].tz);
33         if (!handlerChar) {
34             t_error("asctime_0100 failed: handlerChar is NULL\n");
35             continue;
36         }
37 
38         setenv("TZ", handlerChar, 1);
39         tzset();
40         struct tm *timeptr = localtime(&gTime);
41         if (!timeptr) {
42             EXPECT_PTRNE("asctime_0100", timeptr, NULL);
43             return;
44         }
45         char *returnStr = asctime(timeptr);
46         if (returnStr == NULL) {
47             EXPECT_FALSE("asctime_0100", returnStr == NULL);
48             return;
49         }
50         returnStr[strlen(returnStr) - 1] = 0x00;
51         EXPECT_STREQ("asctime_0100", test_asctime_data[i].result, returnStr);
52     }
53 }
54 
main(void)55 int main(void)
56 {
57     asctime_0100();
58     return t_status;
59 }