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 <time.h>
17#include <unistd.h>
18#include "functionalext.h"
19
20extern int __clock_settime64(clockid_t, const struct timespec *);
21
22/**
23 * @tc.name      : clock_settime_0100
24 * @tc.desc      : Each parameter is valid, the clk parameter is CLOCK_REALTIME, which can set the system
25 *                 time seconds and nanoseconds.
26 * @tc.level     : Level 0
27 */
28void clock_settime_0100(void)
29{
30    struct timespec ts;
31    struct tm tim = {
32        .tm_year = 2022 - 1900,
33        .tm_min = 16,
34        .tm_hour = 18,
35        .tm_mon = 6,
36        .tm_mday = 6,
37    };
38    ts.tv_sec = mktime(&tim);
39    ts.tv_nsec = 0;
40    int ret = -1;
41    ret = clock_settime(CLOCK_REALTIME, &ts);
42    EXPECT_EQ("clock_settime_0100", ret, 0);
43}
44
45/**
46 * @tc.name      : clock_settime64_0100
47 * @tc.desc      : Each parameter is valid, the clk parameter is CLOCK_REALTIME, which can set the system
48 *                 time seconds and nanoseconds.
49 * @tc.level     : Level 0
50 */
51void clock_settime64_0100(void)
52{
53    struct timespec ts;
54    struct tm tim = {
55        .tm_year = 2022 - 1900,
56        .tm_min = 16,
57        .tm_hour = 18,
58        .tm_mon = 6,
59        .tm_mday = 6,
60    };
61    ts.tv_sec = mktime(&tim);
62    ts.tv_nsec = 0;
63    int ret = -1;
64    ret = __clock_settime64(CLOCK_REALTIME, &ts);
65    EXPECT_EQ("clock_settime64_0100", ret, 0);
66}
67
68int main(int argc, char *argv[])
69{
70    clock_settime_0100();
71    clock_settime64_0100();
72    return t_status;
73}