From 8728676a626da0e1594435d2033f79eae451477e Mon Sep 17 00:00:00 2001 From: zqq Date: Fri, 21 Oct 2022 16:57:30 +0800 Subject: [PATCH] fix codecheck Signed-off-by: zqq --- .../communicator/src/protocol_proto.cpp | 2 +- .../communicator/src/send_task_scheduler.cpp | 6 +++--- .../distributeddb/syncer/src/db_ability.cpp | 2 +- .../distributeddb/syncer/src/db_ability.h | 2 +- .../syncer/src/generic_syncer.cpp | 14 ++++++------- .../distributeddb/syncer/src/generic_syncer.h | 1 + .../syncer/src/multi_ver_data_sync.cpp | 2 +- .../src/query_sync_water_mark_helper.cpp | 2 +- .../syncer/src/remote_executor.cpp | 8 +++---- ...buteddb_interfaces_data_operation_test.cpp | 4 ++-- ...distributeddb_interfaces_database_test.cpp | 2 +- ...eddb_interfaces_import_and_export_test.cpp | 21 ++++++++----------- ...stributeddb_interfaces_index_unit_test.cpp | 10 +++------ 13 files changed, 35 insertions(+), 41 deletions(-) diff --git a/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp b/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp index ed79435483b..f4b97c7f6a8 100644 --- a/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp +++ b/frameworks/libs/distributeddb/communicator/src/protocol_proto.cpp @@ -238,7 +238,7 @@ SerialBuffer *ProtocolProto::BuildLabelExchange(uint64_t inDistinctValue, uint64 // Note: don't worry, memory length had been carefully calculated above auto bytePtr = reinterpret_cast(fieldPtr); for (auto &eachLabel : inLabels) { - for (auto &eachByte : eachLabel) { + for (const auto &eachByte : eachLabel) { *bytePtr++ = eachByte; } } diff --git a/frameworks/libs/distributeddb/communicator/src/send_task_scheduler.cpp b/frameworks/libs/distributeddb/communicator/src/send_task_scheduler.cpp index 25a60561e99..23c4e079186 100644 --- a/frameworks/libs/distributeddb/communicator/src/send_task_scheduler.cpp +++ b/frameworks/libs/distributeddb/communicator/src/send_task_scheduler.cpp @@ -37,7 +37,7 @@ void SendTaskScheduler::Initialize() priorityOrder_.push_back(Priority::HIGH); priorityOrder_.push_back(Priority::NORMAL); priorityOrder_.push_back(Priority::LOW); - for (auto &prio : priorityOrder_) { + for (const auto &prio : priorityOrder_) { extraCapacityInByteByPrio_[prio] = 0; taskCountByPrio_[prio] = 0; taskDelayCountByPrio_[prio] = 0; @@ -235,7 +235,7 @@ uint32_t SendTaskScheduler::GetNoDelayTaskCount() const int SendTaskScheduler::ScheduleDelayTask(SendTask &outTask, SendTaskInfo &outTaskInfo) { - for (auto &prio : priorityOrder_) { + for (const auto &prio : priorityOrder_) { if (taskCountByPrio_[prio] == 0) { // No task of this priority continue; @@ -253,7 +253,7 @@ int SendTaskScheduler::ScheduleDelayTask(SendTask &outTask, SendTaskInfo &outTas int SendTaskScheduler::ScheduleNoDelayTask(SendTask &outTask, SendTaskInfo &outTaskInfo) { - for (auto &prio : priorityOrder_) { + for (const auto &prio : priorityOrder_) { if (taskCountByPrio_[prio] == 0 || taskCountByPrio_[prio] == taskDelayCountByPrio_[prio]) { // No no_delay_task of this priority continue; diff --git a/frameworks/libs/distributeddb/syncer/src/db_ability.cpp b/frameworks/libs/distributeddb/syncer/src/db_ability.cpp index 9204f52d4e2..1e701285f37 100644 --- a/frameworks/libs/distributeddb/syncer/src/db_ability.cpp +++ b/frameworks/libs/distributeddb/syncer/src/db_ability.cpp @@ -106,7 +106,7 @@ uint32_t DbAbility::CalculateLen(const DbAbility &curAbility) return Parcel::GetVectorLen(std::vector(buffLen, 0)); } -void DbAbility::SetDbAbilityBuff(std::vector &buff) +void DbAbility::SetDbAbilityBuff(const std::vector &buff) { dbAbility_ = buff; } diff --git a/frameworks/libs/distributeddb/syncer/src/db_ability.h b/frameworks/libs/distributeddb/syncer/src/db_ability.h index a1bb45eb93f..50110ac221f 100644 --- a/frameworks/libs/distributeddb/syncer/src/db_ability.h +++ b/frameworks/libs/distributeddb/syncer/src/db_ability.h @@ -39,7 +39,7 @@ public: static uint32_t CalculateLen(const DbAbility &curAbility); - void SetDbAbilityBuff(std::vector &buff); + void SetDbAbilityBuff(const std::vector &buff); const std::vector &GetDbAbilityBuff() const; diff --git a/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp b/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp index f4657850967..4ddacc35266 100644 --- a/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp +++ b/frameworks/libs/distributeddb/syncer/src/generic_syncer.cpp @@ -59,8 +59,7 @@ GenericSyncer::~GenericSyncer() syncEngine_->OnKill([this]() { this->syncEngine_->Close(); }); RefObject::KillAndDecObjRef(syncEngine_); // waiting all thread exist - std::mutex engineMutex; - std::unique_lock cvLock(engineMutex); + std::unique_lock cvLock(engineMutex_); bool engineFinalize = engineFinalizeCv_.wait_for(cvLock, std::chrono::milliseconds(DBConstant::MIN_TIMEOUT), [this]() { return engineFinalize_; }); if (!engineFinalize) { @@ -414,10 +413,8 @@ int GenericSyncer::InitSyncEngine(ISyncInterface *syncInterface) return E_OK; } else { LOGE("[Syncer] SyncEngine init failed! err:%d.", errCode); - if (syncEngine_ != nullptr) { - RefObject::KillAndDecObjRef(syncEngine_); - syncEngine_ = nullptr; - } + RefObject::KillAndDecObjRef(syncEngine_); + syncEngine_ = nullptr; return errCode; } } @@ -821,7 +818,10 @@ int GenericSyncer::BuildSyncEngine() } syncEngine_->OnLastRef([this]() { LOGD("[Syncer] SyncEngine finalized"); - engineFinalize_ = true; + { + std::lock_guard cvLock(engineMutex_); + engineFinalize_ = true; + } engineFinalizeCv_.notify_all(); }); return E_OK; diff --git a/frameworks/libs/distributeddb/syncer/src/generic_syncer.h b/frameworks/libs/distributeddb/syncer/src/generic_syncer.h index 48e2ecfa67c..a5779c4162d 100644 --- a/frameworks/libs/distributeddb/syncer/src/generic_syncer.h +++ b/frameworks/libs/distributeddb/syncer/src/generic_syncer.h @@ -206,6 +206,7 @@ protected: mutable std::mutex queuedManualSyncLock_; mutable std::mutex syncerLock_; std::string label_; + std::mutex engineMutex_; bool engineFinalize_; std::condition_variable engineFinalizeCv_; diff --git a/frameworks/libs/distributeddb/syncer/src/multi_ver_data_sync.cpp b/frameworks/libs/distributeddb/syncer/src/multi_ver_data_sync.cpp index 9bc8c84f7d5..281113f7469 100644 --- a/frameworks/libs/distributeddb/syncer/src/multi_ver_data_sync.cpp +++ b/frameworks/libs/distributeddb/syncer/src/multi_ver_data_sync.cpp @@ -271,7 +271,7 @@ int MultiVerDataSync::AckRecvCallback(MultiVerSyncTaskContext *context, const Me MultiVerKvEntry *entry = nullptr; packet->GetData(dataEntries); - for (auto &iter : dataEntries) { + for (const auto &iter : dataEntries) { MultiVerKvEntry *item = CreateKvEntry(iter); entries.push_back(item); } diff --git a/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp b/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp index 01964a65079..1d95aec8fde 100644 --- a/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp +++ b/frameworks/libs/distributeddb/syncer/src/query_sync_water_mark_helper.cpp @@ -503,7 +503,7 @@ int QuerySyncWaterMarkHelper::RemoveLeastUsedQuerySyncItems(const std::vector &w1, std::pair &w2) { + [](const std::pair &w1, const std::pair &w2) { return w1.second < w2.second; }); for (uint32_t i = 0; i < removeCount; ++i) { diff --git a/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp b/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp index cac8600fb7b..d3b22993e2a 100644 --- a/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp +++ b/frameworks/libs/distributeddb/syncer/src/remote_executor.cpp @@ -123,7 +123,7 @@ void RemoteExecutor::NotifyDeviceOffline(const std::string &device) LOGD("[RemoteExecutor][NotifyDeviceOffline] device=%s{private} offline", device.c_str()); std::vector removeList; RemoveTaskByDevice(device, removeList); - for (auto &sessionId : removeList) { + for (const auto &sessionId : removeList) { DoFinished(sessionId, -E_PERIPHERAL_INTERFACE_FAIL); } } @@ -158,7 +158,7 @@ void RemoteExecutor::NotifyConnectionClosed(uint64_t connectionId) } std::vector removeList; RemoveTaskByConnection(connectionId, removeList); - for (auto &sessionId : removeList) { + for (const auto &sessionId : removeList) { DoFinished(sessionId, -E_BUSY); } } @@ -854,10 +854,10 @@ void RemoteExecutor::RemoveAllTask(int errCode) deviceWorkingSet_.clear(); searchTaskQueue_.clear(); } - for (auto &callBack : waitToNotify) { + for (const auto &callBack : waitToNotify) { callBack(errCode, nullptr); } - for (auto &sessionId : removeTimerList) { + for (const auto &sessionId : removeTimerList) { RemoveTimer(sessionId); } std::lock_guard autoLock(timeoutLock_); diff --git a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_data_operation_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_data_operation_test.cpp index a664c0bbe6d..a1e219cf153 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_data_operation_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_data_operation_test.cpp @@ -1729,7 +1729,7 @@ HWTEST_F(DistributedDBInterfacesDataOperationTest, PreifxAndOrderBy001, TestSize EXPECT_EQ(entriesRes[4].key, KEY_2); Query query1 = Query::Select().OrderBy("$.field_name1", false); - errCode = g_kvNbDelegatePtrForQuery->GetEntries(query1, entriesRes); + (void) g_kvNbDelegatePtrForQuery->GetEntries(query1, entriesRes); ASSERT_EQ(entriesRes.size(), 5ul); EXPECT_EQ(entriesRes[0].key, KEY_5); EXPECT_EQ(entriesRes[1].key, KEY_4); @@ -1738,7 +1738,7 @@ HWTEST_F(DistributedDBInterfacesDataOperationTest, PreifxAndOrderBy001, TestSize EXPECT_EQ(entriesRes[4].key, KEY_1); Query query2 = Query::Select().PrefixKey({}).OrderBy("$.field_name1", false).OrderBy("$.field_name2", false); - errCode = g_kvNbDelegatePtrForQuery->GetEntries(query2, entriesRes); + (void) g_kvNbDelegatePtrForQuery->GetEntries(query2, entriesRes); ASSERT_EQ(entriesRes.size(), 5ul); EXPECT_EQ(entriesRes[0].key, KEY_5); EXPECT_EQ(entriesRes[1].key, KEY_4); diff --git a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_database_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_database_test.cpp index 95b076c2475..e2916b7481e 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_database_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_database_test.cpp @@ -166,7 +166,7 @@ namespace { EXPECT_TRUE(g_mgr.DeleteKvStore(storeId) == OK); } - void OpenClosedSchemaKvStore(const std::string &storeId, bool isEncrypt, std::string &inSchema) + void OpenClosedSchemaKvStore(const std::string &storeId, bool isEncrypt, const std::string &inSchema) { /** * @tc.steps: step1. create a new db(non-memory), with input schema; diff --git a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_import_and_export_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_import_and_export_test.cpp index 552c2f4f925..1f535f64ac7 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_import_and_export_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_import_and_export_test.cpp @@ -293,6 +293,7 @@ HWTEST_F(DistributedDBInterfacesImportAndExportTest, UndisturbedlMultiExport001, KvStoreSnapshotDelegate *snapshotDelegatePtr = nullptr; GetSnapshotUnitTest(g_kvDelegatePtr, snapshotDelegatePtr); + ASSERT_TRUE(snapshotDelegatePtr != nullptr); /** * @tc.steps: step5. Check whether the imported data is the preset content in step 1. @@ -313,10 +314,8 @@ HWTEST_F(DistributedDBInterfacesImportAndExportTest, UndisturbedlMultiExport001, snapshotDelegatePtr->Get(KEY_5, g_valueCallback); EXPECT_EQ(g_valueStatus, NOT_FOUND); - if (g_kvDelegatePtr != nullptr && snapshotDelegatePtr != nullptr) { - EXPECT_TRUE(g_kvDelegatePtr->ReleaseKvStoreSnapshot(snapshotDelegatePtr) == OK); - snapshotDelegatePtr = nullptr; - } + EXPECT_TRUE(g_kvDelegatePtr->ReleaseKvStoreSnapshot(snapshotDelegatePtr) == OK); + snapshotDelegatePtr = nullptr; EXPECT_EQ(g_mgr.CloseKvStore(g_kvDelegatePtr), OK); EXPECT_EQ(g_mgr.DeleteKvStore(multiStoreId), OK); @@ -451,15 +450,14 @@ HWTEST_F(DistributedDBInterfacesImportAndExportTest, ExportParameterCheck002, Te KvStoreSnapshotDelegate *snapshotDelegatePtr = nullptr; GetSnapshotUnitTest(g_kvDelegatePtr, snapshotDelegatePtr); + ASSERT_TRUE(snapshotDelegatePtr != nullptr); snapshotDelegatePtr->Get(KEY_1, g_valueCallback); EXPECT_EQ(g_valueStatus, OK); EXPECT_EQ(g_value, VALUE_1); - if (g_kvDelegatePtr != nullptr && snapshotDelegatePtr != nullptr) { - EXPECT_TRUE(g_kvDelegatePtr->ReleaseKvStoreSnapshot(snapshotDelegatePtr) == OK); - snapshotDelegatePtr = nullptr; - } + EXPECT_TRUE(g_kvDelegatePtr->ReleaseKvStoreSnapshot(snapshotDelegatePtr) == OK); + snapshotDelegatePtr = nullptr; EXPECT_EQ(g_mgr.CloseKvStore(g_kvDelegatePtr), OK); EXPECT_EQ(g_mgr.DeleteKvStore(multiStoreId), OK); @@ -570,6 +568,7 @@ HWTEST_F(DistributedDBInterfacesImportAndExportTest, NormalImport002, TestSize.L KvStoreSnapshotDelegate *snapshotDelegatePtr = nullptr; GetSnapshotUnitTest(g_kvDelegatePtr, snapshotDelegatePtr); + ASSERT_TRUE(snapshotDelegatePtr != nullptr); /** * @tc.steps: step4. Check whether the data is the same as the backup database. @@ -579,10 +578,8 @@ HWTEST_F(DistributedDBInterfacesImportAndExportTest, NormalImport002, TestSize.L EXPECT_EQ(g_valueStatus, OK); EXPECT_EQ(g_value, VALUE_1); - if (g_kvDelegatePtr != nullptr && snapshotDelegatePtr != nullptr) { - EXPECT_TRUE(g_kvDelegatePtr->ReleaseKvStoreSnapshot(snapshotDelegatePtr) == OK); - snapshotDelegatePtr = nullptr; - } + EXPECT_TRUE(g_kvDelegatePtr->ReleaseKvStoreSnapshot(snapshotDelegatePtr) == OK); + snapshotDelegatePtr = nullptr; // clear resource g_junkFilesList.push_back(multiExportFileName); diff --git a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_index_unit_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_index_unit_test.cpp index 895eb2f2765..0533afbaa4b 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_index_unit_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_index_unit_test.cpp @@ -139,7 +139,7 @@ namespace { bool hasIndex, bool hasSkipSize) { string result = "{\"SCHEMA_VERSION\":\"1.0\",\"SCHEMA_MODE\":\"STRICT\",\"SCHEMA_DEFINE\":{"; - for (auto &entry : define) { + for (const auto &entry : define) { string defineStr = GenerateEachSchemaDefine(entry); result += defineStr; result += ","; @@ -177,7 +177,7 @@ namespace { int intValue = 0; string result(skipSize, '*'); result += "{"; - for (auto &entry : define) { + for (const auto &entry : define) { string defineStr = GenerateValueItem(entry, intValue++); result += defineStr; result += ","; @@ -233,7 +233,7 @@ namespace { inline void CheckIndexFromDbFile(sqlite3 *db, const vector &indexToCheck, int expectCount) { - for (auto &str : indexToCheck) { + for (const auto &str : indexToCheck) { string querySeq = SQL_QUERY_INDEX + "'" + str + "'"; int count = -1; EXPECT_EQ(sqlite3_exec(db, querySeq.c_str(), CallbackReturnCount, &count, nullptr), SQLITE_OK); @@ -625,7 +625,6 @@ HWTEST_F(DistributedDBInterfacesIndexUnitTest, CheckSchemaSkipsize001, TestSize. { PrepareInfoForCheckSchemaSkipsize001(); string storeId = "CheckSchemaSkipsize001"; - string filePath = GetKvStoreDirectory(storeId, DBConstant::DB_TYPE_SINGLE_VER); KvStoreNbDelegate::Option option = {true, false, false}; /** * @tc.steps:step1. Specify an undefined skipsize schema to open the schema database. @@ -666,7 +665,6 @@ HWTEST_F(DistributedDBInterfacesIndexUnitTest, CheckSchemaSkipsize002, TestSize. { PrepareCommonInfo(false); string storeId = "CheckSchemaSkipsize002"; - string filePath = GetKvStoreDirectory(storeId, DBConstant::DB_TYPE_SINGLE_VER); KvStoreNbDelegate::Option option = {true, false, false}; /** * @tc.steps:step1. Set "SCHEMA_SKIPSIZE" in the schema as -1 to create the schema database. @@ -749,7 +747,6 @@ HWTEST_F(DistributedDBInterfacesIndexUnitTest, CheckSchemaSkipsize003, TestSize. { PrepareInfoForCheckSchemaSkipsize003(); string storeId = "CheckSchemaSkipsize003"; - string filePath = GetKvStoreDirectory(storeId, DBConstant::DB_TYPE_SINGLE_VER); KvStoreNbDelegate::Option option = {true, false, false}; /** * @tc.steps:step1. Set "SCHEMA_SKIPSIZE" in the schema as 20 to create the schema database. @@ -792,7 +789,6 @@ HWTEST_F(DistributedDBInterfacesIndexUnitTest, SchemaCompareSkipsize004, TestSiz { PrepareCommonInfo(false); string storeId = "SchemaCompareSkipsize004"; - string filePath = GetKvStoreDirectory(storeId, DBConstant::DB_TYPE_SINGLE_VER); KvStoreNbDelegate::Option option = {true, false, false}; /** * @tc.steps:step1. Set "SCHEMA_SKIPSIZE" in the schema as 0 to create the schema database. -- Gitee