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 #define private public
16 #define protected public
17 
18 #include "cellular_data_client.h"
19 #include "cellular_data_constant.h"
20 #include "data_access_token.h"
21 #include "gtest/gtest.h"
22 #include "telephony_errors.h"
23 
24 namespace OHOS {
25 namespace Telephony {
26 using namespace testing::ext;
27 
28 class CellularDataClientTest : public testing::Test {
29 public:
30     static void SetUpTestCase();
31     static void TearDownTestCase();
32     void SetUp();
33     void TearDown();
34 };
SetUpTestCase()35 void CellularDataClientTest::SetUpTestCase() {}
36 
TearDownTestCase()37 void CellularDataClientTest::TearDownTestCase() {}
38 
SetUp()39 void CellularDataClientTest::SetUp() {}
40 
TearDown()41 void CellularDataClientTest::TearDown() {}
42 
43 /**
44  * @tc.number   EnableIntelligenceSwitch_001
45  * @tc.name     test function branch
46  * @tc.desc     Function test
47  */
48 HWTEST_F(CellularDataClientTest, EnableIntelligenceSwitch_001, TestSize.Level0)
49 {
50     int32_t result = CellularDataClient::GetInstance().EnableIntelligenceSwitch(false);
51     EXPECT_EQ(result, TELEPHONY_ERR_PERMISSION_ERR);
52 }
53 
54 /**
55  * @tc.number   GetApnState_001
56  * @tc.name     test function branch
57  * @tc.desc     Function test
58  */
59 HWTEST_F(CellularDataClientTest, GetApnState_001, TestSize.Level0)
60 {
61     std::string str;
62     int32_t result = CellularDataClient::GetInstance().GetApnState(0, str);
63     EXPECT_EQ(result, 0);
64 }
65 
66 /**
67  * @tc.number   GetDataRecoveryState_001
68  * @tc.name     test function branch
69  * @tc.desc     Function test
70  */
71 HWTEST_F(CellularDataClientTest, GetDataRecoveryState_001, TestSize.Level0)
72 {
73     int32_t result = CellularDataClient::GetInstance().GetDataRecoveryState();
74     EXPECT_EQ(result, 0);
75 }
76 
77 /**
78  * @tc.number   IsCellularDataRoamingEnabled_001
79  * @tc.name     test function branch
80  * @tc.desc     Function test
81  */
82 HWTEST_F(CellularDataClientTest, IsCellularDataRoamingEnabled_001, TestSize.Level0)
83 {
84     bool dataRoamingEnabled = false;
85     CellularDataClient::GetInstance().IsCellularDataRoamingEnabled(0, dataRoamingEnabled);
86     EXPECT_EQ(dataRoamingEnabled, false);
87 }
88 
89 /**
90  * @tc.number   ClearCellularDataConnections_001
91  * @tc.name     test function branch
92  * @tc.desc     Function test
93  */
94 HWTEST_F(CellularDataClientTest, ClearCellularDataConnections_001, TestSize.Level0)
95 {
96     int32_t result = CellularDataClient::GetInstance().ClearCellularDataConnections(0);
97     EXPECT_EQ(result, TELEPHONY_ERR_PERMISSION_ERR);
98 }
99 
100 /**
101  * @tc.number   GetDataConnApnAttr_001
102  * @tc.name     test function branch
103  * @tc.desc     Function test
104  */
105 HWTEST_F(CellularDataClientTest, GetDataConnApnAttr_001, TestSize.Level0)
106 {
107     ApnItem::Attribute apnAttr;
108     int32_t result = CellularDataClient::GetInstance().GetDataConnApnAttr(0, apnAttr);
109     EXPECT_EQ(result, 0);
110 }
111 
112 /**
113  * @tc.number   GetDataConnIpType_001
114  * @tc.name     test function branch
115  * @tc.desc     Function test
116  */
117 HWTEST_F(CellularDataClientTest, GetDataConnIpType_001, TestSize.Level0)
118 {
119     std::string ipType;
120     int32_t result = CellularDataClient::GetInstance().GetDataConnIpType(0, ipType);
121     EXPECT_EQ(result, 0);
122 }
123 
124 /**
125  * @tc.number   ClearAllConnections_001
126  * @tc.name     test function branch
127  * @tc.desc     Function test
128  */
129 HWTEST_F(CellularDataClientTest, ClearAllConnections_001, TestSize.Level0)
130 {
131     int32_t result = CellularDataClient::GetInstance().ClearAllConnections(0, DisConnectionReason::REASON_NORMAL);
132     EXPECT_EQ(result, TELEPHONY_ERR_PERMISSION_ERR);
133 }
134 
135 /**
136  * @tc.number   IsNeedDoRecovery_001
137  * @tc.name     test function branch
138  * @tc.desc     Function test
139  */
140 HWTEST_F(CellularDataClientTest, IsNeedDoRecovery_001, TestSize.Level0)
141 {
142     bool needDoRecovery = false;
143     CellularDataClient::GetInstance().IsNeedDoRecovery(0, needDoRecovery);
144     EXPECT_EQ(needDoRecovery, false);
145 }
146 
147 /**
148  * @tc.number   SetDefaultCellularDataSlotId_001
149  * @tc.name     test function branch
150  * @tc.desc     Function test
151  */
152 HWTEST_F(CellularDataClientTest, SetDefaultCellularDataSlotId_001, TestSize.Level0)
153 {
154     int32_t result = CellularDataClient::GetInstance().SetDefaultCellularDataSlotId(0);
155     EXPECT_EQ(result, TELEPHONY_ERR_PERMISSION_ERR);
156 }
157 
158 /**
159  * @tc.number   SetDefaultCellularDataSlotId_002
160  * @tc.name     test function branch
161  * @tc.desc     Function test
162  */
163 HWTEST_F(CellularDataClientTest, SetDefaultCellularDataSlotId_002, TestSize.Level0)
164 {
165     DataAccessToken token;
166     int32_t result = CellularDataClient::GetInstance().SetDefaultCellularDataSlotId(0);
167     EXPECT_NE(result, 0);
168 }
169 } // namespace Telephony
170 } // namespace OHOS