1570af302Sopenharmony_ci/**
2570af302Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3570af302Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4570af302Sopenharmony_ci * you may not use this file except in compliance with the License.
5570af302Sopenharmony_ci * You may obtain a copy of the License at
6570af302Sopenharmony_ci *
7570af302Sopenharmony_ci *   http://www.apache.org/licenses/LICENSE-2.0
8570af302Sopenharmony_ci *
9570af302Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10570af302Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11570af302Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12570af302Sopenharmony_ci * See the License for the specific language governing permissions and
13570af302Sopenharmony_ci * limitations under the License.
14570af302Sopenharmony_ci */
15570af302Sopenharmony_ci
16570af302Sopenharmony_ci#include <stdlib.h>
17570af302Sopenharmony_ci#include <time.h>
18570af302Sopenharmony_ci#include "asctime_data.h"
19570af302Sopenharmony_ci#include "functionalext.h"
20570af302Sopenharmony_ci#include "strftime_data.h"
21570af302Sopenharmony_ci
22570af302Sopenharmony_cistatic time_t gTime = 1659177614;
23570af302Sopenharmony_cistatic int16_t gBufferSize = 256;
24570af302Sopenharmony_ci
25570af302Sopenharmony_ci/**
26570af302Sopenharmony_ci * @tc.name      : strftime_0100
27570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
28570af302Sopenharmony_ci * @tc.level     : Level 0
29570af302Sopenharmony_ci */
30570af302Sopenharmony_civoid strftime_0100(void)
31570af302Sopenharmony_ci{
32570af302Sopenharmony_ci    for (int32_t i = 0; i < (int32_t)(sizeof(test_asctime_data) / sizeof(test_asctime_data[0])); i++) {
33570af302Sopenharmony_ci        const char *handlerChar = test_handle_path(test_asctime_data[i].tz);
34570af302Sopenharmony_ci        if (!handlerChar) {
35570af302Sopenharmony_ci            t_error("strftime_0100 failed: handlerChar is NULL\n");
36570af302Sopenharmony_ci            continue;
37570af302Sopenharmony_ci        }
38570af302Sopenharmony_ci
39570af302Sopenharmony_ci        setenv("TZ", handlerChar, 1);
40570af302Sopenharmony_ci        tzset();
41570af302Sopenharmony_ci        char buffer[gBufferSize];
42570af302Sopenharmony_ci        struct tm *timeptr = localtime(&gTime);
43570af302Sopenharmony_ci        if (!timeptr) {
44570af302Sopenharmony_ci            EXPECT_PTRNE("strftime_0100", timeptr, NULL);
45570af302Sopenharmony_ci            return;
46570af302Sopenharmony_ci        }
47570af302Sopenharmony_ci        size_t count = strftime(buffer, sizeof(buffer) - 1, "%c", timeptr);
48570af302Sopenharmony_ci        EXPECT_TRUE("strftime_0100", count > 0);
49570af302Sopenharmony_ci        EXPECT_STREQ("strftime_0100", buffer, test_asctime_data[i].result);
50570af302Sopenharmony_ci    }
51570af302Sopenharmony_ci}
52570af302Sopenharmony_ci
53570af302Sopenharmony_ci/**
54570af302Sopenharmony_ci * @tc.name      : strftime_0200
55570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
56570af302Sopenharmony_ci * @tc.level     : Level 0
57570af302Sopenharmony_ci */
58570af302Sopenharmony_civoid strftime_0200(void)
59570af302Sopenharmony_ci{
60570af302Sopenharmony_ci    for (int32_t i = 0; i < (int32_t)(sizeof(test_strftime_data) / sizeof(test_strftime_data[0])); i++) {
61570af302Sopenharmony_ci        const char *handlerChar = test_handle_path(test_strftime_data[i].tz);
62570af302Sopenharmony_ci        if (!handlerChar) {
63570af302Sopenharmony_ci            t_error("strftime_0200 failed: handlerChar is NULL\n");
64570af302Sopenharmony_ci            continue;
65570af302Sopenharmony_ci        }
66570af302Sopenharmony_ci
67570af302Sopenharmony_ci        setenv("TZ", handlerChar, 1);
68570af302Sopenharmony_ci        tzset();
69570af302Sopenharmony_ci        struct tm *timeptr = localtime(&gTime);
70570af302Sopenharmony_ci        if (!timeptr) {
71570af302Sopenharmony_ci            EXPECT_PTRNE("strftime_0200", timeptr, NULL);
72570af302Sopenharmony_ci            return;
73570af302Sopenharmony_ci        }
74570af302Sopenharmony_ci        char buffer[gBufferSize];
75570af302Sopenharmony_ci        size_t count = strftime(buffer, sizeof(buffer) - 1, "%c %Z%z", timeptr);
76570af302Sopenharmony_ci        EXPECT_TRUE("strftime_0200", count > 0);
77570af302Sopenharmony_ci        EXPECT_STREQ("strftime_0200", buffer, test_strftime_data[i].result);
78570af302Sopenharmony_ci    }
79570af302Sopenharmony_ci}
80570af302Sopenharmony_ci
81570af302Sopenharmony_ci/**
82570af302Sopenharmony_ci * @tc.name      : strftime_0300
83570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
84570af302Sopenharmony_ci * @tc.level     : Level 0
85570af302Sopenharmony_ci */
86570af302Sopenharmony_civoid strftime_0300(void)
87570af302Sopenharmony_ci{
88570af302Sopenharmony_ci    const char *handlerChar = test_handle_path("Pacific/Pitcairn");
89570af302Sopenharmony_ci    if (!handlerChar) {
90570af302Sopenharmony_ci        t_error("strftime_0300 failed: handlerChar is NULL\n");
91570af302Sopenharmony_ci        return;
92570af302Sopenharmony_ci    }
93570af302Sopenharmony_ci
94570af302Sopenharmony_ci    setenv("TZ", handlerChar, 1);
95570af302Sopenharmony_ci    tzset();
96570af302Sopenharmony_ci    struct tm *timeptr = localtime(&gTime);
97570af302Sopenharmony_ci    if (!timeptr) {
98570af302Sopenharmony_ci        EXPECT_PTRNE("strftime_0300", timeptr, NULL);
99570af302Sopenharmony_ci        return;
100570af302Sopenharmony_ci    }
101570af302Sopenharmony_ci    char buffer[gBufferSize];
102570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%k", timeptr);
103570af302Sopenharmony_ci    EXPECT_TRUE("strftime_0300", count > 0);
104570af302Sopenharmony_ci    EXPECT_STREQ("strftime_0300", buffer, " 2");
105570af302Sopenharmony_ci}
106570af302Sopenharmony_ci
107570af302Sopenharmony_ci/**
108570af302Sopenharmony_ci * @tc.name      : strftime_0400
109570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
110570af302Sopenharmony_ci * @tc.level     : Level 0
111570af302Sopenharmony_ci */
112570af302Sopenharmony_civoid strftime_0400(void)
113570af302Sopenharmony_ci{
114570af302Sopenharmony_ci    const char *handlerChar = test_handle_path("Asia/Shanghai");
115570af302Sopenharmony_ci    if (!handlerChar) {
116570af302Sopenharmony_ci        t_error("strftime_0400 failed: handlerChar is NULL\n");
117570af302Sopenharmony_ci        return;
118570af302Sopenharmony_ci    }
119570af302Sopenharmony_ci
120570af302Sopenharmony_ci    setenv("TZ", handlerChar, 1);
121570af302Sopenharmony_ci    tzset();
122570af302Sopenharmony_ci    struct tm *timeptr = localtime(&gTime);
123570af302Sopenharmony_ci    if (!timeptr) {
124570af302Sopenharmony_ci        EXPECT_PTRNE("strftime_0400", timeptr, NULL);
125570af302Sopenharmony_ci        return;
126570af302Sopenharmony_ci    }
127570af302Sopenharmony_ci    char buffer[gBufferSize];
128570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%k", timeptr);
129570af302Sopenharmony_ci    EXPECT_TRUE("strftime_0400", count > 0);
130570af302Sopenharmony_ci    EXPECT_STREQ("strftime_0400", buffer, "18");
131570af302Sopenharmony_ci}
132570af302Sopenharmony_ci
133570af302Sopenharmony_ci/**
134570af302Sopenharmony_ci * @tc.name      : strftime_0500
135570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
136570af302Sopenharmony_ci * @tc.level     : Level 0
137570af302Sopenharmony_ci */
138570af302Sopenharmony_civoid strftime_0500(void)
139570af302Sopenharmony_ci{
140570af302Sopenharmony_ci    const char *handlerChar = test_handle_path("Asia/Shanghai");
141570af302Sopenharmony_ci    if (!handlerChar) {
142570af302Sopenharmony_ci        t_error("strftime_0500 failed: handlerChar is NULL\n");
143570af302Sopenharmony_ci        return;
144570af302Sopenharmony_ci    }
145570af302Sopenharmony_ci
146570af302Sopenharmony_ci    setenv("TZ", handlerChar, 1);
147570af302Sopenharmony_ci    tzset();
148570af302Sopenharmony_ci    struct tm *timeptr = localtime(&gTime);
149570af302Sopenharmony_ci    if (!timeptr) {
150570af302Sopenharmony_ci        EXPECT_PTRNE("strftime_0500", timeptr, NULL);
151570af302Sopenharmony_ci        return;
152570af302Sopenharmony_ci    }
153570af302Sopenharmony_ci    char buffer[gBufferSize];
154570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%I", timeptr);
155570af302Sopenharmony_ci    EXPECT_TRUE("strftime_0500", count > 0);
156570af302Sopenharmony_ci    EXPECT_STREQ("strftime_0500", buffer, "06");
157570af302Sopenharmony_ci}
158570af302Sopenharmony_ci
159570af302Sopenharmony_ci/**
160570af302Sopenharmony_ci * @tc.name      : strftime_0600
161570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
162570af302Sopenharmony_ci * @tc.level     : Level 0
163570af302Sopenharmony_ci */
164570af302Sopenharmony_civoid strftime_0600(void)
165570af302Sopenharmony_ci{
166570af302Sopenharmony_ci    const char *handlerChar = test_handle_path("Asia/Shanghai");
167570af302Sopenharmony_ci    if (!handlerChar) {
168570af302Sopenharmony_ci        t_error("strftime_0600 failed: handlerChar is NULL\n");
169570af302Sopenharmony_ci        return;
170570af302Sopenharmony_ci    }
171570af302Sopenharmony_ci
172570af302Sopenharmony_ci    setenv("TZ", handlerChar, 1);
173570af302Sopenharmony_ci    tzset();
174570af302Sopenharmony_ci    struct tm *timeptr = localtime(&gTime);
175570af302Sopenharmony_ci    if (!timeptr) {
176570af302Sopenharmony_ci        EXPECT_PTRNE("strftime_0600", timeptr, NULL);
177570af302Sopenharmony_ci        return;
178570af302Sopenharmony_ci    }
179570af302Sopenharmony_ci    char buffer[gBufferSize];
180570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%P", timeptr);
181570af302Sopenharmony_ci    EXPECT_TRUE("strftime_0600", count > 0);
182570af302Sopenharmony_ci    EXPECT_STREQ("strftime_0600", buffer, "pm");
183570af302Sopenharmony_ci}
184570af302Sopenharmony_ci
185570af302Sopenharmony_ci/**
186570af302Sopenharmony_ci * @tc.name      : strftime_0700
187570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
188570af302Sopenharmony_ci * @tc.level     : Level 0
189570af302Sopenharmony_ci */
190570af302Sopenharmony_civoid strftime_0700(void)
191570af302Sopenharmony_ci{
192570af302Sopenharmony_ci    const char *handlerChar = test_handle_path("Asia/Shanghai");
193570af302Sopenharmony_ci    if (!handlerChar) {
194570af302Sopenharmony_ci        t_error("strftime_0700 failed: handlerChar is NULL\n");
195570af302Sopenharmony_ci        return;
196570af302Sopenharmony_ci    }
197570af302Sopenharmony_ci
198570af302Sopenharmony_ci    setenv("TZ", handlerChar, 1);
199570af302Sopenharmony_ci    tzset();
200570af302Sopenharmony_ci    struct tm *timeptr = localtime(&gTime);
201570af302Sopenharmony_ci    if (!timeptr) {
202570af302Sopenharmony_ci        EXPECT_PTRNE("strftime_0700", timeptr, NULL);
203570af302Sopenharmony_ci        return;
204570af302Sopenharmony_ci    }
205570af302Sopenharmony_ci    char buffer[gBufferSize];
206570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%v", timeptr);
207570af302Sopenharmony_ci    EXPECT_TRUE("strftime_0700", count > 0);
208570af302Sopenharmony_ci    EXPECT_STREQ("strftime_0700", buffer, "30-Jul-2022");
209570af302Sopenharmony_ci}
210570af302Sopenharmony_ci
211570af302Sopenharmony_ci/**
212570af302Sopenharmony_ci * @tc.name      : strftime_0800
213570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
214570af302Sopenharmony_ci * @tc.level     : Level 0
215570af302Sopenharmony_ci */
216570af302Sopenharmony_civoid strftime_0800(void)
217570af302Sopenharmony_ci{
218570af302Sopenharmony_ci    const char *handlerChar = test_handle_path("Asia/Shanghai");
219570af302Sopenharmony_ci    if (!handlerChar) {
220570af302Sopenharmony_ci        t_error("strftime_0800 failed: handlerChar is NULL\n");
221570af302Sopenharmony_ci        return;
222570af302Sopenharmony_ci    }
223570af302Sopenharmony_ci
224570af302Sopenharmony_ci    setenv("TZ", handlerChar, 1);
225570af302Sopenharmony_ci    tzset();
226570af302Sopenharmony_ci    struct tm *timeptr = localtime(&gTime);
227570af302Sopenharmony_ci    if (!timeptr) {
228570af302Sopenharmony_ci        EXPECT_PTRNE("strftime_0800", timeptr, NULL);
229570af302Sopenharmony_ci        return;
230570af302Sopenharmony_ci    }
231570af302Sopenharmony_ci    char buffer[gBufferSize];
232570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%j", timeptr);
233570af302Sopenharmony_ci    EXPECT_TRUE("strftime_0800", count > 0);
234570af302Sopenharmony_ci    EXPECT_STREQ("strftime_0800", buffer, "211");
235570af302Sopenharmony_ci}
236570af302Sopenharmony_ci
237570af302Sopenharmony_ci/**
238570af302Sopenharmony_ci * @tc.name      : strftime_0900
239570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
240570af302Sopenharmony_ci * @tc.level     : Level 0
241570af302Sopenharmony_ci */
242570af302Sopenharmony_civoid strftime_0900(void)
243570af302Sopenharmony_ci{
244570af302Sopenharmony_ci    const char *handlerChar = test_handle_path("Asia/Shanghai");
245570af302Sopenharmony_ci    if (!handlerChar) {
246570af302Sopenharmony_ci        t_error("strftime_0900 failed: handlerChar is NULL\n");
247570af302Sopenharmony_ci        return;
248570af302Sopenharmony_ci    }
249570af302Sopenharmony_ci
250570af302Sopenharmony_ci    setenv("TZ", handlerChar, 1);
251570af302Sopenharmony_ci    tzset();
252570af302Sopenharmony_ci    struct tm *timeptr = localtime(&gTime);
253570af302Sopenharmony_ci    if (!timeptr) {
254570af302Sopenharmony_ci        EXPECT_PTRNE("strftime_0900", timeptr, NULL);
255570af302Sopenharmony_ci        return;
256570af302Sopenharmony_ci    }
257570af302Sopenharmony_ci    char buffer[gBufferSize];
258570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%l", timeptr);
259570af302Sopenharmony_ci    EXPECT_TRUE("strftime_0900", count > 0);
260570af302Sopenharmony_ci    EXPECT_STREQ("strftime_0900", buffer, " 6");
261570af302Sopenharmony_ci}
262570af302Sopenharmony_ci
263570af302Sopenharmony_ci/**
264570af302Sopenharmony_ci * @tc.name      : strftime_1000
265570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
266570af302Sopenharmony_ci * @tc.level     : Level 0
267570af302Sopenharmony_ci */
268570af302Sopenharmony_civoid strftime_1000(void)
269570af302Sopenharmony_ci{
270570af302Sopenharmony_ci    const char *handlerChar = test_handle_path("Asia/Shanghai");
271570af302Sopenharmony_ci    if (!handlerChar) {
272570af302Sopenharmony_ci        t_error("strftime_1000 failed: handlerChar is NULL\n");
273570af302Sopenharmony_ci        return;
274570af302Sopenharmony_ci    }
275570af302Sopenharmony_ci
276570af302Sopenharmony_ci    setenv("TZ", handlerChar, 1);
277570af302Sopenharmony_ci    tzset();
278570af302Sopenharmony_ci    struct tm *timeptr = localtime(&gTime);
279570af302Sopenharmony_ci    if (!timeptr) {
280570af302Sopenharmony_ci        EXPECT_PTRNE("strftime_1000", timeptr, NULL);
281570af302Sopenharmony_ci        return;
282570af302Sopenharmony_ci    }
283570af302Sopenharmony_ci    timeptr->tm_mday = 31;
284570af302Sopenharmony_ci    timeptr->tm_mon = 11;
285570af302Sopenharmony_ci    timeptr->tm_year = 124;
286570af302Sopenharmony_ci    timeptr->tm_wday = 2;
287570af302Sopenharmony_ci    timeptr->tm_yday = 365;
288570af302Sopenharmony_ci
289570af302Sopenharmony_ci    char buffer[gBufferSize];
290570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%V", timeptr);
291570af302Sopenharmony_ci    EXPECT_TRUE("strftime_1000", count > 0);
292570af302Sopenharmony_ci    EXPECT_STREQ("strftime_1000", buffer, "01");
293570af302Sopenharmony_ci}
294570af302Sopenharmony_ci
295570af302Sopenharmony_ci/**
296570af302Sopenharmony_ci * @tc.name      : strftime_1100
297570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
298570af302Sopenharmony_ci * @tc.level     : Level 0
299570af302Sopenharmony_ci */
300570af302Sopenharmony_civoid strftime_1100(void)
301570af302Sopenharmony_ci{
302570af302Sopenharmony_ci    struct tm tm = {0};
303570af302Sopenharmony_ci    char buffer[gBufferSize];
304570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%l", &tm);
305570af302Sopenharmony_ci    EXPECT_TRUE("strftime_1100", count > 0);
306570af302Sopenharmony_ci    EXPECT_STREQ("strftime_1100", buffer, "12");
307570af302Sopenharmony_ci}
308570af302Sopenharmony_ci
309570af302Sopenharmony_ci/**
310570af302Sopenharmony_ci * @tc.name      : strftime_1200
311570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
312570af302Sopenharmony_ci * @tc.level     : Level 0
313570af302Sopenharmony_ci */
314570af302Sopenharmony_civoid strftime_1200(void)
315570af302Sopenharmony_ci{
316570af302Sopenharmony_ci    const char *handlerChar = test_handle_path("Asia/Shanghai");
317570af302Sopenharmony_ci    if (!handlerChar) {
318570af302Sopenharmony_ci        t_error("strftime_1200 failed: handlerChar is NULL\n");
319570af302Sopenharmony_ci        return;
320570af302Sopenharmony_ci    }
321570af302Sopenharmony_ci
322570af302Sopenharmony_ci    setenv("TZ", handlerChar, 1);
323570af302Sopenharmony_ci    tzset();
324570af302Sopenharmony_ci    struct tm *timeptr = localtime(&gTime);
325570af302Sopenharmony_ci    if (!timeptr) {
326570af302Sopenharmony_ci        EXPECT_PTRNE("strftime_1200", timeptr, NULL);
327570af302Sopenharmony_ci        return;
328570af302Sopenharmony_ci    }
329570af302Sopenharmony_ci    timeptr->tm_mday = 28;
330570af302Sopenharmony_ci    timeptr->tm_mon = 12;
331570af302Sopenharmony_ci    timeptr->tm_year = 200;
332570af302Sopenharmony_ci    timeptr->tm_wday = 1;
333570af302Sopenharmony_ci    timeptr->tm_yday = 362;
334570af302Sopenharmony_ci
335570af302Sopenharmony_ci    char buffer[gBufferSize];
336570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%G", timeptr);
337570af302Sopenharmony_ci    EXPECT_TRUE("strftime_1200", count > 0);
338570af302Sopenharmony_ci    EXPECT_STREQ("strftime_1200", buffer, "2101");
339570af302Sopenharmony_ci}
340570af302Sopenharmony_ci
341570af302Sopenharmony_ci/**
342570af302Sopenharmony_ci * @tc.name      : strftime_1300
343570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
344570af302Sopenharmony_ci * @tc.level     : Level 1
345570af302Sopenharmony_ci */
346570af302Sopenharmony_civoid strftime_1300(void)
347570af302Sopenharmony_ci{
348570af302Sopenharmony_ci    const char *handlerChar = test_handle_path("Asia/Shanghai");
349570af302Sopenharmony_ci    if (!handlerChar) {
350570af302Sopenharmony_ci        t_error("strftime_1300 failed: handlerChar is NULL\n");
351570af302Sopenharmony_ci        return;
352570af302Sopenharmony_ci    }
353570af302Sopenharmony_ci
354570af302Sopenharmony_ci    setenv("TZ", handlerChar, 1);
355570af302Sopenharmony_ci    tzset();
356570af302Sopenharmony_ci    struct tm *timeptr = localtime(&gTime);
357570af302Sopenharmony_ci    if (!timeptr) {
358570af302Sopenharmony_ci        EXPECT_PTRNE("strftime_1300", timeptr, NULL);
359570af302Sopenharmony_ci        return;
360570af302Sopenharmony_ci    }
361570af302Sopenharmony_ci    timeptr->tm_mday = 28;
362570af302Sopenharmony_ci    timeptr->tm_mon = 12;
363570af302Sopenharmony_ci    timeptr->tm_year = 100;
364570af302Sopenharmony_ci    timeptr->tm_wday = 1;
365570af302Sopenharmony_ci    timeptr->tm_yday = 362;
366570af302Sopenharmony_ci
367570af302Sopenharmony_ci    char buffer[gBufferSize];
368570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%G", timeptr);
369570af302Sopenharmony_ci    EXPECT_TRUE("strftime_1300", count > 0);
370570af302Sopenharmony_ci    EXPECT_STREQ("strftime_1300", buffer, "2000");
371570af302Sopenharmony_ci}
372570af302Sopenharmony_ci
373570af302Sopenharmony_ci/**
374570af302Sopenharmony_ci * @tc.name      : strftime_1400
375570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
376570af302Sopenharmony_ci * @tc.level     : Level 1
377570af302Sopenharmony_ci */
378570af302Sopenharmony_civoid strftime_1400(void)
379570af302Sopenharmony_ci{
380570af302Sopenharmony_ci    const char *handlerChar = test_handle_path("Asia/Shanghai");
381570af302Sopenharmony_ci    if (!handlerChar) {
382570af302Sopenharmony_ci        t_error("strftime_1400 failed: handlerChar is NULL\n");
383570af302Sopenharmony_ci        return;
384570af302Sopenharmony_ci    }
385570af302Sopenharmony_ci
386570af302Sopenharmony_ci    setenv("TZ", handlerChar, 1);
387570af302Sopenharmony_ci    tzset();
388570af302Sopenharmony_ci    struct tm *timeptr = localtime(&gTime);
389570af302Sopenharmony_ci    if (!timeptr) {
390570af302Sopenharmony_ci        EXPECT_PTRNE("strftime_1400", timeptr, NULL);
391570af302Sopenharmony_ci        return;
392570af302Sopenharmony_ci    }
393570af302Sopenharmony_ci    timeptr->tm_mday = 28;
394570af302Sopenharmony_ci    timeptr->tm_mon = 12;
395570af302Sopenharmony_ci    timeptr->tm_year = 101;
396570af302Sopenharmony_ci    timeptr->tm_wday = 1;
397570af302Sopenharmony_ci    timeptr->tm_yday = 362;
398570af302Sopenharmony_ci
399570af302Sopenharmony_ci    char buffer[gBufferSize];
400570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%G", timeptr);
401570af302Sopenharmony_ci    EXPECT_TRUE("strftime_1400", count > 0);
402570af302Sopenharmony_ci    EXPECT_STREQ("strftime_1400", buffer, "2002");
403570af302Sopenharmony_ci}
404570af302Sopenharmony_ci
405570af302Sopenharmony_ci/**
406570af302Sopenharmony_ci * @tc.name      : strftime_1500
407570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
408570af302Sopenharmony_ci * @tc.level     : Level 1
409570af302Sopenharmony_ci */
410570af302Sopenharmony_civoid strftime_1500(void)
411570af302Sopenharmony_ci{
412570af302Sopenharmony_ci    const char *handlerChar = test_handle_path("Asia/Shanghai");
413570af302Sopenharmony_ci    if (!handlerChar) {
414570af302Sopenharmony_ci        t_error("strftime_1500 failed: handlerChar is NULL\n");
415570af302Sopenharmony_ci        return;
416570af302Sopenharmony_ci    }
417570af302Sopenharmony_ci
418570af302Sopenharmony_ci    setenv("TZ", handlerChar, 1);
419570af302Sopenharmony_ci    tzset();
420570af302Sopenharmony_ci    struct tm *timeptr = localtime(&gTime);
421570af302Sopenharmony_ci    if (!timeptr) {
422570af302Sopenharmony_ci        EXPECT_PTRNE("strftime_1500", timeptr, NULL);
423570af302Sopenharmony_ci        return;
424570af302Sopenharmony_ci    }
425570af302Sopenharmony_ci
426570af302Sopenharmony_ci    char buffer[gBufferSize];
427570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%B", timeptr);
428570af302Sopenharmony_ci    EXPECT_TRUE("strftime_1500", count > 0);
429570af302Sopenharmony_ci    EXPECT_STREQ("strftime_1500", buffer, "July");
430570af302Sopenharmony_ci}
431570af302Sopenharmony_ci
432570af302Sopenharmony_ci/**
433570af302Sopenharmony_ci * @tc.name      : strftime_1600
434570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
435570af302Sopenharmony_ci * @tc.level     : Level 1
436570af302Sopenharmony_ci */
437570af302Sopenharmony_civoid strftime_1600(void)
438570af302Sopenharmony_ci{
439570af302Sopenharmony_ci    const char *handlerChar = test_handle_path("Asia/Shanghai");
440570af302Sopenharmony_ci    if (!handlerChar) {
441570af302Sopenharmony_ci        t_error("strftime_1600 failed: handlerChar is NULL\n");
442570af302Sopenharmony_ci        return;
443570af302Sopenharmony_ci    }
444570af302Sopenharmony_ci
445570af302Sopenharmony_ci    setenv("TZ", handlerChar, 1);
446570af302Sopenharmony_ci    tzset();
447570af302Sopenharmony_ci    struct tm *timeptr = localtime(&gTime);
448570af302Sopenharmony_ci    if (!timeptr) {
449570af302Sopenharmony_ci        EXPECT_PTRNE("strftime_1600", timeptr, NULL);
450570af302Sopenharmony_ci        return;
451570af302Sopenharmony_ci    }
452570af302Sopenharmony_ci    timeptr->tm_mon = 12;
453570af302Sopenharmony_ci
454570af302Sopenharmony_ci    char buffer[gBufferSize];
455570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%B", timeptr);
456570af302Sopenharmony_ci    EXPECT_TRUE("strftime_1600", count > 0);
457570af302Sopenharmony_ci    EXPECT_STREQ("strftime_1600", buffer, "-");
458570af302Sopenharmony_ci}
459570af302Sopenharmony_ci
460570af302Sopenharmony_ci/**
461570af302Sopenharmony_ci * @tc.name      : strftime_1700
462570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
463570af302Sopenharmony_ci * @tc.level     : Level 1
464570af302Sopenharmony_ci */
465570af302Sopenharmony_civoid strftime_1700(void)
466570af302Sopenharmony_ci{
467570af302Sopenharmony_ci    struct tm tm = {0};
468570af302Sopenharmony_ci    tm.tm_hour = 13;
469570af302Sopenharmony_ci    char buffer[gBufferSize];
470570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%l", &tm);
471570af302Sopenharmony_ci    EXPECT_TRUE("strftime_1700", count > 0);
472570af302Sopenharmony_ci    EXPECT_STREQ("strftime_1700", buffer, " 1");
473570af302Sopenharmony_ci}
474570af302Sopenharmony_ci
475570af302Sopenharmony_ci/**
476570af302Sopenharmony_ci * @tc.name      : strftime_1800
477570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
478570af302Sopenharmony_ci * @tc.level     : Level 1
479570af302Sopenharmony_ci */
480570af302Sopenharmony_civoid strftime_1800(void)
481570af302Sopenharmony_ci{
482570af302Sopenharmony_ci    struct tm tm = {0};
483570af302Sopenharmony_ci    char buffer[gBufferSize];
484570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%u", &tm);
485570af302Sopenharmony_ci    EXPECT_TRUE("strftime_1800", count > 0);
486570af302Sopenharmony_ci    EXPECT_STREQ("strftime_1800", buffer, "7");
487570af302Sopenharmony_ci}
488570af302Sopenharmony_ci
489570af302Sopenharmony_ci/**
490570af302Sopenharmony_ci * @tc.name      : strftime_1900
491570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
492570af302Sopenharmony_ci * @tc.level     : Level 1
493570af302Sopenharmony_ci */
494570af302Sopenharmony_civoid strftime_1900(void)
495570af302Sopenharmony_ci{
496570af302Sopenharmony_ci    struct tm tm = {0};
497570af302Sopenharmony_ci    tm.tm_wday = 3;
498570af302Sopenharmony_ci    char buffer[gBufferSize];
499570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%u", &tm);
500570af302Sopenharmony_ci    EXPECT_TRUE("strftime_1900", count > 0);
501570af302Sopenharmony_ci    EXPECT_STREQ("strftime_1900", buffer, "3");
502570af302Sopenharmony_ci}
503570af302Sopenharmony_ci
504570af302Sopenharmony_ci/**
505570af302Sopenharmony_ci * @tc.name      : strftime_2000
506570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
507570af302Sopenharmony_ci * @tc.level     : Level 1
508570af302Sopenharmony_ci */
509570af302Sopenharmony_civoid strftime_2000(void)
510570af302Sopenharmony_ci{
511570af302Sopenharmony_ci    struct tm tm = {0};
512570af302Sopenharmony_ci    tm.tm_year = -1999;
513570af302Sopenharmony_ci    char buffer[gBufferSize];
514570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%-y", &tm);
515570af302Sopenharmony_ci    EXPECT_TRUE("strftime_2000", count > 0);
516570af302Sopenharmony_ci    EXPECT_STREQ("strftime_2000", buffer, "99");
517570af302Sopenharmony_ci}
518570af302Sopenharmony_ci
519570af302Sopenharmony_ci/**
520570af302Sopenharmony_ci * @tc.name      : strftime_2100
521570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
522570af302Sopenharmony_ci * @tc.level     : Level 1
523570af302Sopenharmony_ci */
524570af302Sopenharmony_civoid strftime_2100(void)
525570af302Sopenharmony_ci{
526570af302Sopenharmony_ci    struct tm tm = {0};
527570af302Sopenharmony_ci    tm.tm_isdst = -1;
528570af302Sopenharmony_ci    char buffer[gBufferSize];
529570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%z", &tm);
530570af302Sopenharmony_ci    EXPECT_TRUE("strftime_2100", count == 0);
531570af302Sopenharmony_ci    EXPECT_STREQ("strftime_2100", buffer, "");
532570af302Sopenharmony_ci}
533570af302Sopenharmony_ci
534570af302Sopenharmony_ci/**
535570af302Sopenharmony_ci * @tc.name      : strftime_2200
536570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
537570af302Sopenharmony_ci * @tc.level     : Level 1
538570af302Sopenharmony_ci */
539570af302Sopenharmony_civoid strftime_2200(void)
540570af302Sopenharmony_ci{
541570af302Sopenharmony_ci    struct tm tm = {0};
542570af302Sopenharmony_ci    tm.tm_isdst = -1;
543570af302Sopenharmony_ci    char buffer[gBufferSize];
544570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%Z", &tm);
545570af302Sopenharmony_ci    EXPECT_TRUE("strftime_2200", count == 0);
546570af302Sopenharmony_ci    EXPECT_STREQ("strftime_2200", buffer, "");
547570af302Sopenharmony_ci}
548570af302Sopenharmony_ci
549570af302Sopenharmony_ci/**
550570af302Sopenharmony_ci * @tc.name      : strftime_2300
551570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
552570af302Sopenharmony_ci * @tc.level     : Level 1
553570af302Sopenharmony_ci */
554570af302Sopenharmony_civoid strftime_2300(void)
555570af302Sopenharmony_ci{
556570af302Sopenharmony_ci    struct tm tm = {0};
557570af302Sopenharmony_ci    char buffer[gBufferSize];
558570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%E%", &tm);
559570af302Sopenharmony_ci    EXPECT_TRUE("strftime_2300", count > 0);
560570af302Sopenharmony_ci    EXPECT_STREQ("strftime_2300", buffer, "%");
561570af302Sopenharmony_ci}
562570af302Sopenharmony_ci
563570af302Sopenharmony_ci/**
564570af302Sopenharmony_ci * @tc.name      : strftime_2200
565570af302Sopenharmony_ci * @tc.desc      : according to different time zones, format date
566570af302Sopenharmony_ci * @tc.level     : Level 1
567570af302Sopenharmony_ci */
568570af302Sopenharmony_civoid strftime_2400(void)
569570af302Sopenharmony_ci{
570570af302Sopenharmony_ci    struct tm tm = {0};
571570af302Sopenharmony_ci    char buffer[gBufferSize];
572570af302Sopenharmony_ci    size_t count = strftime(buffer, sizeof(buffer) - 1, "%O%", &tm);
573570af302Sopenharmony_ci    EXPECT_TRUE("strftime_2400", count > 0);
574570af302Sopenharmony_ci    EXPECT_STREQ("strftime_2400", buffer, "%");
575570af302Sopenharmony_ci}
576570af302Sopenharmony_ci
577570af302Sopenharmony_ciint main(void)
578570af302Sopenharmony_ci{
579570af302Sopenharmony_ci    strftime_0100();
580570af302Sopenharmony_ci    strftime_0200();
581570af302Sopenharmony_ci    strftime_0300();
582570af302Sopenharmony_ci    strftime_0400();
583570af302Sopenharmony_ci    strftime_0500();
584570af302Sopenharmony_ci    strftime_0600();
585570af302Sopenharmony_ci    strftime_0700();
586570af302Sopenharmony_ci    strftime_0800();
587570af302Sopenharmony_ci    strftime_0900();
588570af302Sopenharmony_ci    strftime_1000();
589570af302Sopenharmony_ci    strftime_1100();
590570af302Sopenharmony_ci    strftime_1200();
591570af302Sopenharmony_ci    strftime_1300();
592570af302Sopenharmony_ci    strftime_1400();
593570af302Sopenharmony_ci    strftime_1500();
594570af302Sopenharmony_ci    strftime_1600();
595570af302Sopenharmony_ci    strftime_1700();
596570af302Sopenharmony_ci    strftime_1800();
597570af302Sopenharmony_ci    strftime_1900();
598570af302Sopenharmony_ci    strftime_2000();
599570af302Sopenharmony_ci    strftime_2100();
600570af302Sopenharmony_ci    strftime_2200();
601570af302Sopenharmony_ci    strftime_2300();
602570af302Sopenharmony_ci    strftime_2400();
603570af302Sopenharmony_ci    return t_status;
604570af302Sopenharmony_ci}