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 "gmtime_data.h"
19#include "functionalext.h"
20
21static time_t gTime = 1659177614;
22static int16_t gYearBase = 1900;
23static int16_t gBufferSize = 500;
24
25/**
26 * @tc.name      : gmtime_0100
27 * @tc.desc      : according to different time zones, convert date and time to GMT time
28 * @tc.level     : Level 0
29 */
30void gmtime_0100(void)
31{
32    for (int32_t i = 0; i < (int32_t)(sizeof(test_gmtime_data) / sizeof(test_gmtime_data[0])); i++) {
33        const char *handlerChar = test_handle_path(test_gmtime_data[i].tz);
34        if (!handlerChar) {
35            t_error("gmtime_0100 failed: handlerChar is NULL\n");
36            continue;
37        }
38
39        setenv("TZ", handlerChar, 1);
40        tzset();
41        struct tm *gmtm;
42        gmtm = gmtime(&gTime);
43        char buff[gBufferSize];
44        int cnt = sprintf(buff, "%d-%d-%d %d:%d:%d wday=%d,yday=%d,isdst=%d,gmtoff=%ld,zone=%s",
45            (gmtm->tm_year+gYearBase), gmtm->tm_mon, gmtm->tm_mday, gmtm->tm_hour,
46            gmtm->tm_min, gmtm->tm_sec, gmtm->tm_wday, gmtm->tm_yday, gmtm->tm_isdst,
47            gmtm->tm_gmtoff, gmtm->tm_zone);
48        EXPECT_TRUE("gmtime_0100", cnt > 0);
49        EXPECT_STREQ("gmtime_0100", test_gmtime_data[i].result, buff);
50    }
51}
52
53int main(void)
54{
55    gmtime_0100();
56    return t_status;
57}