1f6603c60Sopenharmony_ci/*
2f6603c60Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License.
5f6603c60Sopenharmony_ci * You may obtain a copy of the License at
6f6603c60Sopenharmony_ci *
7f6603c60Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8f6603c60Sopenharmony_ci *
9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and
13f6603c60Sopenharmony_ci * limitations under the License.
14f6603c60Sopenharmony_ci */
15f6603c60Sopenharmony_ci
16f6603c60Sopenharmony_ci#include <stdio.h>
17f6603c60Sopenharmony_ci#include <stdlib.h>
18f6603c60Sopenharmony_ci#include <time.h>
19f6603c60Sopenharmony_ci
20f6603c60Sopenharmony_ci#include <limits.h>
21f6603c60Sopenharmony_ci#include "gtest/gtest.h"
22f6603c60Sopenharmony_ci#include "log.h"
23f6603c60Sopenharmony_ci
24f6603c60Sopenharmony_ciusing namespace testing::ext;
25f6603c60Sopenharmony_citime_t g_time = 18880;
26f6603c60Sopenharmony_cisize_t g_zero = 0;
27f6603c60Sopenharmony_ciclass TimeUtilsTest : public testing::Test {
28f6603c60Sopenharmony_ci};
29f6603c60Sopenharmony_ci
30f6603c60Sopenharmony_ci/**
31f6603c60Sopenharmony_ci* @tc.number     SUB_KERNEL_TIME_API_ASCTIME_0100
32f6603c60Sopenharmony_ci* @tc.name       test asctime api
33f6603c60Sopenharmony_ci* @tc.desc       [C- SOFTWARE -0200]
34f6603c60Sopenharmony_ci*/
35f6603c60Sopenharmony_ciHWTEST_F(TimeUtilsTest, testAscTime, Function | MediumTest | Level1)
36f6603c60Sopenharmony_ci{
37f6603c60Sopenharmony_ci    struct tm timeptr = {0};
38f6603c60Sopenharmony_ci    timeptr.tm_sec = 0;
39f6603c60Sopenharmony_ci    timeptr.tm_min = 10;
40f6603c60Sopenharmony_ci    timeptr.tm_hour = 10;
41f6603c60Sopenharmony_ci    timeptr.tm_mday = 9;
42f6603c60Sopenharmony_ci    timeptr.tm_mon = 7;
43f6603c60Sopenharmony_ci    timeptr.tm_year = 120;
44f6603c60Sopenharmony_ci    timeptr.tm_wday = 7;
45f6603c60Sopenharmony_ci
46f6603c60Sopenharmony_ci    char * returnStr = asctime(&timeptr);
47f6603c60Sopenharmony_ci    LOG("    asctime &timeptr:='{timeptr.tm_year=%d timeptr.tm_mon=%d timeptr.tm_mday=%d}'   "
48f6603c60Sopenharmony_ci        "--> returnStr:='%s'\n", timeptr.tm_year, timeptr.tm_mon, timeptr.tm_mday, returnStr);
49f6603c60Sopenharmony_ci    EXPECT_STREQ("Sun Aug  9 10:10:00 2020\n", returnStr)
50f6603c60Sopenharmony_ci        << "ErrInfo: asctime &timeptr:='{timeptr.tm_year=" << timeptr.tm_year
51f6603c60Sopenharmony_ci        << " timeptr.tm_mon=" << timeptr.tm_mon << "' timeptr.tm_mday=" << timeptr.tm_mday
52f6603c60Sopenharmony_ci        << "}'   --> returnStr:='" << returnStr << "'";
53f6603c60Sopenharmony_ci}
54f6603c60Sopenharmony_ci
55f6603c60Sopenharmony_ci/**
56f6603c60Sopenharmony_ci* @tc.number     SUB_KERNEL_TIME_API_ASCTIMER_0100
57f6603c60Sopenharmony_ci* @tc.name       test asctimer api
58f6603c60Sopenharmony_ci* @tc.desc       [C- SOFTWARE -0200]
59f6603c60Sopenharmony_ci*/
60f6603c60Sopenharmony_ciHWTEST_F(TimeUtilsTest, testAscTimeR, Function | MediumTest | Level1)
61f6603c60Sopenharmony_ci{
62f6603c60Sopenharmony_ci    struct tm timeptr = {0};
63f6603c60Sopenharmony_ci    timeptr.tm_sec = 0;
64f6603c60Sopenharmony_ci    timeptr.tm_min = 10;
65f6603c60Sopenharmony_ci    timeptr.tm_hour = 10;
66f6603c60Sopenharmony_ci    timeptr.tm_mday = 9;
67f6603c60Sopenharmony_ci    timeptr.tm_mon = 7;
68f6603c60Sopenharmony_ci    timeptr.tm_year = 120;
69f6603c60Sopenharmony_ci    timeptr.tm_wday = 7;
70f6603c60Sopenharmony_ci
71f6603c60Sopenharmony_ci    char str[26];
72f6603c60Sopenharmony_ci    char *returnStr = asctime_r(&timeptr, str);
73f6603c60Sopenharmony_ci    EXPECT_STREQ("Sun Aug  9 10:10:00 2020\n", returnStr) << "asctime_r return error!";
74f6603c60Sopenharmony_ci    EXPECT_STREQ(returnStr, str) << "asctime_r buf return error!";
75f6603c60Sopenharmony_ci}
76f6603c60Sopenharmony_ci
77f6603c60Sopenharmony_ci/**
78f6603c60Sopenharmony_ci* @tc.number     SUB_KERNEL_TIME_API_CTIME_0100
79f6603c60Sopenharmony_ci* @tc.name       test ctime api
80f6603c60Sopenharmony_ci* @tc.desc       [C- SOFTWARE -0200]
81f6603c60Sopenharmony_ci*/
82f6603c60Sopenharmony_ciHWTEST_F(TimeUtilsTest, testCtime, Function | MediumTest | Level2)
83f6603c60Sopenharmony_ci{
84f6603c60Sopenharmony_ci    time_t curClock;
85f6603c60Sopenharmony_ci    time(&curClock);
86f6603c60Sopenharmony_ci    char* returnStr = ctime(&curClock);
87f6603c60Sopenharmony_ci    LOG("returnStr = %s\n", returnStr);
88f6603c60Sopenharmony_ci    EXPECT_STRNE(returnStr, "") << "ctime return error!";
89f6603c60Sopenharmony_ci
90f6603c60Sopenharmony_ci    returnStr = ctime(&g_time);
91f6603c60Sopenharmony_ci    EXPECT_STREQ(returnStr, "Thu Jan  1 05:14:40 1970\n") << "ctime return error!";
92f6603c60Sopenharmony_ci}
93f6603c60Sopenharmony_ci
94f6603c60Sopenharmony_ci/**
95f6603c60Sopenharmony_ci* @tc.number     SUB_KERNEL_TIME_API_CTIME_R_0100
96f6603c60Sopenharmony_ci* @tc.name       test ctime_r api
97f6603c60Sopenharmony_ci* @tc.desc       [C- SOFTWARE -0200]
98f6603c60Sopenharmony_ci*/
99f6603c60Sopenharmony_ciHWTEST_F(TimeUtilsTest, testCtimeR, Function | MediumTest | Level3)
100f6603c60Sopenharmony_ci{
101f6603c60Sopenharmony_ci    time_t curClock;
102f6603c60Sopenharmony_ci    time(&curClock);
103f6603c60Sopenharmony_ci    char str[26];
104f6603c60Sopenharmony_ci    char *returnStr = ctime_r(&curClock, str);
105f6603c60Sopenharmony_ci    LOG("str = %s", str);
106f6603c60Sopenharmony_ci    EXPECT_STRNE(returnStr, "") << "ctime_r return error!";
107f6603c60Sopenharmony_ci    EXPECT_STREQ(returnStr, str) << "ctime_r returns not equal";
108f6603c60Sopenharmony_ci
109f6603c60Sopenharmony_ci    returnStr = ctime_r(&g_time, str);
110f6603c60Sopenharmony_ci    EXPECT_STREQ(returnStr, "Thu Jan  1 05:14:40 1970\n") << "ctime_r return error!";
111f6603c60Sopenharmony_ci    EXPECT_STREQ(returnStr, str) << "ctime_r returns not equal";
112f6603c60Sopenharmony_ci}
113f6603c60Sopenharmony_ci
114f6603c60Sopenharmony_ci/**
115f6603c60Sopenharmony_ci* @tc.number     SUB_KERNEL_NDKAPI_TIME_DIFFTIME_0100
116f6603c60Sopenharmony_ci* @tc.name       test difftime api
117f6603c60Sopenharmony_ci* @tc.desc       [C- SOFTWARE -0200]
118f6603c60Sopenharmony_ci*/
119f6603c60Sopenharmony_ciHWTEST_F(TimeUtilsTest, testDifftime, Function | MediumTest | Level2)
120f6603c60Sopenharmony_ci{
121f6603c60Sopenharmony_ci    time_t timeStart, timeEnd;
122f6603c60Sopenharmony_ci    double returnVal;
123f6603c60Sopenharmony_ci    time(&timeStart);
124f6603c60Sopenharmony_ci    sleep(1);
125f6603c60Sopenharmony_ci    time(&timeEnd);
126f6603c60Sopenharmony_ci    returnVal = difftime(timeEnd, timeStart);
127f6603c60Sopenharmony_ci    LOG("    difftime timeEnd:='%lld' timeStart:='%lld'   "
128f6603c60Sopenharmony_ci        "--> returnVal:='%f'\n", timeEnd, timeStart, returnVal);
129f6603c60Sopenharmony_ci    LOG("    sizeof timeEnd:='%d'   sizeof timeStart:='%d'\n", sizeof(timeEnd), sizeof(timeStart));
130f6603c60Sopenharmony_ci    EXPECT_GE(returnVal, 0)
131f6603c60Sopenharmony_ci        << "ErrInfo: difftime timeEnd:='" << timeEnd << "' timeStart:='"
132f6603c60Sopenharmony_ci        << timeStart << "'   --> returnVal:='" << returnVal << "'";
133f6603c60Sopenharmony_ci    EXPECT_LE(returnVal, 2)
134f6603c60Sopenharmony_ci        << "ErrInfo: difftime timeEnd:='" << timeEnd << "' timeStart:='"
135f6603c60Sopenharmony_ci        << timeStart << "'   --> returnVal:='" << returnVal << "'";
136f6603c60Sopenharmony_ci}
137f6603c60Sopenharmony_ci
138f6603c60Sopenharmony_ci/**
139f6603c60Sopenharmony_ci* @tc.number     SUB_KERNEL_NDKAPI_TIME_TIMEGM_0100
140f6603c60Sopenharmony_ci* @tc.name       test timegm api
141f6603c60Sopenharmony_ci* @tc.desc       [C- SOFTWARE -0200]
142f6603c60Sopenharmony_ci*/
143f6603c60Sopenharmony_ciHWTEST_F(TimeUtilsTest, testTimegm, Function | MediumTest | Level3)
144f6603c60Sopenharmony_ci{
145f6603c60Sopenharmony_ci    struct tm timeptr = {0};
146f6603c60Sopenharmony_ci    time_t timeThis;
147f6603c60Sopenharmony_ci    timeptr.tm_sec = 0;
148f6603c60Sopenharmony_ci    timeptr.tm_min = 10;
149f6603c60Sopenharmony_ci    timeptr.tm_hour = 10;
150f6603c60Sopenharmony_ci    timeptr.tm_mday = 9;
151f6603c60Sopenharmony_ci    timeptr.tm_mon = 7;
152f6603c60Sopenharmony_ci    timeptr.tm_year = 120;
153f6603c60Sopenharmony_ci    timeptr.tm_wday = 5;
154f6603c60Sopenharmony_ci
155f6603c60Sopenharmony_ci    timeThis = timegm(&timeptr);
156f6603c60Sopenharmony_ci    LOG("    timegm &timeptr:='{timeptr.tm_year=%d timeptr.tm_mon=%d timeptr.tm_mday=%d}'   "
157f6603c60Sopenharmony_ci        "--> return timeThis:='%lld'\n", timeptr.tm_year, timeptr.tm_mon, timeptr.tm_mday, timeThis);
158f6603c60Sopenharmony_ci    EXPECT_GE(timeThis, 1)
159f6603c60Sopenharmony_ci        << "ErrInfo: timegm &timeptr:='{timeptr.tm_year=" << timeptr.tm_year
160f6603c60Sopenharmony_ci        << " timeptr.tm_mon=" << timeptr.tm_mon << " timeptr.tm_mday="
161f6603c60Sopenharmony_ci        << timeptr.tm_mday << "}'   --> return timeThis:='" << timeThis << "'";
162f6603c60Sopenharmony_ci
163f6603c60Sopenharmony_ci    struct tm *stm2 = gmtime(&g_time);
164f6603c60Sopenharmony_ci    time_t timep = timegm(stm2);
165f6603c60Sopenharmony_ci    LOG("stm = %s;mktime:%ld\n", asctime(stm2), (long)timep);
166f6603c60Sopenharmony_ci    EXPECT_EQ(timep, g_time) << "timegm return error!";
167f6603c60Sopenharmony_ci}
168f6603c60Sopenharmony_ci
169f6603c60Sopenharmony_ci/**
170f6603c60Sopenharmony_ci* @tc.number     SUB_KERNEL_TIME_API_GMTIME_0100
171f6603c60Sopenharmony_ci* @tc.name       test gmtime api
172f6603c60Sopenharmony_ci* @tc.desc       [C- SOFTWARE -0200]
173f6603c60Sopenharmony_ci*/
174f6603c60Sopenharmony_ciHWTEST_F(TimeUtilsTest, testGmtime, Function | MediumTest | Level3)
175f6603c60Sopenharmony_ci{
176f6603c60Sopenharmony_ci    time_t time1 = 18880;
177f6603c60Sopenharmony_ci    struct tm *stm = gmtime(&time1);
178f6603c60Sopenharmony_ci    ASSERT_NE(nullptr, stm);
179f6603c60Sopenharmony_ci    EXPECT_EQ(stm->tm_hour, 05) << "gmtime return error!";
180f6603c60Sopenharmony_ci    EXPECT_STREQ(asctime(stm), "Thu Jan  1 05:14:40 1970\n") << "gmtime return error!";
181f6603c60Sopenharmony_ci
182f6603c60Sopenharmony_ci    time1 = LONG_MAX;
183f6603c60Sopenharmony_ci    stm = gmtime(&time1);
184f6603c60Sopenharmony_ci    ASSERT_NE(nullptr, stm);
185f6603c60Sopenharmony_ci    EXPECT_STREQ(asctime(stm), "Tue Jan 19 03:14:07 2038\n") << "gmtime return error!";
186f6603c60Sopenharmony_ci
187f6603c60Sopenharmony_ci    time1 = 253402300799;
188f6603c60Sopenharmony_ci    stm = gmtime(&time1);
189f6603c60Sopenharmony_ci    ASSERT_NE(nullptr, stm);
190f6603c60Sopenharmony_ci    EXPECT_STREQ(asctime(stm), "Fri Dec 31 23:59:59 9999\n") << "gmtime return error!";
191f6603c60Sopenharmony_ci
192f6603c60Sopenharmony_ci    time1 = LONG_MIN;
193f6603c60Sopenharmony_ci    stm = gmtime(&time1);
194f6603c60Sopenharmony_ci    ASSERT_NE(nullptr, stm);
195f6603c60Sopenharmony_ci    EXPECT_STREQ(asctime(stm), "Fri Dec 13 20:45:52 1901\n") << "gmtime return error!";
196f6603c60Sopenharmony_ci}
197f6603c60Sopenharmony_ci
198f6603c60Sopenharmony_ci/**
199f6603c60Sopenharmony_ci* @tc.number     SUB_KERNEL_TIME_API_GMTIMER_0100
200f6603c60Sopenharmony_ci* @tc.name       test gmtime_r api
201f6603c60Sopenharmony_ci* @tc.desc       [C- SOFTWARE -0200]
202f6603c60Sopenharmony_ci*/
203f6603c60Sopenharmony_ciHWTEST_F(TimeUtilsTest, testGmtimeR, Function | MediumTest | Level3)
204f6603c60Sopenharmony_ci{
205f6603c60Sopenharmony_ci    struct tm res = {0};
206f6603c60Sopenharmony_ci    struct tm *stm = gmtime_r(&g_time, &res);
207f6603c60Sopenharmony_ci    ASSERT_NE(nullptr, stm);
208f6603c60Sopenharmony_ci    EXPECT_EQ(stm->tm_hour, 05) << "gmtime_r return error!";
209f6603c60Sopenharmony_ci    EXPECT_STREQ(asctime(stm), "Thu Jan  1 05:14:40 1970\n") << "gmtime_r return error!";
210f6603c60Sopenharmony_ci    EXPECT_TRUE(stm == &res) << "gmtime_r returns not equal";
211f6603c60Sopenharmony_ci
212f6603c60Sopenharmony_ci    time_t timeNow;
213f6603c60Sopenharmony_ci    time(&timeNow);
214f6603c60Sopenharmony_ci    stm = gmtime_r(&timeNow, &res);
215f6603c60Sopenharmony_ci    ASSERT_NE(nullptr, stm);
216f6603c60Sopenharmony_ci    EXPECT_EQ(stm->tm_year, 70) << "gmtime_r return error!";
217f6603c60Sopenharmony_ci    EXPECT_STRNE(asctime(stm), "") << "gmtime_r return error!";
218f6603c60Sopenharmony_ci    EXPECT_TRUE(stm == &res) << "gmtime_r returns not equal";
219f6603c60Sopenharmony_ci}
220f6603c60Sopenharmony_ci
221f6603c60Sopenharmony_ci/**
222f6603c60Sopenharmony_ci* @tc.number     SUB_KERNEL_TIME_API_MKTIME_0100
223f6603c60Sopenharmony_ci* @tc.name       test mktime api
224f6603c60Sopenharmony_ci* @tc.desc       [C- SOFTWARE -0200]
225f6603c60Sopenharmony_ci*/
226f6603c60Sopenharmony_ciHWTEST_F(TimeUtilsTest, testMktime, Function | MediumTest | Level2)
227f6603c60Sopenharmony_ci{
228f6603c60Sopenharmony_ci    struct tm *localTime;
229f6603c60Sopenharmony_ci    struct tm timeptr = {0};
230f6603c60Sopenharmony_ci    timeptr.tm_sec = 0;
231f6603c60Sopenharmony_ci    timeptr.tm_min = 10;
232f6603c60Sopenharmony_ci    timeptr.tm_hour = 10;
233f6603c60Sopenharmony_ci    timeptr.tm_mday = 9;
234f6603c60Sopenharmony_ci    timeptr.tm_mon = 7;
235f6603c60Sopenharmony_ci    timeptr.tm_year = 120;
236f6603c60Sopenharmony_ci    timeptr.tm_wday = 7;
237f6603c60Sopenharmony_ci    EXPECT_EQ(mktime(&timeptr), 1596967800) << "mktime return error!";
238f6603c60Sopenharmony_ci
239f6603c60Sopenharmony_ci    localTime = localtime(&g_time);
240f6603c60Sopenharmony_ci    ASSERT_NE(nullptr, localTime);
241f6603c60Sopenharmony_ci    time_t timep = mktime(localTime);
242f6603c60Sopenharmony_ci    EXPECT_EQ(timep, 18880) << "mktime return error!";
243f6603c60Sopenharmony_ci}
244f6603c60Sopenharmony_ci
245f6603c60Sopenharmony_ci/**
246f6603c60Sopenharmony_ci* @tc.number     SUB_KERNEL_TIME_API_STRFTIME_0100
247f6603c60Sopenharmony_ci* @tc.name       test strftime api
248f6603c60Sopenharmony_ci* @tc.desc       [C- SOFTWARE -0200]
249f6603c60Sopenharmony_ci*/
250f6603c60Sopenharmony_ciHWTEST_F(TimeUtilsTest, testStrftime, Function | MediumTest | Level3)
251f6603c60Sopenharmony_ci{
252f6603c60Sopenharmony_ci    size_t strftimeBytes = 19;
253f6603c60Sopenharmony_ci    char buffer[80] = {0};
254f6603c60Sopenharmony_ci    time_t mtime = 18880;
255f6603c60Sopenharmony_ci    struct tm *localTime = localtime(&mtime);
256f6603c60Sopenharmony_ci    if (localTime == nullptr) {
257f6603c60Sopenharmony_ci        LOG("localtime errno ");
258f6603c60Sopenharmony_ci        ADD_FAILURE();
259f6603c60Sopenharmony_ci    }
260f6603c60Sopenharmony_ci    size_t ftime = strftime(buffer, sizeof(buffer) - 1, "%Ex %EX %A", localTime);
261f6603c60Sopenharmony_ci    EXPECT_GT(ftime, g_zero) << "strftime return error!";
262f6603c60Sopenharmony_ci    EXPECT_STREQ(buffer, "01/01/70 05:14:40 Thursday") << "buffer return error!";
263f6603c60Sopenharmony_ci
264f6603c60Sopenharmony_ci    mtime = LONG_MAX;
265f6603c60Sopenharmony_ci    localTime = localtime(&mtime);
266f6603c60Sopenharmony_ci    ASSERT_NE(nullptr, localTime);
267f6603c60Sopenharmony_ci    ftime = strftime(buffer, sizeof(buffer) - 1, "%y-%m-%d %H:%M:%S", localTime);
268f6603c60Sopenharmony_ci    EXPECT_STREQ(buffer, "38-01-19 03:14:07") << "buffer return error!";
269f6603c60Sopenharmony_ci
270f6603c60Sopenharmony_ci    mtime = 253402300799;
271f6603c60Sopenharmony_ci    localTime = localtime(&mtime);
272f6603c60Sopenharmony_ci    ASSERT_NE(nullptr, localTime);
273f6603c60Sopenharmony_ci    ftime = strftime(buffer, sizeof(buffer) - 1, "%Y-%m-%d %H:%M:%S", localTime);
274f6603c60Sopenharmony_ci    EXPECT_STREQ(buffer, "9999-12-31 23:59:59") << "buffer return error!";
275f6603c60Sopenharmony_ci
276f6603c60Sopenharmony_ci    mtime = LONG_MIN;
277f6603c60Sopenharmony_ci    localTime = localtime(&mtime);
278f6603c60Sopenharmony_ci    ASSERT_NE(nullptr, localTime);
279f6603c60Sopenharmony_ci    ftime = strftime(buffer, sizeof(buffer) - 1, "%x %X", localTime);
280f6603c60Sopenharmony_ci    EXPECT_STREQ(buffer, "12/13/01 20:45:52") << "buffer return error!";
281f6603c60Sopenharmony_ci
282f6603c60Sopenharmony_ci    ftime = strftime(buffer, sizeof(buffer) - 1, "%Y-%m-%d %H:%M:%S", localTime);
283f6603c60Sopenharmony_ci    EXPECT_EQ(ftime, strftimeBytes) << "strftime return error!";
284f6603c60Sopenharmony_ci    EXPECT_STREQ(buffer, "1901-12-13 20:45:52") << "buffer return error!";
285f6603c60Sopenharmony_ci}
286f6603c60Sopenharmony_ci
287f6603c60Sopenharmony_ci/**
288f6603c60Sopenharmony_ci* @tc.number     SUB_KERNEL_TIME_API_STRFTIMEL_0100
289f6603c60Sopenharmony_ci* @tc.name       test strftime_l api
290f6603c60Sopenharmony_ci* @tc.desc       [C- SOFTWARE -0200]
291f6603c60Sopenharmony_ci*/
292f6603c60Sopenharmony_ciHWTEST_F(TimeUtilsTest, testStrftimeL, Function | MediumTest | Level2)
293f6603c60Sopenharmony_ci{
294f6603c60Sopenharmony_ci    struct tm *tm1;
295f6603c60Sopenharmony_ci    char buffer[80] = {0};
296f6603c60Sopenharmony_ci
297f6603c60Sopenharmony_ci    tm1 = localtime(&g_time);
298f6603c60Sopenharmony_ci    ASSERT_NE(nullptr, tm1);
299f6603c60Sopenharmony_ci    size_t ftime = strftime_l(buffer, sizeof(buffer) - 1, "%F %T %Z", tm1, nullptr);
300f6603c60Sopenharmony_ci    EXPECT_GT(ftime, g_zero) << "strftime return error!";
301f6603c60Sopenharmony_ci    EXPECT_STREQ(buffer, "1970-01-01 05:14:40 UTC") << "buffer return error!";
302f6603c60Sopenharmony_ci}
303f6603c60Sopenharmony_ci
304f6603c60Sopenharmony_ci/**
305f6603c60Sopenharmony_ci* @tc.number     SUB_KERNEL_TIME_API_WCSFTIME_0100
306f6603c60Sopenharmony_ci* @tc.name       test wcsftime api
307f6603c60Sopenharmony_ci* @tc.desc       [C- SOFTWARE -0200]
308f6603c60Sopenharmony_ci*/
309f6603c60Sopenharmony_ciHWTEST_F(TimeUtilsTest, testWcsftime, Function | MediumTest | Level2)
310f6603c60Sopenharmony_ci{
311f6603c60Sopenharmony_ci    size_t wcsftimeBytes = 33;
312f6603c60Sopenharmony_ci    wchar_t buff[48] = {0};
313f6603c60Sopenharmony_ci    struct tm *localTime = localtime(&g_time);
314f6603c60Sopenharmony_ci    ASSERT_NE(nullptr, localTime);
315f6603c60Sopenharmony_ci    size_t len = wcsftime(buff, sizeof(buff) - 1, L"%A %c", localTime);
316f6603c60Sopenharmony_ci    LOG("buff = %ls, len = %ld\n", buff, (long)len);
317f6603c60Sopenharmony_ci    EXPECT_EQ(len, wcsftimeBytes) << "wcsftime return error!";
318f6603c60Sopenharmony_ci    EXPECT_STREQ(buff, L"Thursday Thu Jan  1 05:14:40 1970") << "buff return error!";
319f6603c60Sopenharmony_ci
320f6603c60Sopenharmony_ci    localTime = localtime(&g_time);
321f6603c60Sopenharmony_ci    ASSERT_NE(nullptr, localTime);
322f6603c60Sopenharmony_ci    len = wcsftime(buff, sizeof(buff) - 1, L"%A %c", localTime);
323f6603c60Sopenharmony_ci    LOG("buff = %ls, len = %ld\n", buff, (long)len);
324f6603c60Sopenharmony_ci    EXPECT_EQ(len, wcsftimeBytes) << "wcsftime return error!";
325f6603c60Sopenharmony_ci    EXPECT_STREQ(buff, L"Thursday Thu Jan  1 05:14:40 1970") << "buff return error!";
326f6603c60Sopenharmony_ci}
327