diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp b/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp index 291518d1f412107711b7293b604f5191234c253a..b4fd0d634deca19861d5b08bda53c474b3ac58c4 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp @@ -325,7 +325,7 @@ int SingleVerDataSync::GetUnsyncData(SingleVerSyncTaskContext *context, std::vec SyncType curType = (context->IsQuerySync()) ? SyncType::QUERY_SYNC_TYPE : SyncType::MANUAL_FULL_SYNC_TYPE; GetLocalWaterMark(curType, context->GetQuerySyncId(), context, startMark); WaterMark endMark = MAX_TIMESTAMP; - if ((endMark == 0) || (startMark > endMark)) { + if ((startMark > endMark)) { return E_OK; } ContinueToken token = nullptr; @@ -833,8 +833,8 @@ int SingleVerDataSync::PullResponseStart(SingleVerSyncTaskContext *context) return errCode; } -void SingleVerDataSync::UpdateQueryPeerWaterMark(SyncType syncType, const std::string &queryId, SyncTimeRange &dataTime, - const SingleVerSyncTaskContext *context, UpdateWaterMark isUpdateWaterMark) +void SingleVerDataSync::UpdateQueryPeerWaterMark(SyncType syncType, const std::string &queryId, + const SyncTimeRange &dataTime, const SingleVerSyncTaskContext *context, UpdateWaterMark isUpdateWaterMark) { WaterMark tmpPeerWatermark = dataTime.endTime; WaterMark tmpPeerDeletedWatermark = dataTime.deleteEndTime; diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.h b/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.h index 4e9343aece32f3d8adf78156db81dabb8398b361..4b212023154617926a7ed999bef653330bba78e8 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.h +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.h @@ -180,7 +180,7 @@ protected: int SendDataPacket(SyncType syncType, const DataRequestPacket *packet, SingleVerSyncTaskContext *context); - void UpdateQueryPeerWaterMark(SyncType syncType, const std::string &queryId, SyncTimeRange &dataTime, + void UpdateQueryPeerWaterMark(SyncType syncType, const std::string &queryId, const SyncTimeRange &dataTime, const SingleVerSyncTaskContext *context, UpdateWaterMark isUpdateWaterMark); void UpdatePeerWaterMark(SyncType syncType, const std::string &queryId, const SingleVerSyncTaskContext *context, diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp b/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp index 2827ef3758a52876d8ef91388e83bf89e9f1e98c..51e2b47b604816c55b28d8d1c718eb3624e30496 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.cpp @@ -257,7 +257,7 @@ void SingleVerDataSyncUtils::FillControlRequestPacket(ControlRequestPacket *pack uint32_t version = std::min(context->GetRemoteSoftwareVersion(), SOFTWARE_VERSION_CURRENT); uint32_t flag = 0; if (context->GetMode() == SyncModeType::SUBSCRIBE_QUERY && context->IsAutoSubscribe()) { - flag = flag | SubscribeRequest::IS_AUTO_SUBSCRIBE; + flag = SubscribeRequest::IS_AUTO_SUBSCRIBE; } packet->SetPacketHead(E_OK, version, GetControlCmdType(context->GetMode()), flag); packet->SetQuery(context->GetQuery()); @@ -298,7 +298,7 @@ bool SingleVerDataSyncUtils::IsNeedTriggerQueryAutoSync(Message *inMsg, QuerySyn uint32_t controlCmdType = packet->GetcontrolCmdType(); if (controlCmdType == ControlCmdType::SUBSCRIBE_QUERY_CMD && inMsg->GetMessageType() == TYPE_REQUEST) { const SubscribeRequest *subPacket = inMsg->GetObject(); - if (packet == nullptr) { + if (subPacket == nullptr) { return false; } query = subPacket->GetQuery(); @@ -398,7 +398,7 @@ SyncTimeRange SingleVerDataSyncUtils::GetQuerySyncDataTimeRange(const std::vecto return dataTimeRange; } -SyncTimeRange SingleVerDataSyncUtils::ReviseLocalMark(SyncType syncType, SyncTimeRange &dataTimeRange, +SyncTimeRange SingleVerDataSyncUtils::ReviseLocalMark(SyncType syncType, const SyncTimeRange &dataTimeRange, UpdateWaterMark updateMark) { SyncTimeRange tmpDataTime = dataTimeRange; diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.h b/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.h index 09ff9780c55d029d9d311eb48936e2e84967b5ad..e42472a6075092a1ff3e52244fd1fcf3d6c626e6 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.h +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync_utils.h @@ -79,7 +79,8 @@ public: static SyncTimeRange GetQuerySyncDataTimeRange(const std::vector &inData, WaterMark localMark, WaterMark deleteLocalMark, UpdateWaterMark &isUpdate); - static SyncTimeRange ReviseLocalMark(SyncType syncType, SyncTimeRange &dataTimeRange, UpdateWaterMark updateMark); + static SyncTimeRange ReviseLocalMark(SyncType syncType, const SyncTimeRange &dataTimeRange, + UpdateWaterMark updateMark); static SyncTimeRange GetRecvDataTimeRange(SyncType syncType, const std::vector &data, UpdateWaterMark &isUpdate); diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_engine.cpp b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_engine.cpp index 3f85cb9edbbdca1ad7eeee131b960483d6013b98..13988c72c7dde204a21a3dad3ee4f7ac9f033df1 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_engine.cpp +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_engine.cpp @@ -103,8 +103,8 @@ int SingleVerSyncEngine::SubscribeTimeOut(TimerId id) LOGI("no need to trigger auto subscribe"); return E_OK; } - for (auto &item : allSyncQueries) { - for (auto &query : item.second) { + for (const auto &item : allSyncQueries) { + for (const auto &query : item.second) { InternalSyncParma param; GetSubscribeSyncParam(item.first, query, param); queryAutoSyncCallback_(param); diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp index 8beb7e76154600235c00aee4dbdaf341fea12944..27de0c7a7dc2edb857a900a96d48550882be776c 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.cpp @@ -298,7 +298,7 @@ void SingleVerSyncStateMachine::CommErrAbort(uint32_t sessionId) { std::lock_guard lock(stateMachineLock_); uint32_t requestSessionId = context_->GetRequestSessionId(); - if ((sessionId != 0) && ((sessionId != requestSessionId) || (requestSessionId == 0))) { + if ((sessionId != 0) && ((requestSessionId == 0) || (sessionId != requestSessionId))) { return; } context_->SetCommNormal(false); @@ -1067,7 +1067,7 @@ bool SingleVerSyncStateMachine::IsNeedResetWatchdog(const Message *inMsg) const return false; } -Event SingleVerSyncStateMachine::TransforTimeOutErrCodeToEvent() +Event SingleVerSyncStateMachine::TransforTimeOutErrCodeToEvent() const { if (syncContext_->IsSyncTaskNeedRetry() && (syncContext_->GetRetryTime() < syncContext_->GetSyncRetryTimes())) { return Event::WAIT_TIME_OUT_EVENT; diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.h b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.h index 593568ba595251d3d997be4eabfd7d6629ad170f..59df3bccfcb75d6c7eae30675847a4142327fdef 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.h +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_sync_state_machine.h @@ -201,7 +201,7 @@ private: bool IsNeedResetWatchdog(const Message *inMsg) const; - Event TransforTimeOutErrCodeToEvent(); + Event TransforTimeOutErrCodeToEvent() const; bool AbilityMsgSessionIdCheck(const Message *inMsg); diff --git a/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp b/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp index f0facc99739be521fef358a6589ad2432946009b..c1de6980657f566f258d853c55fc55f78f356593 100644 --- a/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp +++ b/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp @@ -97,7 +97,7 @@ void SubscribeManager::DeleteRemoteSubscribeQuery(const std::string &device, con } void SubscribeManager::PutLocalUnFiniedSubQueries(const std::string &device, - std::vector &subscribeQueries) + const std::vector &subscribeQueries) { LOGI("[SubscribeManager] put local unfinished subscribe queries, nums=%zu", subscribeQueries.size()); std::unique_lock lockGuard(localSubscribeMapLock_); diff --git a/frameworks/libs/distributeddb/syncer/src/subscribe_manager.h b/frameworks/libs/distributeddb/syncer/src/subscribe_manager.h index 42ca070c54b65850421b2d62c5ce5bc16d6283c4..87a38556c2e8a4e814e1815a457534ddafeb2f85 100644 --- a/frameworks/libs/distributeddb/syncer/src/subscribe_manager.h +++ b/frameworks/libs/distributeddb/syncer/src/subscribe_manager.h @@ -63,7 +63,7 @@ public: void DeleteRemoteSubscribeQuery(const std::string &device, const QuerySyncObject &query); // put subscribe queries into unfinished map when remote db online - void PutLocalUnFiniedSubQueries(const std::string &device, std::vector &subscribeQueries); + void PutLocalUnFiniedSubQueries(const std::string &device, const std::vector &subscribeQueries); // get all device unFinished subscribe queries which triggered by auto subscribe and need retry subscribe void GetAllUnFinishSubQueries(std::map> &allSyncQueries) const; diff --git a/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp b/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp index 221dcbca9c5b0f10a7414b4bb26985f33de5643c..8dae7991b4e97b7c23a5f671f48602623fff3c5c 100644 --- a/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp +++ b/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp @@ -765,7 +765,7 @@ void SyncEngine::SetEqualIdentifier() equalIdentifier[item.second].push_back(item.first); } } - for (auto &item : equalIdentifier) { + for (const auto &item : equalIdentifier) { SetEqualIdentifier(item.first, item.second); } } @@ -779,7 +779,7 @@ void SyncEngine::SetEqualIdentifierMap(const std::string &identifier, const std: } iter++; } - for (auto &device : targets) { + for (const auto &device : targets) { equalIdentifierMap_[device] = identifier; } } @@ -835,7 +835,7 @@ void SyncEngine::GetRemoteSubscribeQueries(const std::string &device, std::vecto subManager_->GetRemoteSubscribeQueries(device, subscribeQueries); } -void SyncEngine::PutUnfiniedSubQueries(const std::string &device, std::vector &subscribeQueries) +void SyncEngine::PutUnfiniedSubQueries(const std::string &device, const std::vector &subscribeQueries) { subManager_->PutLocalUnFiniedSubQueries(device, subscribeQueries); } @@ -992,7 +992,7 @@ bool SyncEngine::IsEngineActive() const void SyncEngine::SchemaChange() { std::lock_guard lock(contextMapLock_); - for (auto &entry : syncTaskContextMap_) { + for (const auto &entry : syncTaskContextMap_) { auto context = entry.second; if (context->IsKilled()) { continue; @@ -1111,7 +1111,7 @@ void SyncEngine::AbortMachineIfNeed(uint32_t syncId) ISyncTaskContext *abortContext = nullptr; { std::lock_guard lock(contextMapLock_); - for (auto &entry : syncTaskContextMap_) { + for (const auto &entry : syncTaskContextMap_) { auto context = entry.second; if (context->IsKilled()) { continue; diff --git a/frameworks/libs/distributeddb/syncer/src/sync_engine.h b/frameworks/libs/distributeddb/syncer/src/sync_engine.h index a7f8fad203a4ef0fef94bd758a1940141aba06a6..3c529f6a87e8891961862b466802b3c13de913ce 100644 --- a/frameworks/libs/distributeddb/syncer/src/sync_engine.h +++ b/frameworks/libs/distributeddb/syncer/src/sync_engine.h @@ -93,7 +93,7 @@ public: void GetRemoteSubscribeQueries(const std::string &device, std::vector &subscribeQueries); - void PutUnfiniedSubQueries(const std::string &device, std::vector &subscribeQueries); + void PutUnfiniedSubQueries(const std::string &device, const std::vector &subscribeQueries); void GetAllUnFinishSubQueries(std::map> &allSyncQueries); diff --git a/frameworks/libs/distributeddb/syncer/src/time_sync.cpp b/frameworks/libs/distributeddb/syncer/src/time_sync.cpp index 26cc3b9fd404efeec8256b247d759975a27de633..bcc8f28eb75460c62a0e03bebf1f569625b273aa 100644 --- a/frameworks/libs/distributeddb/syncer/src/time_sync.cpp +++ b/frameworks/libs/distributeddb/syncer/src/time_sync.cpp @@ -150,7 +150,7 @@ int TimeSync::RegisterTransformFunc() return MessageTransform::RegTransformFunction(TIME_SYNC_MESSAGE, func); } -int TimeSync::Initialize(ICommunicator *communicator, std::shared_ptr &metadata, +int TimeSync::Initialize(ICommunicator *communicator, const std::shared_ptr &metadata, const ISyncInterface *storage, const DeviceID &deviceId) { if ((communicator == nullptr) || (storage == nullptr) || (metadata == nullptr)) { diff --git a/frameworks/libs/distributeddb/syncer/src/time_sync.h b/frameworks/libs/distributeddb/syncer/src/time_sync.h index 0b79152cac619ce0c0fccfeb26901b334e7f9e95..263faac16778ab3c22839667fae592b76e937340 100644 --- a/frameworks/libs/distributeddb/syncer/src/time_sync.h +++ b/frameworks/libs/distributeddb/syncer/src/time_sync.h @@ -71,7 +71,7 @@ public: static int DeSerialization(const uint8_t *buffer, uint32_t length, Message *inMsg); // register to communicator - int Initialize(ICommunicator *communicator, std::shared_ptr &metadata, + int Initialize(ICommunicator *communicator, const std::shared_ptr &metadata, const ISyncInterface *storage, const DeviceID &deviceId); int SyncStart(const CommErrHandler &handler = nullptr, uint32_t sessionId = 0); // send timesync request diff --git a/frameworks/libs/distributeddb/test/BUILD.gn b/frameworks/libs/distributeddb/test/BUILD.gn index d65fed7052392a6a7259e1c7e0d1867b21ca7525..5d8a48d35e6d9cf53fbe59f161ed5028d7b59aa8 100644 --- a/frameworks/libs/distributeddb/test/BUILD.gn +++ b/frameworks/libs/distributeddb/test/BUILD.gn @@ -658,7 +658,7 @@ distributeddb_unittest("DistributedDBCommunicatorProxyTest") { } distributeddb_unittest("DistributedDBSingleVerP2PSubscribeSyncTest") { - sources = [ "unittest/common/syncer/distributeddb_single_ver_p2p_subsribe_sync_test.cpp" ] + sources = [ "unittest/common/syncer/distributeddb_single_ver_p2p_subscribe_sync_test.cpp" ] } distributeddb_unittest("DistributedDBMockSyncModuleTest") { diff --git a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_schema_database_upgrade_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_schema_database_upgrade_test.cpp index c0dd063026e1c17546fe5d6fef2abe2f6c4ba9e4..9587a2c46f6ab921b5447d8bc032f170378bf413 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_schema_database_upgrade_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_schema_database_upgrade_test.cpp @@ -96,7 +96,7 @@ namespace { } return oriSchemaStr; } - bool SchemaChecker(const std::string schema) + bool SchemaChecker(const std::string &schema) { SchemaObject schemaObj; return (schemaObj.ParseFromSchemaString(schema) == E_OK); diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_multi_ver_p2p_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_multi_ver_p2p_sync_test.cpp index 70d3ffbcd2af86d0aef10dfcec00985654e753de..f4cce093ad714720a840e3658c8a4aad89ac6593 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_multi_ver_p2p_sync_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_multi_ver_p2p_sync_test.cpp @@ -770,7 +770,7 @@ static bool IsCommitHistorySyncRequestPacketEqual(const CommitHistorySyncRequest std::map commitMapB; inPacketA.GetCommitMap(commitMapA); inPacketB.GetCommitMap(commitMapB); - for (auto &entry : commitMapA) { + for (const auto &entry : commitMapA) { if (commitMapB.count(entry.first) == 0) { return false; } @@ -778,7 +778,7 @@ static bool IsCommitHistorySyncRequestPacketEqual(const CommitHistorySyncRequest return false; } } - for (auto &entry : commitMapB) { + for (const auto &entry : commitMapB) { if (commitMapA.count(entry.first) == 0) { return false; } @@ -897,7 +897,7 @@ static bool IsCommitHistorySyncAckPacketEqual(const CommitHistorySyncAckPacket & return false; } int count = 0; - for (auto &entry : commitVecA) { + for (const auto &entry : commitVecA) { if (!IsMultiVerCommitEqual(entry, commitVecB[count++])) { return false; } diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_relational_ver_p2p_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_relational_ver_p2p_sync_test.cpp index 9c49cac73959152fd4ec71a526d71f7b43038a60..cbc305229bf454b9ba7b4a7fd14439f06e0b491a 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_relational_ver_p2p_sync_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_relational_ver_p2p_sync_test.cpp @@ -145,7 +145,7 @@ namespace { return sqlite3_exec(db, sql.c_str(), nullptr, nullptr, nullptr); } - int CreateTable(sqlite3 *db, std::vector &fieldInfoList, const std::string &tableName) + int CreateTable(sqlite3 *db, const std::vector &fieldInfoList, const std::string &tableName) { std::string sql = "CREATE TABLE " + tableName + "("; int index = 0; @@ -398,7 +398,7 @@ namespace { } void GetSyncDataStep(std::map &dataMap, sqlite3_stmt *statement, - std::vector fieldInfoList) + std::vector &fieldInfoList) { int columnCount = sqlite3_column_count(statement); ASSERT_EQ(static_cast(columnCount), fieldInfoList.size()); @@ -410,7 +410,7 @@ namespace { } void GetSyncData(sqlite3 *db, std::map &dataMap, const std::string &tableName, - std::vector fieldInfoList) + std::vector &fieldInfoList) { sqlite3_stmt *statement = nullptr; EXPECT_EQ(PrepareSelect(db, statement, GetDeviceTableName(tableName)), SQLITE_OK); @@ -434,7 +434,7 @@ namespace { } void PrepareBasicTable(const std::string &tableName, std::vector &fieldInfoList, - std::vector &remoteDeviceVec, bool createDistributedTable = true) + const std::vector &remoteDeviceVec, bool createDistributedTable = true) { sqlite3 *db = nullptr; EXPECT_EQ(GetDB(db), SQLITE_OK); @@ -466,7 +466,7 @@ namespace { } void PrepareVirtualEnvironment(std::map &dataMap, const std::string &tableName, - std::vector &fieldInfoList, std::vector remoteDeviceVec, + std::vector &fieldInfoList, const std::vector remoteDeviceVec, bool createDistributedTable = true) { PrepareBasicTable(tableName, fieldInfoList, remoteDeviceVec, createDistributedTable); @@ -480,13 +480,13 @@ namespace { } void PrepareVirtualEnvironment(std::map &dataMap, - std::vector remoteDeviceVec, bool createDistributedTable = true) + const std::vector remoteDeviceVec, bool createDistributedTable = true) { PrepareVirtualEnvironment(dataMap, g_tableName, g_fieldInfoList, remoteDeviceVec, createDistributedTable); } - void CheckData(std::map &targetMap, const std::string &tableName, - std::vector fieldInfoList) + void CheckData(const std::map &targetMap, const std::string &tableName, + std::vector &fieldInfoList) { std::map dataMap; sqlite3 *db = nullptr; @@ -500,7 +500,7 @@ namespace { } } - void CheckData(std::map &targetMap) + void CheckData(const std::map &targetMap) { CheckData(targetMap, g_tableName, g_fieldInfoList); } @@ -576,7 +576,7 @@ namespace { void PrepareEnvironment(std::map &dataMap, std::vector &localFieldInfoList, std::vector &remoteFieldInfoList, - std::vector remoteDeviceVec) + const std::vector remoteDeviceVec) { PrepareEnvironment(dataMap, g_tableName, localFieldInfoList, remoteFieldInfoList, remoteDeviceVec); } diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_msg_schedule_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_msg_schedule_test.cpp index 9df55d1bb65c8d80ba25eaa61aa9549aa421e17e..f1778d10a06873aa88d1c76715e2fd7bc23063a9 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_msg_schedule_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_msg_schedule_test.cpp @@ -432,8 +432,8 @@ HWTEST_F(DistributedDBSingleVerMsgScheduleTest, MsgSchedule007, TestSize.Level0) msgSchedule.ScheduleInfoHandle(isNeedHandle, false, msg); delete msg; } - Message *msg = msgSchedule.MoveNextMsg(context, isNeedHandle, isNeedContinue); - ASSERT_TRUE(msg == nullptr); + Message *msg2 = msgSchedule.MoveNextMsg(context, isNeedHandle, isNeedContinue); + ASSERT_TRUE(msg2 == nullptr); /** * @tc.steps: step2. put msg seq1_packet1, seq2_packet2 * @tc.expected: get nullptr @@ -448,9 +448,9 @@ HWTEST_F(DistributedDBSingleVerMsgScheduleTest, MsgSchedule007, TestSize.Level0) isNeedHandle = true; isNeedContinue = true; for (uint32_t i = 1; i <= 3; i++) { - Message *msg = msgSchedule.MoveNextMsg(context, isNeedHandle, isNeedContinue); + Message *msg3 = msgSchedule.MoveNextMsg(context, isNeedHandle, isNeedContinue); EXPECT_EQ(isNeedContinue, true); - ASSERT_TRUE(msg == nullptr); + ASSERT_TRUE(msg3 == nullptr); } RefObject::KillAndDecObjRef(context); context = nullptr; diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_query_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_query_sync_test.cpp index cdf06110bd488c406bb5a67eed39661e51510654..112dc2f227098ddc7cbeed13ae8c8acb5270b6f5 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_query_sync_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_query_sync_test.cpp @@ -344,9 +344,11 @@ HWTEST_F(DistributedDBSingleVerP2PQuerySyncTest, NormalSync003, TestSize.Level1) Value value = {'1'}; const int dataSize = 10; status = g_kvDelegatePtr->Put(key, value); + ASSERT_TRUE(status == OK); Key key2 = {'2'}; Value value2 = {'2'}; status = g_kvDelegatePtr->Put(key2, value2); + ASSERT_TRUE(status == OK); /** * @tc.steps: step2. deviceB put {b0, v0} - {b9, v9}, {c, v} @@ -1448,6 +1450,7 @@ HWTEST_F(DistributedDBSingleVerP2PQuerySyncTest, AllPredicateQuerySync001, TestS key.push_back(i); key2.push_back(i); status = g_schemaKvDelegatePtr->Put(key, value); + ASSERT_TRUE(status == OK); status = g_schemaKvDelegatePtr->Put(key2, value2); ASSERT_TRUE(status == OK); key.pop_back(); @@ -1545,6 +1548,7 @@ HWTEST_F(DistributedDBSingleVerP2PQuerySyncTest, AllPredicateQuerySync003, TestS key.push_back(i); key2.push_back(i); status = g_schemaKvDelegatePtr->Put(key, value); + ASSERT_TRUE(status == OK); status = g_schemaKvDelegatePtr->Put(key2, value2); ASSERT_TRUE(status == OK); key.pop_back(); diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_subsribe_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_subscribe_sync_test.cpp similarity index 98% rename from frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_subsribe_sync_test.cpp rename to frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_subscribe_sync_test.cpp index a7ce0829ad300c9a5c505b8655aa42fa20fb74b8..fcf58d5200f03e27bea2ed751b36813722a54c63 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_subsribe_sync_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_subscribe_sync_test.cpp @@ -511,9 +511,9 @@ HWTEST_F(DistributedDBSingleVerP2PSubscribeSyncTest, subscribeManager003, TestSi */ LOGI("============step 3============"); for (int i = 0; i < 8; i++) { - QuerySyncObject querySyncObj(Query::Select().PrefixKey({'a', static_cast('a' + i)})); - ASSERT_TRUE(subManager.ReserveLocalSubscribeQuery(device + std::to_string(i), querySyncObj) == E_OK); - ASSERT_TRUE(subManager.ActiveLocalSubscribeQuery(device + std::to_string(i), querySyncObj) == E_OK); + QuerySyncObject querySyncObj2(Query::Select().PrefixKey({'a', static_cast('a' + i)})); + ASSERT_TRUE(subManager.ReserveLocalSubscribeQuery(device + std::to_string(i), querySyncObj2) == E_OK); + ASSERT_TRUE(subManager.ActiveLocalSubscribeQuery(device + std::to_string(i), querySyncObj2) == E_OK); } QuerySyncObject querySyncObj1(Query::Select().PrefixKey({'a', static_cast('a' + 8)})); ASSERT_TRUE(subManager.ReserveLocalSubscribeQuery(device + std::to_string(8), querySyncObj1) != E_OK); @@ -562,9 +562,9 @@ HWTEST_F(DistributedDBSingleVerP2PSubscribeSyncTest, subscribeManager004, TestSi */ LOGI("============step 3============"); for (int i = 0; i < 8; i++) { - QuerySyncObject querySyncObj(Query::Select().PrefixKey({'a', static_cast('a' + i)})); - ASSERT_TRUE(subManager.ReserveRemoteSubscribeQuery(device + std::to_string(i), querySyncObj) == E_OK); - ASSERT_TRUE(subManager.ActiveRemoteSubscribeQuery(device + std::to_string(i), querySyncObj) == E_OK); + QuerySyncObject querySyncObj2(Query::Select().PrefixKey({'a', static_cast('a' + i)})); + ASSERT_TRUE(subManager.ReserveRemoteSubscribeQuery(device + std::to_string(i), querySyncObj2) == E_OK); + ASSERT_TRUE(subManager.ActiveRemoteSubscribeQuery(device + std::to_string(i), querySyncObj2) == E_OK); } QuerySyncObject querySyncObj1(Query::Select().PrefixKey({'a', static_cast('a' + 8)})); ASSERT_TRUE(subManager.ReserveRemoteSubscribeQuery(device + std::to_string(8), querySyncObj1) != E_OK); diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_sync_check_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_sync_check_test.cpp index 35a3af9eb728b9f805c6bfd68a1979080196c925..5f468630015a4a0f4f52910303702a067ed83e35 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_sync_check_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_sync_check_test.cpp @@ -593,7 +593,7 @@ void SyncWithQuery(vector &devices, const Query &query, const DBSta SyncWithQuery(devices, query, DistributedDB::SYNC_MODE_PUSH_ONLY, targetStatus); } -void SyncWithDeviceOffline(vector &devices, Key &key, Query &query) +void SyncWithDeviceOffline(vector &devices, Key &key, const Query &query) { Value value = {'2'}; ASSERT_TRUE(g_kvDelegatePtr->Put(key, value) == OK); @@ -660,7 +660,6 @@ HWTEST_F(DistributedDBSingleVerP2PSyncCheckTest, AckSessionCheck001, TestSize.Le * @tc.steps: step1. deviceB sync to deviceA just for timeSync and abilitySync * @tc.expected: step1. should return OK. */ - std::map result; ASSERT_TRUE(g_deviceB->Sync(SYNC_MODE_PUSH_ONLY, true) == OK); /** diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_sync_test.cpp index c828bda01c9db8b1ff800b9c4576c5eb73618baf..71bc92db6fdc2cef5eb6336b84b9addd16736d7a 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_sync_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_sync_test.cpp @@ -2302,11 +2302,12 @@ HWTEST_F(DistributedDBSingleVerP2PSyncTest, SaveDataNotify001, TestSize.Level3) */ g_deviceB->SetSaveDataDelayTime(WAIT_30_SECONDS); status = g_kvDelegatePtr->Put(key, value); - + ASSERT_TRUE(status == OK); /** * @tc.steps: step3. deviceA call sync and wait * @tc.expected: step3. sync should return OK. onComplete should be called, deviceB sync success. */ + result.clear(); status = g_tool.SyncTest(g_kvDelegatePtr, devices, SYNC_MODE_PUSH_ONLY, result); ASSERT_TRUE(status == OK); ASSERT_TRUE(result.size() == devices.size()); @@ -2317,11 +2318,12 @@ HWTEST_F(DistributedDBSingleVerP2PSyncTest, SaveDataNotify001, TestSize.Level3) */ g_deviceB->SetSaveDataDelayTime(WAIT_36_SECONDS); status = g_kvDelegatePtr->Put(key, value); - + ASSERT_TRUE(status == OK); /** * @tc.steps: step5. deviceA call sync and wait * @tc.expected: step5. sync should return OK. onComplete should be called, deviceB sync TIME_OUT. */ + result.clear(); status = g_tool.SyncTest(g_kvDelegatePtr, devices, SYNC_MODE_PUSH_ONLY, result); ASSERT_TRUE(status == OK); ASSERT_TRUE(result.size() == devices.size()); @@ -2412,7 +2414,7 @@ HWTEST_F(DistributedDBSingleVerP2PSyncTest, SametimeSync002, TestSize.Level3) } }); std::map result; - auto callback = [&result](std::map map) { + auto callback = [&result](std::map &map) { result = map; }; Query query = Query::Select().PrefixKey({'k', '1'}); @@ -2431,7 +2433,7 @@ HWTEST_F(DistributedDBSingleVerP2PSyncTest, SametimeSync002, TestSize.Level3) }); std::thread subThread([&devices] { std::map result; - auto callback = [&result](std::map map) { + auto callback = [&result](std::map &map) { result = map; }; Query query = Query::Select().PrefixKey({'k', '2'}); @@ -2447,7 +2449,7 @@ HWTEST_F(DistributedDBSingleVerP2PSyncTest, SametimeSync002, TestSize.Level3) std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::map virtualResult; g_deviceB->Sync(DistributedDB::SYNC_MODE_PULL_ONLY, query, - [&virtualResult](std::map map) { + [&virtualResult](std::map &map) { virtualResult = map; }, true); EXPECT_TRUE(status == OK); @@ -2472,7 +2474,7 @@ HWTEST_F(DistributedDBSingleVerP2PSyncTest, DatabaseOnlineCallback001, TestSize. */ std::string targetDev = "DEVICE_X"; bool isCheckOk = false; - auto databaseStatusNotifyCallback = [targetDev, &isCheckOk] (std::string userId, + auto databaseStatusNotifyCallback = [targetDev, &isCheckOk] (std::string userId,2304 std::string appId, std::string storeId, const std::string deviceId, bool onlineStatus) -> void { if (userId == USER_ID && appId == APP_ID && storeId == STORE_ID && deviceId == targetDev && onlineStatus == true) { diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/mock_auto_launch.h b/frameworks/libs/distributeddb/test/unittest/common/syncer/mock_auto_launch.h index af89a85aea477859a44b8ae9387d478ed6b1cebe..6236d010a937b51cfb8c05a785f0d9ec8aa14dc5 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/mock_auto_launch.h +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/mock_auto_launch.h @@ -22,7 +22,7 @@ namespace DistributedDB { class MockAutoLaunch : public AutoLaunch { public: - void SetAutoLaunchItem(const std::string &identify, const std::string &userId, AutoLaunchItem &item) + void SetAutoLaunchItem(const std::string &identify, const std::string &userId, const AutoLaunchItem &item) { std::lock_guard autoLock(extLock_); extItemMap_[identify][userId] = item; diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_relational_ver_sync_db_interface.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_relational_ver_sync_db_interface.cpp index afda4562fedb4ec727905a5487b2df2244db2af5..5ec215d783fa9e7d84513d4f077ba76ddb7145c2 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_relational_ver_sync_db_interface.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_relational_ver_sync_db_interface.cpp @@ -25,7 +25,7 @@ namespace { int GetEntriesFromItems(std::vector &entries, const std::vector &dataItems) { int errCode = E_OK; - for (auto &item : dataItems) { + for (const auto &item : dataItems) { auto entry = new (std::nothrow) GenericSingleVerKvEntry(); if (entry == nullptr) { LOGE("Create entry failed."); @@ -274,7 +274,7 @@ int VirtualRelationalVerSyncDBInterface::DeleteMetaDataByPrefixKey(const Key &ke int VirtualRelationalVerSyncDBInterface::GetAllMetaKeys(std::vector &keys) const { - for (auto &iter : metadata_) { + for (const auto &iter : metadata_) { keys.push_back(iter.first); } LOGD("GetAllMetaKeys size %zu", keys.size()); @@ -364,7 +364,7 @@ void VirtualRelationalVerSyncDBInterface::SetPermitCreateDistributedTable(bool p permitCreateDistributedTable_ = permitCreateDistributedTable; } -void ObjectData::PutDataValue(const std::string &fieldName, const DataValue &value) +void ObjectData::PutDataValue(const std::string &fieldName, const DataValue &value) const { fieldData[fieldName] = value; } diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_relational_ver_sync_db_interface.h b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_relational_ver_sync_db_interface.h index e42cba6be4faa482cd9010aea750c69a917cca4c..a7ca8f479b25a76808da79a77a67248f6614beeb 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_relational_ver_sync_db_interface.h +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_relational_ver_sync_db_interface.h @@ -24,7 +24,7 @@ namespace DistributedDB { struct ObjectData { public: - void PutDataValue(const std::string &fieldName, const DataValue &value); + void PutDataValue(const std::string &fieldName, const DataValue &value) const; int GetDataValue(const std::string &fieldName, DataValue &value) const; private: mutable std::map fieldData; diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_single_ver_sync_db_Interface.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_single_ver_sync_db_Interface.cpp index b826d4845cbf454d11337cf3b7b176c62ee97cc6..259868e48723deb6b7ec9259b5a96a430c2a0b70 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_single_ver_sync_db_Interface.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_single_ver_sync_db_Interface.cpp @@ -31,7 +31,7 @@ namespace { int GetEntriesFromItems(std::vector &entries, const std::vector &dataItems) { int errCode = E_OK; - for (auto &item : dataItems) { + for (const auto &item : dataItems) { auto entry = new (std::nothrow) GenericSingleVerKvEntry(); if (entry == nullptr) { LOGE("Create entry failed.");