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