• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 #include "cloud_pref_impl.h"
20 #include <sys/stat.h>
21 #include <unistd.h>
22 #include "utils_log.h"
23 
24 #define USERID 100
25 namespace OHOS::FileManagement::CloudSync::Test {
26 using namespace testing;
27 using namespace testing::ext;
28 using namespace std;
29 using namespace NativePreferences;
30 
31 class PreferencesMock : public Preferences {
32 public:
33     MOCK_METHOD2(Get, PreferencesValue(const std::string &key, const PreferencesValue &defValue));
34     MOCK_METHOD2(Put, int(const std::string &key, const PreferencesValue &value));
35     MOCK_METHOD2(GetInt, int(const std::string &key, const int &defValue));
36     MOCK_METHOD2(GetString, std::string(const std::string &key, const std::string &defValue));
37     MOCK_METHOD2(GetBool, bool(const std::string &key, const bool &defValue));
38     MOCK_METHOD2(GetFloat, float(const std::string &key, const float &defValue));
39     MOCK_METHOD2(GetDouble, double(const std::string &key, const double &defValue));
40     MOCK_METHOD2(GetLong, int64_t(const std::string &key, const int64_t &defValue));
41     MOCK_METHOD0(GetAll, std::map<std::string, PreferencesValue>());
42     MOCK_METHOD1(HasKey, bool(const std::string &key));
43     MOCK_METHOD2(PutInt, int(const std::string &key, int value));
44     MOCK_METHOD2(PutString, int(const std::string &key, const std::string &value));
45     MOCK_METHOD2(PutBool, int(const std::string &key, bool value));
46     MOCK_METHOD2(PutLong, int(const std::string &key, int64_t value));
47     MOCK_METHOD2(PutFloat, int(const std::string &key, float value));
48     MOCK_METHOD2(PutDouble, int(const std::string &key, double value));
49     MOCK_METHOD1(Delete, int(const std::string &key));
50     MOCK_METHOD0(Clear, int());
51     MOCK_METHOD0(Flush, void());
52     MOCK_METHOD0(FlushSync, int());
53     MOCK_METHOD2(RegisterObserver, int(std::shared_ptr<PreferencesObserver> preferencesObserver, RegisterMode mode));
54     MOCK_METHOD2(UnRegisterObserver, int(std::shared_ptr<PreferencesObserver> preferencesObserver, RegisterMode mode));
55 };
56 
57 class CloudPrefImplTest : public testing::Test {
58 public:
59     static void SetUpTestCase(void);
60     static void TearDownTestCase(void);
61     void SetUp();
62     void TearDown();
63     int32_t userId_;
64     std::string fileName_;
65     std::shared_ptr<CloudPrefImpl> cloudPtr_;
66     static inline std::shared_ptr<PreferencesMock> preferencesMock_;
67 };
68 
SetUpTestCase(void)69 void CloudPrefImplTest::SetUpTestCase(void)
70 {
71     GTEST_LOG_(INFO) << "SetUpTestCase";
72 }
73 
TearDownTestCase(void)74 void CloudPrefImplTest::TearDownTestCase(void)
75 {
76     GTEST_LOG_(INFO) << "TearDownTestCase";
77 }
78 
SetUp(void)79 void CloudPrefImplTest::SetUp(void)
80 {
81     userId_ = USERID;
82     fileName_ = "test";
83     cloudPtr_ = std::make_shared<CloudPrefImpl>(fileName_);
84     if (cloudPtr_ == nullptr) {
85         GTEST_LOG_(INFO) << "cloudPtr_ == nullptr";
86     }
87 
88     preferencesMock_ = std::make_shared<PreferencesMock>();
89     if (preferencesMock_ == nullptr) {
90         GTEST_LOG_(INFO) << "preferencesMock_ == nullptr";
91     }
92     GTEST_LOG_(INFO) << "SetUp";
93 }
94 
TearDown(void)95 void CloudPrefImplTest::TearDown(void)
96 {
97     if (cloudPtr_ != nullptr) {
98         cloudPtr_ = nullptr;
99     }
100 
101     if (preferencesMock_ != nullptr) {
102         preferencesMock_ = nullptr;
103     }
104     GTEST_LOG_(INFO) << "TearDown";
105 }
106 
107 /**
108  * @tc.name: CloudPrefImplTest001
109  * @tc.desc: Verify the CloudPrefImpl function
110  * @tc.type: FUNC
111  * @tc.require: I6H5MH
112  */
113 HWTEST_F(CloudPrefImplTest, CloudPrefImpTest001, TestSize.Level1)
114 {
115     GTEST_LOG_(INFO) << "CloudPrefImpTest001 Start";
116     try {
117         CloudPrefImpl cloudPreImpl("");
118         EXPECT_EQ(cloudPreImpl.pref_, nullptr);
119     } catch (...) {
120         EXPECT_TRUE(false);
121         GTEST_LOG_(INFO) << " CloudPrefImpTest001 ERROR";
122     }
123     GTEST_LOG_(INFO) << "CloudPrefImpTest001 End";
124 }
125 
126 /**
127  * @tc.name: CloudPrefImplTest002
128  * @tc.desc: Verify the CloudPrefImpl function
129  * @tc.type: FUNC
130  * @tc.require: I6H5MH
131  */
132 HWTEST_F(CloudPrefImplTest, CloudPrefImpTest002, TestSize.Level1)
133 {
134     GTEST_LOG_(INFO) << "CloudPrefImpTest002 Start";
135     try {
136         CloudPrefImpl cloudPreImpl(fileName_);
137         EXPECT_NE(cloudPreImpl.pref_, nullptr);
138     } catch (...) {
139         EXPECT_TRUE(false);
140         GTEST_LOG_(INFO) << " CloudPrefImpTest002 ERROR";
141     }
142     GTEST_LOG_(INFO) << "CloudPrefImpTest002 End";
143 }
144 
145 /**
146  * @tc.name: CloudPrefImplTest003
147  * @tc.desc: Verify the CloudPrefImpl function
148  * @tc.type: FUNC
149  * @tc.require: I6H5MH
150  */
151 HWTEST_F(CloudPrefImplTest, CloudPrefImplTest003, TestSize.Level1)
152 {
153     GTEST_LOG_(INFO) << "CloudPrefImplTest003 Start";
154     try {
155         const std::string bundleName = "";
156         std::string fileDir = "/data/service/el1/public/cloudfile/";
157         std::string tableName = "testTable";
158         EXPECT_EQ(access(fileDir.c_str(), F_OK), 0);
159         CloudPrefImpl cloudPreImpl(userId_, bundleName, tableName);
160         EXPECT_NE(cloudPreImpl.pref_, nullptr);
161     } catch (...) {
162         EXPECT_TRUE(false);
163         GTEST_LOG_(INFO) << " CloudPrefImplTest003 ERROR";
164     }
165     GTEST_LOG_(INFO) << "CloudPrefImplTest003 End";
166 }
167 
168 /**
169  * @tc.name: SetStringTest
170  * @tc.desc: Verify the SetString function
171  * @tc.type: FUNC
172  * @tc.require: I6H5MH
173  */
174 HWTEST_F(CloudPrefImplTest, SetStringTest, TestSize.Level1)
175 {
176     GTEST_LOG_(INFO) << "SetStringTest Start";
177     try {
178         EXPECT_NE(cloudPtr_->pref_, nullptr);
179         std::string key;
180         std::string value;
181         cloudPtr_->SetString(key, value);
182         EXPECT_TRUE(true);
183     } catch (...) {
184         EXPECT_TRUE(false);
185         GTEST_LOG_(INFO) << " SetStringTest ERROR";
186     }
187     GTEST_LOG_(INFO) << "SetStringTest End";
188 }
189 
190 /**
191  * @tc.name: GetStringTest
192  * @tc.desc: Verify the GetString function
193  * @tc.type: FUNC
194  * @tc.require: I6H5MH
195  */
196 HWTEST_F(CloudPrefImplTest, GetStringTest, TestSize.Level1)
197 {
198     GTEST_LOG_(INFO) << "GetStringTest Start";
199     try {
200         EXPECT_NE(cloudPtr_->pref_, nullptr);
201         std::string key;
202         std::string value;
203         cloudPtr_->GetString(key, value);
204         EXPECT_TRUE(true);
205     } catch (...) {
206         EXPECT_TRUE(false);
207         GTEST_LOG_(INFO) << " GetStringTest ERROR";
208     }
209     GTEST_LOG_(INFO) << "GetStringTest End";
210 }
211 
212 /**
213  * @tc.name: SetIntTest
214  * @tc.desc: Verify the SetInt function
215  * @tc.type: FUNC
216  * @tc.require: I6H5MH
217  */
218 HWTEST_F(CloudPrefImplTest, SetIntTest, TestSize.Level1)
219 {
220     GTEST_LOG_(INFO) << "SetIntTest Start";
221     try {
222         EXPECT_NE(cloudPtr_->pref_, nullptr);
223         std::string key;
224         int value = 0;
225         cloudPtr_->SetInt(key, value);
226         EXPECT_TRUE(true);
227     } catch (...) {
228         EXPECT_TRUE(false);
229         GTEST_LOG_(INFO) << " SetIntTest ERROR";
230     }
231     GTEST_LOG_(INFO) << "SetIntTest End";
232 }
233 
234 /**
235  * @tc.name: GetIntTest
236  * @tc.desc: Verify the GetInt function
237  * @tc.type: FUNC
238  * @tc.require: I6H5MH
239  */
240 HWTEST_F(CloudPrefImplTest, GetIntTest, TestSize.Level1)
241 {
242     GTEST_LOG_(INFO) << "GetIntTest Start";
243     try {
244         EXPECT_NE(cloudPtr_->pref_, nullptr);
245         std::string key;
246         int32_t value = 0;
247         cloudPtr_->GetInt(key, value);
248         EXPECT_TRUE(true);
249     } catch (...) {
250         EXPECT_TRUE(false);
251         GTEST_LOG_(INFO) << " GetIntTest ERROR";
252     }
253     GTEST_LOG_(INFO) << "GetIntTest End";
254 }
255 
256 /**
257  * @tc.name: ClearTest
258  * @tc.desc: Verify the Clear function
259  * @tc.type: FUNC
260  * @tc.require: I6H5MH
261  */
262 HWTEST_F(CloudPrefImplTest, ClearTest, TestSize.Level1)
263 {
264     GTEST_LOG_(INFO) << "ClearTest Start";
265     try {
266         EXPECT_NE(cloudPtr_->pref_, nullptr);
267         cloudPtr_->Clear();
268         EXPECT_TRUE(true);
269     } catch (...) {
270         EXPECT_TRUE(false);
271         GTEST_LOG_(INFO) << " ClearTest ERROR";
272     }
273     GTEST_LOG_(INFO) << "ClearTest End";
274 }
275 
276 /**
277  * @tc.name: DeleteTest
278  * @tc.desc: Verify the Delete function
279  * @tc.type: FUNC
280  * @tc.require: I6H5MH
281  */
282 HWTEST_F(CloudPrefImplTest, DeleteTest, TestSize.Level1)
283 {
284     GTEST_LOG_(INFO) << "DeleteTest Start";
285     try {
286         EXPECT_NE(cloudPtr_->pref_, nullptr);
287         std::string key;
288         cloudPtr_->Delete(key);
289         EXPECT_TRUE(true);
290     } catch (...) {
291         EXPECT_TRUE(false);
292         GTEST_LOG_(INFO) << " DeleteTest ERROR";
293     }
294     GTEST_LOG_(INFO) << "DeleteTest End";
295 }
296 
297 HWTEST_F(CloudPrefImplTest, CloudPrefImpl_001, TestSize.Level0)
298 {
299     GTEST_LOG_(INFO) << "CloudPrefImpl_001 Start";
300     try {
301         int32_t userId = 100;
302         string bundleName = "testBundle";
303         string tableName = "testTable";
304         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
305         EXPECT_NE(cloudPrefImpl.pref_, nullptr);
306     } catch (...) {
307         EXPECT_TRUE(false);
308         GTEST_LOG_(INFO) << " CloudPrefImpl_001 ERROR";
309     }
310     GTEST_LOG_(INFO) << "CloudPrefImpl_001 End";
311 }
312 
313 HWTEST_F(CloudPrefImplTest, CloudPrefImpl_002, TestSize.Level0)
314 {
315     GTEST_LOG_(INFO) << "CloudPrefImpl_002 Start";
316     try {
317         int32_t userId = -1;
318         string bundleName = "testBundle";
319         string tableName = "testTable";
320         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
321         EXPECT_NE(cloudPrefImpl.pref_, nullptr);
322     } catch (...) {
323         EXPECT_TRUE(false);
324         GTEST_LOG_(INFO) << " CloudPrefImpl_002 ERROR";
325     }
326     GTEST_LOG_(INFO) << "CloudPrefImpl_002 End";
327 }
328 
329 HWTEST_F(CloudPrefImplTest, CloudPrefImpl_003, TestSize.Level0)
330 {
331     GTEST_LOG_(INFO) << "CloudPrefImpl_003 Start";
332     try {
333         int32_t userId = 123;
334         string bundleName = "";
335         string tableName = "testTable";
336         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
337         EXPECT_NE(cloudPrefImpl.pref_, nullptr);
338     } catch (...) {
339         EXPECT_TRUE(false);
340         GTEST_LOG_(INFO) << " CloudPrefImpl_003 ERROR";
341     }
342     GTEST_LOG_(INFO) << "CloudPrefImpl_003 End";
343 }
344 
345 HWTEST_F(CloudPrefImplTest, CloudPrefImpl_004, TestSize.Level0)
346 {
347     GTEST_LOG_(INFO) << "CloudPrefImpl_004 Start";
348     try {
349         int32_t userId = 123;
350         string bundleName = "test_key";
351         string tableName = "";
352         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
353         EXPECT_EQ(cloudPrefImpl.pref_, nullptr);
354     } catch (...) {
355         EXPECT_TRUE(false);
356         GTEST_LOG_(INFO) << " CloudPrefImpl_004 ERROR";
357     }
358     GTEST_LOG_(INFO) << "CloudPrefImpl_004 End";
359 }
360 
361 HWTEST_F(CloudPrefImplTest, SetString_001, TestSize.Level0)
362 {
363     GTEST_LOG_(INFO) << "SetString_001 Start";
364     try {
365         PreferencesMock preferencesMock;
366         string key = "";
367         string value = "test_value";
368         EXPECT_CALL(preferencesMock, PutString(_, _)).WillOnce(Return(X_OK));
369         EXPECT_CALL(preferencesMock, FlushSync()).WillOnce(Return(X_OK));
370 
371         EXPECT_EQ(preferencesMock.PutString(key, value), X_OK);
372         EXPECT_EQ(preferencesMock.FlushSync(), X_OK);
373         cloudPtr_->SetString(key, value);
374         cloudPtr_->GetString(key, value);
375         EXPECT_EQ(key, "");
376     } catch (...) {
377         EXPECT_TRUE(false);
378         GTEST_LOG_(INFO) << " SetString_001 ERROR";
379     }
380     GTEST_LOG_(INFO) << "SetString_001 End";
381 }
382 
383 HWTEST_F(CloudPrefImplTest, SetString_002, TestSize.Level0)
384 {
385     GTEST_LOG_(INFO) << "SetString_002 Start";
386     try {
387         int32_t userId = 100;
388         string bundleName = "";
389         string tableName = "";
390         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
391 
392         string key = "test_key";
393         string value = "";
394         cloudPrefImpl.SetString(key, value);
395         cloudPrefImpl.GetString(key, value);
396         EXPECT_EQ(key, "test_key");
397     } catch (...) {
398         EXPECT_TRUE(false);
399         GTEST_LOG_(INFO) << " SetString_002 ERROR";
400     }
401     GTEST_LOG_(INFO) << "SetString_002 End";
402 }
403 
404 HWTEST_F(CloudPrefImplTest, SetString_003, TestSize.Level0)
405 {
406     GTEST_LOG_(INFO) << "SetString_003 Start";
407     try {
408         int32_t userId = 100;
409         string bundleName = "test_key";
410         string tableName = "";
411         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
412 
413         string key = "test_key";
414         string value = "test_value";
415         cloudPrefImpl.SetString(key, value);
416         cloudPrefImpl.GetString(key, value);
417         EXPECT_EQ(value, "");
418     } catch (...) {
419         EXPECT_TRUE(false);
420         GTEST_LOG_(INFO) << " SetString_003 ERROR";
421     }
422     GTEST_LOG_(INFO) << "SetString_003 End";
423 }
424 
425 HWTEST_F(CloudPrefImplTest, SetString_004, TestSize.Level0)
426 {
427     string key = "";
428     string value = "test_value";
429 
430     EXPECT_CALL(*preferencesMock_, PutString(_, _)).WillOnce(Return(X_OK));
431     EXPECT_CALL(*preferencesMock_, FlushSync()).WillOnce(Return(X_OK));
432 
433     cloudPtr_->SetString(key, value);
434     EXPECT_EQ(key, "");
435     EXPECT_EQ(preferencesMock_->PutString(key, value), X_OK);
436     EXPECT_EQ(preferencesMock_->FlushSync(), X_OK);
437 }
438 
439 HWTEST_F(CloudPrefImplTest, SetLong_001, TestSize.Level0)
440 {
441     GTEST_LOG_(INFO) << "SetLong_001 Start";
442     try {
443         int32_t userId = 100;
444         string bundleName = "test_key";
445         string tableName = "";
446         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
447 
448         string key = "test_key";
449         int64_t value = -1;;
450         cloudPrefImpl.SetLong(key, value);
451         cloudPrefImpl.GetLong(key, value);
452         EXPECT_EQ(key, "test_key");
453     } catch (...) {
454         EXPECT_TRUE(false);
455         GTEST_LOG_(INFO) << " SetLong_001 ERROR";
456     }
457     GTEST_LOG_(INFO) << "SetLong_001 End";
458 }
459 
460 HWTEST_F(CloudPrefImplTest, SetLong_002, TestSize.Level0)
461 {
462     GTEST_LOG_(INFO) << "SetLong_002 Start";
463     try {
464         int32_t userId = 100;
465         string bundleName = "test_key";
466         string tableName = "";
467         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
468 
469         string key = "test_key";
470         int64_t value = 89;
471         cloudPrefImpl.SetLong(key, value);
472         cloudPrefImpl.GetLong(key, value);
473         EXPECT_EQ(key, "test_key");
474     } catch (...) {
475         EXPECT_TRUE(false);
476         GTEST_LOG_(INFO) << " SetLong_002 ERROR";
477     }
478     GTEST_LOG_(INFO) << "SetLong_002 End";
479 }
480 
481 HWTEST_F(CloudPrefImplTest, SetLong_003, TestSize.Level0)
482 {
483     GTEST_LOG_(INFO) << "SetLong_003 Start";
484     try {
485         int32_t userId = 100;
486         string bundleName = "test_key";
487         string tableName = "";
488         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
489 
490         string key = "";
491         int64_t value = -1;
492         cloudPrefImpl.SetLong(key, value);
493         cloudPrefImpl.GetLong(key, value);
494         EXPECT_EQ(key, "");
495     } catch (...) {
496         EXPECT_TRUE(false);
497         GTEST_LOG_(INFO) << " SetLong_003 ERROR";
498     }
499     GTEST_LOG_(INFO) << "SetLong_003 End";
500 }
501 
502 HWTEST_F(CloudPrefImplTest, SetLong_004, TestSize.Level0)
503 {
504     GTEST_LOG_(INFO) << "SetLong_004 Start";
505     try {
506         int32_t userId = 100;
507         string bundleName = "test_key";
508         string tableName = "";
509         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
510 
511         string key = "";
512         int64_t value = 89;
513         cloudPrefImpl.SetLong(key, value);
514         cloudPrefImpl.GetLong(key, value);
515         EXPECT_EQ(key, "");
516     } catch (...) {
517         EXPECT_TRUE(false);
518         GTEST_LOG_(INFO) << " SetLong_004 ERROR";
519     }
520     GTEST_LOG_(INFO) << "SetLong_004 End";
521 }
522 
523 HWTEST_F(CloudPrefImplTest, SetInt_001, TestSize.Level0)
524 {
525     GTEST_LOG_(INFO) << "SetInt_001 Start";
526     try {
527         int32_t userId = 123;
528         string bundleName = "";
529         string tableName = "";
530         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
531 
532         string key = "test_key";
533         int value = 1;
534         cloudPrefImpl.SetInt(key, value);
535         cloudPrefImpl.GetInt(key, value);
536         EXPECT_EQ(key, "test_key");
537     } catch (...) {
538         EXPECT_TRUE(false);
539         GTEST_LOG_(INFO) << " SetInt_001 ERROR";
540     }
541     GTEST_LOG_(INFO) << "SetInt_001 End";
542 }
543 
544 HWTEST_F(CloudPrefImplTest, SetInt_002, TestSize.Level0)
545 {
546     GTEST_LOG_(INFO) << "SetInt_002 Start";
547     try {
548         int32_t userId = 123;
549         string bundleName = "";
550         string tableName = "";
551         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
552 
553         string key = "";
554         int value = 0;
555         cloudPrefImpl.SetInt(key, value);
556         cloudPrefImpl.GetInt(key, value);
557         EXPECT_EQ(key, "");
558     } catch (...) {
559         EXPECT_TRUE(false);
560         GTEST_LOG_(INFO) << " SetInt_002 ERROR";
561     }
562     GTEST_LOG_(INFO) << "SetInt_002 End";
563 }
564 
565 HWTEST_F(CloudPrefImplTest, SetInt_003, TestSize.Level0)
566 {
567     GTEST_LOG_(INFO) << "SetInt_003 Start";
568     try {
569         int32_t userId = 123;
570         string bundleName = "";
571         string tableName = "";
572         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
573 
574         string key = "test_key";
575         int value = 0x7fffffff;
576         cloudPrefImpl.SetInt(key, value);
577         cloudPrefImpl.GetInt(key, value);
578         EXPECT_EQ(key, "test_key");
579     } catch (...) {
580         EXPECT_TRUE(false);
581         GTEST_LOG_(INFO) << " SetInt_003 ERROR";
582     }
583     GTEST_LOG_(INFO) << "SetInt_003 End";
584 }
585 
586 HWTEST_F(CloudPrefImplTest, SetInt_004, TestSize.Level0)
587 {
588     GTEST_LOG_(INFO) << "SetInt_004 Start";
589     try {
590         int32_t userId = 123;
591         string bundleName = "";
592         string tableName = "";
593         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
594 
595         string key = "test_key";
596         int value = 0xffffffff;
597         cloudPrefImpl.SetInt(key, value);
598         cloudPrefImpl.GetInt(key, value);
599         EXPECT_EQ(key, "test_key");
600     } catch (...) {
601         EXPECT_TRUE(false);
602         GTEST_LOG_(INFO) << " SetInt_004 ERROR";
603     }
604     GTEST_LOG_(INFO) << "SetInt_004 End";
605 }
606 
607 HWTEST_F(CloudPrefImplTest, SetBool_001, TestSize.Level0)
608 {
609     GTEST_LOG_(INFO) << "SetBool_001 Start";
610     try {
611         int32_t userId = 123;
612         string bundleName = "";
613         string tableName = "";
614         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
615 
616         string key = "test_key";
617         bool value = true;
618         cloudPrefImpl.SetBool(key, value);
619         cloudPrefImpl.GetBool(key, value);
620         EXPECT_FALSE(value);
621     } catch (...) {
622         EXPECT_TRUE(false);
623         GTEST_LOG_(INFO) << " SetBool_001 ERROR";
624     }
625     GTEST_LOG_(INFO) << "SetBool_001 End";
626 }
627 
628 HWTEST_F(CloudPrefImplTest, SetBool_002, TestSize.Level0)
629 {
630     GTEST_LOG_(INFO) << "SetBool_002 Start";
631     try {
632         int32_t userId = 123;
633         string bundleName = "";
634         string tableName = "";
635         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
636 
637         string key = "test_key";
638         bool value = false;
639         cloudPrefImpl.SetBool(key, value);
640         cloudPrefImpl.GetBool(key, value);
641         EXPECT_FALSE(value);
642     } catch (...) {
643         EXPECT_TRUE(false);
644         GTEST_LOG_(INFO) << " SetBool_002 ERROR";
645     }
646     GTEST_LOG_(INFO) << "SetBool_002 End";
647 }
648 
649 HWTEST_F(CloudPrefImplTest, SetBool_003, TestSize.Level0)
650 {
651     GTEST_LOG_(INFO) << "SetBool_003 Start";
652     try {
653         int32_t userId = 123;
654         string bundleName = "";
655         string tableName = "";
656         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
657 
658         string key = "test_key";
659         bool value = true;
660         cloudPrefImpl.SetBool(key, value);
661         cloudPrefImpl.GetBool(key, value);
662         EXPECT_FALSE(value);
663     } catch (...) {
664         EXPECT_TRUE(false);
665         GTEST_LOG_(INFO) << " SetBool_003 ERROR";
666     }
667     GTEST_LOG_(INFO) << "SetBool_003 End";
668 }
669 
670 HWTEST_F(CloudPrefImplTest, SetBool_004, TestSize.Level0)
671 {
672     GTEST_LOG_(INFO) << "SetBool_004 Start";
673     try {
674         int32_t userId = 123;
675         string bundleName = "";
676         string tableName = "";
677         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
678 
679         string key = "test_key";
680         bool value = false;
681         cloudPrefImpl.SetBool(key, value);
682         cloudPrefImpl.GetBool(key, value);
683         EXPECT_FALSE(value);
684     } catch (...) {
685         EXPECT_TRUE(false);
686         GTEST_LOG_(INFO) << " SetBool_004 ERROR";
687     }
688     GTEST_LOG_(INFO) << "SetBool_004 End";
689 }
690 
691 HWTEST_F(CloudPrefImplTest, Delete_001, TestSize.Level0)
692 {
693     GTEST_LOG_(INFO) << "Delete_001 Start";
694     try {
695         int32_t userId = 123;
696         string bundleName = "";
697         string tableName = "";
698         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
699 
700         string key = "test_key";
701         cloudPrefImpl.Delete(key);
702         EXPECT_EQ(key, "test_key");
703     } catch (...) {
704         EXPECT_TRUE(false);
705         GTEST_LOG_(INFO) << " Delete_001 ERROR";
706     }
707     GTEST_LOG_(INFO) << "Delete_001 End";
708 }
709 
710 HWTEST_F(CloudPrefImplTest, Delete_002, TestSize.Level0)
711 {
712     GTEST_LOG_(INFO) << "Delete_001 Start";
713     try {
714         int32_t userId = 123;
715         string bundleName = "";
716         string tableName = "";
717         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
718 
719         string key = "";
720         cloudPrefImpl.Delete(key);
721         EXPECT_EQ(key, "");
722     } catch (...) {
723         EXPECT_TRUE(false);
724         GTEST_LOG_(INFO) << " Delete_002 ERROR";
725     }
726     GTEST_LOG_(INFO) << "Delete_002 End";
727 }
728 
729 HWTEST_F(CloudPrefImplTest, Delete_003, TestSize.Level0)
730 {
731     GTEST_LOG_(INFO) << "Delete_003 Start";
732     try {
733         int32_t userId = 123;
734         string bundleName = "";
735         string tableName = "";
736         CloudPrefImpl cloudPrefImpl(userId, bundleName, tableName);
737 
738         string key = "/";
739         cloudPrefImpl.Delete(key);
740         EXPECT_EQ(key, "/");
741     } catch (...) {
742         EXPECT_TRUE(false);
743         GTEST_LOG_(INFO) << " Delete_003 ERROR";
744     }
745     GTEST_LOG_(INFO) << "Delete_003 End";
746 }
747 
748 /**
749  * @tc.name: SetStringTest001
750  * @tc.desc: Verify the SetString function
751  * @tc.type: FUNC
752  * @tc.require: I6H5MH
753  */
754 HWTEST_F(CloudPrefImplTest, SetStringTest001, TestSize.Level1)
755 {
756     GTEST_LOG_(INFO) << "SetStringTest001 Start";
757     std::string key;
758     std::string value;
759     cloudPtr_->pref_ = nullptr;
760     cloudPtr_->SetString(key, value);
761     EXPECT_EQ(cloudPtr_->pref_, nullptr);
762 
763     GTEST_LOG_(INFO) << "SetStringTest001 End";
764 }
765 
766 /**
767  * @tc.name: GetStringTest001
768  * @tc.desc: Verify the GetString function
769  * @tc.type: FUNC
770  * @tc.require: I6H5MH
771  */
772 HWTEST_F(CloudPrefImplTest, GetStringTest001, TestSize.Level1)
773 {
774     GTEST_LOG_(INFO) << "GetStringTest001 Start";
775     std::string key;
776     std::string value;
777     cloudPtr_->pref_ = nullptr;
778     cloudPtr_->GetString(key, value);
779     EXPECT_EQ(cloudPtr_->pref_, nullptr);
780 
781     GTEST_LOG_(INFO) << "GetStringTest001 End";
782 }
783 
784 /**
785  * @tc.name: SetLongTest001
786  * @tc.desc: Verify the SetLong function
787  * @tc.type: FUNC
788  * @tc.require: I6H5MH
789  */
790 HWTEST_F(CloudPrefImplTest, SetLongTest001, TestSize.Level1)
791 {
792     GTEST_LOG_(INFO) << "SetLongTest001 Start";
793     std::string key;
794     int64_t value = 0;
795     cloudPtr_->pref_ = nullptr;
796     cloudPtr_->SetLong(key, value);
797     EXPECT_EQ(cloudPtr_->pref_, nullptr);
798 
799     GTEST_LOG_(INFO) << "SetLongTest001 End";
800 }
801 
802 /**
803  * @tc.name: GetLongTest001
804  * @tc.desc: Verify the GetLong function
805  * @tc.type: FUNC
806  * @tc.require: I6H5MH
807  */
808 HWTEST_F(CloudPrefImplTest, GetLongTest001, TestSize.Level1)
809 {
810     GTEST_LOG_(INFO) << "GetLongTest001 Start";
811     std::string key;
812     int64_t value = 0;
813     cloudPtr_->pref_ = nullptr;
814     cloudPtr_->GetLong(key, value);
815     EXPECT_EQ(cloudPtr_->pref_, nullptr);
816 
817     GTEST_LOG_(INFO) << "GetLongTest001 End";
818 }
819 
820 /**
821  * @tc.name: SetIntTest001
822  * @tc.desc: Verify the SetInt function
823  * @tc.type: FUNC
824  * @tc.require: I6H5MH
825  */
826 HWTEST_F(CloudPrefImplTest, SetIntTest001, TestSize.Level1)
827 {
828     GTEST_LOG_(INFO) << "SetIntTest001 Start";
829     std::string key;
830     int value = 0;
831     cloudPtr_->pref_ = nullptr;
832     cloudPtr_->SetInt(key, value);
833     EXPECT_EQ(cloudPtr_->pref_, nullptr);
834 
835     GTEST_LOG_(INFO) << "SetIntTest001 End";
836 }
837 
838 /**
839  * @tc.name: GetIntTest001
840  * @tc.desc: Verify the GetInt function
841  * @tc.type: FUNC
842  * @tc.require: I6H5MH
843  */
844 HWTEST_F(CloudPrefImplTest, GetIntTest001, TestSize.Level1)
845 {
846     GTEST_LOG_(INFO) << "GetIntTest001 Start";
847     std::string key;
848     int32_t value = 0;
849     cloudPtr_->pref_ = nullptr;
850     cloudPtr_->GetInt(key, value);
851     EXPECT_EQ(cloudPtr_->pref_, nullptr);
852 
853     GTEST_LOG_(INFO) << "GetIntTest001 End";
854 }
855 
856 /**
857  * @tc.name: SetBoolTest001
858  * @tc.desc: Verify the SetBool function
859  * @tc.type: FUNC
860  * @tc.require: I6H5MH
861  */
862 HWTEST_F(CloudPrefImplTest, SetBoolTest001, TestSize.Level1)
863 {
864     GTEST_LOG_(INFO) << "SetBoolTest001 Start";
865     std::string key;
866     bool value = true;
867     cloudPtr_->pref_ = nullptr;
868     cloudPtr_->SetBool(key, value);
869     EXPECT_EQ(cloudPtr_->pref_, nullptr);
870 
871     GTEST_LOG_(INFO) << "SetBoolTest001 End";
872 }
873 
874 /**
875  * @tc.name: GetBoolTest001
876  * @tc.desc: Verify the GetBool function
877  * @tc.type: FUNC
878  * @tc.require: I6H5MH
879  */
880 HWTEST_F(CloudPrefImplTest, GetBoolTest001, TestSize.Level1)
881 {
882     GTEST_LOG_(INFO) << "GetBoolTest001 Start";
883     std::string key;
884     bool value = true;
885     cloudPtr_->pref_ = nullptr;
886     cloudPtr_->GetBool(key, value);
887     EXPECT_EQ(cloudPtr_->pref_, nullptr);
888 
889     GTEST_LOG_(INFO) << "GetBoolTest001 End";
890 }
891 
892 /**
893  * @tc.name: ClearTest001
894  * @tc.desc: Verify the Clear function
895  * @tc.type: FUNC
896  * @tc.require: I6H5MH
897  */
898 HWTEST_F(CloudPrefImplTest, ClearTest001, TestSize.Level1)
899 {
900     GTEST_LOG_(INFO) << "ClearTest001 Start";
901     cloudPtr_->pref_ = nullptr;
902     cloudPtr_->Clear();
903     EXPECT_EQ(cloudPtr_->pref_, nullptr);
904 
905     GTEST_LOG_(INFO) << "ClearTest001 End";
906 }
907 
908 /**
909  * @tc.name: DeleteTest001
910  * @tc.desc: Verify the Delete function
911  * @tc.type: FUNC
912  * @tc.require: I6H5MH
913  */
914 HWTEST_F(CloudPrefImplTest, DeleteTest001, TestSize.Level1)
915 {
916     GTEST_LOG_(INFO) << "DeleteTest001 Start";
917     cloudPtr_->pref_ = nullptr;
918     std::string key;
919     cloudPtr_->Delete(key);
920     EXPECT_EQ(cloudPtr_->pref_, nullptr);
921 
922     GTEST_LOG_(INFO) << "DeleteTest001 End";
923 }
924 } // namespace OHOS::FileManagement::CloudSync::Test