1 /*
2 * Copyright (c) 2023 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 <gmock/gmock.h>
17 #include <gtest/gtest.h>
18 #include <cstdint>
19 #include <unistd.h>
20
21 #include "dfs_error.h"
22 #include "net_conn_client.h"
23 #include "parameter.h"
24 #include "sync_rule/net_conn_callback_observer.h"
25 #include "sync_rule/network_status.h"
26 #include "utils_log.h"
27
28 namespace OHOS::FileManagement::CloudSync::Test {
29 using namespace testing;
30 using namespace testing::ext;
31 using namespace std;
32
33 class NetworkStatusTest : public testing::Test {
34 public:
35 static void SetUpTestCase(void);
36 static void TearDownTestCase(void);
37 void SetUp();
38 void TearDown();
39 };
SetUpTestCase(void)40 void NetworkStatusTest::SetUpTestCase(void)
41 {
42 GTEST_LOG_(INFO) << "SetUpTestCase";
43 }
44
TearDownTestCase(void)45 void NetworkStatusTest::TearDownTestCase(void)
46 {
47 GTEST_LOG_(INFO) << "TearDownTestCase";
48 }
49
SetUp(void)50 void NetworkStatusTest::SetUp(void)
51 {
52 GTEST_LOG_(INFO) << "SetUp";
53 }
54
TearDown(void)55 void NetworkStatusTest::TearDown(void)
56 {
57 GTEST_LOG_(INFO) << "TearDown";
58 }
59
60 /**
61 * @tc.name: RegisterNetConnCallbackTest
62 * @tc.desc: Verify the RegisterNetConnCallback function
63 * @tc.type: FUNC
64 * @tc.require: I6JPKG
65 */
66 HWTEST_F(NetworkStatusTest, RegisterNetConnCallbackTest, TestSize.Level1)
67 {
68 GTEST_LOG_(INFO) << "RegisterNetConnCallbackTest Start";
69 try {
70 auto dataSyncManager = std::make_shared<DataSyncManager>();
71 int32_t ret = NetworkStatus::RegisterNetConnCallback(dataSyncManager);
72 EXPECT_EQ(ret, E_GET_NETWORK_MANAGER_FAILED);
73 } catch (...) {
74 EXPECT_TRUE(false);
75 GTEST_LOG_(INFO) << " RegisterNetConnCallbackTest FAILED";
76 }
77 GTEST_LOG_(INFO) << "RegisterNetConnCallbackTest End";
78 }
79
80 /**
81 * @tc.name: GetDefaultNetTest
82 * @tc.desc: Verify the GetDefaultNet function
83 * @tc.type: FUNC
84 * @tc.require: I6JPKG
85 */
86 HWTEST_F(NetworkStatusTest, GetDefaultNetTest, TestSize.Level1)
87 {
88 GTEST_LOG_(INFO) << "GetDefaultNetTest Start";
89 try {
90 int32_t ret = NetworkStatus::GetDefaultNet();
91 EXPECT_EQ(ret, E_GET_NETWORK_MANAGER_FAILED);
92 } catch (...) {
93 EXPECT_TRUE(false);
94 GTEST_LOG_(INFO) << " GetDefaultNetTest FAILED";
95 }
96 GTEST_LOG_(INFO) << "GetDefaultNetTest End";
97 }
98
99 /**
100 * @tc.name: SetNetConnStatusTest001
101 * @tc.desc: Verify the SetNetConnStatus function
102 * @tc.type: FUNC
103 * @tc.require: I6JPKG
104 */
105 HWTEST_F(NetworkStatusTest, SetNetConnStatusTest001, TestSize.Level1)
106 {
107 GTEST_LOG_(INFO) << "SetNetConnStatusTest001 Start";
108 try {
109 NetManagerStandard::NetAllCapabilities netAllCap;
110 NetworkStatus::SetNetConnStatus(netAllCap);
111 EXPECT_TRUE(true);
112 } catch (...) {
113 EXPECT_TRUE(false);
114 GTEST_LOG_(INFO) << " SetNetConnStatusTest001 FAILED";
115 }
116 GTEST_LOG_(INFO) << "SetNetConnStatusTest001 End";
117 }
118
119 /**
120 * @tc.name: GetAndRegisterNetworkTest
121 * @tc.desc: Verify the GetAndRegisterNetwork function
122 * @tc.type: FUNC
123 * @tc.require: I6JPKG
124 */
125 HWTEST_F(NetworkStatusTest, GetAndRegisterNetworkTest, TestSize.Level1)
126 {
127 GTEST_LOG_(INFO) << "GetAndRegisterNetworkTest Start";
128 try {
129 auto dataSyncManager = std::make_shared<DataSyncManager>();
130 int32_t ret = NetworkStatus::GetAndRegisterNetwork(dataSyncManager);
131 EXPECT_EQ(ret, E_GET_NETWORK_MANAGER_FAILED);
132 } catch (...) {
133 EXPECT_TRUE(false);
134 GTEST_LOG_(INFO) << " GetAndRegisterNetworkTest FAILED";
135 }
136 GTEST_LOG_(INFO) << "GetAndRegisterNetworkTest End";
137 }
138
139 /**
140 * @tc.name: InitNetworkTest
141 * @tc.desc: Verify the InitNetwork function
142 * @tc.type: FUNC
143 * @tc.require: I6JPKG
144 */
145 HWTEST_F(NetworkStatusTest, InitNetworkTest, TestSize.Level1)
146 {
147 GTEST_LOG_(INFO) << "InitNetworkTest Start";
148 try {
149 auto dataSyncManager = std::make_shared<DataSyncManager>();
150 NetworkStatus::InitNetwork(dataSyncManager);
151 EXPECT_TRUE(true);
152 } catch (...) {
153 EXPECT_TRUE(false);
154 GTEST_LOG_(INFO) << " InitNetworkTest FAILED";
155 }
156 GTEST_LOG_(INFO) << "InitNetworkTest End";
157 }
158
159 /**
160 * @tc.name: SetNetConnStatusTest002
161 * @tc.desc: Verify the SetNetConnStatus function
162 * @tc.type: FUNC
163 * @tc.require: I6JPKG
164 */
165 HWTEST_F(NetworkStatusTest, SetNetConnStatusTest002, TestSize.Level1)
166 {
167 GTEST_LOG_(INFO) << "SetNetConnStatusTest002 Start";
168 try {
169 NetworkStatus::SetNetConnStatus(NetworkStatus::NO_NETWORK);
170 EXPECT_TRUE(true);
171 } catch (...) {
172 EXPECT_TRUE(false);
173 GTEST_LOG_(INFO) << " SetNetConnStatusTest002 FAILED";
174 }
175 GTEST_LOG_(INFO) << "SetNetConnStatusTest002 End";
176 }
177
178 /**
179 * @tc.name: GetNetConnStatusTest
180 * @tc.desc: Verify the GetNetConnStatus function
181 * @tc.type: FUNC
182 * @tc.require: I6JPKG
183 */
184 HWTEST_F(NetworkStatusTest, GetNetConnStatusTest, TestSize.Level1)
185 {
186 GTEST_LOG_(INFO) << "GetNetConnStatusTest Start";
187 try {
188 auto ret = NetworkStatus::GetNetConnStatus();
189 EXPECT_EQ(ret, NetworkStatus::NO_NETWORK);
190 } catch (...) {
191 EXPECT_TRUE(false);
192 GTEST_LOG_(INFO) << " GetNetConnStatusTest FAILED";
193 }
194 GTEST_LOG_(INFO) << "GetNetConnStatusTest End";
195 }
196 } // namespace OHOS::FileManagement::CloudSync::Test
197