diff --git a/frameworks/innerkitsimpl/distributeddatafwk/test/BUILD.gn b/frameworks/innerkitsimpl/distributeddatafwk/test/BUILD.gn index c8b4b6fe7ac2b5941f1d7ca1d47e6e5ad7bea597..515f153c29e7de868e4d3288bcf03d73d0d83c53 100755 --- a/frameworks/innerkitsimpl/distributeddatafwk/test/BUILD.gn +++ b/frameworks/innerkitsimpl/distributeddatafwk/test/BUILD.gn @@ -73,14 +73,10 @@ ohos_unittest("DistributedKvDataManagerEncryptTest") { ] } -ohos_unittest("KvStoreClientTest") { +ohos_unittest("LocalSubscribeStoreTest") { module_out_path = module_output_path - sources = [ - "unittest/kvstore_client_test.cpp", - "unittest/single_kvstore_client_query_test.cpp", - "unittest/single_kvstore_client_test.cpp", - ] + sources = [ "unittest/local_subscribe_store_test.cpp" ] configs = [ ":module_private_config" ] @@ -98,10 +94,10 @@ ohos_unittest("KvStoreClientTest") { ] } -ohos_unittest("KvStoreSnapshotClientTest") { +ohos_unittest("SingleKvStoreClientQueryTest") { module_out_path = module_output_path - sources = [ "unittest/kvstore_snapshot_client_test.cpp" ] + sources = [ "unittest/single_kvstore_client_query_test.cpp" ] configs = [ ":module_private_config" ] @@ -119,10 +115,10 @@ ohos_unittest("KvStoreSnapshotClientTest") { ] } -ohos_unittest("LocalSubscribeStoreTest") { +ohos_unittest("SingleKvStoreClientTest") { module_out_path = module_output_path - sources = [ "unittest/local_subscribe_store_test.cpp" ] + sources = [ "unittest/single_kvstore_client_test.cpp" ] configs = [ ":module_private_config" ] @@ -165,9 +161,9 @@ group("unittest") { ":BlobTest", ":DistributedKvDataManagerEncryptTest", ":DistributedKvDataManagerTest", - ":KvStoreClientTest", - ":KvStoreSnapshotClientTest", ":LocalSubscribeStoreTest", + ":SingleKvStoreClientQueryTest", + ":SingleKvStoreClientTest", ] } ############################################################################### diff --git a/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/distributed_kv_data_manager_encrypt_test.cpp b/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/distributed_kv_data_manager_encrypt_test.cpp index 59a80d3a18a8f619c76c5f74a5477067070286e0..b2f5b3ec330cc1a85ff354b797b1cb9aee245e4e 100644 --- a/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/distributed_kv_data_manager_encrypt_test.cpp +++ b/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/distributed_kv_data_manager_encrypt_test.cpp @@ -72,7 +72,7 @@ void DistributedKvDataManagerEncryptTest::SetUpTestCase(void) createEnc.createIfMissing = true; createEnc.encrypt = true; createEnc.autoSync = true; - createEnc.kvStoreType = MULTI_VERSION; + createEnc.kvStoreType = SINGLE_VERSION; userId.userId = "account0"; appId.appId = "com.ohos.nb.service"; @@ -107,26 +107,20 @@ void DistributedKvDataManagerEncryptTest::TearDown(void) HWTEST_F(DistributedKvDataManagerEncryptTest, kvstore_ddm_createEncryptedStore_001, TestSize.Level1) { ZLOGI("kvstore_ddm_createEncryptedStore_001 begin."); - std::shared_ptr kvStorePtr; - Status status = manager.GetKvStore(createEnc, appId, storeId, kvStorePtr); + std::shared_ptr kvStore; + Status status = manager.GetSingleKvStore(createEnc, appId, storeId, kvStore); ASSERT_EQ(status, Status::SUCCESS); - ASSERT_NE(kvStorePtr, nullptr); + ASSERT_NE(kvStore, nullptr); Key key = "age"; Value value = "18"; - status = kvStorePtr->Put(key, value); + status = kvStore->Put(key, value); EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; - std::shared_ptr snapshot; - // [create and] open and initialize kvstore snapshot instance. - status = kvStorePtr->GetKvStoreSnapshot(nullptr, snapshot); - EXPECT_EQ(Status::SUCCESS, status) << "KvStore GetKvStoreSnapshot data return wrong status"; - ASSERT_NE(nullptr, snapshot) << "snapshot is nullptr"; // get value from kvstore. Value valueRet; - Status statusRet = snapshot->Get(key, valueRet); - EXPECT_EQ(Status::SUCCESS, statusRet) << "KvStoreSnapshot get data return wrong status"; + Status statusRet = kvStore->Get(key, valueRet); + EXPECT_EQ(Status::SUCCESS, statusRet) << "get data return wrong status"; EXPECT_EQ(value, valueRet) << "value and valueRet are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(snapshot); } diff --git a/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/distributed_kv_data_manager_test.cpp b/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/distributed_kv_data_manager_test.cpp index 857ba5e42c03088e381913e13b25d7622ff90ead..69d55662ef387e04347a432e2feaafd8dba5bc90 100644 --- a/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/distributed_kv_data_manager_test.cpp +++ b/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/distributed_kv_data_manager_test.cpp @@ -84,13 +84,13 @@ void DistributedKvDataManagerTest::SetUpTestCase(void) create.createIfMissing = true; create.encrypt = false; create.autoSync = true; - create.kvStoreType = MULTI_VERSION; + create.kvStoreType = SINGLE_VERSION; noCreate.createIfMissing = false; noCreate.encrypt = false; noCreate.autoSync = true; noCreate.dataOwnership = true; - noCreate.kvStoreType = MULTI_VERSION; + noCreate.kvStoreType = SINGLE_VERSION; userId.userId = "account0"; appId.appId = "com.ohos.kvdatamanager.test"; @@ -126,7 +126,7 @@ void DistributedKvDataManagerTest::TearDown(void) /** * @tc.name: GetKvStore001 -* @tc.desc: Get an exist KvStore +* @tc.desc: Get an exist SingleKvStore * @tc.type: FUNC * @tc.require: SR000CQDU0 AR000BVTDM * @tc.author: liqiao @@ -134,20 +134,20 @@ void DistributedKvDataManagerTest::TearDown(void) HWTEST_F(DistributedKvDataManagerTest, GetKvStore001, TestSize.Level1) { ZLOGI("GetKvStore001 begin."); - std::shared_ptr notExistKvStorePtr; - Status status = manager.GetKvStore(create, appId, storeId64, notExistKvStorePtr); + std::shared_ptr notExistKvStore; + Status status = manager.GetSingleKvStore(create, appId, storeId64, notExistKvStore); ASSERT_EQ(status, Status::SUCCESS); - EXPECT_NE(notExistKvStorePtr, nullptr); + EXPECT_NE(notExistKvStore, nullptr); - std::shared_ptr existKvStorePtr; - status = manager.GetKvStore(noCreate, appId, storeId64, existKvStorePtr); + std::shared_ptr existKvStore; + status = manager.GetSingleKvStore(noCreate, appId, storeId64, existKvStore); ASSERT_EQ(status, Status::SUCCESS); - EXPECT_NE(existKvStorePtr, nullptr); + EXPECT_NE(existKvStore, nullptr); } /** * @tc.name: GetKvStore002 -* @tc.desc: Create and get a new KvStore +* @tc.desc: Create and get a new SingleKvStore * @tc.type: FUNC * @tc.require: SR000CQDU0 AR000BVTDM * @tc.author: liqiao @@ -155,17 +155,17 @@ HWTEST_F(DistributedKvDataManagerTest, GetKvStore001, TestSize.Level1) HWTEST_F(DistributedKvDataManagerTest, GetKvStore002, TestSize.Level1) { ZLOGI("GetKvStore002 begin."); - std::shared_ptr notExistKvStorePtr; - Status status = manager.GetKvStore(create, appId, storeId64, notExistKvStorePtr); + std::shared_ptr notExistKvStore; + Status status = manager.GetSingleKvStore(create, appId, storeId64, notExistKvStore); ASSERT_EQ(status, Status::SUCCESS); - EXPECT_NE(notExistKvStorePtr, nullptr); + EXPECT_NE(notExistKvStore, nullptr); manager.CloseKvStore(appId, storeId64); manager.DeleteKvStore(appId, storeId64); } /** * @tc.name: GetKvStore003 -* @tc.desc: Get a non-existing KvStore, and the callback function should receive STORE_NOT_FOUND and +* @tc.desc: Get a non-existing SingleKvStore, and the callback function should receive STORE_NOT_FOUND and * get a nullptr. * @tc.type: FUNC * @tc.require: SR000CQDU0 AR000BVTDM @@ -174,15 +174,15 @@ HWTEST_F(DistributedKvDataManagerTest, GetKvStore002, TestSize.Level1) HWTEST_F(DistributedKvDataManagerTest, GetKvStore003, TestSize.Level1) { ZLOGI("GetKvStore003 begin."); - std::shared_ptr notExistKvStorePtr; - Status status = manager.GetKvStore(noCreate, appId, storeId64, notExistKvStorePtr); + std::shared_ptr notExistKvStore; + Status status = manager.GetSingleKvStore(noCreate, appId, storeId64, notExistKvStore); ASSERT_EQ(status, Status::STORE_NOT_FOUND); - EXPECT_EQ(notExistKvStorePtr, nullptr); + EXPECT_EQ(notExistKvStore, nullptr); } /** * @tc.name: GetKvStore004 -* @tc.desc: Create a KvStore with an empty storeId, and the callback function should receive +* @tc.desc: Create a SingleKvStore with an empty storeId, and the callback function should receive * @tc.type: FUNC * @tc.require: SR000CQDU0 AR000BVTDM * @tc.author: liqiao @@ -190,15 +190,15 @@ HWTEST_F(DistributedKvDataManagerTest, GetKvStore003, TestSize.Level1) HWTEST_F(DistributedKvDataManagerTest, GetKvStore004, TestSize.Level1) { ZLOGI("GetKvStore004 begin."); - std::shared_ptr notExistKvStorePtr; - Status status = manager.GetKvStore(create, appId, storeIdEmpty, notExistKvStorePtr); + std::shared_ptr notExistKvStore; + Status status = manager.GetSingleKvStore(create, appId, storeIdEmpty, notExistKvStore); ASSERT_EQ(status, Status::INVALID_ARGUMENT); - EXPECT_EQ(notExistKvStorePtr, nullptr); + EXPECT_EQ(notExistKvStore, nullptr); } /** * @tc.name: GetKvStore005 -* @tc.desc: Get a KvStore with an empty storeId, and the callback function should receive INVALID_ARGUMENT +* @tc.desc: Get a SingleKvStore with an empty storeId, and the callback function should receive INVALID_ARGUMENT * @tc.type: FUNC * @tc.require: SR000CQDU0 AR000BVTDM * @tc.author: liqiao @@ -206,15 +206,15 @@ HWTEST_F(DistributedKvDataManagerTest, GetKvStore004, TestSize.Level1) HWTEST_F(DistributedKvDataManagerTest, GetKvStore005, TestSize.Level1) { ZLOGI("GetKvStore005 begin."); - std::shared_ptr notExistKvStorePtr; - Status status = manager.GetKvStore(noCreate, appId, storeIdEmpty, notExistKvStorePtr); + std::shared_ptr notExistKvStore; + Status status = manager.GetSingleKvStore(noCreate, appId, storeIdEmpty, notExistKvStore); ASSERT_EQ(status, Status::INVALID_ARGUMENT); - EXPECT_EQ(notExistKvStorePtr, nullptr); + EXPECT_EQ(notExistKvStore, nullptr); } /** * @tc.name: GetKvStore006 -* @tc.desc: Create a KvStore with a 65-byte storeId, and the callback function should receive INVALID_ARGUMENT +* @tc.desc: Create a SingleKvStore with a 65-byte storeId, and the callback function should receive INVALID_ARGUMENT * @tc.type: FUNC * @tc.require: SR000CQDU0 AR000BVTDM * @tc.author: liqiao @@ -222,15 +222,15 @@ HWTEST_F(DistributedKvDataManagerTest, GetKvStore005, TestSize.Level1) HWTEST_F(DistributedKvDataManagerTest, GetKvStore006, TestSize.Level1) { ZLOGI("GetKvStore006 begin."); - std::shared_ptr notExistKvStorePtr; - Status status = manager.GetKvStore(create, appId, storeId65, notExistKvStorePtr); + std::shared_ptr notExistKvStore; + Status status = manager.GetSingleKvStore(create, appId, storeId65, notExistKvStore); ASSERT_EQ(status, Status::INVALID_ARGUMENT); - EXPECT_EQ(notExistKvStorePtr, nullptr); + EXPECT_EQ(notExistKvStore, nullptr); } /** * @tc.name: GetKvStore007 -* @tc.desc: Get a KvStore with a 65-byte storeId, the callback function should receive INVALID_ARGUMENT +* @tc.desc: Get a SingleKvStore with a 65-byte storeId, the callback function should receive INVALID_ARGUMENT * @tc.type: FUNC * @tc.require: SR000CQDU0 AR000BVTDM * @tc.author: liqiao @@ -238,10 +238,10 @@ HWTEST_F(DistributedKvDataManagerTest, GetKvStore006, TestSize.Level1) HWTEST_F(DistributedKvDataManagerTest, GetKvStore007, TestSize.Level1) { ZLOGI("GetKvStore007 begin."); - std::shared_ptr notExistKvStorePtr; - Status status = manager.GetKvStore(noCreate, appId, storeId65, notExistKvStorePtr); + std::shared_ptr notExistKvStore; + Status status = manager.GetSingleKvStore(noCreate, appId, storeId65, notExistKvStore); ASSERT_EQ(status, Status::INVALID_ARGUMENT); - EXPECT_EQ(notExistKvStorePtr, nullptr); + EXPECT_EQ(notExistKvStore, nullptr); } /** @@ -262,7 +262,7 @@ HWTEST_F(DistributedKvDataManagerTest, GetAllKvStore001, TestSize.Level1) /** * @tc.name: GetAllKvStore002 -* @tc.desc: Get all KvStore IDs when no KvStore exists, and the callback function should receive a 0-length vector. +* @tc.desc: Get all SingleKvStore IDs when no KvStore exists, and the callback function should receive a empty vector. * @tc.type: FUNC * @tc.require: SR000CQDU0 AR000BVTDM * @tc.author: liqiao @@ -276,14 +276,14 @@ HWTEST_F(DistributedKvDataManagerTest, GetAllKvStore002, TestSize.Level1) id2.storeId = "id2"; StoreId id3; id3.storeId = "id3"; - std::shared_ptr kvStore; - Status status = manager.GetKvStore(create, appId, id1, kvStore); + std::shared_ptr kvStore; + Status status = manager.GetSingleKvStore(create, appId, id1, kvStore); ASSERT_NE(kvStore, nullptr); ASSERT_EQ(status, Status::SUCCESS); - status = manager.GetKvStore(create, appId, id2, kvStore); + status = manager.GetSingleKvStore(create, appId, id2, kvStore); ASSERT_NE(kvStore, nullptr); ASSERT_EQ(status, Status::SUCCESS); - status = manager.GetKvStore(create, appId, id3, kvStore); + status = manager.GetSingleKvStore(create, appId, id3, kvStore); ASSERT_NE(kvStore, nullptr); ASSERT_EQ(status, Status::SUCCESS); std::vector storeIds; @@ -320,10 +320,10 @@ HWTEST_F(DistributedKvDataManagerTest, GetAllKvStore002, TestSize.Level1) HWTEST_F(DistributedKvDataManagerTest, CloseKvStore001, TestSize.Level1) { ZLOGI("CloseKvStore001 begin."); - std::shared_ptr kvStorePtr; - Status status = manager.GetKvStore(create, appId, storeId64, kvStorePtr); + std::shared_ptr kvStore; + Status status = manager.GetSingleKvStore(create, appId, storeId64, kvStore); ASSERT_EQ(status, Status::SUCCESS); - ASSERT_NE(kvStorePtr, nullptr); + ASSERT_NE(kvStore, nullptr); Status stat = manager.CloseKvStore(appId, storeId64); EXPECT_EQ(stat, Status::SUCCESS); @@ -331,7 +331,7 @@ HWTEST_F(DistributedKvDataManagerTest, CloseKvStore001, TestSize.Level1) /** * @tc.name: CloseKvStore002 -* @tc.desc: Close a closed KvStore, and the callback function should return SUCCESS. +* @tc.desc: Close a closed SingleKvStore, and the callback function should return SUCCESS. * @tc.type: FUNC * @tc.require: SR000CQDU0 AR000BVTDM * @tc.author: liqiao @@ -339,10 +339,10 @@ HWTEST_F(DistributedKvDataManagerTest, CloseKvStore001, TestSize.Level1) HWTEST_F(DistributedKvDataManagerTest, CloseKvStore002, TestSize.Level1) { ZLOGI("CloseKvStore002 begin."); - std::shared_ptr kvStorePtr; - Status status = manager.GetKvStore(create, appId, storeId64, kvStorePtr); + std::shared_ptr kvStore; + Status status = manager.GetSingleKvStore(create, appId, storeId64, kvStore); ASSERT_EQ(status, Status::SUCCESS); - ASSERT_NE(kvStorePtr, nullptr); + ASSERT_NE(kvStore, nullptr); manager.CloseKvStore(appId, storeId64); Status stat = manager.CloseKvStore(appId, storeId64); @@ -351,7 +351,7 @@ HWTEST_F(DistributedKvDataManagerTest, CloseKvStore002, TestSize.Level1) /** * @tc.name: CloseKvStore003 -* @tc.desc: Close a KvStore with an empty storeId, and the callback function should return INVALID_ARGUMENT. +* @tc.desc: Close a SingleKvStore with an empty storeId, and the callback function should return INVALID_ARGUMENT. * @tc.type: FUNC * @tc.require: SR000CQDU0 AR000BVTDM * @tc.author: liqiao @@ -365,7 +365,7 @@ HWTEST_F(DistributedKvDataManagerTest, CloseKvStore003, TestSize.Level1) /** * @tc.name: CloseKvStore004 -* @tc.desc: Close a KvStore with a 65-byte storeId, and the callback function should return INVALID_ARGUMENT. +* @tc.desc: Close a SingleKvStore with a 65-byte storeId, and the callback function should return INVALID_ARGUMENT. * @tc.type: FUNC * @tc.require: SR000CQDU0 AR000BVTDM * @tc.author: liqiao @@ -379,7 +379,7 @@ HWTEST_F(DistributedKvDataManagerTest, CloseKvStore004, TestSize.Level1) /** * @tc.name: CloseKvStore005 -* @tc.desc: Close a non-existing KvStore, and the callback function should return STORE_NOT_OPEN. +* @tc.desc: Close a non-existing SingleKvStore, and the callback function should return STORE_NOT_OPEN. * @tc.type: FUNC * @tc.require: SR000CQDU0 AR000BVTDM * @tc.author: liqiao @@ -393,7 +393,7 @@ HWTEST_F(DistributedKvDataManagerTest, CloseKvStore005, TestSize.Level1) /** * @tc.name: CloseKvStoreMulti001 -* @tc.desc: Open a KvStore several times and close them one by one, and the callback function should return SUCCESS. +* @tc.desc: Open a SingleKvStore several times and close them one by one. * @tc.type: FUNC * @tc.require: SR000CQDU0 AR000CSKRU * @tc.author: liqiao @@ -401,15 +401,15 @@ HWTEST_F(DistributedKvDataManagerTest, CloseKvStore005, TestSize.Level1) HWTEST_F(DistributedKvDataManagerTest, CloseKvStoreMulti001, TestSize.Level1) { ZLOGI("CloseKvStoreMulti001 begin."); - std::shared_ptr notExistKvStorePtr; - Status status = manager.GetKvStore(create, appId, storeId64, notExistKvStorePtr); + std::shared_ptr notExistKvStore; + Status status = manager.GetSingleKvStore(create, appId, storeId64, notExistKvStore); ASSERT_EQ(status, Status::SUCCESS); - EXPECT_NE(notExistKvStorePtr, nullptr); + EXPECT_NE(notExistKvStore, nullptr); - std::shared_ptr existKvStorePtr; - manager.GetKvStore(noCreate, appId, storeId64, existKvStorePtr); + std::shared_ptr existKvStore; + manager.GetSingleKvStore(noCreate, appId, storeId64, existKvStore); ASSERT_EQ(status, Status::SUCCESS); - EXPECT_NE(existKvStorePtr, nullptr); + EXPECT_NE(existKvStore, nullptr); Status stat = manager.CloseKvStore(appId, storeId64); EXPECT_EQ(stat, Status::SUCCESS); @@ -420,7 +420,7 @@ HWTEST_F(DistributedKvDataManagerTest, CloseKvStoreMulti001, TestSize.Level1) /** * @tc.name: CloseKvStoreMulti002 -* @tc.desc: Open a KvStore several times and close them one by one, and the callback function should return SUCCESS. +* @tc.desc: Open a SingleKvStore several times and close them one by one. * @tc.type: FUNC * @tc.require: SR000CQDU0 AR000CSKRU * @tc.author: liqiao @@ -428,20 +428,20 @@ HWTEST_F(DistributedKvDataManagerTest, CloseKvStoreMulti001, TestSize.Level1) HWTEST_F(DistributedKvDataManagerTest, CloseKvStoreMulti002, TestSize.Level1) { ZLOGI("CloseKvStoreMulti002 begin."); - std::shared_ptr notExistKvStorePtr; - Status status = manager.GetKvStore(create, appId, storeId64, notExistKvStorePtr); + std::shared_ptr notExistKvStore; + Status status = manager.GetSingleKvStore(create, appId, storeId64, notExistKvStore); ASSERT_EQ(status, Status::SUCCESS); - EXPECT_NE(notExistKvStorePtr, nullptr); + EXPECT_NE(notExistKvStore, nullptr); - std::shared_ptr existKvStorePtr1; - status = manager.GetKvStore(noCreate, appId, storeId64, existKvStorePtr1); + std::shared_ptr existKvStore1; + status = manager.GetSingleKvStore(noCreate, appId, storeId64, existKvStore1); ASSERT_EQ(status, Status::SUCCESS); - EXPECT_NE(existKvStorePtr1, nullptr); + EXPECT_NE(existKvStore1, nullptr); - std::shared_ptr existKvStorePtr2; - status = manager.GetKvStore(noCreate, appId, storeId64, existKvStorePtr2); + std::shared_ptr existKvStore2; + status = manager.GetSingleKvStore(noCreate, appId, storeId64, existKvStore2); ASSERT_EQ(status, Status::SUCCESS); - EXPECT_NE(existKvStorePtr2, nullptr); + EXPECT_NE(existKvStore2, nullptr); Status stat = manager.CloseKvStore(appId, storeId64); EXPECT_EQ(stat, Status::SUCCESS); @@ -456,63 +456,6 @@ HWTEST_F(DistributedKvDataManagerTest, CloseKvStoreMulti002, TestSize.Level1) EXPECT_NE(stat, Status::SUCCESS); } -/** -* @tc.name: CloseKvStoreMulti003 -* @tc.desc: Open a KvStore several times and close them one by one, and the callback function should return SUCCESS. -* @tc.type: FUNC -* @tc.require: SR000CQDU0 AR000CSKRU -* @tc.author: liqiao -*/ -HWTEST_F(DistributedKvDataManagerTest, CloseKvStoreMulti003, TestSize.Level1) -{ - ZLOGI("CloseKvStoreMulti003 begin."); - std::shared_ptr notExistKvStorePtr; - Status status = manager.GetKvStore(create, appId, storeId64, notExistKvStorePtr); - ASSERT_EQ(status, Status::SUCCESS); - EXPECT_NE(notExistKvStorePtr, nullptr); - - std::shared_ptr existKvStorePtr1; - status = manager.GetKvStore(noCreate, appId, storeId64, existKvStorePtr1); - ASSERT_EQ(status, Status::SUCCESS); - EXPECT_NE(existKvStorePtr1, nullptr); - - std::shared_ptr existKvStorePtr2; - status = manager.GetKvStore(noCreate, appId, storeId64, existKvStorePtr2); - ASSERT_EQ(status, Status::SUCCESS); - EXPECT_NE(existKvStorePtr2, nullptr); - - Status stat = manager.CloseKvStore(appId, storeId64); - EXPECT_EQ(stat, Status::SUCCESS); - - stat = manager.CloseKvStore(appId, storeId64); - EXPECT_EQ(stat, Status::SUCCESS); - - Key keyInt = "math_score_int"; - Value valueInt = Value(TransferTypeToByteArray(-100)); - status = existKvStorePtr2->Put(keyInt, valueInt); - EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - existKvStorePtr2->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - - std::shared_ptr existKvStorePtr3; - status = manager.GetKvStore(noCreate, appId, storeId64, existKvStorePtr3); - ASSERT_EQ(status, Status::SUCCESS); - EXPECT_NE(existKvStorePtr3, nullptr); - - stat = manager.CloseKvStore(appId, storeId64); - EXPECT_EQ(stat, Status::SUCCESS); - - Value valueRetInt; - Status statusTmp = kvStoreSnapshotPtr->Get(keyInt, valueRetInt); - EXPECT_EQ(Status::SUCCESS, statusTmp) << "KvStoreSnapshot get data return wrong status"; - EXPECT_EQ(valueInt, valueRetInt) << "valueInt and valueRetInt are not equal"; - - stat = manager.CloseKvStore(appId, storeId64); - EXPECT_EQ(stat, Status::SUCCESS); -} - /** * @tc.name: CloseAllKvStore001 * @tc.desc: Close all opened KvStores, and the callback function should return SUCCESS. @@ -523,15 +466,15 @@ HWTEST_F(DistributedKvDataManagerTest, CloseKvStoreMulti003, TestSize.Level1) HWTEST_F(DistributedKvDataManagerTest, CloseAllKvStore001, TestSize.Level1) { ZLOGI("CloseAllKvStore001 begin."); - std::shared_ptr kvStorePtr1; - Status status = manager.GetKvStore(create, appId, storeId64, kvStorePtr1); + std::shared_ptr kvStore1; + Status status = manager.GetSingleKvStore(create, appId, storeId64, kvStore1); ASSERT_EQ(status, Status::SUCCESS); - ASSERT_NE(kvStorePtr1, nullptr); + ASSERT_NE(kvStore1, nullptr); - std::shared_ptr kvStorePtr2; - status = manager.GetKvStore(create, appId, storeIdTest, kvStorePtr2); + std::shared_ptr kvStore2; + status = manager.GetSingleKvStore(create, appId, storeIdTest, kvStore2); ASSERT_EQ(status, Status::SUCCESS); - ASSERT_NE(kvStorePtr2, nullptr); + ASSERT_NE(kvStore2, nullptr); Status stat = manager.CloseAllKvStore(appId); EXPECT_EQ(stat, Status::SUCCESS); @@ -547,15 +490,15 @@ HWTEST_F(DistributedKvDataManagerTest, CloseAllKvStore001, TestSize.Level1) HWTEST_F(DistributedKvDataManagerTest, CloseAllKvStore002, TestSize.Level1) { ZLOGI("CloseAllKvStore002 begin."); - std::shared_ptr kvStorePtr1; - Status status = manager.GetKvStore(create, appId, storeId64, kvStorePtr1); + std::shared_ptr kvStore; + Status status = manager.GetSingleKvStore(create, appId, storeId64, kvStore); ASSERT_EQ(status, Status::SUCCESS); - ASSERT_NE(kvStorePtr1, nullptr); + ASSERT_NE(kvStore, nullptr); - std::shared_ptr kvStorePtr2; - status = manager.GetKvStore(create, appId, storeIdTest, kvStorePtr2); + std::shared_ptr kvStore2; + status = manager.GetSingleKvStore(create, appId, storeIdTest, kvStore2); ASSERT_EQ(status, Status::SUCCESS); - ASSERT_NE(kvStorePtr2, nullptr); + ASSERT_NE(kvStore2, nullptr); Status stat = manager.CloseKvStore(appId, storeId64); EXPECT_EQ(stat, Status::SUCCESS); @@ -574,10 +517,10 @@ HWTEST_F(DistributedKvDataManagerTest, CloseAllKvStore002, TestSize.Level1) HWTEST_F(DistributedKvDataManagerTest, DeleteKvStore001, TestSize.Level1) { ZLOGI("DeleteKvStore001 begin."); - std::shared_ptr kvStorePtr; - Status status = manager.GetKvStore(create, appId, storeId64, kvStorePtr); + std::shared_ptr kvStore; + Status status = manager.GetSingleKvStore(create, appId, storeId64, kvStore); ASSERT_EQ(status, Status::SUCCESS); - ASSERT_NE(kvStorePtr, nullptr); + ASSERT_NE(kvStore, nullptr); Status stat = manager.CloseKvStore(appId, storeId64); ASSERT_EQ(stat, Status::SUCCESS); @@ -588,7 +531,7 @@ HWTEST_F(DistributedKvDataManagerTest, DeleteKvStore001, TestSize.Level1) /** * @tc.name: DeleteKvStore002 -* @tc.desc: Delete an opened KvStore, and the callback function should return SUCCESS. +* @tc.desc: Delete an opened SingleKvStore, and the callback function should return SUCCESS. * @tc.type: FUNC * @tc.require: SR000CQDU0 AR000BVTDM * @tc.author: liqiao @@ -596,10 +539,10 @@ HWTEST_F(DistributedKvDataManagerTest, DeleteKvStore001, TestSize.Level1) HWTEST_F(DistributedKvDataManagerTest, DeleteKvStore002, TestSize.Level1) { ZLOGI("DeleteKvStore002 begin."); - std::shared_ptr kvStorePtr; - Status status = manager.GetKvStore(create, appId, storeId64, kvStorePtr); + std::shared_ptr kvStore; + Status status = manager.GetSingleKvStore(create, appId, storeId64, kvStore); ASSERT_EQ(status, Status::SUCCESS); - ASSERT_NE(kvStorePtr, nullptr); + ASSERT_NE(kvStore, nullptr); // first close it if opened, and then delete it. Status stat = manager.DeleteKvStore(appId, storeId64); @@ -659,14 +602,14 @@ HWTEST_F(DistributedKvDataManagerTest, DeleteKvStore005, TestSize.Level1) HWTEST_F(DistributedKvDataManagerTest, DeleteAllKvStore001, TestSize.Level1) { ZLOGI("DeleteAllKvStore001 begin."); - std::shared_ptr kvStorePtr1; - Status status = manager.GetKvStore(create, appId, storeId64, kvStorePtr1); + std::shared_ptr kvStore1; + Status status = manager.GetSingleKvStore(create, appId, storeId64, kvStore1); ASSERT_EQ(status, Status::SUCCESS); - ASSERT_NE(kvStorePtr1, nullptr); - std::shared_ptr kvStorePtr2; - status = manager.GetKvStore(create, appId, storeIdTest, kvStorePtr2); + ASSERT_NE(kvStore1, nullptr); + std::shared_ptr kvStore2; + status = manager.GetSingleKvStore(create, appId, storeIdTest, kvStore2); ASSERT_EQ(status, Status::SUCCESS); - ASSERT_NE(kvStorePtr2, nullptr); + ASSERT_NE(kvStore2, nullptr); Status stat = manager.CloseKvStore(appId, storeId64); EXPECT_EQ(stat, Status::SUCCESS); stat = manager.CloseKvStore(appId, storeIdTest); @@ -686,14 +629,14 @@ HWTEST_F(DistributedKvDataManagerTest, DeleteAllKvStore001, TestSize.Level1) HWTEST_F(DistributedKvDataManagerTest, DeleteAllKvStore002, TestSize.Level1) { ZLOGI("DeleteAllKvStore002 begin."); - std::shared_ptr kvStorePtr1; - Status status = manager.GetKvStore(create, appId, storeId64, kvStorePtr1); + std::shared_ptr kvStore1; + Status status = manager.GetSingleKvStore(create, appId, storeId64, kvStore1); ASSERT_EQ(status, Status::SUCCESS); - ASSERT_NE(kvStorePtr1, nullptr); - std::shared_ptr kvStorePtr2; - status = manager.GetKvStore(create, appId, storeIdTest, kvStorePtr2); + ASSERT_NE(kvStore1, nullptr); + std::shared_ptr kvStore2; + status = manager.GetSingleKvStore(create, appId, storeIdTest, kvStore2); ASSERT_EQ(status, Status::SUCCESS); - ASSERT_NE(kvStorePtr2, nullptr); + ASSERT_NE(kvStore2, nullptr); Status stat = manager.CloseKvStore(appId, storeId64); EXPECT_EQ(stat, Status::SUCCESS); @@ -725,14 +668,14 @@ HWTEST_F(DistributedKvDataManagerTest, DeleteAllKvStore003, TestSize.Level1) HWTEST_F(DistributedKvDataManagerTest, DeleteAllKvStore004, TestSize.Level1) { ZLOGI("DeleteAllKvStore004 begin."); - std::shared_ptr kvStorePtr1; - Status status = manager.GetKvStore(create, appId, storeId64, kvStorePtr1); + std::shared_ptr kvStore1; + Status status = manager.GetSingleKvStore(create, appId, storeId64, kvStore1); ASSERT_EQ(status, Status::SUCCESS); - ASSERT_NE(kvStorePtr1, nullptr); - std::shared_ptr kvStorePtr2; - status = manager.GetKvStore(create, appId, storeIdTest, kvStorePtr2); + ASSERT_NE(kvStore1, nullptr); + std::shared_ptr kvStore2; + status = manager.GetSingleKvStore(create, appId, storeIdTest, kvStore2); ASSERT_EQ(status, Status::SUCCESS); - ASSERT_NE(kvStorePtr2, nullptr); + ASSERT_NE(kvStore2, nullptr); Status stat = manager.CloseKvStore(appId, storeId64); EXPECT_EQ(stat, Status::SUCCESS); stat = manager.CloseKvStore(appId, storeIdTest); @@ -753,9 +696,9 @@ HWTEST_F(DistributedKvDataManagerTest, DeleteAllKvStore004, TestSize.Level1) HWTEST_F(DistributedKvDataManagerTest, RegisterKvStoreServiceDeathRecipient001, TestSize.Level1) { ZLOGI("RegisterKvStoreServiceDeathRecipient001 begin."); - std::shared_ptr kvStoreDeathRecipientPtr = std::make_shared(); - manager.RegisterKvStoreServiceDeathRecipient(kvStoreDeathRecipientPtr); - kvStoreDeathRecipientPtr->OnRemoteDied(); + std::shared_ptr kvStoreDeathRecipient = std::make_shared(); + manager.RegisterKvStoreServiceDeathRecipient(kvStoreDeathRecipient); + kvStoreDeathRecipient->OnRemoteDied(); } /** diff --git a/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/kvstore_client_test.cpp b/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/kvstore_client_test.cpp deleted file mode 100644 index f82da60587c64daa43dcedd5669d835e2dda09ca..0000000000000000000000000000000000000000 --- a/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/kvstore_client_test.cpp +++ /dev/null @@ -1,1263 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "KvStoreClientTest" - -#include -#include -#include -#include -#include -#include "distributed_kv_data_manager.h" -#include "log_print.h" -#include "types.h" - -using namespace testing::ext; -using namespace OHOS::DistributedKv; - -class KvStoreClientTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - - static std::shared_ptr kvStorePtr; // declare kvstore instance. - static std::shared_ptr kvStoreSnapshotPtr; // declare kvstore instance. - static Status statusGetKvStore; - static Status statusGetSnapshot; - static int MAX_VALUE_SIZE; -}; - -std::shared_ptr KvStoreClientTest::kvStorePtr = nullptr; -std::shared_ptr KvStoreClientTest::kvStoreSnapshotPtr = nullptr; -Status KvStoreClientTest::statusGetKvStore = Status::ERROR; -Status KvStoreClientTest::statusGetSnapshot = Status::ERROR; -int KvStoreClientTest::MAX_VALUE_SIZE = 4 * 1024 * 1024; - -void KvStoreClientTest::SetUpTestCase(void) -{ - DistributedKvDataManager manager; - Options options; - options.createIfMissing = true; - options.encrypt = false; - options.autoSync = true; - options.kvStoreType = KvStoreType::MULTI_VERSION; - - AppId appId; - appId.appId = "odmf"; // define app name. - StoreId storeId; - storeId.storeId = "student"; // define kvstore(database) name. - - manager.CloseAllKvStore(appId); - manager.DeleteAllKvStore(appId); - - // [create and] open and initialize kvstore instance. - statusGetKvStore = manager.GetKvStore(options, appId, storeId, kvStorePtr); - - // [create and] open and initialize kvstore snapshot instance. - statusGetSnapshot = kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); -} - -void KvStoreClientTest::TearDownTestCase(void) -{} - -void KvStoreClientTest::SetUp(void) -{} - -void KvStoreClientTest::TearDown(void) -{} - -/** -* @tc.name: KvStoreDdmGetKvStoreSnapshot001 -* @tc.desc: Get the KvStore snapshot. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmGetKvStoreSnapshot001, TestSize.Level2) -{ - ZLOGI("KvStoreDdmGetKvStoreSnapshot001 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - Key key = "name"; - Value value = "test"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - // get values from KvStore before putting them into KvStore. - Value valueRet; - Status statusRet1 = kvStoreSnapshotPtr->Get(key, valueRet); - EXPECT_EQ(Status::KEY_NOT_FOUND, statusRet1) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ("", valueRet.ToString()) << "value and valueRet are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); - - Status status = kvStorePtr->Put(key, value); // insert or update key-value - EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data failed, wrong status"; - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - // get values from KvStore after putting them into KvStore. - Status statusRet2 = kvStoreSnapshotPtr->Get(key, valueRet); - EXPECT_EQ(Status::SUCCESS, statusRet2) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(value, valueRet) << "value and valueRet are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmPut001 -* @tc.desc: Put int values to KvStore. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPut001, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPut001 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - // store int value to kvstore. - Key keyInt = "math_score_int"; - int scoreInt = -383468; - Value valueInt = Value(TransferTypeToByteArray(scoreInt)); - Status status = kvStorePtr->Put(keyInt, valueInt); // insert or update key-value - EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - // get int value from kvstore. - Value valueRetInt; - Status statusTmp = kvStoreSnapshotPtr->Get(keyInt, valueRetInt); - EXPECT_EQ(Status::SUCCESS, statusTmp) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(valueInt, valueRetInt) << "valueInt and valueRetInt are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmPut002 -* @tc.desc: Put Float values to KvStore. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPut002, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPut002 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - // store float value to kvstore. - Key keyFloat = "math_score_float"; - float scoreFloat = 3.14f; - Value valueFloat = Value(TransferTypeToByteArray(scoreFloat)); - Status status = kvStorePtr->Put(keyFloat, valueFloat); // insert or update key-value - EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - // get float value from kvstore. - Value valueRetFloat; - Status statusTmp = kvStoreSnapshotPtr->Get(keyFloat, valueRetFloat); - EXPECT_EQ(Status::SUCCESS, statusTmp) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(valueFloat, valueRetFloat) << "valueFloat and valueRetFloat are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmPut003 -* @tc.desc: Put Double values to KvStore. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPut003, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPut003 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - // store double value to kvstore. - Key keyDouble = "math_score_double"; - double scoreDouble = 28.785f; - Value valueDouble = Value(TransferTypeToByteArray(scoreDouble)); - Status status = kvStorePtr->Put(keyDouble, valueDouble); // insert or update key-value - EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - // get double value from kvstore. - Value valueRetDouble; - Status statusTmp = kvStoreSnapshotPtr->Get(keyDouble, valueRetDouble); - EXPECT_EQ(Status::SUCCESS, statusTmp) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(valueDouble, valueRetDouble) << "valueDouble and valueRetDouble are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmPut004 -* @tc.desc: put unsigned int value to kvstore -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPut004, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPut004 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - // store unsigned int value to kvstore. - Key keyUInt = "math_score_size_t"; - size_t scoreUInt = 28; - Value valueUInt = Value(TransferTypeToByteArray(scoreUInt)); - Status status = kvStorePtr->Put(keyUInt, valueUInt); // insert or update key-value - EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - // get unsigned int value from kvstore. - Value valueRetUInt; - Status statusTmp = kvStoreSnapshotPtr->Get(keyUInt, valueRetUInt); - EXPECT_EQ(Status::SUCCESS, statusTmp) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(valueUInt, valueRetUInt) << "valueUInt and valueRetUInt are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmPut005 -* @tc.desc: Put Long values to KvStore. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPut005, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPut005 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - // store long int value to kvstore. - Key keyInt64 = "math_score_int64_t"; - std::int64_t scoreInt64 = 12345678; - Value valueInt64 = Value(TransferTypeToByteArray(scoreInt64)); - Status status = kvStorePtr->Put(keyInt64, valueInt64); // insert or update key-value - EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - // get long int value from kvstore. - Value valueRetint64; - Status statusTmp = kvStoreSnapshotPtr->Get(keyInt64, valueRetint64); - EXPECT_EQ(Status::SUCCESS, statusTmp) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(valueInt64, valueRetint64) << "valueInt64 and valueRetint64 are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmPut006 -* @tc.desc: Put JSON values to KvStore. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPut006, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPut006 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - // store json value to kvstore. - Key key = "student_name_zhangsan"; - Value value = "{\"class\":20, \"age\":18, \"gradle\":\"good\"}"; - Status status = kvStorePtr->Put(key, value); // insert or update key-value - EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - // get json value from kvstore. - Value valueRet; - Status statusTmp = kvStoreSnapshotPtr->Get(key, valueRet); - EXPECT_EQ(Status::SUCCESS, statusTmp) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(value, valueRet) << "value and valueRet are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmPut007 -* @tc.desc: Put strings containing '\0' to KvStore. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPut007, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPut007 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - // store normal string to kvstore. - Key key = "teacher_name_wanger"; - std::string str = "class:20\0, age:50"; - Value value = Value(str); - Status status = kvStorePtr->Put(key, value); // insert or update key-value - EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - // get string value from kvstore. - Value valueRet; - Status statusTmp = kvStoreSnapshotPtr->Get(key, valueRet); - EXPECT_EQ(Status::SUCCESS, statusTmp) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(value, valueRet) << "value and valueRet are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmPut008 -* @tc.desc: Put normal strings to KvStore. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPut008, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPut008 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - // store normal string to kvstore. - Key key = "teacher_name_wanger"; - std::string str = "class:20, age:50"; - Value value = Value(str); - Status status = kvStorePtr->Put(key, value); // insert or update key-value - EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - // get string value from kvstore. - Value valueRet; - Status statusTmp = kvStoreSnapshotPtr->Get(key, valueRet); - EXPECT_EQ(Status::SUCCESS, statusTmp) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(value, valueRet) << "value and valueRet are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmPut009 -* @tc.desc: Update strings in KvStore. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPut009, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPut009 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - Key key = "student_name_lisi"; - std::string str1 = "age:18"; - Value value1 = Value(str1); - Status status1 = kvStorePtr->Put(key, value1); // insert or update key-value - EXPECT_EQ(Status::SUCCESS, status1) << "KvStore put data failed, wrong status"; - - std::string str2 = "age:20"; - Value value2 = Value(str2); - Status status2 = kvStorePtr->Put(key, value2); // insert or update key-value - EXPECT_EQ(Status::SUCCESS, status2) << "KvStore put data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - // get string value from kvstore. - Value valueRet; - Status statusTmp = kvStoreSnapshotPtr->Get(key, valueRet); - EXPECT_EQ(Status::SUCCESS, statusTmp) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(value2, valueRet) << "value2 and valueRet are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmPut010 -* @tc.desc: Put empty keys to KvStore. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPut010, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPut010 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - Key key = ""; - std::string str = "age:18"; - Value value = Value(str); - Status status = kvStorePtr->Put(key, value); // insert or update key-value - EXPECT_EQ(Status::INVALID_ARGUMENT, status) << "KvStore put data failed, wrong status"; -} - -/** -* @tc.name: KvStoreDdmPut011 -* @tc.desc: Put empty keys to KvStore. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPut011, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPut011 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - Key key = "student_name_lisi"; - std::string str = ""; - Value value = Value(str); - Status status = kvStorePtr->Put(key, value); // insert or update key-value - EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data failed, wrong status"; -} - -/** -* @tc.name: KvStoreDdmPut012 -* @tc.desc: Generate keys with a length of more than 1024 bytes. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPut012, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPut012 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - // Generate key and the length is more than 1024; - std::string strKey("student"); - for (int i = 0; i < 1024; i++) { - strKey += "a"; - } - Key key = strKey; - - std::string str = "class:2, age:50"; - Value value = Value(str); - Status status = kvStorePtr->Put(key, value); // insert or update key-value - EXPECT_EQ(Status::INVALID_ARGUMENT, status) << "KvStore put data failed, wrong status"; -} - -/** -* @tc.name: KvStoreDdmPut013 -* @tc.desc: Put keys with only blank space to KvStore. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPut013, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPut013 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - Key key = " "; - std::string str = "class:2, age:50"; - Value value = Value(str); - Status status = kvStorePtr->Put(key, value); // insert or update key-value - EXPECT_EQ(Status::INVALID_ARGUMENT, status) << "KvStore put data failed, wrong status"; -} - -/** -* @tc.name: KvStoreDdmPut014 -* @tc.desc: Put values greater than MAX_VALUE_SIZE to KvStore. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liqiao -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPut014, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPut014 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - // store values greater than MAX_VALUE_SIZE to KvStore. - Key key = "student_name_zhangsan"; - std::vector val(MAX_VALUE_SIZE); - for (int i = 0; i < MAX_VALUE_SIZE; i++) { - val[i] = static_cast(i); - } - Value value = val; - Status status = kvStorePtr->Put(key, value); // insert or update key-value - EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data failed, wrong status"; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - // get values greater than MAX_VALUE_SIZE from KvStore. - Value valueRet; - Status statusTmp = kvStoreSnapshotPtr->Get(key, valueRet); - EXPECT_EQ(Status::SUCCESS, statusTmp) << "KvStoreSnapshot get large data failed, wrong status"; - EXPECT_EQ(value, valueRet) << "value and valueRet are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmDelete001 -* @tc.desc: Delete data which key exists -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmDelete001, TestSize.Level2) -{ - ZLOGI("KvStoreDdmDelete001 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - Key key = "student_name_lisi"; - std::string str = "age:18"; - Value value = Value(str); - Status status1 = kvStorePtr->Put(key, value); // insert or update key-value - EXPECT_EQ(Status::SUCCESS, status1) << "KvStore put data failed, wrong status"; - - Status status2 = kvStorePtr->Delete(key); // delete data - EXPECT_EQ(Status::SUCCESS, status2) << "KvStore delete data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - // get value from kvstore. - Value valueRet; - Status statusRet = kvStoreSnapshotPtr->Get(key, valueRet); - EXPECT_EQ(Status::KEY_NOT_FOUND, statusRet) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ("", valueRet.ToString()) << "valueRet EQ fail"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmDelete002 -* @tc.desc: Delete data that contains non-existing keys. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmDelete002, TestSize.Level2) -{ - ZLOGI("KvStoreDdmDelete002 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - Key key = "student_name_lisi"; - Status status1 = kvStorePtr->Delete(key); // delete data - EXPECT_EQ(Status::SUCCESS, status1) << "KvStore delete data failed, wrong status"; - Status status2 = kvStorePtr->Delete(key); // delete data which not exist - EXPECT_EQ(Status::SUCCESS, status2) << "KvStore delete data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - // get value from kvstore. - Value valueRet; - Status statusRet = kvStoreSnapshotPtr->Get(key, valueRet); - EXPECT_EQ(Status::KEY_NOT_FOUND, statusRet) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ("", valueRet.ToString()) << "valueRet EQ fail"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmDelete003 -* @tc.desc: Delete data that contains invalid keys. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmDelete003, TestSize.Level2) -{ - ZLOGI("KvStoreDdmDelete003 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - Key key = ""; - Status status = kvStorePtr->Delete(key); // delete data which key is invalid - EXPECT_EQ(Status::INVALID_ARGUMENT, status) << "KvStore delete data failed, wrong status"; -} - -/** -* @tc.name: KvStoreDdmClear001 -* @tc.desc: Clear data in KvStore. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmClear001, TestSize.Level2) -{ - ZLOGI("KvStoreDdmClear001 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - Key key1 = "age"; - Value value1 = "18"; - Status status1 = kvStorePtr->Put(key1, value1); // insert or update key-value - EXPECT_EQ(Status::SUCCESS, status1) << "KvStore put data failed, wrong status"; - - Key key2 = "name"; - Value value2 = "test"; - Status status2 = kvStorePtr->Put(key2, value2); // insert or update key-value - EXPECT_EQ(Status::SUCCESS, status2) << "KvStore put data failed, wrong status"; - - Status status3 = kvStorePtr->Clear(); // clear data - EXPECT_EQ(Status::SUCCESS, status3) << "KvStore clear data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - Value valueRet1; - Status statusRet1 = kvStoreSnapshotPtr->Get(key1, valueRet1); - EXPECT_EQ(Status::KEY_NOT_FOUND, statusRet1) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ("", valueRet1.ToString()) << "valueRet EQ fail"; - - Value valueRet2; - Status statusRet2 = kvStoreSnapshotPtr->Get(key2, valueRet2); - EXPECT_EQ(Status::KEY_NOT_FOUND, statusRet2) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ("", valueRet2.ToString()) << "valueRet EQ fail"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmClear002 -* @tc.desc: Clearn data in an empty KvStore. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmClear002, TestSize.Level2) -{ - ZLOGI("KvStoreDdmClear002 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - Status status1 = kvStorePtr->Clear(); // clear data - EXPECT_EQ(Status::SUCCESS, status1) << "KvStore clear data failed, wrong status"; - - Status status2 = kvStorePtr->Clear(); // clear data which kvstore is empty - EXPECT_EQ(Status::SUCCESS, status2) << "KvStore clear data failed, wrong status"; -} - -/** -* @tc.name: KvStoreDdmPutBatch001 -* @tc.desc: Put data to KvStore in batch. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPutBatch001, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPutBatch001 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - kvStorePtr->Clear(); - - // store entries to kvstore. - std::vector entries; - Entry entry1, entry2, entry3; - entry1.key = "student_name_mali"; - entry1.value = "age:20"; - entry2.key = "student_name_caixu"; - entry2.value = "age:19"; - entry3.key = "student_name_liuyue"; - entry3.value = "age:23"; - entries.push_back(entry1); - entries.push_back(entry2); - entries.push_back(entry3); - - Status status = kvStorePtr->PutBatch(entries); - EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - // get value from kvstore. - Value valueRet1; - Status statusRet1 = kvStoreSnapshotPtr->Get(entry1.key, valueRet1); - EXPECT_EQ(Status::SUCCESS, statusRet1) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(entry1.value, valueRet1) << "value and valueRet are not equal"; - - Value valueRet2; - Status statusRet2 = kvStoreSnapshotPtr->Get(entry2.key, valueRet2); - EXPECT_EQ(Status::SUCCESS, statusRet2) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(entry2.value, valueRet2) << "value and valueRet are not equal"; - - Value valueRet3; - Status statusRet3 = kvStoreSnapshotPtr->Get(entry3.key, valueRet3); - EXPECT_EQ(Status::SUCCESS, statusRet3) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(entry3.value, valueRet3) << "value and valueRet are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmPutBatch002 -* @tc.desc: Update data in KvStore in batch. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPutBatch002, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPutBatch002 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - kvStorePtr->Clear(); - - // before update. - std::vector entriesBefore; - Entry entry1, entry2, entry3; - entry1.key = "student_name_mali"; - entry1.value = "age:20"; - entry2.key = "student_name_caixu"; - entry2.value = "age:19"; - entry3.key = "student_name_liuyue"; - entry3.value = "age:23"; - entriesBefore.push_back(entry1); - entriesBefore.push_back(entry2); - entriesBefore.push_back(entry3); - - // after update. - std::vector entriesAfter; - Entry entry4, entry5, entry6; - entry4.key = "student_name_mali"; - entry4.value = "age:20, sex:girl"; - entry5.key = "student_name_caixu"; - entry5.value = "age:19, sex:boy"; - entry6.key = "student_name_liuyue"; - entry6.value = "age:23, sex:girl"; - entriesAfter.push_back(entry4); - entriesAfter.push_back(entry5); - entriesAfter.push_back(entry6); - - Status status = kvStorePtr->PutBatch(entriesAfter); - EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - // get value from kvstore. - Value valueRet1; - Status statusRet1 = kvStoreSnapshotPtr->Get(entry4.key, valueRet1); - EXPECT_EQ(Status::SUCCESS, statusRet1) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(entry4.value, valueRet1) << "value and valueRet are not equal"; - - Value valueRet2; - Status statusRet2 = kvStoreSnapshotPtr->Get(entry5.key, valueRet2); - EXPECT_EQ(Status::SUCCESS, statusRet2) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(entry5.value, valueRet2) << "value and valueRet are not equal"; - - Value valueRet3; - Status statusRet3 = kvStoreSnapshotPtr->Get(entry6.key, valueRet3); - EXPECT_EQ(Status::SUCCESS, statusRet3) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(entry6.value, valueRet3) << "value and valueRet are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmPutBatch003 -* @tc.desc: Put data that contains invalid data to KvStore in batch. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPutBatch003, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPutBatch003 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - kvStorePtr->Clear(); - - // before update. - std::vector entries; - Entry entry1, entry2, entry3; - entry1.key = " "; - entry1.value = "age:20"; - entry2.key = "student_name_caixu"; - entry2.value = " "; - entry3.key = "student_name_liuyue"; - entry3.value = "age:23"; - entries.push_back(entry1); - entries.push_back(entry2); - entries.push_back(entry3); - - Status status = kvStorePtr->PutBatch(entries); - EXPECT_EQ(Status::INVALID_ARGUMENT, status) << "KvStore putbatch data failed, wrong status"; -} - -/** -* @tc.name: KvStoreDdmPutBatch004 -* @tc.desc: Put data that contains invalid data to KvStore in batch. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPutBatch004, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPutBatch004 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - kvStorePtr->Clear(); - - // before update. - std::vector entries; - Entry entry1, entry2, entry3; - entry1.key = ""; - entry1.value = "age:20"; - entry2.key = "student_name_caixu"; - entry2.value = ""; - entry3.key = "student_name_liuyue"; - entry3.value = "age:23"; - entries.push_back(entry1); - entries.push_back(entry2); - entries.push_back(entry3); - - Status status = kvStorePtr->PutBatch(entries); - EXPECT_EQ(Status::INVALID_ARGUMENT, status) << "KvStore putbatch data failed, wrong status"; -} - -static std::string Generate1025KeyLen() -{ - // Generate key and the length is more than 1024; - std::string str("prefix"); - for (int i = 0; i < 1024; i++) { - str += "a"; - } - return str; -} -/** -* @tc.name: KvStoreDdmPutBatch005 -* @tc.desc: Put data that contains invalid data to KvStore in batch. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPutBatch005, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPutBatch005 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - kvStorePtr->Clear(); - - // before update. - std::vector entries; - Entry entry1, entry2, entry3; - entry1.key = Generate1025KeyLen(); - entry1.value = "age:20"; - entry2.key = "student_name_caixu"; - entry2.value = "age:19"; - entry3.key = "student_name_liuyue"; - entry3.value = "age:23"; - entries.push_back(entry1); - entries.push_back(entry2); - entries.push_back(entry3); - - Status status = kvStorePtr->PutBatch(entries); - EXPECT_EQ(Status::INVALID_ARGUMENT, status) << "KvStore putbatch data failed, wrong status"; -} - -/** -* @tc.name: KvStoreDdmPutBatch006 -* @tc.desc: Put large data to KvStore in batch. -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmPutBatch006, TestSize.Level2) -{ - ZLOGI("KvStoreDdmPutBatch006 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - kvStorePtr->Clear(); - - std::vector val(MAX_VALUE_SIZE); - for (int i = 0; i < MAX_VALUE_SIZE; i++) { - val[i] = static_cast(i); - } - Value value = val; - - // before update. - std::vector entries; - Entry entry1, entry2, entry3; - entry1.key = "ruby"; - entry1.value = value; - entry2.key = "weiss"; - entry2.value = value; - entry3.key = "blake"; - entry3.value = value; - entries.push_back(entry1); - entries.push_back(entry2); - entries.push_back(entry3); - - Status status = kvStorePtr->PutBatch(entries); - EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data failed, wrong status"; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - // get value from kvstore. - Value valueRet1; - Status statusRet1 = kvStoreSnapshotPtr->Get(entry1.key, valueRet1); - EXPECT_EQ(Status::SUCCESS, statusRet1) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(entry1.value, valueRet1) << "value and valueRet are not equal"; - - Value valueRet2; - Status statusRet2 = kvStoreSnapshotPtr->Get(entry2.key, valueRet2); - EXPECT_EQ(Status::SUCCESS, statusRet2) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(entry2.value, valueRet2) << "value and valueRet are not equal"; - - Value valueRet3; - Status statusRet3 = kvStoreSnapshotPtr->Get(entry3.key, valueRet3); - EXPECT_EQ(Status::SUCCESS, statusRet3) << "KvStoreSnapshot get data failed, wrong status"; - EXPECT_EQ(entry3.value, valueRet3) << "value and valueRet are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmDeleteBatch001 -* @tc.desc: delete batch data normally -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmDeleteBatch001, TestSize.Level2) -{ - ZLOGI("KvStoreDdmDeleteBatch001 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - kvStorePtr->Clear(); - - // store entries to kvstore. - std::vector entries; - Entry entry1, entry2, entry3; - entry1.key = "student_name_mali"; - entry1.value = "age:20"; - entry2.key = "student_name_caixu"; - entry2.value = "age:19"; - entry3.key = "student_name_liuyue"; - entry3.value = "age:23"; - entries.push_back(entry1); - entries.push_back(entry2); - entries.push_back(entry3); - - std::vector keys; - keys.push_back("student_name_mali"); - keys.push_back("student_name_caixu"); - keys.push_back("student_name_liuyue"); - - Status status1 = kvStorePtr->PutBatch(entries); - EXPECT_EQ(Status::SUCCESS, status1) << "KvStore putbatch data failed, wrong status"; - - Status status2 = kvStorePtr->DeleteBatch(keys); - EXPECT_EQ(Status::SUCCESS, status2) << "KvStore deletebatch data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - Key keyPrefixStudent = "student_name_"; - std::vector students; - Key token; - kvStoreSnapshotPtr->GetEntries(keyPrefixStudent, students); - EXPECT_EQ(0, static_cast(students.size())) << "KvStore is not empty, deletebatch fail"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmDeleteBatch002 -* @tc.desc: delete batch data which some keys are not in kvstore -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmDeleteBatch002, TestSize.Level2) -{ - ZLOGI("KvStoreDdmDeleteBatch002 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - kvStorePtr->Clear(); - - // store entries to kvstore. - std::vector entries; - Entry entry1, entry2, entry3; - entry1.key = "student_name_mali"; - entry1.value = "age:20"; - entry2.key = "student_name_caixu"; - entry2.value = "age:19"; - entry3.key = "student_name_liuyue"; - entry3.value = "age:23"; - entries.push_back(entry1); - entries.push_back(entry2); - entries.push_back(entry3); - - std::vector keys; - keys.push_back("student_name_mali"); - keys.push_back("student_name_caixu"); - keys.push_back("student_name_liuyue"); - keys.push_back("student_not_exist"); - - Status status1 = kvStorePtr->PutBatch(entries); - EXPECT_EQ(Status::SUCCESS, status1) << "KvStore putbatch data failed, wrong status"; - - Status status2 = kvStorePtr->DeleteBatch(keys); - EXPECT_EQ(Status::SUCCESS, status2) << "KvStore deletebatch data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - Key keyPrefixStudent = "student_name_"; - std::vector students; - Key token; - kvStoreSnapshotPtr->GetEntries(keyPrefixStudent, students); - EXPECT_EQ(0, static_cast(students.size())) << "KvStore is not empty, deletebatch fail"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmDeleteBatch003 -* @tc.desc: delete batch data which some keys are invalid -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmDeleteBatch003, TestSize.Level2) -{ - ZLOGI("KvStoreDdmDeleteBatch003 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - kvStorePtr->Clear(); - - // store entries to kvstore. - std::vector entries; - Entry entry1, entry2, entry3; - entry1.key = "student_name_mali"; - entry1.value = "age:20"; - entry2.key = "student_name_caixu"; - entry2.value = "age:19"; - entry3.key = "student_name_liuyue"; - entry3.value = "age:23"; - entries.push_back(entry1); - entries.push_back(entry2); - entries.push_back(entry3); - - std::vector keys; - keys.push_back("student_name_mali"); - keys.push_back("student_name_caixu"); - keys.push_back(""); - - Status status1 = kvStorePtr->PutBatch(entries); - EXPECT_EQ(Status::SUCCESS, status1) << "KvStore putbatch data failed, wrong status"; - - Status status2 = kvStorePtr->DeleteBatch(keys); - EXPECT_EQ(Status::INVALID_ARGUMENT, status2) << "KvStore deletebatch data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - Key keyPrefixStudent = "student_name_"; - std::vector students; - Key token; - kvStoreSnapshotPtr->GetEntries(keyPrefixStudent, students); - EXPECT_EQ(3, static_cast(students.size())) << "invalid argument, deletebatch fail"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmDeleteBatch004 -* @tc.desc: delete batch data which some keys are invalid -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmDeleteBatch004, TestSize.Level2) -{ - ZLOGI("KvStoreDdmDeleteBatch004 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - kvStorePtr->Clear(); - - // store entries to kvstore. - std::vector entries; - Entry entry1, entry2, entry3; - entry1.key = "student_name_mali"; - entry1.value = "age:20"; - entry2.key = "student_name_caixu"; - entry2.value = "age:19"; - entry3.key = "student_name_liuyue"; - entry3.value = "age:23"; - entries.push_back(entry1); - entries.push_back(entry2); - entries.push_back(entry3); - - std::vector keys; - keys.push_back("student_name_mali"); - keys.push_back("student_name_caixu"); - keys.push_back(" "); - - Status status1 = kvStorePtr->PutBatch(entries); - EXPECT_EQ(Status::SUCCESS, status1) << "KvStore putbatch data failed, wrong status"; - - Status status2 = kvStorePtr->DeleteBatch(keys); - EXPECT_EQ(Status::INVALID_ARGUMENT, status2) << "KvStore deletebatch data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - Key keyPrefixStudent = "student_name_"; - std::vector students; - Key token; - kvStoreSnapshotPtr->GetEntries(keyPrefixStudent, students); - EXPECT_EQ(3, static_cast(students.size())) << "invalid argument, deletebatch fail"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmDeleteBatch005 -* @tc.desc: delete batch data which some keys are invalid -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmDeleteBatch005, TestSize.Level2) -{ - ZLOGI("KvStoreDdmDeleteBatch005 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - kvStorePtr->Clear(); - - // store entries to kvstore. - std::vector entries; - Entry entry1, entry2, entry3; - entry1.key = "student_name_mali"; - entry1.value = "age:20"; - entry2.key = "student_name_caixu"; - entry2.value = "age:19"; - entry3.key = "student_name_liuyue"; - entry3.value = "age:23"; - entries.push_back(entry1); - entries.push_back(entry2); - entries.push_back(entry3); - - std::vector keys; - keys.push_back("student_name_mali"); - keys.push_back("student_name_caixu"); - Key keyTmp = Generate1025KeyLen(); - keys.push_back(keyTmp); - - Status status1 = kvStorePtr->PutBatch(entries); - EXPECT_EQ(Status::SUCCESS, status1) << "KvStore putbatch data failed, wrong status"; - - Status status2 = kvStorePtr->DeleteBatch(keys); - EXPECT_EQ(Status::INVALID_ARGUMENT, status2) << "KvStore deletebatch data failed, wrong status"; - std::shared_ptr kvStoreSnapshotPtr; - - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - Key keyPrefixStudent = "student_name_"; - std::vector students; - Key token; - kvStoreSnapshotPtr->GetEntries(keyPrefixStudent, students); - EXPECT_EQ(3, static_cast(students.size())) << "invalid argument, deletebatch fail"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreDdmGetStoreId001 -* @tc.desc: get kvstore id -* @tc.type: FUNC -* @tc.require: AR000C6GBG AR000CQS36 -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreClientTest, KvStoreDdmGetStoreId001, TestSize.Level2) -{ - ZLOGI("KvStoreDdmGetStoreId001 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore failed, wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - StoreId id = kvStorePtr->GetStoreId(); - EXPECT_EQ("student", id.storeId) << "GetStoreId fail"; -} diff --git a/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/kvstore_snapshot_client_test.cpp b/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/kvstore_snapshot_client_test.cpp deleted file mode 100644 index 599b5156043ac94ac845c8544edcbba7a2ed00b5..0000000000000000000000000000000000000000 --- a/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/kvstore_snapshot_client_test.cpp +++ /dev/null @@ -1,440 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "KvStoreSnapshotClientTest" - -#include -#include -#include -#include -#include -#include "distributed_kv_data_manager.h" -#include "log_print.h" -#include "types.h" - -using namespace testing::ext; -using namespace OHOS::DistributedKv; - -class KvStoreSnapshotClientTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - - static std::shared_ptr kvStorePtr; // declare kv store instance. - static Status statusGetKvStore; - static DistributedKvDataManager manager; -}; - -DistributedKvDataManager KvStoreSnapshotClientTest::manager; -std::shared_ptr KvStoreSnapshotClientTest::kvStorePtr = nullptr; -Status KvStoreSnapshotClientTest::statusGetKvStore = Status::ERROR; - -void KvStoreSnapshotClientTest::SetUpTestCase(void) -{ - ZLOGI("KvStoreSnapshotClientTest::SetUpTestCase"); - Options options; - options.createIfMissing = true; - options.encrypt = false; // not supported yet. - options.autoSync = true; // not supported yet. - options.kvStoreType = KvStoreType::MULTI_VERSION; - - AppId appId; - appId.appId = "odmf"; // define app name. - StoreId storeId; - storeId.storeId = "student"; // define kvstore(database) name. - - manager.CloseAllKvStore(appId); - manager.DeleteAllKvStore(appId); - // [create and] open and initialize kvstore instance. - statusGetKvStore = manager.GetKvStore(options, appId, storeId, kvStorePtr); -} - -void KvStoreSnapshotClientTest::TearDownTestCase(void) -{ - ZLOGI("KvStoreSnapshotClientTest::TearDownTestCase"); - if (kvStorePtr != nullptr) { - AppId appId; - appId.appId = "odmf"; // define app name. - StoreId storeId; - storeId.storeId = "student"; // define kvstore(database) name. - manager.CloseKvStore(appId, storeId); - } -} - -void KvStoreSnapshotClientTest::SetUp(void) -{} - -void KvStoreSnapshotClientTest::TearDown(void) -{} - -/** -* @tc.name: KvStoreSnapshotDdmGet001 -* @tc.desc: Get values of keys in KvStore. -* @tc.type: FUNC -* @tc.require: AR000C6GBG -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreSnapshotClientTest, KvStoreSnapshotDdmGet001, TestSize.Level1) -{ - ZLOGI("KvStoreSnapshotDdmGet001 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - Key key = "age"; - Value value = "18"; - Status status = kvStorePtr->Put(key, value); // insert or update key-value - EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; - - std::shared_ptr snapshot; - // [create and] open and initialize kvstore snapshot instance. - status = kvStorePtr->GetKvStoreSnapshot(nullptr, snapshot); - EXPECT_EQ(Status::SUCCESS, status) << "KvStore GetKvStoreSnapshot return wrong status"; - EXPECT_NE(nullptr, snapshot) << "kvStoreSnapshotPtr is nullptr"; - // get value from kvstore. - Value valueRet; - Status statusRet = snapshot->Get(key, valueRet); - EXPECT_EQ(Status::SUCCESS, statusRet) << "KvStoreSnapshot get data return wrong status"; - - EXPECT_EQ(value, valueRet) << "value and valueRet are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(snapshot); -} - -/** -* @tc.name: KvStoreSnapshotDdmGet002 -* @tc.desc: Get key values in KvStore when keys do not exist. -* @tc.type: FUNC -* @tc.require: AR000C6GBG -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreSnapshotClientTest, KvStoreSnapshotDdmGet002, TestSize.Level1) -{ - ZLOGI("KvStoreSnapshotDdmGet002 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - - Key key = "age"; - Value value = "18"; - Status status1 = kvStorePtr->Put(key, value); // insert or update key-value - EXPECT_EQ(Status::SUCCESS, status1) << "KvStore put data return wrong status"; - - Status status2 = kvStorePtr->Delete(key); // delete data - EXPECT_EQ(Status::SUCCESS, status2) << "KvStore delete data return wrong status"; - - std::shared_ptr snapshot; - // [create and] open and initialize kvstore snapshot instance. - status1 = kvStorePtr->GetKvStoreSnapshot(nullptr, snapshot); - EXPECT_EQ(Status::SUCCESS, status1) << "KvStore GetKvStoreSnapshot return wrong status"; - EXPECT_NE(nullptr, snapshot) << "kvStoreSnapshotPtr is nullptr"; - - // get value from kvstore. - Value valueRet; - Status statusRet = snapshot->Get(key, valueRet); - EXPECT_EQ(Status::KEY_NOT_FOUND, statusRet); - EXPECT_EQ(Status::KEY_NOT_FOUND, statusRet) << "KvStoreSnapshot get data return wrong status"; - EXPECT_EQ("", valueRet.ToString()) << "value and valueRet are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(snapshot); -} - -/** -* @tc.name: KvStoreSnapshotDdmGet003 -* @tc.desc: Get key values in KvStore when keys are invalid. -* @tc.type: FUNC -* @tc.require: AR000C6GBG -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreSnapshotClientTest, KvStoreSnapshotDdmGet003, TestSize.Level1) -{ - ZLOGI("KvStoreSnapshotDdmGet003 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - std::shared_ptr snapshot; - // [create and] open and initialize kvstore snapshot instance. - Status status = kvStorePtr->GetKvStoreSnapshot(nullptr, snapshot); - EXPECT_EQ(Status::SUCCESS, status) << "GetKvStoreSnapshot return wrong status"; - EXPECT_NE(nullptr, snapshot) << "kvStoreSnapshotPtr is nullptr"; - - // get value from kvstore. - Key key; - Value valueRet; - Status statusRet = snapshot->Get(key, valueRet); - EXPECT_EQ(Status::INVALID_ARGUMENT, statusRet); - EXPECT_EQ(Status::INVALID_ARGUMENT, statusRet) << "KvStoreSnapshot get data return wrong status"; - EXPECT_EQ("", valueRet.ToString()) << "value and valueRet are not equal"; - kvStorePtr->ReleaseKvStoreSnapshot(snapshot); -} - -/** -* @tc.name: KvStoreSnapshotDdmGetEntries001 -* @tc.desc: Get key entries from KvStore. -* @tc.type: FUNC -* @tc.require: AR000C6GBG -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreSnapshotClientTest, KvStoreSnapshotDdmGetEntries001, TestSize.Level1) -{ - ZLOGI("KvStoreSnapshotDdmGetEntries001 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - - // store entries to kvstore. - std::vector entries; - Entry entry1, entry2, entry3; - entry1.key = "student_name_mali"; - entry1.value = "age:20"; - entry2.key = "student_name_caixu"; - entry2.value = "age:19"; - entry3.key = "student_name_liuyue"; - entry3.value = "age:23"; - entries.push_back(entry1); - entries.push_back(entry2); - entries.push_back(entry3); - - Status status = kvStorePtr->PutBatch(entries); - EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; - - // get entries - Key keyPrefixStudent = "student_name_"; - std::vector students; - Key token; - Status statusTmp = Status::ERROR; - std::shared_ptr kvStoreSnapshotPtr; - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - statusTmp = kvStoreSnapshotPtr->GetEntries(keyPrefixStudent, students); - EXPECT_EQ(3, static_cast(students.size())) << "GetEntries failed"; - EXPECT_EQ(Status::SUCCESS, statusTmp) << "KvStore GetEntries data return wrong status"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreSnapshotDdmGetEntries002 -* @tc.desc: Get key entries from KvStore when the keyPrefix does not exist. -* @tc.type: FUNC -* @tc.require: AR000C6GBG -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreSnapshotClientTest, KvStoreSnapshotDdmGetEntries002, TestSize.Level1) -{ - ZLOGI("KvStoreSnapshotDdmGetEntries002 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - - // store entries to kvstore. - std::vector entries; - Entry entry1, entry2, entry3; - entry1.key = "student_name_mali"; - entry1.value = "age:20"; - entry2.key = "student_name_caixu"; - entry2.value = "age:19"; - entry3.key = "student_name_liuyue"; - entry3.value = "age:23"; - entries.push_back(entry1); - entries.push_back(entry2); - entries.push_back(entry3); - - Status status = kvStorePtr->PutBatch(entries); - EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; - - // get entries - Key keyPrefixStudent = "teacher_name_"; - std::vector students; - Key token; - Status statusTmp = Status::ERROR; - std::shared_ptr kvStoreSnapshotPtr; - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - statusTmp = kvStoreSnapshotPtr->GetEntries(keyPrefixStudent, students); - EXPECT_EQ(0, static_cast(students.size())) << "GetEntries fail"; - EXPECT_EQ(Status::KEY_NOT_FOUND, statusTmp) << "KvStore GetEntries data return wrong status"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreSnapshotDdmGetEntries003 -* @tc.desc: Get all key entries from KvStore when the keys are empty. -* @tc.type: FUNC -* @tc.require: AR000C6GBG -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreSnapshotClientTest, KvStoreSnapshotDdmGetEntries003, TestSize.Level1) -{ - ZLOGI("KvStoreSnapshotDdmGetEntries003 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - - // store entries to kvstore. - std::vector entries; - Entry entry1, entry2, entry3; - entry1.key = "student_name_mali"; - entry1.value = "age:20"; - entry2.key = "student_name_caixu"; - entry2.value = "age:19"; - entry3.key = "student_name_liuyue"; - entry3.value = "age:23"; - entries.push_back(entry1); - entries.push_back(entry2); - entries.push_back(entry3); - - Status status = kvStorePtr->PutBatch(entries); - EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; - - // get entries - Key keyPrefixStudent = ""; - std::vector students; - Key token; - Status statusTmp = Status::ERROR; - std::shared_ptr kvStoreSnapshotPtr; - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - statusTmp = kvStoreSnapshotPtr->GetEntries(keyPrefixStudent, students); - EXPECT_EQ(3, static_cast(students.size())) << "GetEntries fail"; - EXPECT_EQ(Status::SUCCESS, statusTmp) << "KvStore GetEntries data return wrong status"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: KvStoreSnapshotDdmGetEntries004 -* @tc.desc: Get all key entries from KvStore when the keys contain only space blank. -* @tc.type: FUNC -* @tc.require: AR000C6GBG -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreSnapshotClientTest, KvStoreSnapshotDdmGetEntries004, TestSize.Level1) -{ - ZLOGI("KvStoreSnapshotDdmGetEntries004 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - - // store entries to kvstore. - std::vector entries; - Entry entry1, entry2, entry3; - entry1.key = "student_name_mali"; - entry1.value = "age:20"; - entry2.key = "student_name_caixu"; - entry2.value = "age:19"; - entry3.key = "student_name_liuyue"; - entry3.value = "age:23"; - entries.push_back(entry1); - entries.push_back(entry2); - entries.push_back(entry3); - - Status status = kvStorePtr->PutBatch(entries); - EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; - - // get entries - Key keyPrefixStudent = " "; - std::vector students; - Key token; - Status statusTmp = Status::ERROR; - std::shared_ptr kvStoreSnapshotPtr; - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - statusTmp = kvStoreSnapshotPtr->GetEntries(keyPrefixStudent, students); - EXPECT_EQ(3, static_cast(students.size())) << "GetEntries fail"; - EXPECT_EQ(Status::SUCCESS, statusTmp) << "KvStore GetEntries data return wrong status"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -static std::string Generate1025KeyLen() -{ - // Generate key and the length is more than 1024; - std::string str("prefix"); - for (int i = 0; i < 1024; i++) { - str += "a"; - } - return str; -} - -/** -* @tc.name: KvStoreSnapshotDdmGetEntries005 -* @tc.desc: Get key entries from KvStore when the keyPrefix is invalid. -* @tc.type: FUNC -* @tc.require: AR000C6GBG -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreSnapshotClientTest, KvStoreSnapshotDdmGetEntries005, TestSize.Level1) -{ - ZLOGI("KvStoreSnapshotDdmGetEntries005 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - - // store entries to kvstore. - std::vector entries; - Entry entry1, entry2, entry3; - entry1.key = "student_name_mali"; - entry1.value = "age:20"; - entry2.key = "student_name_caixu"; - entry2.value = "age:19"; - entry3.key = "student_name_liuyue"; - entry3.value = "age:23"; - entries.push_back(entry1); - entries.push_back(entry2); - entries.push_back(entry3); - - Status status = kvStorePtr->PutBatch(entries); - EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; - - // get entries - Key keyPrefixStudent = Generate1025KeyLen(); - std::vector students; - Key token; - Status statusTmp = Status::ERROR; - std::shared_ptr kvStoreSnapshotPtr; - // [create and] open and initialize kvstore snapshot instance. - kvStorePtr->GetKvStoreSnapshot(nullptr, kvStoreSnapshotPtr); - - EXPECT_NE(nullptr, kvStoreSnapshotPtr) << "kvStoreSnapshotPtr is nullptr"; - statusTmp = kvStoreSnapshotPtr->GetEntries(keyPrefixStudent, students); - EXPECT_EQ(0, static_cast(students.size())) << "invalid argument, GetEntries fail"; - EXPECT_EQ(Status::INVALID_ARGUMENT, statusTmp) << "KvStore GetEntries data return wrong status"; - kvStorePtr->ReleaseKvStoreSnapshot(kvStoreSnapshotPtr); -} - -/** -* @tc.name: EntryIpcInterfaceTest001 -* @tc.desc: Marshal and unmarshall key entries. -* @tc.type: FUNC -* @tc.require: AR000C6GBG -* @tc.author: liuyuhui -*/ -HWTEST_F(KvStoreSnapshotClientTest, EntryIpcInterfaceTest001, TestSize.Level1) -{ - ZLOGI("EntryIpcInterfaceTest001 begin."); - Entry entryIn, *entryOut; - entryIn.key = "student_name_mali"; - entryIn.value = "age:20"; - OHOS::Parcel parcel; - entryIn.Marshalling(parcel); - entryOut = Entry::Unmarshalling(parcel); - EXPECT_NE(entryOut, nullptr); - EXPECT_EQ(entryOut->key.ToString(), std::string("student_name_mali")); - EXPECT_EQ(entryOut->value.ToString(), std::string("age:20")); - delete entryOut; -} diff --git a/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/local_subscribe_store_test.cpp b/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/local_subscribe_store_test.cpp index fde1cd3d26f29465d0adb9a9e99a143c0f1cbd33..8dd8fa6efe561daee4788eefd7be3fd035556a55 100644 --- a/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/local_subscribe_store_test.cpp +++ b/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/local_subscribe_store_test.cpp @@ -37,41 +37,52 @@ public: void TearDown(); static DistributedKvDataManager manager; - static std::shared_ptr kvStorePtr; // declare kvstore instance. + static std::shared_ptr kvStore; static Status statusGetKvStore; static AppId appId; static StoreId storeId; static int usleepTime; }; -std::shared_ptr LocalSubscribeStoreTest::kvStorePtr = nullptr; +std::shared_ptr LocalSubscribeStoreTest::kvStore = nullptr; Status LocalSubscribeStoreTest::statusGetKvStore = Status::ERROR; DistributedKvDataManager LocalSubscribeStoreTest::manager; AppId LocalSubscribeStoreTest::appId; StoreId LocalSubscribeStoreTest::storeId; void LocalSubscribeStoreTest::SetUpTestCase(void) +{ +} + +void LocalSubscribeStoreTest::TearDownTestCase(void) +{ + manager.CloseKvStore(appId, kvStore); + kvStore = nullptr; + manager.DeleteKvStore(appId, storeId); +} + +void LocalSubscribeStoreTest::SetUp(void) { Options options; options.createIfMissing = true; options.encrypt = false; // not supported yet. options.autoSync = true; // not supported yet. - options.kvStoreType = KvStoreType::MULTI_VERSION; + options.kvStoreType = KvStoreType::SINGLE_VERSION; appId.appId = "odmf"; // define app name. storeId.storeId = "student"; // define kvstore(database) name manager.DeleteKvStore(appId, storeId); // [create and] open and initialize kvstore instance. - statusGetKvStore = manager.GetKvStore(options, appId, storeId, kvStorePtr); + statusGetKvStore = manager.GetSingleKvStore(options, appId, storeId, kvStore); + EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; + EXPECT_NE(nullptr, kvStore) << "kvStore is nullptr"; } -void LocalSubscribeStoreTest::TearDownTestCase(void) -{} - -void LocalSubscribeStoreTest::SetUp(void) -{} - void LocalSubscribeStoreTest::TearDown(void) -{} +{ + manager.CloseKvStore(appId, kvStore); + kvStore = nullptr; + manager.DeleteKvStore(appId, storeId); +} class KvStoreObserverUnitTest : public KvStoreObserver { public: @@ -116,24 +127,9 @@ void KvStoreObserverUnitTest::OnChange(const ChangeNotification &changeNotificat { ZLOGD("begin."); callCount_++; - const auto &insert = changeNotification.GetInsertEntries(); - insertEntries_.clear(); - for (const auto &entry : insert) { - insertEntries_.push_back(entry); - } - - const auto &update = changeNotification.GetUpdateEntries(); - updateEntries_.clear(); - for (const auto &entry : update) { - updateEntries_.push_back(entry); - } - - const auto &del = changeNotification.GetDeleteEntries(); - deleteEntries_.clear(); - for (const auto &entry : del) { - deleteEntries_.push_back(entry); - } - + insertEntries_ = changeNotification.GetInsertEntries(); + updateEntries_ = changeNotification.GetUpdateEntries(); + deleteEntries_ = changeNotification.GetDeleteEntries(); changeNotification.GetDeviceId(); isClear_ = changeNotification.IsClear(); } @@ -163,18 +159,15 @@ uint64_t KvStoreObserverUnitTest::GetCallCount() const HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore001, TestSize.Level1) { ZLOGI("KvStoreDdmSubscribeKvStore001 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; EXPECT_EQ(static_cast(observer->GetCallCount()), 0); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; observer = nullptr; } @@ -189,12 +182,9 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore001, TestSize.Level1 HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore002, TestSize.Level1) { ZLOGI("KvStoreDdmSubscribeKvStore002 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; std::shared_ptr observer = nullptr; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::INVALID_ARGUMENT, status) << "SubscribeKvStore return wrong status"; } @@ -208,25 +198,21 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore002, TestSize.Level1 HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore003, TestSize.Level1) { ZLOGI("KvStoreDdmSubscribeKvStore003 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; Key key = "Id1"; Value value = "subscribe"; - status = kvStorePtr->Put(key, value); // insert or update key-value + status = kvStore->Put(key, value); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; observer = nullptr; } @@ -241,29 +227,25 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore003, TestSize.Level1 HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore004, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStore004 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::STORE_ALREADY_SUBSCRIBE, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::STORE_ALREADY_SUBSCRIBE, status) << "SubscribeKvStore return wrong status"; Key key = "Id1"; Value value = "subscribe"; - status = kvStorePtr->Put(key, value); // insert or update key-value + status = kvStore->Put(key, value); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -277,10 +259,6 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore004, TestSize.Level2 HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore005, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStore005 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer1 = std::make_shared(); observer1->ResetToZero(); std::shared_ptr observer2 = std::make_shared(); @@ -289,27 +267,27 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore005, TestSize.Level2 observer3->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer1); + Status status = kvStore->SubscribeKvStore(subscribeType, observer1); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore failed, wrong status"; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer2); + status = kvStore->SubscribeKvStore(subscribeType, observer2); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore failed, wrong status"; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer3); + status = kvStore->SubscribeKvStore(subscribeType, observer3); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore failed, wrong status"; Key key = "Id1"; Value value = "subscribe"; - status = kvStorePtr->Put(key, value); // insert or update key-value + status = kvStore->Put(key, value); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "Putting data to KvStore failed, wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer1->GetCallCount()), 1); EXPECT_EQ(static_cast(observer2->GetCallCount()), 1); EXPECT_EQ(static_cast(observer3->GetCallCount()), 1); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer1); + status = kvStore->UnSubscribeKvStore(subscribeType, observer1); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer2); + status = kvStore->UnSubscribeKvStore(subscribeType, observer2); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer3); + status = kvStore->UnSubscribeKvStore(subscribeType, observer3); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -323,45 +301,41 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore005, TestSize.Level2 HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore006, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStore006 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; Key key1 = "Id1"; Value value1 = "subscribe"; - status = kvStorePtr->Put(key1, value1); // insert or update key-value + status = kvStore->Put(key1, value1); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; Key key2 = "Id2"; Value value2 = "subscribe"; - status = kvStorePtr->Put(key2, value2); // insert or update key-value + status = kvStore->Put(key2, value2); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); - kvStorePtr->SubscribeKvStore(subscribeType, observer); + kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; EXPECT_EQ(static_cast(observer->GetCallCount()), 1); Key key3 = "Id3"; Value value3 = "subscribe"; - status = kvStorePtr->Put(key3, value3); // insert or update key-value + status = kvStore->Put(key3, value3); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 2); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -375,36 +349,32 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore006, TestSize.Level2 HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore007, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStore007 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; Key key1 = "Id1"; Value value1 = "subscribe"; - status = kvStorePtr->Put(key1, value1); // insert or update key-value + status = kvStore->Put(key1, value1); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; Key key2 = "Id2"; Value value2 = "subscribe"; - status = kvStorePtr->Put(key2, value2); // insert or update key-value + status = kvStore->Put(key2, value2); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; Key key3 = "Id3"; Value value3 = "subscribe"; - status = kvStorePtr->Put(key3, value3); // insert or update key-value + status = kvStore->Put(key3, value3); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 3); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -418,36 +388,32 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore007, TestSize.Level2 HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore008, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStore008 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; Key key1 = "Id1"; Value value1 = "subscribe"; - status = kvStorePtr->Put(key1, value1); // insert or update key-value + status = kvStore->Put(key1, value1); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; Key key2 = "Id2"; Value value2 = "subscribe"; - status = kvStorePtr->Put(key2, value2); // insert or update key-value + status = kvStore->Put(key2, value2); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; Key key3 = "Id1"; Value value3 = "subscribe03"; - status = kvStorePtr->Put(key3, value3); // insert or update key-value + status = kvStore->Put(key3, value3); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 3); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -461,15 +427,11 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore008, TestSize.Level2 HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore009, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStore009 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; // before update. @@ -494,14 +456,14 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore009, TestSize.Level2 entries2.push_back(entry4); entries2.push_back(entry5); - status = kvStorePtr->PutBatch(entries1); + status = kvStore->PutBatch(entries1); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; - status = kvStorePtr->PutBatch(entries2); + status = kvStore->PutBatch(entries2); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; usleep(1000000); EXPECT_EQ(static_cast(observer->GetCallCount()), 2); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -515,15 +477,11 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore009, TestSize.Level2 HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore010, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStore010 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; // before update. @@ -548,14 +506,14 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore010, TestSize.Level2 entries2.push_back(entry4); entries2.push_back(entry5); - status = kvStorePtr->PutBatch(entries1); + status = kvStore->PutBatch(entries1); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; - status = kvStorePtr->PutBatch(entries2); + status = kvStore->PutBatch(entries2); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 2); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -569,9 +527,6 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore010, TestSize.Level2 HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore011, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStore011 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); @@ -587,18 +542,18 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore011, TestSize.Level2 entries.push_back(entry2); entries.push_back(entry3); - Status status = kvStorePtr->PutBatch(entries); + Status status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->Delete("Id1"); + status = kvStore->Delete("Id1"); EXPECT_EQ(Status::SUCCESS, status) << "KvStore Delete data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -612,9 +567,6 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore011, TestSize.Level2 HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore012, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStore012 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); @@ -630,18 +582,18 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore012, TestSize.Level2 entries.push_back(entry2); entries.push_back(entry3); - Status status = kvStorePtr->PutBatch(entries); + Status status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->Delete("Id4"); + status = kvStore->Delete("Id4"); EXPECT_EQ(Status::SUCCESS, status) << "KvStore Delete data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 0); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -655,9 +607,6 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore012, TestSize.Level2 HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore013, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStore013 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); @@ -673,18 +622,16 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore013, TestSize.Level2 entries.push_back(entry2); entries.push_back(entry3); - Status status = kvStorePtr->PutBatch(entries); + Status status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->Clear(); - EXPECT_EQ(Status::SUCCESS, status) << "KvStore Clear data return wrong status"; usleep(USLEEP_TIME); - EXPECT_EQ(static_cast(observer->GetCallCount()), 1); + EXPECT_EQ(static_cast(observer->GetCallCount()), 0); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -698,21 +645,16 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore013, TestSize.Level2 HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore014, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStore014 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->Clear(); - EXPECT_EQ(Status::SUCCESS, status) << "KvStore Clear data return wrong status"; usleep(USLEEP_TIME); - EXPECT_EQ(static_cast(observer->GetCallCount()), 1); + EXPECT_EQ(static_cast(observer->GetCallCount()), 0); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -726,9 +668,6 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore014, TestSize.Level2 HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore015, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStore015 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); @@ -748,19 +687,19 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore015, TestSize.Level2 keys.push_back("Id1"); keys.push_back("Id2"); - Status status = kvStorePtr->PutBatch(entries); + Status status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->DeleteBatch(keys); + status = kvStore->DeleteBatch(keys); EXPECT_EQ(Status::SUCCESS, status) << "KvStore DeleteBatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -774,9 +713,6 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore015, TestSize.Level2 HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore016, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStore016 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); @@ -796,19 +732,19 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore016, TestSize.Level2 keys.push_back("Id4"); keys.push_back("Id5"); - Status status = kvStorePtr->PutBatch(entries); + Status status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->DeleteBatch(keys); + status = kvStore->DeleteBatch(keys); EXPECT_EQ(Status::SUCCESS, status) << "KvStore DeleteBatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 0); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -822,19 +758,16 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore016, TestSize.Level2 HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore020, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStore020 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::STORE_NOT_SUBSCRIBE, status) << "UnSubscribeKvStore return wrong status"; } @@ -848,20 +781,16 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStore020, TestSize.Level2 HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification001, TestSize.Level1) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification001 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; Key key = "Id1"; Value value = "subscribe"; - status = kvStorePtr->Put(key, value); // insert or update key-value + status = kvStore->Put(key, value); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); @@ -871,7 +800,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification001, Tes EXPECT_EQ("subscribe", observer->insertEntries_[0].value.ToString()); ZLOGD("kvstore_ddm_subscribekvstore_003 size:%zu.", observer->insertEntries_.size()); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -885,24 +814,20 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification001, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification002, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification002 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::STORE_ALREADY_SUBSCRIBE, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::STORE_ALREADY_SUBSCRIBE, status) << "SubscribeKvStore return wrong status"; Key key = "Id1"; Value value = "subscribe"; - status = kvStorePtr->Put(key, value); // insert or update key-value + status = kvStore->Put(key, value); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); @@ -910,7 +835,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification002, Tes EXPECT_EQ("Id1", observer->insertEntries_[0].key.ToString()); EXPECT_EQ("subscribe", observer->insertEntries_[0].value.ToString()); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -924,10 +849,6 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification002, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification003, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification003 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer1 = std::make_shared(); observer1->ResetToZero(); std::shared_ptr observer2 = std::make_shared(); @@ -936,16 +857,16 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification003, Tes observer3->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer1); + Status status = kvStore->SubscribeKvStore(subscribeType, observer1); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer2); + status = kvStore->SubscribeKvStore(subscribeType, observer2); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer3); + status = kvStore->SubscribeKvStore(subscribeType, observer3); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; Key key = "Id1"; Value value = "subscribe"; - status = kvStorePtr->Put(key, value); // insert or update key-value + status = kvStore->Put(key, value); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer1->GetCallCount()), 1); @@ -963,11 +884,11 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification003, Tes EXPECT_EQ("Id1", observer3->insertEntries_[0].key.ToString()); EXPECT_EQ("subscribe", observer3->insertEntries_[0].value.ToString()); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer1); + status = kvStore->UnSubscribeKvStore(subscribeType, observer1); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer2); + status = kvStore->UnSubscribeKvStore(subscribeType, observer2); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer3); + status = kvStore->UnSubscribeKvStore(subscribeType, observer3); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -981,20 +902,16 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification003, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification004, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification004 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; Key key1 = "Id1"; Value value1 = "subscribe"; - status = kvStorePtr->Put(key1, value1); // insert or update key-value + status = kvStore->Put(key1, value1); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); @@ -1002,12 +919,12 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification004, Tes EXPECT_EQ("Id1", observer->insertEntries_[0].key.ToString()); EXPECT_EQ("subscribe", observer->insertEntries_[0].value.ToString()); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; Key key2 = "Id2"; Value value2 = "subscribe"; - status = kvStorePtr->Put(key2, value2); // insert or update key-value + status = kvStore->Put(key2, value2); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); @@ -1015,12 +932,12 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification004, Tes EXPECT_EQ("Id1", observer->insertEntries_[0].key.ToString()); EXPECT_EQ("subscribe", observer->insertEntries_[0].value.ToString()); - kvStorePtr->SubscribeKvStore(subscribeType, observer); + kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; EXPECT_EQ(static_cast(observer->GetCallCount()), 1); Key key3 = "Id3"; Value value3 = "subscribe"; - status = kvStorePtr->Put(key3, value3); // insert or update key-value + status = kvStore->Put(key3, value3); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 2); @@ -1028,7 +945,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification004, Tes EXPECT_EQ("Id3", observer->insertEntries_[0].key.ToString()); EXPECT_EQ("subscribe", observer->insertEntries_[0].value.ToString()); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -1042,20 +959,16 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification004, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification005, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification005 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; Key key1 = "Id1"; Value value1 = "subscribe"; - status = kvStorePtr->Put(key1, value1); // insert or update key-value + status = kvStore->Put(key1, value1); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->insertEntries_.size()), 1); @@ -1064,7 +977,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification005, Tes Key key2 = "Id2"; Value value2 = "subscribe"; - status = kvStorePtr->Put(key2, value2); // insert or update key-value + status = kvStore->Put(key2, value2); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->insertEntries_.size()), 1); @@ -1073,7 +986,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification005, Tes Key key3 = "Id3"; Value value3 = "subscribe"; - status = kvStorePtr->Put(key3, value3); // insert or update key-value + status = kvStore->Put(key3, value3); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->insertEntries_.size()), 1); @@ -1083,7 +996,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification005, Tes usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 3); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -1097,20 +1010,16 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification005, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification006, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification006 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; Key key1 = "Id1"; Value value1 = "subscribe"; - status = kvStorePtr->Put(key1, value1); // insert or update key-value + status = kvStore->Put(key1, value1); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->insertEntries_.size()), 1); @@ -1119,7 +1028,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification006, Tes Key key2 = "Id1"; Value value2 = "subscribe"; - status = kvStorePtr->Put(key2, value2); // insert or update key-value + status = kvStore->Put(key2, value2); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->updateEntries_.size()), 1); @@ -1128,7 +1037,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification006, Tes Key key3 = "Id1"; Value value3 = "subscribe"; - status = kvStorePtr->Put(key3, value3); // insert or update key-value + status = kvStore->Put(key3, value3); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->updateEntries_.size()), 1); @@ -1138,7 +1047,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification006, Tes usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 3); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -1152,30 +1061,26 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification006, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification007, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification007 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); Key key1 = "Id1"; Value value1 = "subscribe"; - Status status = kvStorePtr->Put(key1, value1); // insert or update key-value + Status status = kvStore->Put(key1, value1); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; Key key2 = "Id2"; Value value2 = "subscribe"; - status = kvStorePtr->Put(key2, value2); // insert or update key-value + status = kvStore->Put(key2, value2); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; Key key3 = "Id1"; Value value3 = "subscribe03"; - status = kvStorePtr->Put(key3, value3); // insert or update key-value + status = kvStore->Put(key3, value3); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; usleep(USLEEP_TIME); @@ -1184,7 +1089,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification007, Tes EXPECT_EQ("Id1", observer->updateEntries_[0].key.ToString()); EXPECT_EQ("subscribe03", observer->updateEntries_[0].value.ToString()); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -1198,10 +1103,6 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification007, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification008, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification008 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::vector entries; Entry entry1, entry2, entry3; @@ -1215,13 +1116,13 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification008, Tes entries.push_back(entry2); entries.push_back(entry3); - Status status = kvStorePtr->PutBatch(entries); + Status status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; entries.clear(); entry1.key = "Id1"; @@ -1230,7 +1131,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification008, Tes entry2.value = "subscribe_modify"; entries.push_back(entry1); entries.push_back(entry2); - status = kvStorePtr->PutBatch(entries); + status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; usleep(USLEEP_TIME); @@ -1241,7 +1142,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification008, Tes EXPECT_EQ("Id2", observer->updateEntries_[1].key.ToString()); EXPECT_EQ("subscribe_modify", observer->updateEntries_[1].value.ToString()); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -1255,15 +1156,11 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification008, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification009, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification009 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; std::vector entries; @@ -1279,7 +1176,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification009, Tes entries.push_back(entry2); entries.push_back(entry3); - status = kvStorePtr->PutBatch(entries); + status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); @@ -1291,7 +1188,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification009, Tes EXPECT_EQ("Id3", observer->insertEntries_[2].key.ToString()); EXPECT_EQ("subscribe", observer->insertEntries_[2].value.ToString()); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -1305,15 +1202,11 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification009, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification010, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification010 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; std::vector entries; @@ -1329,7 +1222,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification010, Tes entries.push_back(entry2); entries.push_back(entry3); - status = kvStorePtr->PutBatch(entries); + status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); @@ -1341,7 +1234,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification010, Tes EXPECT_EQ(static_cast(observer->updateEntries_.size()), 0); EXPECT_EQ(static_cast(observer->deleteEntries_.size()), 0); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -1355,15 +1248,11 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification010, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification011, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification011 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; std::vector entries; @@ -1379,7 +1268,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification011, Tes entries.push_back(entry2); entries.push_back(entry3); - status = kvStorePtr->PutBatch(entries); + status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); @@ -1389,7 +1278,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification011, Tes EXPECT_EQ(static_cast(observer->updateEntries_.size()), 0); EXPECT_EQ(static_cast(observer->deleteEntries_.size()), 0); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -1403,15 +1292,11 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification011, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification012, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification012 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; std::vector entries1; @@ -1436,7 +1321,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification012, Tes entries2.push_back(entry4); entries2.push_back(entry5); - status = kvStorePtr->PutBatch(entries1); + status = kvStore->PutBatch(entries1); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->insertEntries_.size()), 3); @@ -1447,7 +1332,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification012, Tes EXPECT_EQ("Id3", observer->insertEntries_[2].key.ToString()); EXPECT_EQ("subscribe", observer->insertEntries_[2].value.ToString()); - status = kvStorePtr->PutBatch(entries2); + status = kvStore->PutBatch(entries2); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->insertEntries_.size()), 2); @@ -1458,7 +1343,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification012, Tes EXPECT_EQ(static_cast(observer->GetCallCount()), 2); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -1472,15 +1357,11 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification012, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification013, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification013 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; std::vector entries1; @@ -1505,7 +1386,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification013, Tes entries2.push_back(entry4); entries2.push_back(entry5); - status = kvStorePtr->PutBatch(entries1); + status = kvStore->PutBatch(entries1); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->insertEntries_.size()), 3); @@ -1516,7 +1397,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification013, Tes EXPECT_EQ("Id3", observer->insertEntries_[2].key.ToString()); EXPECT_EQ("subscribe", observer->insertEntries_[2].value.ToString()); - status = kvStorePtr->PutBatch(entries2); + status = kvStore->PutBatch(entries2); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->updateEntries_.size()), 1); @@ -1528,7 +1409,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification013, Tes EXPECT_EQ(static_cast(observer->GetCallCount()), 2); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -1542,15 +1423,11 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification013, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification014, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification014 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; std::vector entries1; @@ -1575,7 +1452,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification014, Tes entries2.push_back(entry4); entries2.push_back(entry5); - status = kvStorePtr->PutBatch(entries1); + status = kvStore->PutBatch(entries1); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->insertEntries_.size()), 3); @@ -1586,7 +1463,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification014, Tes EXPECT_EQ("Id3", observer->insertEntries_[2].key.ToString()); EXPECT_EQ("subscribe", observer->insertEntries_[2].value.ToString()); - status = kvStorePtr->PutBatch(entries2); + status = kvStore->PutBatch(entries2); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->updateEntries_.size()), 2); @@ -1597,7 +1474,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification014, Tes EXPECT_EQ(static_cast(observer->GetCallCount()), 2); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -1611,15 +1488,11 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification014, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification015, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification015 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; std::vector entries1; @@ -1644,7 +1517,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification015, Tes entries2.push_back(entry4); entries2.push_back(entry5); - status = kvStorePtr->PutBatch(entries1); + status = kvStore->PutBatch(entries1); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->updateEntries_.size()), 0); @@ -1655,7 +1528,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification015, Tes EXPECT_EQ("Id3", observer->insertEntries_[1].key.ToString()); EXPECT_EQ("subscribe", observer->insertEntries_[1].value.ToString()); - status = kvStorePtr->PutBatch(entries2); + status = kvStore->PutBatch(entries2); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->updateEntries_.size()), 1); @@ -1667,7 +1540,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification015, Tes EXPECT_EQ(static_cast(observer->GetCallCount()), 2); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -1681,15 +1554,11 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification015, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification016, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification016 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; const int ENTRIES_MAX_LEN = 100; @@ -1701,14 +1570,14 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification016, Tes entries.push_back(entry); } - status = kvStorePtr->PutBatch(entries); + status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); EXPECT_EQ(static_cast(observer->insertEntries_.size()), 100); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -1722,9 +1591,6 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification016, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification017, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification017 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); @@ -1740,13 +1606,13 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification017, Tes entries.push_back(entry2); entries.push_back(entry3); - Status status = kvStorePtr->PutBatch(entries); + Status status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->Delete("Id1"); + status = kvStore->Delete("Id1"); EXPECT_EQ(Status::SUCCESS, status) << "KvStore Delete data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); @@ -1754,7 +1620,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification017, Tes EXPECT_EQ("Id1", observer->deleteEntries_[0].key.ToString()); EXPECT_EQ("subscribe", observer->deleteEntries_[0].value.ToString()); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -1768,9 +1634,6 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification017, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification018, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification018 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); @@ -1786,19 +1649,19 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification018, Tes entries.push_back(entry2); entries.push_back(entry3); - Status status = kvStorePtr->PutBatch(entries); + Status status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->Delete("Id4"); + status = kvStore->Delete("Id4"); EXPECT_EQ(Status::SUCCESS, status) << "KvStore Delete data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 0); EXPECT_EQ(static_cast(observer->deleteEntries_.size()), 0); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -1812,9 +1675,6 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification018, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification019, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification019 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); @@ -1830,13 +1690,13 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification019, Tes entries.push_back(entry2); entries.push_back(entry3); - Status status = kvStorePtr->PutBatch(entries); + Status status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->Delete("Id1"); + status = kvStore->Delete("Id1"); EXPECT_EQ(Status::SUCCESS, status) << "KvStore Delete data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); @@ -1844,13 +1704,13 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification019, Tes EXPECT_EQ("Id1", observer->deleteEntries_[0].key.ToString()); EXPECT_EQ("subscribe", observer->deleteEntries_[0].value.ToString()); - status = kvStorePtr->Delete("Id1"); + status = kvStore->Delete("Id1"); EXPECT_EQ(Status::SUCCESS, status) << "KvStore Delete data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); EXPECT_EQ(static_cast(observer->deleteEntries_.size()), 1); // not callback so not clear - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -1864,9 +1724,6 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification019, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification020, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification020 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); @@ -1886,14 +1743,14 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification020, Tes keys.push_back("Id1"); keys.push_back("Id2"); - Status status = kvStorePtr->PutBatch(entries); + Status status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->DeleteBatch(keys); + status = kvStore->DeleteBatch(keys); EXPECT_EQ(Status::SUCCESS, status) << "KvStore DeleteBatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); @@ -1903,7 +1760,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification020, Tes EXPECT_EQ("Id2", observer->deleteEntries_[1].key.ToString()); EXPECT_EQ("subscribe", observer->deleteEntries_[1].value.ToString()); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -1917,9 +1774,6 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification020, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification021, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification021 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); @@ -1939,20 +1793,20 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification021, Tes keys.push_back("Id4"); keys.push_back("Id5"); - Status status = kvStorePtr->PutBatch(entries); + Status status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->DeleteBatch(keys); + status = kvStore->DeleteBatch(keys); EXPECT_EQ(Status::SUCCESS, status) << "KvStore DeleteBatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 0); EXPECT_EQ(static_cast(observer->deleteEntries_.size()), 0); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -1967,9 +1821,6 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification021, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification022, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification022 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); @@ -1989,14 +1840,14 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification022, Tes keys.push_back("Id1"); keys.push_back("Id2"); - Status status = kvStorePtr->PutBatch(entries); + Status status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; - status = kvStorePtr->DeleteBatch(keys); + status = kvStore->DeleteBatch(keys); EXPECT_EQ(Status::SUCCESS, status) << "KvStore DeleteBatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); @@ -2006,13 +1857,13 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification022, Tes EXPECT_EQ("Id2", observer->deleteEntries_[1].key.ToString()); EXPECT_EQ("subscribe", observer->deleteEntries_[1].value.ToString()); - status = kvStorePtr->DeleteBatch(keys); + status = kvStore->DeleteBatch(keys); EXPECT_EQ(Status::SUCCESS, status) << "KvStore DeleteBatch data return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); EXPECT_EQ(static_cast(observer->deleteEntries_.size()), 2); // not callback so not clear - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -2026,14 +1877,11 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification022, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification023, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification023 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; Key key1 = "Id1"; @@ -2055,17 +1903,16 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification023, Tes keys.push_back("Id2"); keys.push_back("Id3"); - kvStorePtr->Clear(); - status = kvStorePtr->Put(key1, value1); // insert or update key-value + status = kvStore->Put(key1, value1); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; - status = kvStorePtr->PutBatch(entries); + status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; - status = kvStorePtr->Delete(key1); + status = kvStore->Delete(key1); EXPECT_EQ(Status::SUCCESS, status) << "KvStore delete data return wrong status"; - status = kvStorePtr->DeleteBatch(keys); + status = kvStore->DeleteBatch(keys); EXPECT_EQ(Status::SUCCESS, status) << "KvStore DeleteBatch data return wrong status"; usleep(USLEEP_TIME); - EXPECT_EQ(static_cast(observer->GetCallCount()), 5); + EXPECT_EQ(static_cast(observer->GetCallCount()), 4); // every callback will clear vector EXPECT_EQ(static_cast(observer->deleteEntries_.size()), 2); EXPECT_EQ("Id2", observer->deleteEntries_[0].key.ToString()); @@ -2075,7 +1922,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification023, Tes EXPECT_EQ(static_cast(observer->updateEntries_.size()), 0); EXPECT_EQ(static_cast(observer->insertEntries_.size()), 0); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -2089,14 +1936,11 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification023, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification024, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification024 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; Key key1 = "Id1"; @@ -2118,24 +1962,23 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification024, Tes keys.push_back("Id2"); keys.push_back("Id3"); - status = kvStorePtr->StartTransaction(); + status = kvStore->StartTransaction(); EXPECT_EQ(Status::SUCCESS, status) << "KvStore startTransaction return wrong status"; - kvStorePtr->Clear(); - status = kvStorePtr->Put(key1, value1); // insert or update key-value + status = kvStore->Put(key1, value1); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; - status = kvStorePtr->PutBatch(entries); + status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; - status = kvStorePtr->Delete(key1); + status = kvStore->Delete(key1); EXPECT_EQ(Status::SUCCESS, status) << "KvStore delete data return wrong status"; - status = kvStorePtr->DeleteBatch(keys); + status = kvStore->DeleteBatch(keys); EXPECT_EQ(Status::SUCCESS, status) << "KvStore DeleteBatch data return wrong status"; - status = kvStorePtr->Commit(); + status = kvStore->Commit(); EXPECT_EQ(Status::SUCCESS, status) << "KvStore Commit return wrong status"; usleep(USLEEP_TIME); EXPECT_EQ(static_cast(observer->GetCallCount()), 1); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } @@ -2149,14 +1992,11 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification024, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification025, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification025 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; Key key1 = "Id1"; @@ -2178,18 +2018,17 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification025, Tes keys.push_back("Id2"); keys.push_back("Id3"); - status = kvStorePtr->StartTransaction(); + status = kvStore->StartTransaction(); EXPECT_EQ(Status::SUCCESS, status) << "KvStore startTransaction return wrong status"; - kvStorePtr->Clear(); - status = kvStorePtr->Put(key1, value1); // insert or update key-value + status = kvStore->Put(key1, value1); // insert or update key-value EXPECT_EQ(Status::SUCCESS, status) << "KvStore put data return wrong status"; - status = kvStorePtr->PutBatch(entries); + status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; - status = kvStorePtr->Delete(key1); + status = kvStore->Delete(key1); EXPECT_EQ(Status::SUCCESS, status) << "KvStore delete data return wrong status"; - status = kvStorePtr->DeleteBatch(keys); + status = kvStore->DeleteBatch(keys); EXPECT_EQ(Status::SUCCESS, status) << "KvStore DeleteBatch data return wrong status"; - status = kvStorePtr->Rollback(); + status = kvStore->Rollback(); EXPECT_EQ(Status::SUCCESS, status) << "KvStore Commit return wrong status"; usleep(USLEEP_TIME); @@ -2198,7 +2037,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification025, Tes EXPECT_EQ(static_cast(observer->updateEntries_.size()), 0); EXPECT_EQ(static_cast(observer->deleteEntries_.size()), 0); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; observer = nullptr; } @@ -2213,15 +2052,11 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification025, Tes HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification026, TestSize.Level2) { ZLOGI("KvStoreDdmSubscribeKvStoreNotification026 begin."); - EXPECT_EQ(Status::SUCCESS, statusGetKvStore) << "statusGetKvStore return wrong status"; - EXPECT_NE(nullptr, kvStorePtr) << "kvStorePtr is nullptr"; - kvStorePtr->Clear(); - std::shared_ptr observer = std::make_shared(); observer->ResetToZero(); SubscribeType subscribeType = SubscribeType::SUBSCRIBE_TYPE_ALL; - Status status = kvStorePtr->SubscribeKvStore(subscribeType, observer); + Status status = kvStore->SubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "SubscribeKvStore return wrong status"; std::vector entries; @@ -2258,7 +2093,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification026, Tes entries.push_back(entry3); entries.push_back(entry4); - status = kvStorePtr->PutBatch(entries); + status = kvStore->PutBatch(entries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putbatch data return wrong status"; usleep(USLEEP_TIME); @@ -2281,7 +2116,7 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification026, Tes updateEntries.push_back(entry5); updateEntries.push_back(entry6); updateEntries.push_back(entry7); - status = kvStorePtr->PutBatch(updateEntries); + status = kvStore->PutBatch(updateEntries); EXPECT_EQ(Status::SUCCESS, status) << "KvStore putBatch update data return wrong status"; usleep(USLEEP_TIME); @@ -2292,53 +2127,13 @@ HWTEST_F(LocalSubscribeStoreTest, KvStoreDdmSubscribeKvStoreNotification026, Tes EXPECT_EQ("SingleKvStoreDdmPutBatch006_4", observer->updateEntries_[2].key.ToString()); EXPECT_EQ(false, observer->isClear_); - status = kvStorePtr->Delete("SingleKvStoreDdmPutBatch006_3"); + status = kvStore->Delete("SingleKvStoreDdmPutBatch006_3"); EXPECT_EQ(Status::SUCCESS, status) << "KvStore delete data return wrong status"; usleep(1000000); EXPECT_EQ(static_cast(observer->deleteEntries_.size()), 1); EXPECT_EQ("SingleKvStoreDdmPutBatch006_3", observer->deleteEntries_[0].key.ToString()); EXPECT_EQ(static_cast(observer->GetCallCount()), 3); - status = kvStorePtr->UnSubscribeKvStore(subscribeType, observer); + status = kvStore->UnSubscribeKvStore(subscribeType, observer); EXPECT_EQ(Status::SUCCESS, status) << "UnSubscribeKvStore return wrong status"; } - -/** -* @tc.name: ChangeNotificationMarshalling001 -* @tc.desc: Test changenotification marshalling and unmarshalling function -* @tc.type: FUNC -* @tc.require: AR000CIFGM -* @tc.author: liuyuhui -*/ -HWTEST_F(LocalSubscribeStoreTest, ChangeNotificationMarshalling001, TestSize.Level1) -{ - ZLOGI("ChangeNotificationMarshalling001 begin."); - Entry insert, update, del; - insert.key = "insert"; - update.key = "update"; - del.key = "delete"; - insert.value = "insert_value"; - update.value = "update_value"; - del.value = "delete_value"; - std::vector inserts, updates, deleteds; - inserts.push_back(insert); - updates.push_back(update); - deleteds.push_back(del); - - ChangeNotification changeIn(std::move(inserts), std::move(updates), std::move(deleteds), std::string(), false); - OHOS::Parcel parcel; - changeIn.Marshalling(parcel); - ChangeNotification *changeOut = ChangeNotification::Unmarshalling(parcel); - ASSERT_NE(changeOut, nullptr); - ASSERT_EQ(changeOut->GetInsertEntries().size(), 1UL); - EXPECT_EQ(changeOut->GetInsertEntries().front().key.ToString(), std::string("insert")); - EXPECT_EQ(changeOut->GetInsertEntries().front().value.ToString(), std::string("insert_value")); - ASSERT_EQ(changeOut->GetUpdateEntries().size(), 1UL); - EXPECT_EQ(changeOut->GetUpdateEntries().front().key.ToString(), std::string("update")); - EXPECT_EQ(changeOut->GetUpdateEntries().front().value.ToString(), std::string("update_value")); - ASSERT_EQ(changeOut->GetDeleteEntries().size(), 1UL); - EXPECT_EQ(changeOut->GetDeleteEntries().front().key.ToString(), std::string("delete")); - EXPECT_EQ(changeOut->GetDeleteEntries().front().value.ToString(), std::string("delete_value")); - EXPECT_EQ(changeOut->IsClear(), false); - delete changeOut; -} diff --git a/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/types_util_test.cpp b/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/types_util_test.cpp index 5fbf59d3074cd0bbf5d16a653158a5c043762b82..33269c4c91f6fac4d2e77af9bf73eba623fa9494 100644 --- a/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/types_util_test.cpp +++ b/frameworks/innerkitsimpl/distributeddatafwk/test/unittest/types_util_test.cpp @@ -43,3 +43,47 @@ HWTEST_F(TypesUtilTest, DeviceInfo, TestSize.Level0) ASSERT_EQ(clientDev.deviceName, serverDev.deviceName); ASSERT_EQ(clientDev.deviceType, serverDev.deviceType); } + +HWTEST_F(TypesUtilTest, Entry, TestSize.Level0) +{ + MessageParcel parcel; + Entry entryIn; + entryIn.key = "student_name_mali"; + entryIn.value = "age:20"; + ASSERT_TRUE(ITypesUtil::Marshalling(entryIn, parcel)); + Entry entryOut; + ASSERT_TRUE(ITypesUtil::Unmarshalling(parcel, entryOut)); + EXPECT_EQ(entryOut.key.ToString(), std::string("student_name_mali")); + EXPECT_EQ(entryOut.value.ToString(), std::string("age:20")); +} + +HWTEST_F(TypesUtilTest, ChangeNotification, TestSize.Level1) +{ + Entry insert, update, del; + insert.key = "insert"; + update.key = "update"; + del.key = "delete"; + insert.value = "insert_value"; + update.value = "update_value"; + del.value = "delete_value"; + std::vector inserts, updates, deleteds; + inserts.push_back(insert); + updates.push_back(update); + deleteds.push_back(del); + + ChangeNotification changeIn(std::move(inserts), std::move(updates), std::move(deleteds), std::string(), false); + MessageParcel parcel; + ASSERT_TRUE(ITypesUtil::Marshalling(changeIn, parcel)); + ChangeNotification changeOut({}, {}, {}, "", false); + ASSERT_TRUE(ITypesUtil::Unmarshalling(parcel, changeOut)); + ASSERT_EQ(changeOut.GetInsertEntries().size(), 1UL); + EXPECT_EQ(changeOut.GetInsertEntries().front().key.ToString(), std::string("insert")); + EXPECT_EQ(changeOut.GetInsertEntries().front().value.ToString(), std::string("insert_value")); + ASSERT_EQ(changeOut.GetUpdateEntries().size(), 1UL); + EXPECT_EQ(changeOut.GetUpdateEntries().front().key.ToString(), std::string("update")); + EXPECT_EQ(changeOut.GetUpdateEntries().front().value.ToString(), std::string("update_value")); + ASSERT_EQ(changeOut.GetDeleteEntries().size(), 1UL); + EXPECT_EQ(changeOut.GetDeleteEntries().front().key.ToString(), std::string("delete")); + EXPECT_EQ(changeOut.GetDeleteEntries().front().value.ToString(), std::string("delete_value")); + EXPECT_EQ(changeOut.IsClear(), false); +} \ No newline at end of file diff --git a/frameworks/jskitsimpl/distributeddata/include/js_field_node.h b/frameworks/jskitsimpl/distributeddata/include/js_field_node.h index dc016569c6913c77555715e2b94491d68065626f..26c752583c6dd9f9aa7e99c6f1ab840dd7a0f3f4 100644 --- a/frameworks/jskitsimpl/distributeddata/include/js_field_node.h +++ b/frameworks/jskitsimpl/distributeddata/include/js_field_node.h @@ -14,8 +14,8 @@ */ #ifndef OHOS_FIELD_NODE_H #define OHOS_FIELD_NODE_H +#include #include -#include "nlohmann/json.hpp" #include "js_util.h" #include "napi_queue.h" diff --git a/services/distributeddataservice/adapter/permission/src/permission_validator.cpp b/services/distributeddataservice/adapter/permission/src/permission_validator.cpp index f96bd9b3b266bd2525178e8057d11a60dae78df0..9792682d2216b0ac67b7dac2a6b62569ad790b29 100644 --- a/services/distributeddataservice/adapter/permission/src/permission_validator.cpp +++ b/services/distributeddataservice/adapter/permission/src/permission_validator.cpp @@ -60,7 +60,6 @@ void PermissionValidator::UpdateKvStoreTupleMap(const KvStoreTuple &srcKvStoreTu return ClientPermissionValidator::GetInstance().UpdateKvStoreTupleMap(srcKvStoreTuple, dstKvStoreTuple); } - // Check whether the bundle name is in the system service list. bool PermissionValidator::IsSystemService(const std::string &bundleName) { diff --git a/services/distributeddataservice/app/src/kvstore_app_manager.cpp b/services/distributeddataservice/app/src/kvstore_app_manager.cpp index 35ae7d0006e9db829ffd25b64767631512c280e9..7537cda5d15179648342df218b1447afc6dd9419 100644 --- a/services/distributeddataservice/app/src/kvstore_app_manager.cpp +++ b/services/distributeddataservice/app/src/kvstore_app_manager.cpp @@ -436,8 +436,7 @@ KvStoreAppManager::PathType KvStoreAppManager::ConvertPathType(int32_t uid, cons default: break; } - auto *checker = CheckerManager::GetInstance().GetChecker("SystemChecker"); - if (checker == nullptr || !checker->IsValid(uid, bundleName)) { + if (CheckerManager::GetInstance().GetAppId(bundleName, uid) != bundleName) { return PATH_CE; } return PATH_DE; diff --git a/services/distributeddataservice/app/src/single_kvstore_impl.cpp b/services/distributeddataservice/app/src/single_kvstore_impl.cpp index 3a8caf612a1c79d12f8c250204a702924c696b6c..ddd67136104b037f3a9e5958d3fc556be137a797 100644 --- a/services/distributeddataservice/app/src/single_kvstore_impl.cpp +++ b/services/distributeddataservice/app/src/single_kvstore_impl.cpp @@ -499,7 +499,7 @@ void SingleKvStoreImpl::GetResultSet(const Key &prefixKey, std::lock_guard lg(storeResultSetMutex_); sptr storeResultSet = CreateResultSet(dbResultSet, tmpKeyPrefix); callback(Status::SUCCESS, storeResultSet); - storeResultSetMap_.emplace(storeResultSet.GetRefPtr(), storeResultSet); + storeResultSetMap_.emplace(storeResultSet->AsObject().GetRefPtr(), storeResultSet); return; } if (status == DistributedDB::DBStatus::INVALID_PASSWD_OR_CORRUPTED_DB) { @@ -544,7 +544,7 @@ void SingleKvStoreImpl::GetResultSetWithQuery(const std::string &query, std::lock_guard lg(storeResultSetMutex_); sptr storeResultSet = CreateResultSet(dbResultSet, {}); callback(Status::SUCCESS, storeResultSet); - storeResultSetMap_.emplace(storeResultSet.GetRefPtr(), storeResultSet); + storeResultSetMap_.emplace(storeResultSet->AsObject().GetRefPtr(), storeResultSet); return; } switch (status) { @@ -660,7 +660,7 @@ Status SingleKvStoreImpl::CloseResultSet(sptr resultSet) std::shared_lock lock(storeNbDelegateMutex_); std::lock_guard lg(storeResultSetMutex_); Status status; - auto it = storeResultSetMap_.find(resultSet.GetRefPtr()); + auto it = storeResultSetMap_.find(resultSet->AsObject().GetRefPtr()); if (it == storeResultSetMap_.end()) { ZLOGE("ResultSet not found in this store."); return Status::INVALID_ARGUMENT; diff --git a/services/distributeddataservice/app/src/single_kvstore_impl.h b/services/distributeddataservice/app/src/single_kvstore_impl.h index 0c9fbe2bb6614538f51fa9cc680e5258e7b7429e..2320fdbe7227af9f2b2bcf23521e47ef35801202 100644 --- a/services/distributeddataservice/app/src/single_kvstore_impl.h +++ b/services/distributeddataservice/app/src/single_kvstore_impl.h @@ -149,7 +149,7 @@ private: std::mutex observerMapMutex_; std::map observerMap_; std::mutex storeResultSetMutex_; - std::map> storeResultSetMap_; + std::map> storeResultSetMap_; sptr syncCallback_; int openCount_; diff --git a/services/distributeddataservice/app/test/moduletest/distributeddata_account_event_test.cpp b/services/distributeddataservice/app/test/moduletest/distributeddata_account_event_test.cpp index 2009d3cd4d5e2e71a5b482e6bf633ee2ae75493e..ce442c69bc8893a35c2953860071ef422533f56b 100644 --- a/services/distributeddataservice/app/test/moduletest/distributeddata_account_event_test.cpp +++ b/services/distributeddataservice/app/test/moduletest/distributeddata_account_event_test.cpp @@ -14,29 +14,19 @@ */ #include -#include #include -#include #include "kvstore_account_observer.h" -#include "kvstore_observer_client.h" #include "kvstore_data_service.h" -#include "kvstore_impl.h" #include "refbase.h" #include "types.h" -#include -#include -#include -#include -#include "directory_ex.h" -#include "constant.h" +#include "bootstrap.h" #include "common_event_subscriber.h" #include "common_event_support.h" #include "common_event_manager.h" -#include "ohos/aafwk/content/want.h" -#include "ohos_account_kits.h" #include "gtest/gtest.h" using namespace testing::ext; using namespace OHOS::DistributedKv; +using namespace OHOS::DistributedData; using namespace OHOS; using namespace OHOS::EventFwk; @@ -111,348 +101,6 @@ void DistributedDataAccountEventTest::ChangeUser(int uid) } } -/** - * @tc.name: KvStore data storage path verify when get KvStore with default device account and harmony account logout. - * @tc.desc: Verify that the KvStore data storage path is consistent with the path spliced by distributedDB interface. - * with default device account and harmony account logout. - * @tc.type: FUNC - * @tc.require: SR000DOH0F AR000DPSE5 - * @tc.author: FengLin - */ -HWTEST_F(DistributedDataAccountEventTest, GetKvStore_DefaultDeviceAccount_001, TestSize.Level3) -{ - Options options; - options.createIfMissing = true; - options.encrypt = false; - options.autoSync = true; - options.kvStoreType = KvStoreType::MULTI_VERSION; - - AppId appId; - appId.appId = "com.ohos.distributeddata.accountmsttest"; - StoreId storeId; - storeId.storeId = "AccountEventStore001"; - std::string hashedStoreId; - - // Step1. Splice kvStore data storage expected path by distributedDB hash interface and clear directory. - DistributedDB::DBStatus dbStatus = - DistributedDB::KvStoreDelegateManager::GetDatabaseDir(storeId.storeId, hashedStoreId); - EXPECT_EQ(dbStatus, DistributedDB::OK) << "Get data directory name from DB failed."; - std::string appDataStoragePath; - appDataStoragePath = KvStoreAppManager::GetDataStoragePath("0", appId.appId, KvStoreAppManager::PATH_CE); - const std::string kvStoreDataStorageExpectPath = Constant::Concatenate( - { appDataStoragePath, "/", appId.appId, "/", hashedStoreId }); - DIR *dir = opendir(kvStoreDataStorageExpectPath.c_str()); - if (dir != nullptr) { - ForceRemoveDirectory(kvStoreDataStorageExpectPath); - closedir(dir); - } - dir = opendir(kvStoreDataStorageExpectPath.c_str()); - EXPECT_EQ(dir, nullptr) << "KvStore data storage directory was not cleared successfully."; - - // Step2. Get KvStore and check the created data storage path is consistent with the expected directory. - KvStoreDataService kvStoreDataService; - sptr iKvStoreImplPtr; - Status status = kvStoreDataService.GetKvStore(options, appId, storeId, - [&](sptr kvStore) { iKvStoreImplPtr = std::move(kvStore); }); - EXPECT_EQ(status, Status::SUCCESS) << "GetKvStore return wrong status"; - EXPECT_NE(iKvStoreImplPtr, nullptr) << "GetKvStore executed failed"; - dir = opendir(kvStoreDataStorageExpectPath.c_str()); - status = kvStoreDataService.CloseKvStore(appId, storeId); - EXPECT_NE(dir, nullptr) << "KvStore data storage directory created is not consistent with the expected."; - closedir(dir); -} - -/** - * @tc.name: Re-operate exist KvStore successfully verify when harmony account login/logout. - * @tc.desc: Verify that after harmony account login/logout, re-operate exist KvStore successfully. - * @tc.type: FUNC - * @tc.require: SR000DOH0F AR000DPSE7 - * @tc.author: FengLin - */ -HWTEST_F(DistributedDataAccountEventTest, GetKvStore_DefaultDeviceAccount_002, TestSize.Level3) -{ - Options options; - options.createIfMissing = true; - options.encrypt = false; - options.autoSync = true; - options.kvStoreType = KvStoreType::MULTI_VERSION; - - AppId appId; - appId.appId = "com.ohos.distributeddata.accountmsttest"; - StoreId storeId; - storeId.storeId = "AccountEventStore002"; - std::string hashedStoreId; - - // Step1. Get KvStore with specified appId and storeId when harmony account logout. - KvStoreDataService kvStoreDataService; - sptr iKvStoreImplPtr; - Status status = kvStoreDataService.GetKvStore(options, appId, storeId, - [&](sptr kvStore) { iKvStoreImplPtr = std::move(kvStore); }); - EXPECT_EQ(status, Status::SUCCESS) << "GetKvStore return wrong status"; - EXPECT_NE(iKvStoreImplPtr, nullptr) << "GetKvStore executed failed"; - - Key key = "Von"; - Value value = "Leon"; - status = iKvStoreImplPtr->Put(key, value); - EXPECT_EQ(status, Status::SUCCESS) << "PUT string to KvStore return wrong status"; - - // Step2. Get KvStoreSnapshot and verify get value from KvStore correctly. - sptr kvStoreObserverClient = - new KvStoreObserverClient(storeId, SubscribeType::SUBSCRIBE_TYPE_ALL, nullptr, KvStoreType::MULTI_VERSION); - sptr snapshotProxyTmp; - auto snapshotCallbackFunction = [&](Status statusTmp, sptr snapshotProxy) { - status = statusTmp; - snapshotProxyTmp = snapshotProxy; - }; - iKvStoreImplPtr->GetKvStoreSnapshot(kvStoreObserverClient, snapshotCallbackFunction); - Value getValue = ""; - snapshotProxyTmp->Get(key, getValue); - EXPECT_EQ(getValue, value) << "Get string from KvStore not equal to PUT"; - - sleep(WAIT_TIME_FOR_ACCOUNT_OPERATION); - // Step3. Harmony account login - DistributedDataAccountEventTest::HarmonyAccountLogin(); - - // Step4. Verify get value from KvStore and put string to KvStore with last KvStoreSnapShot correctly after LOGIN. - getValue.Clear(); - snapshotProxyTmp->Get(key, getValue); - EXPECT_EQ(getValue, value) << "Get string from KvStore not equal to PUT after LOGIN"; - - Key key2 = "Von2"; - Value value2 = "Leon2"; - status = iKvStoreImplPtr->Put(key2, value2); - EXPECT_EQ(status, Status::SUCCESS) << "PUT string to KvStore return wrong status"; - - sptr kvStoreObserverClient1 = - new KvStoreObserverClient(storeId, SubscribeType::SUBSCRIBE_TYPE_ALL, nullptr, KvStoreType::MULTI_VERSION); - sptr snapshotProxyTmp1; - auto snapshotCallbackFunction1 = [&](Status statusTmp, sptr snapshotProxy) { - status = statusTmp; - snapshotProxyTmp1 = snapshotProxy; - }; - iKvStoreImplPtr->GetKvStoreSnapshot(kvStoreObserverClient1, snapshotCallbackFunction1); - - getValue.Clear(); - snapshotProxyTmp1->Get(key2, getValue); - EXPECT_EQ(getValue, value2) << "Get string from KvStore not equal to PUT after LOGIN"; - - // Step6. Harmony account logout - DistributedDataAccountEventTest::HarmonyAccountLogout(); - - // Step7. Verify get value from KvStore and put string to KvStore with last KvStoreSnapShot correctly after LOGOUT. - getValue.Clear(); - snapshotProxyTmp->Get(key, getValue); - EXPECT_EQ(getValue, value) << ", Get string from KvStore not equal to PUT after LOGOUT"; - - Key key3 = "Von3"; - Value value3 = "Leon3"; - status = iKvStoreImplPtr->Put(key3, value3); - EXPECT_EQ(status, Status::SUCCESS) << "PUT string to KvStore return wrong status"; - - sptr kvStoreObserverClient2 = - new KvStoreObserverClient(storeId, SubscribeType::SUBSCRIBE_TYPE_ALL, nullptr, KvStoreType::MULTI_VERSION); - sptr snapshotProxyTmp2; - auto snapshotCallbackFunction2 = [&](Status statusTmp, sptr snapshotProxy) { - status = statusTmp; - snapshotProxyTmp2 = snapshotProxy; - }; - iKvStoreImplPtr->GetKvStoreSnapshot(kvStoreObserverClient2, snapshotCallbackFunction2); - getValue.Clear(); - snapshotProxyTmp2->Get(key3, getValue); - EXPECT_EQ(getValue, value3) << "Get string from KvStore not equal to PUT after LOGOUT"; - - iKvStoreImplPtr->ReleaseKvStoreSnapshot(snapshotProxyTmp); - iKvStoreImplPtr->ReleaseKvStoreSnapshot(snapshotProxyTmp1); - iKvStoreImplPtr->ReleaseKvStoreSnapshot(snapshotProxyTmp2); - status = kvStoreDataService.CloseKvStore(appId, storeId); - EXPECT_EQ(status, Status::SUCCESS) << "CloseKvStore return wrong status after harmony account logout"; - - // Step7. Verify that when harmony account logout and in the situation that the exist KvStore has been closed, - // re-get exist KvStore successfully and the KvStoreImplPtr not equal with the one before harmony account logout. - sptr iKvStoreImplLogoutPtr; - status = kvStoreDataService.GetKvStore(options, appId, storeId, - [&](sptr kvStore) { iKvStoreImplLogoutPtr = std::move(kvStore); }); - EXPECT_EQ(status, Status::SUCCESS) << "GetKvStore return wrong status after harmony account logout"; - EXPECT_NE(iKvStoreImplLogoutPtr, nullptr) << "GetKvStore executed failed after harmony account logout"; - EXPECT_NE(iKvStoreImplPtr, iKvStoreImplLogoutPtr) << "kvStoreImpl NE fail after harmony account logout"; - status = kvStoreDataService.CloseKvStore(appId, storeId); - EXPECT_EQ(status, Status::SUCCESS) << "CloseKvStore return wrong status after harmony account logout"; -} - -/** - * @tc.name: KvStore data storage path verify when the ownership of distributed data set to ACCOUNT. - * @tc.desc: Verify that in the situation that distributed data ownership set to ACCOUNT, get KvStore successfully - * and verify that the KvStore data storage path is consistent with the path spliced by distributedDB interface. - * @tc.type: FUNC - * @tc.require: SR000DOH0F AR000DPTQ8 - * @tc.author: FengLin - */ -HWTEST_F(DistributedDataAccountEventTest, GetKvStore_DefaultDeviceAccount_003, TestSize.Level3) -{ - Options options; - options.createIfMissing = true; - options.encrypt = false; - options.autoSync = true; - options.kvStoreType = KvStoreType::MULTI_VERSION; - - AppId appId; - appId.appId = "com.ohos.distributeddata.accountmsttest"; - StoreId storeId; - storeId.storeId = "AccountEventStore003"; - std::string hashedStoreId; - KvStoreDataService kvStoreDataService; - - // Step1. Set distributed data ownership to ACCOUNT. - options.dataOwnership = false; - - // Step2. Splice kvStore data storage expected path by distributedDB hash interface and clear directory. - DistributedDB::DBStatus dbStatus = DistributedDB::KvStoreDelegateManager::GetDatabaseDir( - storeId.storeId, appId.appId, AccountDelegate::GetInstance()->GetCurrentAccountId(), hashedStoreId); - EXPECT_EQ(dbStatus, DistributedDB::OK) << "Get data directory name from DB failed."; - - std::string appDataStoragePath; - appDataStoragePath = KvStoreAppManager::GetDataStoragePath("0", appId.appId, KvStoreAppManager::PATH_CE); - const std::string kvStoreDataStorageExpectPath = Constant::Concatenate( - { appDataStoragePath, "/", appId.appId, "/", hashedStoreId }); - DIR *dir = opendir(kvStoreDataStorageExpectPath.c_str()); - if (dir != nullptr) { - ForceRemoveDirectory(kvStoreDataStorageExpectPath); - closedir(dir); - } - dir = opendir(kvStoreDataStorageExpectPath.c_str()); - EXPECT_EQ(dir, nullptr) << "KvStore data storage directory was not cleared successfully."; - - // Step2. Get KvStore and check the created data storage path is consistent with the expected directory. - sptr iKvStoreImplPtr; - Status status = kvStoreDataService.GetKvStore(options, appId, storeId, - [&](sptr kvStore) { iKvStoreImplPtr = std::move(kvStore); }); - EXPECT_EQ(status, Status::SUCCESS) << "GetKvStore return wrong status"; - EXPECT_NE(iKvStoreImplPtr, nullptr) << "GetKvStore executed failed"; - dir = opendir(kvStoreDataStorageExpectPath.c_str()); - status = kvStoreDataService.CloseKvStore(appId, storeId); - EXPECT_NE(dir, nullptr) << "KvStore data storage directory created is not consistent with the expected."; - closedir(dir); -} - -/** - * @tc.name: System upgrade kvStore data migration verify when the data ownership changed from ACCUNT to DEVICE. - * @tc.desc: Verify that in the situation that distributed data ownership set to ACCOUNT, get KvStore successfully - * then set data ownership set to DEVICE, harmony account login, re-get kvStore successfully and verify that the - * KvStore data storage path changed to the path spliced by distributedDB interface. - * @tc.type: FUNC - * @tc.require: SR000DOH0F AR000DPSDH - * @tc.author: FengLin - */ -HWTEST_F(DistributedDataAccountEventTest, GetKvStore_DefaultDeviceAccount_004, TestSize.Level3) -{ - Options options; - options.createIfMissing = true; - options.encrypt = false; - options.autoSync = true; - options.kvStoreType = KvStoreType::MULTI_VERSION; - - AppId appId; - appId.appId = "com.ohos.distributeddata.accountmsttest"; - StoreId storeId; - storeId.storeId = "AccountEventStore004"; - std::string hashedStoreId; - KvStoreDataService kvStoreDataService; - - // Step1. Set distributed data ownership to ACCOUNT. - options.dataOwnership = false; - - // Step2. Splice kvStore data storage expected path by distributedDB hash interface and clear directory. - DistributedDB::DBStatus dbStatus = DistributedDB::KvStoreDelegateManager::GetDatabaseDir( - storeId.storeId, appId.appId, AccountDelegate::GetInstance()->GetCurrentAccountId(), hashedStoreId); - EXPECT_EQ(dbStatus, DistributedDB::OK) << "Get data directory name from DB failed."; - - std::string appDataStoragePath; - appDataStoragePath = KvStoreAppManager::GetDataStoragePath("0", appId.appId, KvStoreAppManager::PATH_CE); - std::string kvStoreDataStorageExpectPath = Constant::Concatenate( - { appDataStoragePath, "/", appId.appId, "/", hashedStoreId }); - DIR *dir = opendir(kvStoreDataStorageExpectPath.c_str()); - if (dir != nullptr) { - ForceRemoveDirectory(kvStoreDataStorageExpectPath); - closedir(dir); - } - dir = opendir(kvStoreDataStorageExpectPath.c_str()); - EXPECT_EQ(dir, nullptr) << "KvStore data storage directory was not cleared successfully."; - - // Step2. Get KvStore. - sptr iKvStoreImplPtr; - Status status = kvStoreDataService.GetKvStore(options, appId, storeId, - [&](sptr kvStore) { iKvStoreImplPtr = std::move(kvStore); }); - EXPECT_EQ(status, Status::SUCCESS) << "GetKvStore return wrong status"; - EXPECT_NE(iKvStoreImplPtr, nullptr) << "GetKvStore executed failed"; - status = kvStoreDataService.CloseKvStore(appId, storeId); - EXPECT_EQ(status, Status::SUCCESS) << "CloseKvStore return wrong status"; - - // Step3. Set distributed data ownership to DEVICE. - options.dataOwnership = true; - - // Step4. Harmony account login - DistributedDataAccountEventTest::HarmonyAccountLogin(); - - // Step5. Re-Get KvStore and verify the data storage path has been changed to only store id hashed path. - sptr iKvStoreImplRePtr; - status = kvStoreDataService.GetKvStore(options, appId, storeId, - [&](sptr kvStore) { iKvStoreImplRePtr = std::move(kvStore); }); - EXPECT_EQ(status, Status::SUCCESS) << "GetKvStore return wrong status when harmony account login"; - EXPECT_NE(iKvStoreImplRePtr, nullptr) << "GetKvStore executed failed when harmony account login"; - status = kvStoreDataService.CloseKvStore(appId, storeId); - EXPECT_EQ(status, Status::SUCCESS) << "CloseKvStore return wrong status when harmony account login"; - - hashedStoreId.clear(); - dbStatus = DistributedDB::KvStoreDelegateManager::GetDatabaseDir(storeId.storeId, hashedStoreId); - EXPECT_EQ(dbStatus, DistributedDB::OK) << "Get data directory name from DB failed."; - kvStoreDataStorageExpectPath.clear(); - kvStoreDataStorageExpectPath = Constant::Concatenate({ appDataStoragePath, "/", appId.appId, "/", hashedStoreId }); - dir = opendir(kvStoreDataStorageExpectPath.c_str()); - EXPECT_NE(dir, nullptr) << "KvStore data storage directory was not changed correctly."; - closedir(dir); -} - -/** - * @tc.name: APP get KvStore failed verify when DDS is processing harmony account login event. - * @tc.desc: Verify that in the situation that DDS is processing harmony account login event, - * APP will get KvStore failed. - * @tc.type: FUNC - * @tc.require: SR000DOH0F AR000DPSE6 - * @tc.author: FengLin - */ -HWTEST_F(DistributedDataAccountEventTest, GetKvStore_DefaultDeviceAccount_005, TestSize.Level3) -{ - Options options; - options.createIfMissing = true; - options.encrypt = false; - options.autoSync = true; - options.kvStoreType = KvStoreType::MULTI_VERSION; - - AppId appId; - appId.appId = "com.ohos.distributeddata.accountmsttest"; - StoreId storeId; - storeId.storeId = "AccountEventStore005"; - std::string hashedStoreId; - KvStoreDataService kvStoreDataService; - - // Step1. Harmony account login. - DistributedDataAccountEventTest::HarmonyAccountLogin(); - - // Step2. Set DDS status to processing harmony account login event. - g_kvStoreAccountEventStatus = 1; - - // Step3. Get KvStore. - sptr iKvStoreImplPtr; - Status status = kvStoreDataService.GetKvStore(options, appId, storeId, - [&](sptr kvStore) { iKvStoreImplPtr = std::move(kvStore); }); - // Caution: When the function opened, this verify should be EQ - EXPECT_NE(status, Status::SYSTEM_ACCOUNT_EVENT_PROCESSING) << "GetKvStore return unexpectedstatus"; - EXPECT_NE(iKvStoreImplPtr, nullptr) << "GetKvStore executed with unexpectedresult"; - - // Step4. Restore DDS status to finish harmony account login event process. - g_kvStoreAccountEventStatus = 0; -} - /** * @tc.name: Re-get exist SingleKvStore successfully verify when harmony account login/logout. * @tc.desc: Verify that after harmony account login/logout, re-operate exist SingleKvStore successfully. @@ -476,6 +124,11 @@ HWTEST_F(DistributedDataAccountEventTest, GetKvStore_DefaultDeviceAccount_006, T // Step1. Get KvStore with specified appId and storeId when harmony account logout. KvStoreDataService kvStoreDataService; + KvStoreMetaManager::GetInstance().InitMetaParameter(); + Bootstrap::GetInstance().LoadComponents(); + Bootstrap::GetInstance().LoadDirectory(); + Bootstrap::GetInstance().LoadCheckers(); + Bootstrap::GetInstance().LoadNetworks(); sptr iSingleKvStorePtr; Status status = kvStoreDataService.GetSingleKvStore(options, appId, storeId, [&](sptr singleKvStore) { iSingleKvStorePtr = std::move(singleKvStore); }); diff --git a/services/distributeddataservice/app/test/unittest/kvstore_sync_manager_test.cpp b/services/distributeddataservice/app/test/unittest/kvstore_sync_manager_test.cpp index 8540bb88238b0b40dd3ef54501d9bdb61324855e..22fa1154e9ae341bd55af0d305c816a0af5a5ac4 100644 --- a/services/distributeddataservice/app/test/unittest/kvstore_sync_manager_test.cpp +++ b/services/distributeddataservice/app/test/unittest/kvstore_sync_manager_test.cpp @@ -30,12 +30,21 @@ using DistributedDB::UtKvStoreNbDelegateImpl; class KvStoreSyncManagerTest : public testing::Test { public: + class Waiter { + public: + bool GetValue(uint32_t interval = CHECK_WAITING_TIME); + bool SetValue(bool value); + private: + std::mutex mutex_; + std::condition_variable cv_; + bool isFinished = false; + }; static void SetUpTestCase(void); static void TearDownTestCase(void); void SetUp(); void TearDown(); - static const uint32_t CHECK_WAITING_TIME = 50000; // 50ms + static const uint32_t CHECK_WAITING_TIME = 250; // 250ms void CreateKvStorePair(bool isAutoSync, const std::string &storeId, std::shared_ptr &kvStore, std::shared_ptr &kvNb, @@ -44,6 +53,29 @@ protected: uint64_t seqId_ = 0; }; +bool KvStoreSyncManagerTest::Waiter::GetValue(uint32_t interval) +{ + std::unique_lock lg(mutex_); + if (isFinished) { + return isFinished; + } + KvStoreSyncManager::GetInstance()->AddSyncOperation(uintptr_t(this), interval, + [this](const auto &end)->Status { + SetValue(true); + return SUCCESS; + }, nullptr); + cv_.wait(lg, [this] { return isFinished; }); + return isFinished; +} + +bool KvStoreSyncManagerTest::Waiter::SetValue(bool value) +{ + std::unique_lock lg(mutex_); + isFinished = value; + cv_.notify_one(); + return isFinished; +} + void KvStoreSyncManagerTest::SetUpTestCase(void) {} @@ -66,6 +98,8 @@ void KvStoreSyncManagerTest::CreateKvStorePair(bool isAutoSync, const std::strin kvNb2 = std::make_unique(storeId, "DevB"); kvNb->SetNeighbor(kvNb2); kvNb2->SetNeighbor(kvNb); + kvNb->SetAutoSync(isAutoSync); + kvNb2->SetAutoSync(isAutoSync); Options options = { .autoSync = isAutoSync }; std::string userId = "syncManagerTest"; @@ -94,13 +128,14 @@ HWTEST_F(KvStoreSyncManagerTest, KvStoreSyncManagerTest001, TestSize.Level1) std::vector syncDevices; syncDevices.push_back("devB"); uint32_t syncDelayMs = 0; // ms - + Waiter waiter; Key key1("key1"); Value value1("value1"); Value value1Tmp; kvStore->Put(key1, value1); + waiter.SetValue(false); kvStore->Sync(syncDevices, SyncMode::PUSH, syncDelayMs, ++seqId_); - usleep(CHECK_WAITING_TIME); + waiter.GetValue(); kvStore2->Get(key1, value1Tmp); EXPECT_EQ(value1.ToString(), value1Tmp.ToString()); @@ -108,14 +143,16 @@ HWTEST_F(KvStoreSyncManagerTest, KvStoreSyncManagerTest001, TestSize.Level1) Value value2("value2"); Value value2Tmp; kvStore->Put(key2, value2); + waiter.SetValue(false); kvStore->Sync(syncDevices, SyncMode::PUSH, syncDelayMs, ++seqId_); - usleep(CHECK_WAITING_TIME); + waiter.GetValue(); kvStore2->Get(key2, value2Tmp); EXPECT_EQ(value2.ToString(), value2Tmp.ToString()); kvStore->Delete(key2); + waiter.SetValue(false); kvStore->Sync(syncDevices, SyncMode::PUSH, syncDelayMs, ++seqId_); - usleep(CHECK_WAITING_TIME); + waiter.GetValue(); Status ret = kvStore2->Get(key2, value2Tmp); EXPECT_EQ(ret, Status::KEY_NOT_FOUND); @@ -143,31 +180,34 @@ HWTEST_F(KvStoreSyncManagerTest, KvStoreSyncManagerTest002, TestSize.Level1) syncDevices.push_back("devB"); uint32_t syncDelayMs = 200; // ms + Waiter waiter; Key key1("key1"); Value value1("value1"); Value value1Tmp; kvStore->Put(key1, value1); + waiter.SetValue(false); kvStore->Sync(syncDevices, SyncMode::PUSH, syncDelayMs, ++seqId_); - usleep(CHECK_WAITING_TIME); + waiter.GetValue(); Status ret = kvStore2->Get(key1, value1Tmp); - EXPECT_EQ(ret, Status::KEY_NOT_FOUND); + EXPECT_EQ(ret, Status::SUCCESS); Key key2("key2"); Value value2("value2"); Value value2Tmp; kvStore->Put(key2, value2); + waiter.SetValue(false); kvStore->Sync(syncDevices, SyncMode::PUSH, syncDelayMs, ++seqId_); - usleep(CHECK_WAITING_TIME); + waiter.GetValue(); ret = kvStore2->Get(key2, value2Tmp); - EXPECT_EQ(ret, Status::KEY_NOT_FOUND); + EXPECT_EQ(ret, Status::SUCCESS); kvStore->Delete(key2); + waiter.SetValue(false); kvStore->Sync(syncDevices, SyncMode::PUSH, syncDelayMs, ++seqId_); - usleep(CHECK_WAITING_TIME); ret = kvStore2->Get(key2, value2Tmp); - EXPECT_EQ(ret, Status::KEY_NOT_FOUND); + EXPECT_EQ(ret, Status::SUCCESS); - usleep(syncDelayMs * 1000); + waiter.GetValue(); ret = kvStore2->Get("key1", value1Tmp); EXPECT_EQ(ret, Status::SUCCESS); EXPECT_EQ(value1.ToString(), value1Tmp.ToString()); @@ -197,7 +237,6 @@ HWTEST_F(KvStoreSyncManagerTest, KvStoreSyncManagerTest003, TestSize.Level1) Value value1("value1"); Value value1Tmp; kvStore->Put(key1, value1); - usleep(CHECK_WAITING_TIME); kvStore2->Get(key1, value1Tmp); EXPECT_EQ(value1.ToString(), value1Tmp.ToString()); @@ -205,12 +244,10 @@ HWTEST_F(KvStoreSyncManagerTest, KvStoreSyncManagerTest003, TestSize.Level1) Value value2("value2"); Value value2Tmp; kvStore->Put(key2, value2); - usleep(CHECK_WAITING_TIME); kvStore2->Get(key2, value2Tmp); EXPECT_EQ(value2.ToString(), value2Tmp.ToString()); kvStore->Delete(key2); - usleep(CHECK_WAITING_TIME); Status ret = kvStore2->Get(key2, value2Tmp); EXPECT_EQ(ret, Status::KEY_NOT_FOUND); @@ -241,24 +278,19 @@ HWTEST_F(KvStoreSyncManagerTest, KvStoreSyncManagerTest004, TestSize.Level1) Value value1("value1"); Value value1Tmp; kvStore->Put(key1, value1); - usleep(CHECK_WAITING_TIME); Status ret = kvStore2->Get(key1, value1Tmp); - EXPECT_EQ(ret, Status::KEY_NOT_FOUND); + EXPECT_EQ(ret, Status::SUCCESS); Key key2("key2"); Value value2("value2"); Value value2Tmp; kvStore->Put(key2, value2); - usleep(CHECK_WAITING_TIME); ret = kvStore2->Get(key2, value2Tmp); - EXPECT_EQ(ret, Status::KEY_NOT_FOUND); + EXPECT_EQ(ret, Status::SUCCESS); kvStore->Delete(key2); - usleep(CHECK_WAITING_TIME); ret = kvStore2->Get(key2, value2Tmp); EXPECT_EQ(ret, Status::KEY_NOT_FOUND); - - usleep(syncDelay.allowedDelayMs * 1000); ret = kvStore2->Get(key1, value1Tmp); EXPECT_EQ(ret, Status::SUCCESS); EXPECT_EQ(value1.ToString(), value1Tmp.ToString()); @@ -292,22 +324,24 @@ HWTEST_F(KvStoreSyncManagerTest, KvStoreSyncManagerTest005, TestSize.Level1) uint32_t sync1DelayMs = 0; // ms uint32_t sync3DelayMs = 100; // ms + Waiter waiter; Key key1("key1"); Value value1("value1"); Value value1Tmp; + waiter.SetValue(false); kvStore3->Put(key1, value1); kvStore3->Sync(syncDevices, SyncMode::PUSH, sync3DelayMs, ++seqId_); kvStore->Put(key1, value1); kvStore->Sync(syncDevices, SyncMode::PUSH, sync1DelayMs, ++seqId_); - - usleep(CHECK_WAITING_TIME); + waiter.GetValue(50); + waiter.SetValue(false); Status ret = kvStore2->Get(key1, value1Tmp); EXPECT_EQ(ret, Status::SUCCESS); EXPECT_EQ(value1.ToString(), value1Tmp.ToString()); ret = kvStore4->Get(key1, value1Tmp); EXPECT_EQ(ret, Status::KEY_NOT_FOUND); - usleep(sync3DelayMs * 1000); + waiter.GetValue(sync3DelayMs); ret = kvStore4->Get(key1, value1Tmp); EXPECT_EQ(ret, Status::SUCCESS); EXPECT_EQ(value1.ToString(), value1Tmp.ToString()); @@ -342,14 +376,12 @@ HWTEST_F(KvStoreSyncManagerTest, KvStoreSyncManagerTest006, TestSize.Level1) kvStore->Put(key, value); if ((i % batch) == (batch - 1)) { - usleep(CHECK_WAITING_TIME); std::vector entries; Status ret1 = kvStore2->GetEntries(prefix, entries); - EXPECT_EQ(ret1, Status::KEY_NOT_FOUND); + EXPECT_EQ(ret1, Status::SUCCESS); } } - usleep(syncDelay.allowedDelayMs * 1000); std::vector entries; Status ret = kvStore2->GetEntries(prefix, entries); EXPECT_EQ(ret, Status::SUCCESS); @@ -382,22 +414,24 @@ HWTEST_F(KvStoreSyncManagerTest, KvStoreSyncManagerTest007, TestSize.Level1) uint32_t sync1DelayMs = 0; // ms uint32_t sync3DelayMs = 200; // ms + Waiter waiter; Key key1("key1"); Value value1("value1"); Value value1Tmp; + waiter.SetValue(false); kvStore->Put(key1, value1); kvNb->SetSyncStatus(DistributedDB::TIME_OUT); kvStore->Sync(syncDevices, SyncMode::PUSH, sync1DelayMs, ++seqId_); kvStore3->Put(key1, value1); kvStore3->Sync(syncDevices, SyncMode::PUSH, sync3DelayMs, ++seqId_); - usleep(CHECK_WAITING_TIME); + waiter.GetValue(50); Status ret = kvStore2->Get(key1, value1Tmp); EXPECT_EQ(ret, Status::KEY_NOT_FOUND); ret = kvStore4->Get(key1, value1Tmp); EXPECT_EQ(ret, Status::KEY_NOT_FOUND); - - usleep(sync3DelayMs * 1000); + waiter.SetValue(false); + waiter.GetValue(sync3DelayMs); ret = kvStore4->Get(key1, value1Tmp); EXPECT_EQ(ret, Status::KEY_NOT_FOUND); diff --git a/services/distributeddataservice/app/test/unittest/meta_data_manager_test.cpp b/services/distributeddataservice/app/test/unittest/meta_data_manager_test.cpp index 5cff4ef63ed393d8b008c8a78c29baf85b758d1f..8024789ea7ffc789b8b2458378f0e3eb422bf845 100644 --- a/services/distributeddataservice/app/test/unittest/meta_data_manager_test.cpp +++ b/services/distributeddataservice/app/test/unittest/meta_data_manager_test.cpp @@ -107,6 +107,7 @@ HWTEST_F(MetaDataManagerTest, MetaBasic_01, TestSize.Level1) ASSERT_TRUE(result); sem.Wait(); EXPECT_TRUE(student.name == changedKey); + MetaDataManager::GetInstance().Unsubscribe(prefix); Student student1; result = MetaDataManager::GetInstance().LoadMeta(student.name, student1); diff --git a/services/distributeddataservice/app/test/unittest/session_manager_test.cpp b/services/distributeddataservice/app/test/unittest/session_manager_test.cpp index fe2093af7736a064a21e277d25ef8abdeb404bbf..3229670368bf777801be9a9300ca6f1b14cde0b1 100644 --- a/services/distributeddataservice/app/test/unittest/session_manager_test.cpp +++ b/services/distributeddataservice/app/test/unittest/session_manager_test.cpp @@ -54,9 +54,9 @@ public: static void TearDownTestCase() { auto peerUserMetaKey = UserMetaRow::GetKeyFor(PEER_DEVICE_ID); - metaDelegate->Delete(peerUserMetaKey); + MetaDataManager::GetInstance().DelMeta(std::string(peerUserMetaKey.begin(), peerUserMetaKey.end())); auto peerCapMetaKey = CapMetaRow::GetKeyFor(PEER_DEVICE_ID); - metaDelegate->Delete(peerCapMetaKey); + MetaDataManager::GetInstance().DelMeta(std::string(peerCapMetaKey.begin(), peerCapMetaKey.end())); } void SetUp() { @@ -87,7 +87,7 @@ HWTEST_F(SessionManagerTest, PackAndUnPack01, TestSize.Level2) uint32_t routeHeadSize = 0; sendHandler->GetHeadDataSize(routeHeadSize); ASSERT_GT(routeHeadSize, 0); - std::unique_ptr data = std::make_unique(routeHeadSize); + std::unique_ptr data = std::make_unique(routeHeadSize); sendHandler->FillHeadData(data.get(), routeHeadSize, routeHeadSize); std::vector users; diff --git a/services/distributeddataservice/app/test/unittest/ut_kvstore_nb_delegate_impl.cpp b/services/distributeddataservice/app/test/unittest/ut_kvstore_nb_delegate_impl.cpp index 745e24f351b4e39f1f8345b40c5ef851d4c527f3..70b5544f884a4621784f0f4bf631d3e8a8944206 100644 --- a/services/distributeddataservice/app/test/unittest/ut_kvstore_nb_delegate_impl.cpp +++ b/services/distributeddataservice/app/test/unittest/ut_kvstore_nb_delegate_impl.cpp @@ -92,7 +92,10 @@ DBStatus UtKvStoreNbDelegateImpl::CloseResultSet(KvStoreResultSet *&resultSet) DBStatus UtKvStoreNbDelegateImpl::Put(const Key &key, const Value &value) { DbValue dbValue{ value, true, false, false }; - return DoPut(key, dbValue); + auto status = DoPut(key, dbValue); + void *autoSync = &isAutoSync_; + Pragma(AUTO_SYNC, reinterpret_cast(autoSync)); + return status; } DBStatus UtKvStoreNbDelegateImpl::DoPut(const Key &key, const DbValue &dbValue) @@ -122,7 +125,10 @@ DBStatus UtKvStoreNbDelegateImpl::PutByOtherDevice(const Key &key, const Value & DBStatus UtKvStoreNbDelegateImpl::Delete(const Key &key) { - return DoDelete(key, true); + auto status = DoDelete(key, true); + void *autoSync = &isAutoSync_; + Pragma(AUTO_SYNC, reinterpret_cast(autoSync)); + return status; } DBStatus UtKvStoreNbDelegateImpl::DoDelete(const Key &key, bool isLocalDelete) @@ -384,4 +390,9 @@ DBStatus UtKvStoreNbDelegateImpl::UnSubscribeRemoteQuery(const std::vector &neighbor); + void SetAutoSync(bool isAutoSync); DBStatus PutLocalBatch(const std::vector &entries) override; DBStatus DeleteLocalBatch(const std::vector &keys) override; @@ -136,6 +137,7 @@ private: std::vector observerMap_{}; std::weak_ptr neighbor_{}; DBStatus syncStatus_{ OK }; + bool isAutoSync_; }; } // namespace DistributedDB diff --git a/services/distributeddataservice/framework/checker/checker_manager.cpp b/services/distributeddataservice/framework/checker/checker_manager.cpp index 8fc87f6a532e16fa5a5e4773a7283d7c1f2ec256..33ef408815ccbc93f7322d857387bf4a80195fff 100644 --- a/services/distributeddataservice/framework/checker/checker_manager.cpp +++ b/services/distributeddataservice/framework/checker/checker_manager.cpp @@ -51,10 +51,6 @@ void CheckerManager::RegisterPlugin(const std::string &checker, std::function metaStore); API_EXPORT bool SaveMeta(const std::string &key, const Serializable &value); API_EXPORT bool LoadMeta(const std::string &key, Serializable &value); + API_EXPORT bool DelMeta(const std::string &key); API_EXPORT bool SubscribeMeta(const std::string &prefix, Observer observer); - + API_EXPORT bool Unsubscribe(std::string filter); private: MetaDataManager(); ~MetaDataManager(); diff --git a/services/distributeddataservice/framework/metadata/meta_data_manager.cpp b/services/distributeddataservice/framework/metadata/meta_data_manager.cpp index 64b3f55eaab21af51e3cf06c299df6757c08552a..efed9b81ff8df975521aa747718053caecc1b162 100644 --- a/services/distributeddataservice/framework/metadata/meta_data_manager.cpp +++ b/services/distributeddataservice/framework/metadata/meta_data_manager.cpp @@ -130,6 +130,17 @@ bool MetaDataManager::LoadMeta(const std::string &key, Serializable &value) return true; } +bool MetaDataManager::DelMeta(const std::string &key) +{ + if (!inited_) { + return false; + } + + DistributedDB::Value data; + auto status = metaStore_->Delete({ key.begin(), key.end() }); + return ((status == DistributedDB::DBStatus::OK) || (status == DistributedDB::DBStatus::NOT_FOUND)); +} + bool MetaDataManager::SubscribeMeta(const std::string &prefix, Observer observer) { if (!inited_) { @@ -141,4 +152,13 @@ bool MetaDataManager::SubscribeMeta(const std::string &prefix, Observer observer return std::make_shared(metaStore_, key, observer); }); } + +bool MetaDataManager::Unsubscribe(std::string filter) +{ + if (!inited_) { + return false; + } + + return metaObservers_.Erase(filter); +} } // namespace OHOS::DistributedData \ No newline at end of file diff --git a/services/distributeddataservice/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp b/services/distributeddataservice/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp index 134edd218c8a02201006c266e0866f2521f76317..f43bb8677c07da9a755efe5aaf9352101e3e3ad9 100644 --- a/services/distributeddataservice/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp +++ b/services/distributeddataservice/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp @@ -1563,36 +1563,54 @@ void SQLiteSingleVerNaturalStore::InitDataBaseOption(const KvDBProperties &kvDBP int SQLiteSingleVerNaturalStore::TransObserverTypeToRegisterFunctionType( int observerType, RegisterFuncType &type) const { - static const std::map transMap { + static constexpr TransPair transMap[] = { { static_cast(SQLITE_GENERAL_NS_PUT_EVENT), OBSERVER_SINGLE_VERSION_NS_PUT_EVENT }, { static_cast(SQLITE_GENERAL_NS_SYNC_EVENT), OBSERVER_SINGLE_VERSION_NS_SYNC_EVENT }, { static_cast(SQLITE_GENERAL_NS_LOCAL_PUT_EVENT), OBSERVER_SINGLE_VERSION_NS_LOCAL_EVENT }, { static_cast(SQLITE_GENERAL_CONFLICT_EVENT), OBSERVER_SINGLE_VERSION_NS_CONFLICT_EVENT }, }; - auto iter = transMap.find(observerType); - if (iter == transMap.end()) { + auto funcType = GetFuncType(observerType, transMap, sizeof(transMap) / sizeof(TransPair)); + if (funcType == REGISTER_FUNC_TYPE_MAX) { return -E_NOT_SUPPORT; } - type = iter->second; + type = funcType; return E_OK; } int SQLiteSingleVerNaturalStore::TransConflictTypeToRegisterFunctionType( int conflictType, RegisterFuncType &type) const { - static const std::map transMap { + static constexpr TransPair transMap[] = { { static_cast(SQLITE_GENERAL_NS_FOREIGN_KEY_ONLY), CONFLICT_SINGLE_VERSION_NS_FOREIGN_KEY_ONLY }, { static_cast(SQLITE_GENERAL_NS_FOREIGN_KEY_ORIG), CONFLICT_SINGLE_VERSION_NS_FOREIGN_KEY_ORIG }, { static_cast(SQLITE_GENERAL_NS_NATIVE_ALL), CONFLICT_SINGLE_VERSION_NS_NATIVE_ALL }, }; - auto iter = transMap.find(conflictType); - if (iter == transMap.end()) { + auto funcType = GetFuncType(conflictType, transMap, sizeof(transMap) / sizeof(TransPair)); + if (funcType == REGISTER_FUNC_TYPE_MAX) { return -E_NOT_SUPPORT; } - type = iter->second; + type = funcType; return E_OK; } +RegisterFuncType SQLiteSingleVerNaturalStore::GetFuncType(int index, const TransPair *transMap, int32_t len) +{ + int32_t head = 0; + int32_t end = len - 1; + while (head < end) { + int32_t mid = (head + end) / 2; + if (transMap[mid].index < index) { + head = mid + 1; + continue; + } + if (transMap[mid].index > index) { + end = mid - 1; + } + return transMap[mid].funcType; + } + return REGISTER_FUNC_TYPE_MAX; +} + int SQLiteSingleVerNaturalStore::GetSchema(SchemaObject &schema) const { int errCode = E_OK; diff --git a/services/distributeddataservice/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h b/services/distributeddataservice/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h index ba92829f72ae8cd243317eeb5a3f777dcb89a7a0..a01e597731e28c1545fe6e0d735ed2025f1a6ce5 100644 --- a/services/distributeddataservice/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h +++ b/services/distributeddataservice/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h @@ -190,6 +190,11 @@ public: uint64_t GetMaxLogSize() const; private: + struct TransPair { + int index; + RegisterFuncType funcType; + }; + static RegisterFuncType GetFuncType(int index, const TransPair *transMap, int32_t len); int CheckDatabaseRecovery(const KvDBProperties &kvDBProp); void CommitAndReleaseNotifyData(SingleVerNaturalStoreCommitNotifyData *&committedData,