• 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 static int16_t gBufferSize = 256;
23 
24 extern char *__ctime64_r (const time_t *, char *);
25 
26 /**
27  * @tc.name      : ctime_r_0100
28  * @tc.desc      : according to different time zones, covert date and time to string
29  * @tc.level     : Level 0
30  */
ctime_r_0100(void)31 void ctime_r_0100(void)
32 {
33     for (int32_t i = 0;i < (int32_t)(sizeof(test_asctime_data) / sizeof(test_asctime_data[0])); i++) {
34         const char *handlerChar = test_handle_path(test_asctime_data[i].tz);
35         if (!handlerChar) {
36             t_error("ctime_r_0100 failed: handlerChar is NULL\n");
37             continue;
38         }
39 
40         setenv("TZ", handlerChar, 1);
41         tzset();
42         char s[gBufferSize];
43         char *returnStr = ctime_r(&gTime, s);
44         if (returnStr == NULL) {
45             EXPECT_FALSE("ctime_r_0100", returnStr == NULL);
46             return;
47         }
48         returnStr[strlen(returnStr) - 1] = 0x00;
49         EXPECT_STREQ("ctime_r_0100", returnStr, test_asctime_data[i].result);
50         EXPECT_STREQ("ctime_r_0100", returnStr, s);
51     }
52 }
53 
54 /**
55  * @tc.name      : ctime64_r_0100
56  * @tc.desc      : according to different time zones, covert date and time to string
57  * @tc.level     : Level 0
58  */
ctime64_r_0100(void)59 void ctime64_r_0100(void)
60 {
61     for (int32_t i = 0;i < (int32_t)(sizeof(test_asctime_data) / sizeof(test_asctime_data[0])); i++) {
62         const char *handlerChar = test_handle_path(test_asctime_data[i].tz);
63         if (!handlerChar) {
64             t_error("ctime64_r_0100 failed: handlerChar is NULL\n");
65             continue;
66         }
67 
68         setenv("TZ", handlerChar, 1);
69         tzset();
70         char s[gBufferSize];
71         char *returnStr = __ctime64_r(&gTime, s);
72         if (returnStr == NULL) {
73             EXPECT_FALSE("ctime64_r_0100", returnStr == NULL);
74             return;
75         }
76         returnStr[strlen(returnStr) - 1] = 0x00;
77         EXPECT_STREQ("ctime64_r_0100", returnStr, test_asctime_data[i].result);
78         EXPECT_STREQ("ctime64_r_0100", returnStr, s);
79     }
80 }
81 
main(void)82 int main(void)
83 {
84     ctime_r_0100();
85     ctime64_r_0100();
86     return t_status;
87 }