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