• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 private public
17 #include <gtest/gtest.h>
18 
19 #define private public
20 #define protected public
21 #include "notification_rdb_data_mgr.h"
22 #undef private
23 #undef protected
24 #include "rdb_store.h"
25 #include "value_object.h"
26 
27 namespace {
28     bool g_mockQueryRet = true;
29 }
30 
31 extern void MockHasBlock(bool mockRet);
32 extern void MockGoToFirstRow(bool mockRet);
33 extern void MockGetString(bool mockRet);
34 
35 using namespace testing::ext;
36 using namespace OHOS::NativeRdb;
37 namespace OHOS {
38 namespace Notification {
39 class RdbStoreDataCallBackNotificationStorageTest : public testing::Test {
40 public:
SetUpTestCase()41     static void SetUpTestCase() {};
TearDownTestCase()42     static void TearDownTestCase() {};
SetUp()43     void SetUp() {};
TearDown()44     void TearDown() {};
45 };
46 
47 class RdbStoreTest : public RdbStore {
48     public:
Insert(int64_t & outRowId,const std::string & table,const ValuesBucket & initialValues)49         virtual int Insert(int64_t &outRowId, const std::string &table, const ValuesBucket &initialValues)
50         {
51             return NativeRdb::E_ERROR;
52         };
BatchInsert(int64_t & outInsertNum,const std::string & table,const std::vector<ValuesBucket> & initialBatchValues)53         virtual int BatchInsert(int64_t &outInsertNum, const std::string &table,
54             const std::vector<ValuesBucket> &initialBatchValues)
55         {
56             return NativeRdb::E_ERROR;
57         };
Replace(int64_t & outRowId,const std::string & table,const ValuesBucket & initialValues)58         virtual int Replace(int64_t &outRowId, const std::string &table, const ValuesBucket &initialValues)
59         {
60             return NativeRdb::E_ERROR;
61         };
InsertWithConflictResolution(int64_t & outRowId,const std::string & table,const ValuesBucket & initialValues,ConflictResolution conflictResolution=ConflictResolution::ON_CONFLICT_NONE)62         virtual int InsertWithConflictResolution(int64_t &outRowId, const std::string &table,
63             const ValuesBucket &initialValues,
64             ConflictResolution conflictResolution = ConflictResolution::ON_CONFLICT_NONE)
65         {
66             return NativeRdb::E_ERROR;
67         };
Update(int & changedRows,const std::string & table,const ValuesBucket & values,const std::string & whereClaus,const std::vector<std::string> & whereArgs)68         virtual int Update(int &changedRows, const std::string &table, const ValuesBucket &values,
69             const std::string &whereClaus,
70             const std::vector<std::string> &whereArgs)
71         {
72             return NativeRdb::E_ERROR;
73         };
Update(int & changedRows,const std::string & table,const ValuesBucket & values,const std::string & whereClause="",const std::vector<ValueObject> & bindArgs={})74         virtual int Update(int &changedRows, const std::string &table, const ValuesBucket &values,
75             const std::string &whereClause = "",
76             const std::vector<ValueObject> &bindArgs = {})
77         {
78             return NativeRdb::E_ERROR;
79         };
UpdateWithConflictResolution(int & changedRows,const std::string & table,const ValuesBucket & values,const std::string & whereClause,const std::vector<std::string> & whereArgs,ConflictResolution conflictResolution)80         virtual int UpdateWithConflictResolution(int &changedRows, const std::string &table, const ValuesBucket &values,
81             const std::string &whereClause, const std::vector<std::string> &whereArgs,
82             ConflictResolution conflictResolution)
83         {
84             return NativeRdb::E_ERROR;
85         };
UpdateWithConflictResolution(int & changedRows,const std::string & table,const ValuesBucket & values,const std::string & whereClause="",const std::vector<ValueObject> & bindArgs={},ConflictResolution conflictResolution=ConflictResolution::ON_CONFLICT_NONE)86         virtual int UpdateWithConflictResolution(int &changedRows, const std::string &table, const ValuesBucket &values,
87             const std::string &whereClause = "", const std::vector<ValueObject> &bindArgs = {},
88             ConflictResolution conflictResolution = ConflictResolution::ON_CONFLICT_NONE)
89         {
90             return NativeRdb::E_ERROR;
91         };
Delete(int & deletedRows,const std::string & table,const std::string & whereClause,const std::vector<std::string> & whereArgs)92         virtual int Delete(int &deletedRows, const std::string &table, const std::string &whereClause,
93             const std::vector<std::string> &whereArgs)
94         {
95             return NativeRdb::E_ERROR;
96         };
Delete(int & deletedRows,const std::string & table,const std::string & whereClause="",const std::vector<ValueObject> & bindArgs={})97         virtual int Delete(int &deletedRows, const std::string &table, const std::string &whereClause = "",
98             const std::vector<ValueObject> &bindArgs = {})
99         {
100             return NativeRdb::E_ERROR;
101         };
Query(int & errCode,bool distinct,const std::string & table,const std::vector<std::string> & columns,const std::string & whereClause="",const std::vector<ValueObject> & bindArgs={},const std::string & groupBy="",const std::string & indexName="",const std::string & orderBy="",const int & limit=AbsPredicates::INIT_LIMIT_VALUE,const int & offset=AbsPredicates::INIT_LIMIT_VALUE)102         virtual std::shared_ptr<AbsSharedResultSet> Query(int &errCode, bool distinct, const std::string &table,
103             const std::vector<std::string> &columns, const std::string &whereClause = "",
104             const std::vector<ValueObject> &bindArgs = {}, const std::string &groupBy = "",
105             const std::string &indexName = "", const std::string &orderBy = "",
106             const int &limit = AbsPredicates::INIT_LIMIT_VALUE,
107             const int &offset = AbsPredicates::INIT_LIMIT_VALUE)
108         {
109             return nullptr;
110         };
QuerySql(const std::string & sql,const std::vector<std::string> & selectionArgs)111         virtual std::shared_ptr<AbsSharedResultSet> QuerySql(
112             const std::string &sql, const std::vector<std::string> &selectionArgs)
113         {
114             return nullptr;
115         };
QuerySql(const std::string & sql,const std::vector<ValueObject> & selectionArgs={})116         virtual std::shared_ptr<AbsSharedResultSet> QuerySql(
117             const std::string &sql, const std::vector<ValueObject> &selectionArgs = {})
118         {
119             return nullptr;
120         };
QueryByStep(const std::string & sql,const std::vector<std::string> & selectionArgs)121         virtual std::shared_ptr<ResultSet> QueryByStep(
122             const std::string &sql, const std::vector<std::string> &selectionArgs)
123         {
124             return nullptr;
125         };
QueryByStep(const std::string & sql,const std::vector<ValueObject> & bindArgs={})126         virtual std::shared_ptr<ResultSet> QueryByStep(
127             const std::string &sql, const std::vector<ValueObject> &bindArgs = {})
128         {
129             return nullptr;
130         };
ExecuteSql(const std::string & sql,const std::vector<ValueObject> & bindArgs=std::vector<ValueObject> ())131         virtual int ExecuteSql(
132             const std::string &sql, const std::vector<ValueObject> &bindArgs = std::vector<ValueObject>())
133         {
134             return NativeRdb::E_ERROR;
135         };
ExecuteAndGetLong(int64_t & outValue,const std::string & sql,const std::vector<ValueObject> & bindArgs=std::vector<ValueObject> ())136         virtual int ExecuteAndGetLong(int64_t &outValue, const std::string &sql,
137             const std::vector<ValueObject> &bindArgs = std::vector<ValueObject>())
138         {
139             return NativeRdb::E_ERROR;
140         };
ExecuteAndGetString(std::string & outValue,const std::string & sql,const std::vector<ValueObject> & bindArgs=std::vector<ValueObject> ())141         virtual int ExecuteAndGetString(std::string &outValue, const std::string &sql,
142             const std::vector<ValueObject> &bindArgs = std::vector<ValueObject>())
143         {
144             return NativeRdb::E_ERROR;
145         };
ExecuteForLastInsertedRowId(int64_t & outValue,const std::string & sql,const std::vector<ValueObject> & bindArgs=std::vector<ValueObject> ())146         virtual int ExecuteForLastInsertedRowId(int64_t &outValue, const std::string &sql,
147             const std::vector<ValueObject> &bindArgs = std::vector<ValueObject>())
148         {
149             return NativeRdb::E_ERROR;
150         };
ExecuteForChangedRowCount(int64_t & outValue,const std::string & sql,const std::vector<ValueObject> & bindArgs=std::vector<ValueObject> ())151         virtual int ExecuteForChangedRowCount(int64_t &outValue, const std::string &sql,
152             const std::vector<ValueObject> &bindArgs = std::vector<ValueObject>())
153         {
154             return NativeRdb::E_ERROR;
155         };
Backup(const std::string databasePath,const std::vector<uint8_t> destEncryptKey)156         virtual int Backup(const std::string databasePath, const std::vector<uint8_t> destEncryptKey)
157         {
158             return NativeRdb::E_ERROR;
159         };
Attach(const std::string & alias,const std::string & pathName,const std::vector<uint8_t> destEncryptKey)160         virtual int Attach(
161             const std::string &alias, const std::string &pathName, const std::vector<uint8_t> destEncryptKey)
162         {
163             return NativeRdb::E_ERROR;
164         };
165 
Count(int64_t & outValue,const AbsRdbPredicates & predicates)166         virtual int Count(int64_t &outValue, const AbsRdbPredicates &predicates)
167         {
168             return NativeRdb::E_ERROR;
169         };
Query(const AbsRdbPredicates & predicates,const std::vector<std::string> & columns)170         virtual std::shared_ptr<AbsSharedResultSet> Query(
171             const AbsRdbPredicates &predicates, const std::vector<std::string> &columns)
172         {
173             if (g_mockQueryRet == false) {
174                 std::string name = "aa";
175                 std::shared_ptr<AbsSharedResultSet> resultSet =
176                     std::make_unique<AbsSharedResultSet>(name);
177                 return resultSet;
178             }
179             return nullptr;
180         };
QueryByStep(const AbsRdbPredicates & predicates,const std::vector<std::string> & columns)181         virtual std::shared_ptr<ResultSet> QueryByStep(
182             const AbsRdbPredicates &predicates, const std::vector<std::string> &columns)
183         {
184             return nullptr;
185         };
RemoteQuery(const std::string & device,const AbsRdbPredicates & predicates,const std::vector<std::string> & columns,int & errCode)186         virtual std::shared_ptr<ResultSet> RemoteQuery(const std::string &device,
187             const AbsRdbPredicates &predicates, const std::vector<std::string> &columns, int &errCode)
188         {
189             return nullptr;
190         };
Update(int & changedRows,const ValuesBucket & values,const AbsRdbPredicates & predicates)191         virtual int Update(int &changedRows, const ValuesBucket &values, const AbsRdbPredicates &predicates)
192         {
193             return NativeRdb::E_ERROR;
194         };
Delete(int & deletedRows,const AbsRdbPredicates & predicates)195         virtual int Delete(int &deletedRows, const AbsRdbPredicates &predicates)
196         {
197             return NativeRdb::E_ERROR;
198         };
199 
GetStatus()200         virtual int GetStatus()
201         {
202             return NativeRdb::E_ERROR;
203         };
SetStatus(int status)204         virtual void SetStatus(int status) {};
GetVersion(int & version)205         virtual int GetVersion(int &version)
206         {
207             return NativeRdb::E_ERROR;
208         };
SetVersion(int version)209         virtual int SetVersion(int version)
210         {
211             return NativeRdb::E_ERROR;
212         };
BeginTransaction()213         virtual int BeginTransaction()
214         {
215             return NativeRdb::E_ERROR;
216         };
RollBack()217         virtual int RollBack()
218         {
219             return NativeRdb::E_ERROR;
220         };
Commit()221         virtual int Commit()
222         {
223             return NativeRdb::E_ERROR;
224         };
IsInTransaction()225         virtual bool IsInTransaction()
226         {
227             return false;
228         };
GetPath()229         virtual std::string GetPath()
230         {
231             return "";
232         }
IsHoldingConnection()233         virtual bool IsHoldingConnection()
234         {
235             return false;
236         };
IsOpen() const237         virtual bool IsOpen() const
238         {
239             return false;
240         };
IsReadOnly() const241         virtual bool IsReadOnly() const
242         {
243             return false;
244         };
IsMemoryRdb() const245         virtual bool IsMemoryRdb() const
246         {
247             return false;
248         };
Restore(const std::string backupPath,const std::vector<uint8_t> & newKey)249         virtual int Restore(const std::string backupPath, const std::vector<uint8_t> &newKey)
250         {
251             return NativeRdb::E_ERROR;
252         };
ChangeDbFileForRestore(const std::string newPath,const std::string backupPath,const std::vector<uint8_t> & newKey)253         virtual int ChangeDbFileForRestore(const std::string newPath, const std::string backupPath,
254             const std::vector<uint8_t> &newKey)
255         {
256             return NativeRdb::E_ERROR;
257         };
258 
SetDistributedTables(const std::vector<std::string> & tables,int type,const DistributedRdb::DistributedConfig & distributedConfig)259         virtual int SetDistributedTables(const std::vector<std::string>& tables, int type,
260             const DistributedRdb::DistributedConfig &distributedConfig)
261         {
262             return E_ERROR;
263         };
264 
ObtainDistributedTableName(const std::string & device,const std::string & table,int & errCode)265         virtual std::string ObtainDistributedTableName(
266             const std::string &device, const std::string &table, int &errCode)
267         {
268             return "";
269         }
270 
Sync(const SyncOption & option,const AbsRdbPredicates & predicate,const AsyncBrief & async)271         virtual int Sync(const SyncOption& option, const AbsRdbPredicates& predicate, const AsyncBrief& async)
272         {
273             return E_ERROR;
274         };
275 
Sync(const SyncOption & option,const AbsRdbPredicates & predicate,const AsyncDetail & async)276         virtual int Sync(const SyncOption& option, const AbsRdbPredicates& predicate, const AsyncDetail& async)
277         {
278             return E_ERROR;
279         };
280 
Sync(const SyncOption & option,const std::vector<std::string> & tables,const AsyncDetail & async)281         virtual int Sync(const SyncOption& option, const std::vector<std::string>& tables, const AsyncDetail& async)
282         {
283             return E_ERROR;
284         };
285 
Subscribe(const SubscribeOption & option,RdbStoreObserver * observer)286         virtual int Subscribe(const SubscribeOption& option, RdbStoreObserver *observer)
287         {
288             return E_ERROR;
289         };
290 
UnSubscribe(const SubscribeOption & option,RdbStoreObserver * observer)291         virtual int UnSubscribe(const SubscribeOption& option, RdbStoreObserver *observer)
292         {
293             return E_ERROR;
294         };
295 
RegisterAutoSyncCallback(std::shared_ptr<DetailProgressObserver> syncObserver)296         virtual int RegisterAutoSyncCallback(std::shared_ptr<DetailProgressObserver> syncObserver)
297         {
298             return E_ERROR;
299         };
300 
UnregisterAutoSyncCallback(std::shared_ptr<DetailProgressObserver> syncObserver)301         virtual int UnregisterAutoSyncCallback(std::shared_ptr<DetailProgressObserver> syncObserver)
302         {
303             return E_ERROR;
304         };
305 
Notify(const std::string & event)306         virtual int Notify(const std::string &event)
307         {
308             return E_ERROR;
309         }
310 
DropDeviceData(const std::vector<std::string> & devices,const DropOption & option)311         virtual bool DropDeviceData(const std::vector<std::string>& devices, const DropOption& option)
312         {
313             return false;
314         };
315 
GetModifyTime(const std::string & table,const std::string & columnName,std::vector<PRIKey> & keys)316         virtual ModifyTime GetModifyTime(
317             const std::string &table, const std::string &columnName, std::vector<PRIKey> &keys)
318         {
319             return {};
320         };
321 
CleanDirtyData(const std::string & table,uint64_t cursor)322         virtual int CleanDirtyData(const std::string &table, uint64_t cursor)
323         {
324             return E_ERROR;
325         };
326 };
327 
328 /**
329  * @tc.name      : RdbStoreDataCallBack_00100
330  * @tc.number    :
331  * @tc.desc      : test OnOpen function and hasTableInit_ is true
332  */
333 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00100, Function | SmallTest | Level1)
334 {
335     NotificationRdbConfig notificationRdbConfig;
336     std::unique_ptr<RdbStoreDataCallBackNotificationStorage> rdbStoreData_ =
337         std::make_unique<RdbStoreDataCallBackNotificationStorage>(notificationRdbConfig);
338     rdbStoreData_->hasTableInit_ = true;
339     RdbStoreTest rdbStore;
340     EXPECT_EQ(rdbStoreData_->OnOpen(rdbStore), NativeRdb::E_OK);
341 }
342 
343 /**
344  * @tc.name      : RdbStoreDataCallBack_00200
345  * @tc.number    :
346  * @tc.desc      : test OnOpen function and ret != NativeRdb::E_OK
347  */
348 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00200, Function | SmallTest | Level1)
349 {
350     NotificationRdbConfig notificationRdbConfig;
351     std::unique_ptr<RdbStoreDataCallBackNotificationStorage> rdbStoreData_ =
352         std::make_unique<RdbStoreDataCallBackNotificationStorage>(notificationRdbConfig);
353     rdbStoreData_->hasTableInit_ = false;
354     RdbStoreTest rdbStore;
355     EXPECT_EQ(rdbStoreData_->OnOpen(rdbStore), NativeRdb::E_OK);
356 }
357 
358 /**
359  * @tc.name      : RdbStoreDataCallBack_00300
360  * @tc.number    :
361  * @tc.desc      : test Init function and rdbStore_ == nullptr
362  */
363 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00300, Function | SmallTest | Level1)
364 {
365     NotificationRdbConfig notificationRdbConfig;
366     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
367         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
368     EXPECT_EQ(notificationDataMgr->Init(), NativeRdb::E_ERROR);
369 }
370 
371 /**
372  * @tc.name      : RdbStoreDataCallBack_00400
373  * @tc.number    :
374  * @tc.desc      : test Destroy function and rdbStore_ == nullptr
375  */
376 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00400, Function | SmallTest | Level1)
377 {
378     NotificationRdbConfig notificationRdbConfig;
379     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
380         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
381     EXPECT_EQ(notificationDataMgr->Destroy(), NativeRdb::E_ERROR);
382 }
383 
384 /**
385  * @tc.name      : RdbStoreDataCallBack_00500
386  * @tc.number    :
387  * @tc.desc      : test Destroy function and ret != NativeRdb::E_OK
388  */
389 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00500, Function | SmallTest | Level1)
390 {
391     NotificationRdbConfig notificationRdbConfig;
392     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
393         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
394     notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>();
395     EXPECT_EQ(notificationDataMgr->Destroy(), NativeRdb::E_ERROR);
396 }
397 
398 /**
399  * @tc.name      : RdbStoreDataCallBack_00600
400  * @tc.number    :
401  * @tc.desc      : test InsertData function and rdbStore_ == nullptr
402  */
403 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00600, Function | SmallTest | Level1)
404 {
405     NotificationRdbConfig notificationRdbConfig;
406     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
407         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
408     notificationDataMgr->rdbStore_ = nullptr;
409     std::string key = "<key>";
410     std::string value = "<value>";
411     EXPECT_EQ(notificationDataMgr->InsertData(key, value), NativeRdb::E_ERROR);
412 }
413 
414 /**
415  * @tc.name      : RdbStoreDataCallBack_00700
416  * @tc.number    :
417  * @tc.desc      : test InsertData function and ret != NativeRdb::E_OK
418  */
419 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00700, Function | SmallTest | Level1)
420 {
421     NotificationRdbConfig notificationRdbConfig;
422     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
423         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
424     notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>();
425     std::string key = "<key>";
426     std::string value = "<value>";
427     EXPECT_EQ(notificationDataMgr->InsertData(key, value), NativeRdb::E_ERROR);
428 }
429 
430 /**
431  * @tc.name      : RdbStoreDataCallBack_00800
432  * @tc.number    :
433  * @tc.desc      : test InsertBatchData function and rdbStore_ == nullptr
434  */
435 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00800, Function | SmallTest | Level1)
436 {
437     NotificationRdbConfig notificationRdbConfig;
438     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
439         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
440     notificationDataMgr->rdbStore_ = nullptr;
441     std::unordered_map<std::string, std::string> values;
442     EXPECT_EQ(notificationDataMgr->InsertBatchData(values), NativeRdb::E_ERROR);
443 }
444 
445 /**
446  * @tc.name      : RdbStoreDataCallBack_00900
447  * @tc.number    :
448  * @tc.desc      : test InsertBatchData function and ret != NativeRdb::E_OK
449  */
450 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00900, Function | SmallTest | Level1)
451 {
452     NotificationRdbConfig notificationRdbConfig;
453     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
454         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
455     notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>();
456     std::unordered_map<std::string, std::string> values = {
457         { "--help", "--help"},
458         { "--all", "--all"},
459         { "--event", "--event"},
460         { "-h", "-h" },
461         { "-a", "-a" },
462         { "-e", "-e" },
463     };
464     EXPECT_EQ(notificationDataMgr->InsertBatchData(values), NativeRdb::E_ERROR);
465 }
466 
467 /**
468  * @tc.name      : RdbStoreDataCallBack_01000
469  * @tc.number    :
470  * @tc.desc      : test DeleteData function and rdbStore_ == nullptr
471  */
472 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01000, Function | SmallTest | Level1)
473 {
474     NotificationRdbConfig notificationRdbConfig;
475     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
476         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
477     notificationDataMgr->rdbStore_ = nullptr;
478     std::string key = "<key>";
479     EXPECT_EQ(notificationDataMgr->DeleteData(key), NativeRdb::E_ERROR);
480 }
481 
482 /**
483  * @tc.name      : RdbStoreDataCallBack_01100
484  * @tc.number    :
485  * @tc.desc      : test DeleteData function and ret != NativeRdb::E_OK
486  */
487 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01100, Function | SmallTest | Level1)
488 {
489     NotificationRdbConfig notificationRdbConfig;
490     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
491         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
492     notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>();
493     std::string key = "<key>";
494     EXPECT_EQ(notificationDataMgr->DeleteData(key), NativeRdb::E_ERROR);
495 }
496 
497 /**
498  * @tc.name      : RdbStoreDataCallBack_01200
499  * @tc.number    :
500  * @tc.desc      : test DeleteBathchData function and rdbStore_ == nullptr
501  */
502 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01200, Function | SmallTest | Level1)
503 {
504     NotificationRdbConfig notificationRdbConfig;
505     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
506         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
507     notificationDataMgr->rdbStore_ = nullptr;
508     std::vector<std::string> keys;
509     EXPECT_EQ(notificationDataMgr->DeleteBathchData(keys), NativeRdb::E_ERROR);
510 }
511 
512 /**
513  * @tc.name      : RdbStoreDataCallBack_01300
514  * @tc.number    :
515  * @tc.desc      : test DeleteBathchData function and ret != NativeRdb::E_OK
516  */
517 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01300, Function | SmallTest | Level1)
518 {
519     NotificationRdbConfig notificationRdbConfig;
520     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
521         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
522     notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>();
523     std::vector<std::string> keys;
524     std::string key = "<key>";
525     keys.emplace_back(key);
526     EXPECT_EQ(notificationDataMgr->DeleteBathchData(keys), NativeRdb::E_ERROR);
527 }
528 
529 /**
530  * @tc.name      : RdbStoreDataCallBack_01400
531  * @tc.number    :
532  * @tc.desc      : test QueryData function and rdbStore_ == nullptr
533  */
534 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01400, Function | SmallTest | Level1)
535 {
536     NotificationRdbConfig notificationRdbConfig;
537     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
538         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
539     notificationDataMgr->rdbStore_ = nullptr;
540     std::string key = "<key>";
541     std::string value = "<value>";
542     EXPECT_EQ(notificationDataMgr->QueryData(key, value), NativeRdb::E_ERROR);
543 }
544 
545 /**
546  * @tc.name      : RdbStoreDataCallBack_01500
547  * @tc.number    :
548  * @tc.desc      : test QueryData function and absSharedResultSet == nullptr
549  */
550 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01500, Function | SmallTest | Level1)
551 {
552     NotificationRdbConfig notificationRdbConfig;
553     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
554         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
555     notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>();
556     std::string key = "<key>";
557     std::string value = "<value>";
558     g_mockQueryRet = true;
559     EXPECT_EQ(notificationDataMgr->QueryData(key, value), NativeRdb::E_ERROR);
560 }
561 
562 /**
563  * @tc.name      : RdbStoreDataCallBack_01600
564  * @tc.number    :
565  * @tc.desc      : test QueryData function and ret != NativeRdb::E_OK
566  */
567 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01600, Function | SmallTest | Level1)
568 {
569     NotificationRdbConfig notificationRdbConfig;
570     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
571         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
572     notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>();
573     std::string key = "<key>";
574     std::string value = "<value>";
575     g_mockQueryRet = false;
576     MockHasBlock(true);
577     MockGoToFirstRow(true);
578     MockGetString(false);
579     EXPECT_EQ(notificationDataMgr->QueryData(key, value), NativeRdb::E_ERROR);
580 }
581 
582 /**
583  * @tc.name      : RdbStoreDataCallBack_01700
584  * @tc.number    :
585  * @tc.desc      : test QueryDataBeginWithKey function and rdbStore_ == nullptr
586  */
587 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01700, Function | SmallTest | Level1)
588 {
589     NotificationRdbConfig notificationRdbConfig;
590     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
591         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
592     notificationDataMgr->rdbStore_ = nullptr;
593     std::string key = "<key>";
594     std::unordered_map<std::string, std::string> values;
595     EXPECT_EQ(notificationDataMgr->QueryDataBeginWithKey(key, values), NativeRdb::E_ERROR);
596 }
597 
598 /**
599  * @tc.name      : RdbStoreDataCallBack_01800
600  * @tc.number    :
601  * @tc.desc      : test QueryDataBeginWithKey function and absSharedResultSet == nullptr
602  */
603 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01800, Function | SmallTest | Level1)
604 {
605     NotificationRdbConfig notificationRdbConfig;
606     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
607         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
608     notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>();
609     g_mockQueryRet = true;
610     std::string key = "<key>";
611     std::unordered_map<std::string, std::string> values;
612     EXPECT_EQ(notificationDataMgr->QueryDataBeginWithKey(key, values), NativeRdb::E_ERROR);
613 }
614 
615 /**
616  * @tc.name      : RdbStoreDataCallBack_01900
617  * @tc.number    :
618  * @tc.desc      : test QueryDataBeginWithKey function and ret != NativeRdb::E_OK
619  */
620 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01900, Function | SmallTest | Level1)
621 {
622     NotificationRdbConfig notificationRdbConfig;
623     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
624         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
625     notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>();
626     g_mockQueryRet = false;
627     MockHasBlock(true);
628     MockGoToFirstRow(true);
629     MockGetString(false);
630     std::string key = "<key>";
631     std::unordered_map<std::string, std::string> values;
632     EXPECT_EQ(notificationDataMgr->QueryDataBeginWithKey(key, values), NativeRdb::E_ERROR);
633 }
634 
635 /**
636  * @tc.name      : RdbStoreDataCallBack_02000
637  * @tc.number    :
638  * @tc.desc      : test QueryAllData function and rdbStore_ == nullptr
639  */
640 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_02000, Function | SmallTest | Level1)
641 {
642     NotificationRdbConfig notificationRdbConfig;
643     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
644         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
645     notificationDataMgr->rdbStore_ = nullptr;
646     std::unordered_map<std::string, std::string> datas;
647     EXPECT_EQ(notificationDataMgr->QueryAllData(datas), NativeRdb::E_ERROR);
648 }
649 
650 /**
651  * @tc.name      : RdbStoreDataCallBack_02100
652  * @tc.number    :
653  * @tc.desc      : test QueryAllData function and absSharedResultSet == nullptr
654  */
655 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_02100, Function | SmallTest | Level1)
656 {
657     NotificationRdbConfig notificationRdbConfig;
658     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
659         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
660     notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>();
661     g_mockQueryRet = true;
662     std::unordered_map<std::string, std::string> datas;
663     EXPECT_EQ(notificationDataMgr->QueryAllData(datas), NativeRdb::E_ERROR);
664 }
665 
666 /**
667  * @tc.name      : RdbStoreDataCallBack_02200
668  * @tc.number    :
669  * @tc.desc      : test QueryAllData function and GoToFirstRow != NativeRdb::E_OK
670  */
671 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_02200, Function | SmallTest | Level1)
672 {
673     NotificationRdbConfig notificationRdbConfig;
674     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
675         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
676     notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>();
677     g_mockQueryRet = false;
678     MockHasBlock(true);
679     MockGoToFirstRow(false);
680     std::unordered_map<std::string, std::string> datas;
681     EXPECT_EQ(notificationDataMgr->QueryAllData(datas), NativeRdb::E_EMPTY_VALUES_BUCKET);
682 }
683 
684 /**
685  * @tc.name      : RdbStoreDataCallBack_02300
686  * @tc.number    :
687  * @tc.desc      : test QueryAllData function and GetString != NativeRdb::E_OK
688  */
689 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_02300, Function | SmallTest | Level1)
690 {
691     NotificationRdbConfig notificationRdbConfig;
692     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
693         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
694     notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>();
695     g_mockQueryRet = false;
696     MockHasBlock(true);
697     MockGoToFirstRow(true);
698     MockGetString(false);
699     std::unordered_map<std::string, std::string> datas;
700     EXPECT_EQ(notificationDataMgr->QueryAllData(datas), NativeRdb::E_ERROR);
701 }
702 
703 /**
704  * @tc.name      : RdbStoreDataCallBack_02400
705  * @tc.number    :
706  * @tc.desc      : test QueryAllData function and GetString == NativeRdb::E_OK
707  */
708 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_02400, Function | SmallTest | Level1)
709 {
710     NotificationRdbConfig notificationRdbConfig;
711     std::unique_ptr<NotificationDataMgr> notificationDataMgr =
712         std::make_unique<NotificationDataMgr>(notificationRdbConfig);
713     notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>();
714     g_mockQueryRet = false;
715     MockHasBlock(true);
716     MockGoToFirstRow(true);
717     MockGetString(true);
718     std::unordered_map<std::string, std::string> datas;
719     EXPECT_EQ(notificationDataMgr->QueryAllData(datas), NativeRdb::E_OK);
720 }
721 }  // namespace Notification
722 }  // namespace OHOS
723