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 std::vector<std::string> & tables,const AsyncDetail & async)276 virtual int Sync(const SyncOption& option, const std::vector<std::string>& tables, const AsyncDetail& async) 277 { 278 return E_ERROR; 279 }; 280 Subscribe(const SubscribeOption & option,RdbStoreObserver * observer)281 virtual int Subscribe(const SubscribeOption& option, RdbStoreObserver *observer) 282 { 283 return E_ERROR; 284 }; 285 UnSubscribe(const SubscribeOption & option,RdbStoreObserver * observer)286 virtual int UnSubscribe(const SubscribeOption& option, RdbStoreObserver *observer) 287 { 288 return E_ERROR; 289 }; 290 Notify(const std::string & event)291 virtual int Notify(const std::string &event) 292 { 293 return E_ERROR; 294 } 295 DropDeviceData(const std::vector<std::string> & devices,const DropOption & option)296 virtual bool DropDeviceData(const std::vector<std::string>& devices, const DropOption& option) 297 { 298 return false; 299 }; 300 GetModifyTime(const std::string & table,const std::string & columnName,std::vector<PRIKey> & keys)301 virtual std::map<PRIKey, Date> GetModifyTime( 302 const std::string &table, const std::string &columnName, std::vector<PRIKey> &keys) 303 { 304 return {}; 305 }; 306 }; 307 308 /** 309 * @tc.name : RdbStoreDataCallBack_00100 310 * @tc.number : 311 * @tc.desc : test OnOpen function and hasTableInit_ is true 312 */ 313 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00100, Function | SmallTest | Level1) 314 { 315 NotificationRdbConfig notificationRdbConfig; 316 std::unique_ptr<RdbStoreDataCallBackNotificationStorage> rdbStoreData_ = 317 std::make_unique<RdbStoreDataCallBackNotificationStorage>(notificationRdbConfig); 318 rdbStoreData_->hasTableInit_ = true; 319 RdbStoreTest rdbStore; 320 EXPECT_EQ(rdbStoreData_->OnOpen(rdbStore), NativeRdb::E_OK); 321 } 322 323 /** 324 * @tc.name : RdbStoreDataCallBack_00200 325 * @tc.number : 326 * @tc.desc : test OnOpen function and ret != NativeRdb::E_OK 327 */ 328 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00200, Function | SmallTest | Level1) 329 { 330 NotificationRdbConfig notificationRdbConfig; 331 std::unique_ptr<RdbStoreDataCallBackNotificationStorage> rdbStoreData_ = 332 std::make_unique<RdbStoreDataCallBackNotificationStorage>(notificationRdbConfig); 333 rdbStoreData_->hasTableInit_ = false; 334 RdbStoreTest rdbStore; 335 EXPECT_EQ(rdbStoreData_->OnOpen(rdbStore), NativeRdb::E_OK); 336 } 337 338 /** 339 * @tc.name : RdbStoreDataCallBack_00300 340 * @tc.number : 341 * @tc.desc : test Init function and rdbStore_ == nullptr 342 */ 343 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00300, Function | SmallTest | Level1) 344 { 345 NotificationRdbConfig notificationRdbConfig; 346 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 347 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 348 EXPECT_EQ(notificationDataMgr->Init(), NativeRdb::E_ERROR); 349 } 350 351 /** 352 * @tc.name : RdbStoreDataCallBack_00400 353 * @tc.number : 354 * @tc.desc : test Destroy function and rdbStore_ == nullptr 355 */ 356 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00400, Function | SmallTest | Level1) 357 { 358 NotificationRdbConfig notificationRdbConfig; 359 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 360 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 361 EXPECT_EQ(notificationDataMgr->Destroy(), NativeRdb::E_ERROR); 362 } 363 364 /** 365 * @tc.name : RdbStoreDataCallBack_00500 366 * @tc.number : 367 * @tc.desc : test Destroy function and ret != NativeRdb::E_OK 368 */ 369 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00500, Function | SmallTest | Level1) 370 { 371 NotificationRdbConfig notificationRdbConfig; 372 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 373 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 374 notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>(); 375 EXPECT_EQ(notificationDataMgr->Destroy(), NativeRdb::E_ERROR); 376 } 377 378 /** 379 * @tc.name : RdbStoreDataCallBack_00600 380 * @tc.number : 381 * @tc.desc : test InsertData function and rdbStore_ == nullptr 382 */ 383 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00600, Function | SmallTest | Level1) 384 { 385 NotificationRdbConfig notificationRdbConfig; 386 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 387 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 388 notificationDataMgr->rdbStore_ = nullptr; 389 std::string key = "<key>"; 390 std::string value = "<value>"; 391 EXPECT_EQ(notificationDataMgr->InsertData(key, value), NativeRdb::E_ERROR); 392 } 393 394 /** 395 * @tc.name : RdbStoreDataCallBack_00700 396 * @tc.number : 397 * @tc.desc : test InsertData function and ret != NativeRdb::E_OK 398 */ 399 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00700, Function | SmallTest | Level1) 400 { 401 NotificationRdbConfig notificationRdbConfig; 402 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 403 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 404 notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>(); 405 std::string key = "<key>"; 406 std::string value = "<value>"; 407 EXPECT_EQ(notificationDataMgr->InsertData(key, value), NativeRdb::E_ERROR); 408 } 409 410 /** 411 * @tc.name : RdbStoreDataCallBack_00800 412 * @tc.number : 413 * @tc.desc : test InsertBatchData function and rdbStore_ == nullptr 414 */ 415 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00800, Function | SmallTest | Level1) 416 { 417 NotificationRdbConfig notificationRdbConfig; 418 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 419 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 420 notificationDataMgr->rdbStore_ = nullptr; 421 std::unordered_map<std::string, std::string> values; 422 EXPECT_EQ(notificationDataMgr->InsertBatchData(values), NativeRdb::E_ERROR); 423 } 424 425 /** 426 * @tc.name : RdbStoreDataCallBack_00900 427 * @tc.number : 428 * @tc.desc : test InsertBatchData function and ret != NativeRdb::E_OK 429 */ 430 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_00900, Function | SmallTest | Level1) 431 { 432 NotificationRdbConfig notificationRdbConfig; 433 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 434 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 435 notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>(); 436 std::unordered_map<std::string, std::string> values = { 437 { "--help", "--help"}, 438 { "--all", "--all"}, 439 { "--event", "--event"}, 440 { "-h", "-h" }, 441 { "-a", "-a" }, 442 { "-e", "-e" }, 443 }; 444 EXPECT_EQ(notificationDataMgr->InsertBatchData(values), NativeRdb::E_ERROR); 445 } 446 447 /** 448 * @tc.name : RdbStoreDataCallBack_01000 449 * @tc.number : 450 * @tc.desc : test DeleteData function and rdbStore_ == nullptr 451 */ 452 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01000, Function | SmallTest | Level1) 453 { 454 NotificationRdbConfig notificationRdbConfig; 455 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 456 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 457 notificationDataMgr->rdbStore_ = nullptr; 458 std::string key = "<key>"; 459 EXPECT_EQ(notificationDataMgr->DeleteData(key), NativeRdb::E_ERROR); 460 } 461 462 /** 463 * @tc.name : RdbStoreDataCallBack_01100 464 * @tc.number : 465 * @tc.desc : test DeleteData function and ret != NativeRdb::E_OK 466 */ 467 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01100, Function | SmallTest | Level1) 468 { 469 NotificationRdbConfig notificationRdbConfig; 470 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 471 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 472 notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>(); 473 std::string key = "<key>"; 474 EXPECT_EQ(notificationDataMgr->DeleteData(key), NativeRdb::E_ERROR); 475 } 476 477 /** 478 * @tc.name : RdbStoreDataCallBack_01200 479 * @tc.number : 480 * @tc.desc : test DeleteBathchData function and rdbStore_ == nullptr 481 */ 482 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01200, Function | SmallTest | Level1) 483 { 484 NotificationRdbConfig notificationRdbConfig; 485 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 486 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 487 notificationDataMgr->rdbStore_ = nullptr; 488 std::vector<std::string> keys; 489 EXPECT_EQ(notificationDataMgr->DeleteBathchData(keys), NativeRdb::E_ERROR); 490 } 491 492 /** 493 * @tc.name : RdbStoreDataCallBack_01300 494 * @tc.number : 495 * @tc.desc : test DeleteBathchData function and ret != NativeRdb::E_OK 496 */ 497 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01300, Function | SmallTest | Level1) 498 { 499 NotificationRdbConfig notificationRdbConfig; 500 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 501 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 502 notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>(); 503 std::vector<std::string> keys; 504 std::string key = "<key>"; 505 keys.emplace_back(key); 506 EXPECT_EQ(notificationDataMgr->DeleteBathchData(keys), NativeRdb::E_ERROR); 507 } 508 509 /** 510 * @tc.name : RdbStoreDataCallBack_01400 511 * @tc.number : 512 * @tc.desc : test QueryData function and rdbStore_ == nullptr 513 */ 514 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01400, Function | SmallTest | Level1) 515 { 516 NotificationRdbConfig notificationRdbConfig; 517 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 518 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 519 notificationDataMgr->rdbStore_ = nullptr; 520 std::string key = "<key>"; 521 std::string value = "<value>"; 522 EXPECT_EQ(notificationDataMgr->QueryData(key, value), NativeRdb::E_ERROR); 523 } 524 525 /** 526 * @tc.name : RdbStoreDataCallBack_01500 527 * @tc.number : 528 * @tc.desc : test QueryData function and absSharedResultSet == nullptr 529 */ 530 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01500, Function | SmallTest | Level1) 531 { 532 NotificationRdbConfig notificationRdbConfig; 533 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 534 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 535 notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>(); 536 std::string key = "<key>"; 537 std::string value = "<value>"; 538 g_mockQueryRet = true; 539 EXPECT_EQ(notificationDataMgr->QueryData(key, value), NativeRdb::E_ERROR); 540 } 541 542 /** 543 * @tc.name : RdbStoreDataCallBack_01600 544 * @tc.number : 545 * @tc.desc : test QueryData function and ret != NativeRdb::E_OK 546 */ 547 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01600, Function | SmallTest | Level1) 548 { 549 NotificationRdbConfig notificationRdbConfig; 550 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 551 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 552 notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>(); 553 std::string key = "<key>"; 554 std::string value = "<value>"; 555 g_mockQueryRet = false; 556 MockHasBlock(true); 557 MockGoToFirstRow(true); 558 MockGetString(false); 559 EXPECT_EQ(notificationDataMgr->QueryData(key, value), NativeRdb::E_ERROR); 560 } 561 562 /** 563 * @tc.name : RdbStoreDataCallBack_01700 564 * @tc.number : 565 * @tc.desc : test QueryDataBeginWithKey function and rdbStore_ == nullptr 566 */ 567 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01700, Function | SmallTest | Level1) 568 { 569 NotificationRdbConfig notificationRdbConfig; 570 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 571 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 572 notificationDataMgr->rdbStore_ = nullptr; 573 std::string key = "<key>"; 574 std::unordered_map<std::string, std::string> values; 575 EXPECT_EQ(notificationDataMgr->QueryDataBeginWithKey(key, values), NativeRdb::E_ERROR); 576 } 577 578 /** 579 * @tc.name : RdbStoreDataCallBack_01800 580 * @tc.number : 581 * @tc.desc : test QueryDataBeginWithKey function and absSharedResultSet == nullptr 582 */ 583 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01800, Function | SmallTest | Level1) 584 { 585 NotificationRdbConfig notificationRdbConfig; 586 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 587 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 588 notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>(); 589 g_mockQueryRet = true; 590 std::string key = "<key>"; 591 std::unordered_map<std::string, std::string> values; 592 EXPECT_EQ(notificationDataMgr->QueryDataBeginWithKey(key, values), NativeRdb::E_ERROR); 593 } 594 595 /** 596 * @tc.name : RdbStoreDataCallBack_01900 597 * @tc.number : 598 * @tc.desc : test QueryDataBeginWithKey function and ret != NativeRdb::E_OK 599 */ 600 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_01900, Function | SmallTest | Level1) 601 { 602 NotificationRdbConfig notificationRdbConfig; 603 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 604 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 605 notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>(); 606 g_mockQueryRet = false; 607 MockHasBlock(true); 608 MockGoToFirstRow(true); 609 MockGetString(false); 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_02000 617 * @tc.number : 618 * @tc.desc : test QueryAllData function and rdbStore_ == nullptr 619 */ 620 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_02000, Function | SmallTest | Level1) 621 { 622 NotificationRdbConfig notificationRdbConfig; 623 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 624 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 625 notificationDataMgr->rdbStore_ = nullptr; 626 std::unordered_map<std::string, std::string> datas; 627 EXPECT_EQ(notificationDataMgr->QueryAllData(datas), NativeRdb::E_ERROR); 628 } 629 630 /** 631 * @tc.name : RdbStoreDataCallBack_02100 632 * @tc.number : 633 * @tc.desc : test QueryAllData function and absSharedResultSet == nullptr 634 */ 635 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_02100, Function | SmallTest | Level1) 636 { 637 NotificationRdbConfig notificationRdbConfig; 638 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 639 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 640 notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>(); 641 g_mockQueryRet = true; 642 std::unordered_map<std::string, std::string> datas; 643 EXPECT_EQ(notificationDataMgr->QueryAllData(datas), NativeRdb::E_ERROR); 644 } 645 646 /** 647 * @tc.name : RdbStoreDataCallBack_02200 648 * @tc.number : 649 * @tc.desc : test QueryAllData function and GoToFirstRow != NativeRdb::E_OK 650 */ 651 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_02200, Function | SmallTest | Level1) 652 { 653 NotificationRdbConfig notificationRdbConfig; 654 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 655 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 656 notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>(); 657 g_mockQueryRet = false; 658 MockHasBlock(true); 659 MockGoToFirstRow(false); 660 std::unordered_map<std::string, std::string> datas; 661 EXPECT_EQ(notificationDataMgr->QueryAllData(datas), NativeRdb::E_EMPTY_VALUES_BUCKET); 662 } 663 664 /** 665 * @tc.name : RdbStoreDataCallBack_02300 666 * @tc.number : 667 * @tc.desc : test QueryAllData function and GetString != NativeRdb::E_OK 668 */ 669 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_02300, Function | SmallTest | Level1) 670 { 671 NotificationRdbConfig notificationRdbConfig; 672 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 673 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 674 notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>(); 675 g_mockQueryRet = false; 676 MockHasBlock(true); 677 MockGoToFirstRow(true); 678 MockGetString(false); 679 std::unordered_map<std::string, std::string> datas; 680 EXPECT_EQ(notificationDataMgr->QueryAllData(datas), NativeRdb::E_ERROR); 681 } 682 683 /** 684 * @tc.name : RdbStoreDataCallBack_02400 685 * @tc.number : 686 * @tc.desc : test QueryAllData function and GetString == NativeRdb::E_OK 687 */ 688 HWTEST_F(RdbStoreDataCallBackNotificationStorageTest, RdbStoreDataCallBack_02400, Function | SmallTest | Level1) 689 { 690 NotificationRdbConfig notificationRdbConfig; 691 std::unique_ptr<NotificationDataMgr> notificationDataMgr = 692 std::make_unique<NotificationDataMgr>(notificationRdbConfig); 693 notificationDataMgr->rdbStore_ = std::make_shared<RdbStoreTest>(); 694 g_mockQueryRet = false; 695 MockHasBlock(true); 696 MockGoToFirstRow(true); 697 MockGetString(true); 698 std::unordered_map<std::string, std::string> datas; 699 EXPECT_EQ(notificationDataMgr->QueryAllData(datas), NativeRdb::E_OK); 700 } 701 } // namespace Notification 702 } // namespace OHOS 703