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 <locale.h>
18 #include <time.h>
19 #include "asctime_data.h"
20 #include "functionalext.h"
21
22 static time_t gTime = 1659177614;
23 static int16_t gBufferSize = 80;
24
25 /**
26 * @tc.name : strftime_l_0100
27 * @tc.desc : according to different time zones, format date
28 * @tc.level : Level 0
29 */
strftime_l_0100(void)30 void strftime_l_0100(void)
31 {
32 for (int32_t i = 0; i < (int32_t)(sizeof(test_asctime_data) / sizeof(test_asctime_data[0])); i++) {
33 const char *handlerChar = test_handle_path(test_asctime_data[i].tz);
34 if (!handlerChar) {
35 t_error("strftime_l_0100 failed: handlerChar is NULL\n");
36 continue;
37 }
38
39 setenv("TZ", handlerChar, 1);
40 tzset();
41 struct tm *timeptr = localtime(&gTime);
42 if (!timeptr) {
43 EXPECT_PTRNE("strftime_l_0100", timeptr, NULL);
44 return;
45 }
46 char buffer[gBufferSize];
47 locale_t m_locale = newlocale(LC_ALL_MASK, "en_US", NULL);
48 strftime_l(buffer, sizeof(buffer) - 1, "%c", timeptr, m_locale);
49 EXPECT_STREQ("strftime_l_0100", buffer, test_asctime_data[i].result);
50 }
51 }
52
main(void)53 int main(void)
54 {
55 strftime_l_0100();
56 return t_status;
57 }