1 /*
2  * Copyright (c) 2024 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 <gtest/gtest.h>
17 #include "time_service.h"
18 #include <cstddef>
19 
20 using namespace std;
21 using namespace testing::ext;
22 
23 namespace NativeTest {
24 class TimeServiceNativeTest : public testing::Test {
25 public:
SetUpTestCase(void)26     static void SetUpTestCase(void) {};
TearDownTestCase(void)27     static void TearDownTestCase(void) {};
SetUp(void)28     void SetUp(void) {};
TearDown(void)29     void TearDown(void) {};
30 };
31 
32 /**
33 * @tc.name: GetTimeZone001.
34 * @tc.desc: Test success status for OH_TimeService_GetTimeZone.
35 * @tc.type: FUNC
36 */
37 HWTEST_F(TimeServiceNativeTest, GetTimeZone001, TestSize.Level0)
38 {
39     int len = 40;
40     char *bufTmp = static_cast<char *>(malloc(len));
41     auto ret = OH_TimeService_GetTimeZone(bufTmp, len);
42     EXPECT_EQ(ret, TIMESERVICE_ERR_OK);
43 }
44 
45 /**
46 * @tc.name: GetTimeZone002.
47 * @tc.desc: Test failure status for OH_TimeService_GetTimeZone.
48 * @tc.type: FUNC
49 */
50 HWTEST_F(TimeServiceNativeTest, GetTimeZone002, TestSize.Level0)
51 {
52     int len = 0;
53     char *bufTmp = static_cast<char *>(malloc(len + 1));
54     auto ret = OH_TimeService_GetTimeZone(bufTmp, len);
55     EXPECT_EQ(ret, TIMESERVICE_ERR_INVALID_PARAMETER);
56 }
57 
58 /**
59 * @tc.name: GetTimeZone003.
60 * @tc.desc: Test failure status for OH_TimeService_GetTimeZone.
61 * @tc.type: FUNC
62 */
63 HWTEST_F(TimeServiceNativeTest, GetTimeZone003, TestSize.Level0)
64 {
65     int len = 100;
66     auto ret = OH_TimeService_GetTimeZone(NULL, len);
67     EXPECT_EQ(ret, TIMESERVICE_ERR_INVALID_PARAMETER);
68 }
69 }