• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define LOG_TAG "CloudDataTest"
17 
18 #include <condition_variable>
19 #include <gtest/gtest.h>
20 #include <unistd.h>
21 
22 #include "accesstoken_kit.h"
23 #include "cloud_manager.h"
24 #include "cloud_notifier_stub.h"
25 #include "cloud_service_proxy.h"
26 #include "cloud_types.h"
27 #include "cloud_types_util.h"
28 #include "logger.h"
29 #include "rdb_types.h"
30 #include "token_setproc.h"
31 
32 namespace OHOS::CloudData {
33 using namespace testing::ext;
34 using namespace OHOS::Security::AccessToken;
35 using namespace OHOS::Rdb;
36 using namespace DistributedRdb;
37 uint64_t g_selfTokenID = 0;
38 static constexpr const char *TEST_BUNDLE_NAME = "bundleName";
39 static constexpr const char *TEST_ACCOUNT_ID = "testId";
40 static constexpr const char *TEST_STORE_ID = "storeId";
AllocSystemHapToken(const HapPolicyParams & policy)41 void AllocSystemHapToken(const HapPolicyParams &policy)
42 {
43     HapInfoParams info = {
44         .userID = 100,
45         .bundleName = "ohos.clouddatatest.demo",
46         .instIndex = 0,
47         .appIDDesc = "ohos.clouddatatest.demo",
48         .isSystemApp = true
49     };
50     auto token = AccessTokenKit::AllocHapToken(info, policy);
51     SetSelfTokenID(token.tokenIDEx);
52 }
53 
AllocNormalHapToken(const HapPolicyParams & policy)54 void AllocNormalHapToken(const HapPolicyParams &policy)
55 {
56     HapInfoParams info = {
57         .userID = 100,
58         .bundleName = "ohos.clouddatatest.demo",
59         .instIndex = 0,
60         .appIDDesc = "ohos.clouddatatest.demo",
61         .isSystemApp = false
62     };
63     auto token = AccessTokenKit::AllocHapToken(info, policy);
64     SetSelfTokenID(token.tokenIDEx);
65 }
66 
67 HapPolicyParams g_normalPolicy = {
68     .apl = APL_NORMAL,
69     .domain = "test.domain",
70     .permList = {
71         {
72             .permissionName = "ohos.permission.CLOUDDATA_CONFIG",
73             .bundleName = "ohos.clouddatatest.demo",
74             .grantMode = 1,
75             .availableLevel = APL_NORMAL,
76             .label = "label",
77             .labelId = 1,
78             .description = "ohos.clouddatatest.demo",
79             .descriptionId = 1
80         }
81     },
82     .permStateList = {
83         {
84             .permissionName = "ohos.permission.CLOUDDATA_CONFIG",
85             .isGeneral = true,
86             .resDeviceID = { "local" },
87             .grantStatus = { PermissionState::PERMISSION_GRANTED },
88             .grantFlags = { 1 }
89         }
90     }
91 };
92 
93 HapPolicyParams g_systemPolicy = {
94     .apl = APL_SYSTEM_BASIC,
95     .domain = "test.domain",
96     .permList = {
97         {
98             .permissionName = "ohos.permission.CLOUDDATA_CONFIG",
99             .bundleName = "ohos.clouddatatest.demo",
100             .grantMode = 1,
101             .availableLevel = APL_SYSTEM_BASIC,
102             .label = "label",
103             .labelId = 1,
104             .description = "ohos.clouddatatest.demo",
105             .descriptionId = 1
106         }
107     },
108     .permStateList = {
109         {
110             .permissionName = "ohos.permission.CLOUDDATA_CONFIG",
111             .isGeneral = true,
112             .resDeviceID = { "local" },
113             .grantStatus = { PermissionState::PERMISSION_GRANTED },
114             .grantFlags = { 1 }
115         }
116     }
117 };
118 
119 HapPolicyParams g_notPermissonPolicy = {
120     .apl = APL_SYSTEM_BASIC,
121     .domain = "test.domain",
122     .permList = {
123         {
124             .permissionName = "ohos.permission.TEST",
125             .bundleName = "ohos.clouddatatest.demo",
126             .grantMode = 1,
127             .availableLevel = APL_SYSTEM_BASIC,
128             .label = "label",
129             .labelId = 1,
130             .description = "ohos.clouddatatest.demo",
131             .descriptionId = 1
132         }
133     },
134     .permStateList = {
135         {
136             .permissionName = "ohos.permission.TEST",
137             .isGeneral = true,
138             .resDeviceID = { "local" },
139             .grantStatus = { PermissionState::PERMISSION_GRANTED },
140             .grantFlags = { 1 }
141         }
142     }
143 };
144 
145 class CloudDataTest : public testing::Test {
146 public:
147     static void SetUpTestCase(void);
148     static void TearDownTestCase(void);
SetUp()149     void SetUp()
150     {
151     }
TearDown()152     void TearDown()
153     {
154         SetSelfTokenID(g_selfTokenID);
155     }
156 
157     static std::mutex syncCompleteLock_;
158     static std::condition_variable syncCompleteCv_;
159     static int32_t progressStatus_;
160     static int32_t code_;
161     static constexpr uint32_t delayTime = 2000;
162 };
163 
164 std::mutex CloudDataTest::syncCompleteLock_;
165 std::condition_variable CloudDataTest::syncCompleteCv_;
166 int32_t CloudDataTest::progressStatus_ = Progress::SYNC_BEGIN;
167 int32_t CloudDataTest::code_ = ProgressCode::SUCCESS;
168 
SetUpTestCase(void)169 void CloudDataTest::SetUpTestCase(void)
170 {
171     LOG_INFO("SetUpTestCase in.");
172     g_selfTokenID = GetSelfTokenID();
173 }
174 
TearDownTestCase(void)175 void CloudDataTest::TearDownTestCase(void)
176 {
177     LOG_INFO("TearDownTestCase in.");
178     SetSelfTokenID(g_selfTokenID);
179 }
180 
181 /* *
182  * @tc.name: CloudSync_SyncComplete_001
183  * @tc.desc: Test the CloudSync API with syncComplete callback
184  * @tc.type: FUNC
185  * @tc.require:
186  */
187 HWTEST_F(CloudDataTest, CloudSync_SyncComplete_001, TestSize.Level1)
188 {
189     AllocSystemHapToken(g_systemPolicy);
190     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
191     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
__anonefc6bfbd0102(DistributedRdb::Details &&details) 192     auto progress = [](DistributedRdb::Details &&details) {
193         ASSERT_NE(details.size(), 0);
194         progressStatus_ = details.begin()->second.progress;
195         code_ = details.begin()->second.code;
196         LOG_INFO("CloudSync_SyncComplete_001, progressStatus_:%{public}d, code_:%{public}d", progressStatus_, code_);
197         if (progressStatus_ == Progress::SYNC_FINISH) {
198             LOG_INFO("CloudSync_SyncComplete_001, start to notify, progressStatus_:%{public}d, code_:%{public}d",
199                 progressStatus_, code_);
200             std::unique_lock<std::mutex> lock(syncCompleteLock_);
201             syncCompleteCv_.notify_one();
202         }
203     };
204     int32_t syncMode = 4; // 4 is native_first
205     uint32_t seqNum = 101;
206     auto status = proxy->CloudSync(TEST_BUNDLE_NAME, TEST_STORE_ID, { syncMode, seqNum }, progress);
207     EXPECT_EQ(status, CloudService::SUCCESS);
208     std::unique_lock<std::mutex> lock(syncCompleteLock_);
__anonefc6bfbd0202null209     auto result = syncCompleteCv_.wait_for(lock, std::chrono::milliseconds(CloudDataTest::delayTime), [] {
210         LOG_INFO("CloudSync_SyncComplete_001, wait_for in, progressStatus_:%{public}d, code_:%{public}d",
211             progressStatus_, code_);
212         return progressStatus_ == Progress::SYNC_FINISH && code_ == ProgressCode::CLOUD_DISABLED;
213     });
214     EXPECT_TRUE(result);
215     LOG_INFO("CloudSync_SyncComplete_001 test end.");
216 }
217 
218 /* *
219  * @tc.name: CloudDataTest_001
220  * @tc.desc: Test the system application permissions of the QueryStatistics API
221  * @tc.type: FUNC
222  * @tc.require:
223  */
224 HWTEST_F(CloudDataTest, CloudDataTest_001, TestSize.Level0)
225 {
226     AllocNormalHapToken(g_normalPolicy);
227     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
228     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
229     auto [status, info] = proxy->QueryStatistics(TEST_ACCOUNT_ID, TEST_BUNDLE_NAME, TEST_STORE_ID);
230     EXPECT_EQ(status, CloudService::PERMISSION_DENIED);
231     EXPECT_TRUE(info.empty());
232 }
233 
234 /* *
235  * @tc.name: CloudDataTest_002
236  * @tc.desc: Test the permissions of the QueryStatistics API
237  * @tc.type: FUNC
238  * @tc.require:
239  */
240 HWTEST_F(CloudDataTest, CloudDataTest_002, TestSize.Level1)
241 {
242     AllocSystemHapToken(g_notPermissonPolicy);
243     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
244     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
245     auto [status, info] = proxy->QueryStatistics(TEST_ACCOUNT_ID, TEST_BUNDLE_NAME, TEST_STORE_ID);
246     EXPECT_EQ(status, CloudService::CLOUD_CONFIG_PERMISSION_DENIED);
247     EXPECT_TRUE(info.empty());
248 }
249 
250 /* *
251  * @tc.name: CloudDataTest_003
252  * @tc.desc: Test the permissions of the QueryStatistics API
253  * @tc.type: FUNC
254  * @tc.require:
255  */
256 HWTEST_F(CloudDataTest, CloudDataTest_003, TestSize.Level1)
257 {
258     AllocSystemHapToken(g_systemPolicy);
259     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
260     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
261     auto [status, info] = proxy->QueryStatistics(TEST_ACCOUNT_ID, TEST_BUNDLE_NAME, TEST_STORE_ID);
262     EXPECT_EQ(status, CloudService::ERROR);
263     EXPECT_TRUE(info.empty());
264 }
265 
266 /* *
267  * @tc.name: EnableCloud001
268  * @tc.desc: Test the EnableCloud API
269  * @tc.type: FUNC
270  * @tc.require:
271  */
272 HWTEST_F(CloudDataTest, EnableCloud001, TestSize.Level0)
273 {
274     AllocSystemHapToken(g_systemPolicy);
275     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
276     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
277     std::map<std::string, int32_t> switches;
278     switches.emplace(TEST_BUNDLE_NAME, 0);
279     auto status = proxy->EnableCloud(TEST_ACCOUNT_ID, switches);
280     EXPECT_NE(status, CloudService::SUCCESS);
281 }
282 
283 /* *
284  * @tc.name: DisableCloud001
285  * @tc.desc: Test the DisableCloud API
286  * @tc.type: FUNC
287  * @tc.require:
288  */
289 HWTEST_F(CloudDataTest, DisableCloud001, TestSize.Level0)
290 {
291     AllocSystemHapToken(g_systemPolicy);
292     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
293     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
294     auto status = proxy->DisableCloud(TEST_ACCOUNT_ID);
295     EXPECT_NE(status, CloudService::SUCCESS);
296 }
297 
298 /* *
299  * @tc.name: ChangeAppSwitch001
300  * @tc.desc: Test the ChangeAppSwitch API
301  * @tc.type: FUNC
302  * @tc.require:
303  */
304 HWTEST_F(CloudDataTest, ChangeAppSwitch001, TestSize.Level0)
305 {
306     AllocSystemHapToken(g_systemPolicy);
307     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
308     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
309     auto status = proxy->ChangeAppSwitch(TEST_ACCOUNT_ID, TEST_BUNDLE_NAME, 0);
310     EXPECT_NE(status, CloudService::SUCCESS);
311 }
312 
313 /* *
314  * @tc.name: Clean001
315  * @tc.desc: Test the Clean API
316  * @tc.type: FUNC
317  * @tc.require:
318  */
319 HWTEST_F(CloudDataTest, Clean001, TestSize.Level1)
320 {
321     AllocSystemHapToken(g_systemPolicy);
322     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
323     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
324     std::map<std::string, int32_t> actions;
325     actions.emplace(TEST_BUNDLE_NAME, 0);
326     auto status = proxy->Clean(TEST_ACCOUNT_ID, actions);
327     EXPECT_EQ(status, CloudService::ERROR);
328 }
329 
330 /* *
331  * @tc.name: NotifyDataChange001
332  * @tc.desc: Test the NotifyDataChange API
333  * @tc.type: FUNC
334  * @tc.require:
335  */
336 HWTEST_F(CloudDataTest, NotifyDataChange001, TestSize.Level1)
337 {
338     AllocSystemHapToken(g_systemPolicy);
339     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
340     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
341     auto status = proxy->NotifyDataChange("id", "data", 100);
342     EXPECT_EQ(status, CloudService::INVALID_ARGUMENT);
343 }
344 
345 /* *
346  * @tc.name: NotifyDataChange002
347  * @tc.desc: Test the NotifyDataChange API
348  * @tc.type: FUNC
349  * @tc.require:
350  */
351 HWTEST_F(CloudDataTest, NotifyDataChange002, TestSize.Level1)
352 {
353     AllocSystemHapToken(g_systemPolicy);
354     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
355     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
356     auto status = proxy->NotifyDataChange(TEST_ACCOUNT_ID, TEST_BUNDLE_NAME);
357     EXPECT_EQ(status, CloudService::INVALID_ARGUMENT);
358 }
359 
360 /* *
361  * @tc.name: SetGlobalCloudStrategy001
362  * @tc.desc: Test the SetGlobalCloudStrategy API
363  * @tc.type: FUNC
364  * @tc.require:
365  */
366 HWTEST_F(CloudDataTest, SetGlobalCloudStrategy001, TestSize.Level1)
367 {
368     AllocSystemHapToken(g_systemPolicy);
369     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
370     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
371     std::vector<CommonType::Value> values = { 0 };
372     auto status = proxy->SetGlobalCloudStrategy(Strategy::STRATEGY_NETWORK, values);
373     EXPECT_EQ(status, CloudService::SUCCESS);
374 }
375 
376 /* *
377  * @tc.name: QueryLastSyncInfo001
378  * @tc.desc: Test the system application permissions of the QueryLastSyncInfo API
379  * @tc.type: FUNC
380  * @tc.require:
381  */
382 HWTEST_F(CloudDataTest, QueryLastSyncInfo001, TestSize.Level0)
383 {
384     AllocNormalHapToken(g_normalPolicy);
385     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
386     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
387     auto [status, info] = proxy->QueryLastSyncInfo(TEST_ACCOUNT_ID, TEST_BUNDLE_NAME, TEST_STORE_ID);
388     EXPECT_EQ(status, CloudService::PERMISSION_DENIED);
389     EXPECT_TRUE(info.empty());
390 }
391 
392 /* *
393  * @tc.name: QueryLastSyncInfo002
394  * @tc.desc: Test the permission name of the QueryLastSyncInfo API
395  * @tc.type: FUNC
396  * @tc.require:
397  */
398 HWTEST_F(CloudDataTest, QueryLastSyncInfo002, TestSize.Level1)
399 {
400     AllocSystemHapToken(g_notPermissonPolicy);
401     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
402     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
403     auto [status, info] = proxy->QueryLastSyncInfo(TEST_ACCOUNT_ID, TEST_BUNDLE_NAME, TEST_STORE_ID);
404     EXPECT_EQ(status, CloudService::CLOUD_CONFIG_PERMISSION_DENIED);
405     EXPECT_TRUE(info.empty());
406 }
407 
408 /* *
409  * @tc.name: AllocResourceAndShare001
410  * @tc.desc: Test the system application permissions of the AllocResourceAndShare001 API
411  * @tc.type: FUNC
412  * @tc.require:
413  */
414 HWTEST_F(CloudDataTest, AllocResourceAndShare001, TestSize.Level0)
415 {
416     AllocNormalHapToken(g_normalPolicy);
417     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
418     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
419     DistributedRdb::PredicatesMemo predicates;
420     predicates.tables_.push_back(TEST_BUNDLE_NAME);
421     std::vector<std::string> columns;
422     CloudData::Participants participants;
423     auto [ret, _] = proxy->AllocResourceAndShare(TEST_STORE_ID, predicates, columns, participants);
424     EXPECT_EQ(ret, CloudService::PERMISSION_DENIED);
425 }
426 
427 /* *
428  * @tc.name: Share001
429  * @tc.desc: Test the system application permissions of the Share001 API
430  * @tc.type: FUNC
431  * @tc.require:
432  */
433 HWTEST_F(CloudDataTest, Share001, TestSize.Level0)
434 {
435     AllocNormalHapToken(g_normalPolicy);
436     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
437     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
438     std::string sharingRes = "";
439     CloudData::Participants participants{};
440     CloudData::Results results;
441     auto ret = proxy->Share(sharingRes, participants, results);
442     EXPECT_EQ(ret, CloudService::PERMISSION_DENIED);
443 }
444 
445 /* *
446  * @tc.name: Unshare001
447  * @tc.desc: Test the system application permissions of the Unshare001 API
448  * @tc.type: FUNC
449  * @tc.require:
450  */
451 HWTEST_F(CloudDataTest, Unshare001, TestSize.Level0)
452 {
453     AllocNormalHapToken(g_normalPolicy);
454     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
455     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
456     std::string sharingRes = "";
457     CloudData::Participants participants{};
458     CloudData::Results results;
459     auto ret = proxy->Unshare(sharingRes, participants, results);
460     EXPECT_EQ(ret, CloudService::PERMISSION_DENIED);
461 }
462 
463 /* *
464  * @tc.name: Exit001
465  * @tc.desc: Test the system application permissions of the Exit001 API
466  * @tc.type: FUNC
467  * @tc.require:
468  */
469 HWTEST_F(CloudDataTest, Exit001, TestSize.Level0)
470 {
471     AllocNormalHapToken(g_normalPolicy);
472     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
473     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
474     std::string sharingRes = "";
475     std::pair<int32_t, std::string> result;
476     auto ret = proxy->Exit(sharingRes, result);
477     EXPECT_EQ(ret, CloudService::PERMISSION_DENIED);
478 }
479 
480 /* *
481  * @tc.name: ChangePrivilege001
482  * @tc.desc: Test the system application permissions of the ChangePrivilege001 API
483  * @tc.type: FUNC
484  * @tc.require:
485  */
486 HWTEST_F(CloudDataTest, ChangePrivilege001, TestSize.Level0)
487 {
488     AllocNormalHapToken(g_normalPolicy);
489     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
490     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
491     std::string sharingRes = "";
492     CloudData::Participants participants{};
493     CloudData::Results results;
494     auto ret = proxy->ChangePrivilege(sharingRes, participants, results);
495     EXPECT_EQ(ret, CloudService::PERMISSION_DENIED);
496 }
497 
498 /* *
499  * @tc.name: Query001
500  * @tc.desc: Test the system application permissions of the Query001 API
501  * @tc.type: FUNC
502  * @tc.require:
503  */
504 HWTEST_F(CloudDataTest, Query001, TestSize.Level0)
505 {
506     AllocNormalHapToken(g_normalPolicy);
507     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
508     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
509     std::string sharingRes = "";
510     CloudData::QueryResults result;
511     auto ret = proxy->Query(sharingRes, result);
512     EXPECT_EQ(ret, CloudService::PERMISSION_DENIED);
513 }
514 
515 /* *
516  * @tc.name:QueryByInvitation001
517  * @tc.desc: Test the system application permissions of the QueryByInvitation001 API
518  * @tc.type: FUNC
519  * @tc.require:
520  */
521 HWTEST_F(CloudDataTest, QueryByInvitation001, TestSize.Level0)
522 {
523     AllocNormalHapToken(g_normalPolicy);
524     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
525     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
526     std::string invitation = "";
527     CloudData::QueryResults result;
528     auto ret = proxy->QueryByInvitation(invitation, result);
529     EXPECT_EQ(ret, CloudService::PERMISSION_DENIED);
530 }
531 
532 /* *
533  * @tc.name:ConfirmInvitation001
534  * @tc.desc: Test the system application permissions of the ConfirmInvitation001 API
535  * @tc.type: FUNC
536  * @tc.require:
537  */
538 HWTEST_F(CloudDataTest, ConfirmInvitation001, TestSize.Level0)
539 {
540     AllocNormalHapToken(g_normalPolicy);
541     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
542     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
543     std::string sharingRes = "";
544     int32_t confirmation = 0;
545     std::tuple<int32_t, std::string, std::string> result;
546     auto ret = proxy->ConfirmInvitation(sharingRes, confirmation, result);
547     EXPECT_EQ(ret, CloudService::PERMISSION_DENIED);
548 }
549 
550 /* *
551  * @tc.name:ChangeConfirmation001
552  * @tc.desc: Test the system application permissions of the ChangeConfirmation001 API
553  * @tc.type: FUNC
554  * @tc.require:
555  */
556 HWTEST_F(CloudDataTest, ChangeConfirmation001, TestSize.Level0)
557 {
558     AllocNormalHapToken(g_normalPolicy);
559     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
560     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
561     std::string sharingRes = "";
562     int32_t confirmation = 0;
563     std::pair<int32_t, std::string> result;
564     auto ret = proxy->ChangeConfirmation(sharingRes, confirmation, result);
565     EXPECT_EQ(ret, CloudService::PERMISSION_DENIED);
566 }
567 
568 /* *
569  * @tc.name:SetCloudStrategy001
570  * @tc.desc: Test the system application permissions of the SetCloudStrategy001 API
571  * @tc.type: FUNC
572  * @tc.require:
573  */
574 HWTEST_F(CloudDataTest, SetCloudStrategy001, TestSize.Level1)
575 {
576     AllocNormalHapToken(g_normalPolicy);
577     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
578     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
579     std::vector<CommonType::Value> values;
580     values.push_back(CloudData::NetWorkStrategy::WIFI);
581     CloudData::Strategy strategy = CloudData::Strategy::STRATEGY_BUTT;
582     auto ret = proxy->SetCloudStrategy(strategy, values);
583     EXPECT_EQ(ret, CloudService::IPC_ERROR);
584     strategy = CloudData::Strategy::STRATEGY_NETWORK;
585     ret = proxy->SetCloudStrategy(strategy, values);
586     EXPECT_EQ(ret, CloudService::SUCCESS);
587 }
588 
589 /* *
590  * @tc.name: CloudSync001
591  * @tc.desc: Test the invalid param of the CloudSync API
592  * @tc.type: FUNC
593  * @tc.require:
594  */
595 HWTEST_F(CloudDataTest, CloudSync001, TestSize.Level1)
596 {
597     AllocNormalHapToken(g_normalPolicy);
598     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
599     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
600     auto ret = proxy->CloudSync(TEST_BUNDLE_NAME, TEST_STORE_ID, {}, nullptr);  // no progress
601     EXPECT_EQ(ret, CloudService::INVALID_ARGUMENT);
602     LOG_INFO("CloudSync001 test end.");
603 }
604 
605 /* *
606  * @tc.name: CloudSync002
607  * @tc.desc: Test the CloudSync API
608  * @tc.type: FUNC
609  * @tc.require:
610  */
611 HWTEST_F(CloudDataTest, CloudSync002, TestSize.Level1)
612 {
613     AllocSystemHapToken(g_systemPolicy);
614     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
615     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
__anonefc6bfbd0302(DistributedRdb::Details &&) 616     auto progress = [](DistributedRdb::Details &&) {};
617     auto status = proxy->CloudSync(TEST_BUNDLE_NAME, TEST_STORE_ID, {}, progress);
618     EXPECT_EQ(status, CloudService::INVALID_ARGUMENT);  // invalid syncMode
619     LOG_INFO("CloudSync002 test end.");
620 }
621 
622 /* *
623  * @tc.name: CloudSync003
624  * @tc.desc: Test the CloudSync API
625  * @tc.type: FUNC
626  * @tc.require:
627  */
628 HWTEST_F(CloudDataTest, CloudSync003, TestSize.Level1)
629 {
630     AllocSystemHapToken(g_systemPolicy);
631     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
632     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
__anonefc6bfbd0402(DistributedRdb::Details &&) 633     auto progress = [](DistributedRdb::Details &&) {};
634     int32_t syncMode = 4; // 4 is native_first
635     uint32_t seqNum = 10;
636     auto status = proxy->CloudSync(TEST_BUNDLE_NAME, TEST_STORE_ID, { syncMode, seqNum }, progress);
637     EXPECT_EQ(status, CloudService::SUCCESS);
638     LOG_INFO("CloudSync003 test end.");
639 }
640 
641 /* *
642  * @tc.name: CloudSync004
643  * @tc.desc: Test the hap permission of the CloudSync API
644  * @tc.type: FUNC
645  * @tc.require:
646  */
647 HWTEST_F(CloudDataTest, CloudSync004, TestSize.Level1)
648 {
649     AllocNormalHapToken(g_normalPolicy);
650     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
651     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
__anonefc6bfbd0502(DistributedRdb::Details &&) 652     auto progress = [](DistributedRdb::Details &&) {};
653     int32_t syncMode = 4; // 4 is native_first
654     uint32_t seqNum = 100;
655     auto status = proxy->CloudSync(TEST_BUNDLE_NAME, TEST_STORE_ID, { syncMode, seqNum }, progress);
656     EXPECT_EQ(status, CloudService::PERMISSION_DENIED);
657     LOG_INFO("CloudSync004 test end.");
658 }
659 
660 /* *
661  * @tc.name: CloudSync005
662  * @tc.desc: Test the permissions of the CloudSync API
663  * @tc.type: FUNC
664  * @tc.require:
665  */
666 HWTEST_F(CloudDataTest, CloudSync005, TestSize.Level1)
667 {
668     AllocSystemHapToken(g_notPermissonPolicy);
669     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
670     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
__anonefc6bfbd0602(DistributedRdb::Details &&) 671     auto progress = [](DistributedRdb::Details &&) {};
672     int32_t syncMode = 4; // 4 is native_first
673     uint32_t seqNum = 1000;
674     auto status = proxy->CloudSync(TEST_BUNDLE_NAME, TEST_STORE_ID, { syncMode, seqNum }, progress);
675     EXPECT_EQ(status, CloudService::CLOUD_CONFIG_PERMISSION_DENIED);
676     LOG_INFO("CloudSync005 test end.");
677 }
678 
679 /* *
680  * @tc.name: CloudSync006
681  * @tc.desc: Test the CloudSync API
682  * @tc.type: FUNC
683  * @tc.require:
684  */
685 HWTEST_F(CloudDataTest, CloudSync006, TestSize.Level1)
686 {
687     AllocSystemHapToken(g_systemPolicy);
688     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
689     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
__anonefc6bfbd0702(DistributedRdb::Details &&) 690     auto progress = [](DistributedRdb::Details &&) {};
691     int32_t syncMode = 4; // 4 is native_first
692     uint32_t seqNum = 20;
693     auto status = proxy->CloudSync(TEST_BUNDLE_NAME, TEST_STORE_ID, { syncMode, seqNum }, progress);
694     EXPECT_EQ(status, CloudService::SUCCESS);
695 
696     // same seqNum, register progress failed.
697     status = proxy->CloudSync(TEST_BUNDLE_NAME, TEST_STORE_ID, { syncMode, seqNum }, progress);
698     EXPECT_EQ(status, CloudService::ERROR);
699     LOG_INFO("CloudSync006 test end.");
700 }
701 
702 /* *
703  * @tc.name: CloudSync007
704  * @tc.desc: Test the invalid param of the CloudSync API
705  * @tc.type: FUNC
706  * @tc.require:
707  */
708 HWTEST_F(CloudDataTest, CloudSync007, TestSize.Level1)
709 {
710     AllocNormalHapToken(g_normalPolicy);
711     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
712     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
__anonefc6bfbd0802(DistributedRdb::Details &&) 713     auto progress = [](DistributedRdb::Details &&) {};
714     int32_t syncMode = 4; // 4 is native_first
715     uint32_t seqNum = 21;
716     auto ret = proxy->CloudSync("", TEST_STORE_ID, { syncMode, seqNum }, progress);  // bundleName is empty
717     EXPECT_EQ(ret, CloudService::INVALID_ARGUMENT);
718     LOG_INFO("CloudSync007 test end.");
719 }
720 
721 /* *
722  * @tc.name: CloudSync008
723  * @tc.desc: Test the invalid param of the CloudSync API
724  * @tc.type: FUNC
725  * @tc.require:
726  */
727 HWTEST_F(CloudDataTest, CloudSync008, TestSize.Level1)
728 {
729     AllocNormalHapToken(g_normalPolicy);
730     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
731     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
__anonefc6bfbd0902(DistributedRdb::Details &&) 732     auto progress = [](DistributedRdb::Details &&) {};
733     int32_t syncMode = 4; // 4 is native_first
734     uint32_t seqNum = 22;
735     auto ret = proxy->CloudSync(TEST_BUNDLE_NAME, "", { syncMode, seqNum }, progress);  // storeId is empty
736     EXPECT_EQ(ret, CloudService::INVALID_ARGUMENT);
737     LOG_INFO("CloudSync008 test end.");
738 }
739 
740 /* *
741  * @tc.name: CloudSync009
742  * @tc.desc: Test the invalid param of the CloudSync API
743  * @tc.type: FUNC
744  * @tc.require:
745  */
746 HWTEST_F(CloudDataTest, CloudSync009, TestSize.Level1)
747 {
748     AllocNormalHapToken(g_normalPolicy);
749     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
750     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
__anonefc6bfbd0a02(DistributedRdb::Details &&) 751     auto progress = [](DistributedRdb::Details &&) {};
752     int32_t syncMode = 10;
753     uint32_t seqNum = 22;
754     auto ret = proxy->CloudSync(TEST_BUNDLE_NAME, TEST_STORE_ID, { syncMode, seqNum }, progress);  // invalid syncMode
755     EXPECT_EQ(ret, CloudService::INVALID_ARGUMENT);
756     LOG_INFO("CloudSync009 test end.");
757 }
758 
759 /* *
760  * @tc.name: InitNotifier001
761  * @tc.desc: Test the InitNotifier API
762  * @tc.type: FUNC
763  * @tc.require:
764  */
765 HWTEST_F(CloudDataTest, InitNotifier001, TestSize.Level1)
766 {
767     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
768     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
769     sptr<CloudNotifierStub> notifier = nullptr;
770     auto status = proxy->InitNotifier(notifier);  // can not Marshalling a 'nullptr'
771     EXPECT_EQ(status, CloudService::IPC_PARCEL_ERROR);
772     LOG_INFO("InitNotifier001 test end.");
773 }
774 
775 /* *
776  * @tc.name: InitNotifier002
777  * @tc.desc: Test the InitNotifier API
778  * @tc.type: FUNC
779  * @tc.require:
780  */
781 HWTEST_F(CloudDataTest, InitNotifier002, TestSize.Level1)
782 {
783     auto [state, proxy] = CloudManager::GetInstance().GetCloudService();
784     ASSERT_EQ(state == CloudService::SUCCESS && proxy != nullptr, true);
785     sptr<CloudNotifierStub> notifier = new (std::nothrow) CloudNotifierStub(nullptr);
786     auto status = proxy->InitNotifier(notifier);
787     EXPECT_EQ(status, CloudService::SUCCESS);
788     LOG_INFO("InitNotifier002 test end.");
789 }
790 
791 /* *
792  * @tc.name: MarshallingOptionTest
793  * @tc.desc: Test the Marshalling interface
794  * @tc.type: FUNC
795  * @tc.require:
796  */
797 HWTEST_F(CloudDataTest, MarshallingOptionTest, TestSize.Level1)
798 {
799     LOG_INFO("MarshallingOptionTest test in.");
800     CloudData::CloudService::Option input;
801     input.syncMode = 4;
802     input.seqNum = 10;
803     MessageParcel parcel;
804     bool ret = ITypesUtil::Marshalling(input, parcel);
805     EXPECT_TRUE(ret);
806 
807     CloudData::CloudService::Option output;
808     ret = ITypesUtil::Unmarshalling(output, parcel);
809     EXPECT_TRUE(ret);
810     EXPECT_EQ(output.syncMode, input.syncMode);
811     EXPECT_EQ(output.seqNum, input.seqNum);
812     LOG_INFO("MarshallingOptionTest test end.");
813 }
814 } // namespace OHOS::CloudData