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 <gtest/gtest.h>
17 #include <memory>
18
19 #include "cloud_sync_manager_impl.h"
20 #include "cloud_sync_service_proxy.h"
21 #include "dfs_error.h"
22 #include "i_cloud_sync_service_mock.h"
23 #include "iservice_registry.h"
24 #include "service_callback_mock.h"
25
26 namespace OHOS {
27 namespace FileManagement::CloudSync {
28 namespace Test {
29 using namespace testing::ext;
30 using namespace testing;
31 using namespace std;
32
33 class CloudSyncManagerTest : public testing::Test {
34 public:
35 static void SetUpTestCase(void);
36 static void TearDownTestCase(void);
37 void SetUp();
38 void TearDown();
39 std::shared_ptr<CloudSyncManagerImpl> managePtr_;
40 };
41
42 class CloudSyncCallbackDerived : public CloudSyncCallback {
43 public:
OnSyncStateChanged(CloudSyncState state,ErrorType error)44 void OnSyncStateChanged(CloudSyncState state, ErrorType error)
45 {
46 std::cout << "OnSyncStateChanged" << std::endl;
47 }
48 };
49
SetUpTestCase(void)50 void CloudSyncManagerTest::SetUpTestCase(void)
51 {
52 std::cout << "SetUpTestCase" << std::endl;
53 }
54
TearDownTestCase(void)55 void CloudSyncManagerTest::TearDownTestCase(void)
56 {
57 std::cout << "TearDownTestCase" << std::endl;
58 }
59
SetUp(void)60 void CloudSyncManagerTest::SetUp(void)
61 {
62 managePtr_ = make_shared<CloudSyncManagerImpl>();
63 std::cout << "SetUp" << std::endl;
64 }
65
TearDown(void)66 void CloudSyncManagerTest::TearDown(void)
67 {
68 managePtr_ = nullptr;
69 std::cout << "TearDown" << std::endl;
70 }
71
72 /**
73 * @tc.name: RegisterCallbackTest
74 * @tc.desc: Verify the RegisterCallback function.
75 * @tc.type: FUNC
76 * @tc.require: I6H5MH
77 */
78 HWTEST_F(CloudSyncManagerTest, RegisterCallbackTest, TestSize.Level1)
79 {
80 GTEST_LOG_(INFO) << "RegisterCallbackTest Start";
81 try {
82 shared_ptr<CloudSyncCallback> callback = make_shared<CloudSyncCallbackDerived>();
83 auto res = managePtr_->RegisterCallback(callback);
84 EXPECT_EQ(res, E_SA_LOAD_FAILED);
85 } catch (...) {
86 EXPECT_TRUE(false);
87 GTEST_LOG_(INFO) << " RegisterCallbackTest FAILED";
88 }
89 GTEST_LOG_(INFO) << "RegisterCallbackTest End";
90 }
91
92 /**
93 * @tc.name: StartSyncTest
94 * @tc.desc: Verify the StartSync function.
95 * @tc.type: FUNC
96 * @tc.require: I6H5MH
97 */
98 HWTEST_F(CloudSyncManagerTest, StartSyncTest, TestSize.Level1)
99 {
100 GTEST_LOG_(INFO) << "StartSyncTest Start";
101 try {
102 bool forceFlag = false;
103 shared_ptr<CloudSyncCallback> callback = make_shared<CloudSyncCallbackDerived>();
104 auto res = managePtr_->StartSync();
105 EXPECT_EQ(res, E_SA_LOAD_FAILED);
106 res = managePtr_->StartSync(forceFlag, callback);
107 EXPECT_EQ(res, E_SA_LOAD_FAILED);
108 } catch (...) {
109 EXPECT_TRUE(false);
110 GTEST_LOG_(INFO) << " StartSyncTest FAILED";
111 }
112 GTEST_LOG_(INFO) << "StartSyncTest End";
113 }
114
115 /*
116 * @tc.name: StopSyncTest
117 * @tc.desc: Verify the StopSync function.
118 * @tc.type: FUNC
119 * @tc.require: I6H5MH
120 */
121 HWTEST_F(CloudSyncManagerTest, StopSyncTest, TestSize.Level1)
122 {
123 GTEST_LOG_(INFO) << "StopSyncTest Start";
124 try {
125 int res = managePtr_->StopSync();
126 EXPECT_EQ(res, E_SA_LOAD_FAILED);
127 } catch (...) {
128 EXPECT_TRUE(false);
129 GTEST_LOG_(INFO) << " StopSyncTest FAILED";
130 }
131 GTEST_LOG_(INFO) << "StopSyncTest End";
132 }
133
134 /*
135 * @tc.name: ChangeAppSwitchTest
136 * @tc.desc: Verify the ChangeAppSwitch function.
137 * @tc.type: FUNC
138 * @tc.require: I6H5MH
139 */
140 HWTEST_F(CloudSyncManagerTest, ChangeAppSwitchTest, TestSize.Level1)
141 {
142 GTEST_LOG_(INFO) << "ChangeAppSwitchTest Start";
143 try {
144 std::string accoutId = "accoutId";
145 std::string bundleName = "bundleName";
146 bool status = true;
147 auto res = managePtr_->ChangeAppSwitch(accoutId, bundleName, status);
148 EXPECT_EQ(res, E_SA_LOAD_FAILED);
149 } catch (...) {
150 EXPECT_TRUE(false);
151 GTEST_LOG_(INFO) << " ChangeAppSwitchTest FAILED";
152 }
153 GTEST_LOG_(INFO) << "ChangeAppSwitchTest End";
154 }
155
156 /*
157 * @tc.name: NotifyDataChangeTest
158 * @tc.desc: Verify the NotifyDataChange function.
159 * @tc.type: FUNC
160 * @tc.require: I6H5MH
161 */
162 HWTEST_F(CloudSyncManagerTest, NotifyDataChangeTest, TestSize.Level1)
163 {
164 GTEST_LOG_(INFO) << "NotifyDataChangeTest Start";
165 try {
166 std::string accoutId = "accoutId";
167 std::string bundleName = "bundleName";
168 auto res = managePtr_->NotifyDataChange(accoutId, bundleName);
169 EXPECT_EQ(res, E_SA_LOAD_FAILED);
170 } catch (...) {
171 EXPECT_TRUE(false);
172 GTEST_LOG_(INFO) << " NotifyDataChangeTest FAILED";
173 }
174 GTEST_LOG_(INFO) << "NotifyDataChangeTest End";
175 }
176
177 /*
178 * @tc.name: StartDownloadFileTest
179 * @tc.desc: Verify the StartDownloadFile function.
180 * @tc.type: FUNC
181 * @tc.require: I6H5MH
182 */
183 HWTEST_F(CloudSyncManagerTest, StartDownloadFileTest, TestSize.Level1)
184 {
185 GTEST_LOG_(INFO) << "NotifyDataChangeTest Start";
186 try {
187 std::string uri = "uri";
188 auto res = managePtr_->StartDownloadFile(uri);
189 EXPECT_EQ(res, E_SA_LOAD_FAILED);
190 } catch (...) {
191 EXPECT_TRUE(false);
192 GTEST_LOG_(INFO) << " StartDownloadFileTest FAILED";
193 }
194 GTEST_LOG_(INFO) << "StartDownloadFileTest End";
195 }
196
197 /*
198 * @tc.name: StopDownloadFileTest
199 * @tc.desc: Verify the StopDownloadFile function.
200 * @tc.type: FUNC
201 * @tc.require: I6H5MH
202 */
203 HWTEST_F(CloudSyncManagerTest, StopDownloadFileTest, TestSize.Level1)
204 {
205 GTEST_LOG_(INFO) << "NotifyDataChangeTest Start";
206 try {
207 std::string uri = "uri";
208 auto res = managePtr_->StopDownloadFile(uri);
209 EXPECT_EQ(res, E_SA_LOAD_FAILED);
210 } catch (...) {
211 EXPECT_TRUE(false);
212 GTEST_LOG_(INFO) << " StopDownloadFileTest FAILED";
213 }
214 GTEST_LOG_(INFO) << "StopDownloadFileTest End";
215 }
216
217 /*
218 * @tc.name: RegisterDownloadFileCallbackTest
219 * @tc.desc: Verify the UnregisterDownloadFileCallback function.
220 * @tc.type: FUNC
221 * @tc.require: I6H5MH
222 */
223 HWTEST_F(CloudSyncManagerTest, RegisterDownloadFileCallbackTest, TestSize.Level1)
224 {
225 GTEST_LOG_(INFO) << "NotifyDataChangeTest Start";
226 try {
227 auto res = managePtr_->UnregisterDownloadFileCallback();
228 EXPECT_EQ(res, E_SA_LOAD_FAILED);
229 } catch (...) {
230 EXPECT_TRUE(false);
231 GTEST_LOG_(INFO) << " RegisterDownloadFileCallbackTest FAILED";
232 }
233 GTEST_LOG_(INFO) << "RegisterDownloadFileCallbackTest End";
234 }
235
236 /*
237 * @tc.name: EnableCloudTest
238 * @tc.desc: Verify the EnableCloud function.
239 * @tc.type: FUNC
240 * @tc.require: I6H5MH
241 */
242 HWTEST_F(CloudSyncManagerTest, EnableCloudTest, TestSize.Level1)
243 {
244 GTEST_LOG_(INFO) << "NotifyDataChangeTest Start";
245 try {
246 std::string accoutId = "accoutId";
247 SwitchDataObj switchData;
248 auto res = managePtr_->EnableCloud(accoutId, switchData);
249 EXPECT_EQ(res, E_SA_LOAD_FAILED);
250 } catch (...) {
251 EXPECT_TRUE(false);
252 GTEST_LOG_(INFO) << " EnableCloudTest FAILED";
253 }
254 GTEST_LOG_(INFO) << "EnableCloudTest End";
255 }
256
257 /*
258 * @tc.name: DisableCloudTest
259 * @tc.desc: Verify the DisableCloud function.
260 * @tc.type: FUNC
261 * @tc.require: I6H5MH
262 */
263 HWTEST_F(CloudSyncManagerTest, DisableCloudTest, TestSize.Level1)
264 {
265 GTEST_LOG_(INFO) << "NotifyDataChangeTest Start";
266 try {
267 std::string accoutId = "accoutId";
268 auto res = managePtr_->DisableCloud(accoutId);
269 EXPECT_EQ(res, E_SA_LOAD_FAILED);
270 } catch (...) {
271 EXPECT_TRUE(false);
272 GTEST_LOG_(INFO) << " DisableCloudTest FAILED";
273 }
274 GTEST_LOG_(INFO) << "DisableCloudTest End";
275 }
276
277 /*
278 * @tc.name: CleanTest
279 * @tc.desc: Verify the Clean function.
280 * @tc.type: FUNC
281 * @tc.require: I6H5MH
282 */
283 HWTEST_F(CloudSyncManagerTest, CleanTest, TestSize.Level1)
284 {
285 GTEST_LOG_(INFO) << "NotifyDataChangeTest Start";
286 try {
287 std::string accoutId = "accoutId";
288 CleanOptions cleanOptions;
289 auto res = managePtr_->Clean(accoutId, cleanOptions);
290 EXPECT_EQ(res, E_SA_LOAD_FAILED);
291 } catch (...) {
292 EXPECT_TRUE(false);
293 GTEST_LOG_(INFO) << " CleanTest FAILED";
294 }
295 GTEST_LOG_(INFO) << "CleanTest End";
296 }
297 } // namespace Test
298 } // namespace FileManagement::CloudSync
299 } // namespace OHOS
300