From f7f899161a15217e02852082321b21b7a5c4d291 Mon Sep 17 00:00:00 2001 From: zWang64 <996104054@qq.com> Date: Wed, 12 Feb 2025 17:47:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A0=BC=E5=BC=8F=E5=92=8Cpr?= =?UTF-8?q?int?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zWang64 <996104054@qq.com> --- frameworks/libs/distributeddb/BUILD.gn | 12 ++------ .../src/cloud/assets_download_manager.cpp | 2 +- .../distributeddb/common/src/log_print.cpp | 14 ++++----- .../src/common/include/rd_log_print.h | 12 ++++---- .../src/common/src/rd_log_print.cpp | 30 +++++++++++-------- .../relational/relational_store_delegate.h | 5 +++- ...terfaces_relational_tracker_table_test.cpp | 11 +++---- .../distributeddb_cloud_check_sync_test.cpp | 4 +-- ...stributeddb_cloud_save_cloud_data_test.cpp | 3 +- .../distributeddb_rdb_collaboration_test.cpp | 12 ++++---- ...relational_cloud_syncable_storage_test.cpp | 5 ++-- ...teddb_cloud_async_download_assets_test.cpp | 2 +- ...buteddb_single_ver_p2p_query_sync_test.cpp | 2 +- 13 files changed, 60 insertions(+), 54 deletions(-) diff --git a/frameworks/libs/distributeddb/BUILD.gn b/frameworks/libs/distributeddb/BUILD.gn index 4fb4f009fef..da27de4597d 100644 --- a/frameworks/libs/distributeddb/BUILD.gn +++ b/frameworks/libs/distributeddb/BUILD.gn @@ -145,16 +145,12 @@ config("tokenizer_config") { "$tokenizer_path/sqlite_adapter/include", "$tokenizer_path/sqlite_adapter/src", ] - defines = [ - "HARMONY_OS", - ] + defines = [ "HARMONY_OS" ] } config("tokenizer_public_config") { visibility = [ ":*" ] - include_dirs = [ - "$tokenizer_path/sqlite_adapter/include", - ] + include_dirs = [ "$tokenizer_path/sqlite_adapter/include" ] } ohos_shared_library("customtokenizer") { @@ -185,9 +181,7 @@ ohos_shared_library("customtokenizer") { "hilog:libhilog", ] - public_external_deps = [ - "sqlite:sqlite", - ] + public_external_deps = [ "sqlite:sqlite" ] subsystem_name = "distributeddatamgr" innerapi_tags = [ "platformsdk_indirect" ] diff --git a/frameworks/libs/distributeddb/common/src/cloud/assets_download_manager.cpp b/frameworks/libs/distributeddb/common/src/cloud/assets_download_manager.cpp index 103a22bcd9a..1f3ad794474 100644 --- a/frameworks/libs/distributeddb/common/src/cloud/assets_download_manager.cpp +++ b/frameworks/libs/distributeddb/common/src/cloud/assets_download_manager.cpp @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "assets_download_manager.h" +#include "cloud/assets_download_manager.h" #include "cloud/cloud_db_constant.h" #include "db_errno.h" diff --git a/frameworks/libs/distributeddb/common/src/log_print.cpp b/frameworks/libs/distributeddb/common/src/log_print.cpp index 92a014de32a..372ea9b8ffb 100644 --- a/frameworks/libs/distributeddb/common/src/log_print.cpp +++ b/frameworks/libs/distributeddb/common/src/log_print.cpp @@ -36,26 +36,26 @@ public: return; } #ifdef DB_DEBUG_ENV - const std::string format = "%s"; +#define FORMAT "%s" #else - const std::string format = "%{public}s"; +#define FORMAT "%{public}s" #endif OHOS::HiviewDFX::HiLogLabel label = { LOG_CORE, 0xD001630, tag.c_str() }; // log module id. switch (level) { case Level::LEVEL_DEBUG: - (void)OHOS::HiviewDFX::HiLog::Debug(label, format.c_str(), msg.c_str()); + (void)HILOG_IMPL(label.type, LOG_DEBUG, label.domain, label.tag, FORMAT, msg.c_str()); break; case Level::LEVEL_INFO: - (void)OHOS::HiviewDFX::HiLog::Info(label, format.c_str(), msg.c_str()); + (void)HILOG_IMPL(label.type, LOG_INFO, label.domain, label.tag, FORMAT, msg.c_str()); break; case Level::LEVEL_WARN: - (void)OHOS::HiviewDFX::HiLog::Warn(label, format.c_str(), msg.c_str()); + (void)HILOG_IMPL(label.type, LOG_WARN, label.domain, label.tag, FORMAT, msg.c_str()); break; case Level::LEVEL_ERROR: - (void)OHOS::HiviewDFX::HiLog::Error(label, format.c_str(), msg.c_str()); + (void)HILOG_IMPL(label.type, LOG_ERROR, label.domain, label.tag, FORMAT, msg.c_str()); break; case Level::LEVEL_FATAL: - (void)OHOS::HiviewDFX::HiLog::Fatal(label, format.c_str(), msg.c_str()); + (void)HILOG_IMPL(label.type, LOG_FATAL, label.domain, label.tag, FORMAT, msg.c_str()); break; default: break; diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/rd_log_print.h b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/rd_log_print.h index 3e092f7ee06..d46e17d2a65 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/rd_log_print.h +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/common/include/rd_log_print.h @@ -21,7 +21,7 @@ namespace DocumentDB { constexpr const char *LOG_TAG_DOC = "GAUSSDB_RD"; -class RdLogPrint { +class LogPrint { public: enum class Level { LEVEL_DEBUG, @@ -36,9 +36,9 @@ public: } // namespace DocumentDB #define NO_LOG(...) // No log in normal and release. Used for the convenience when deep debugging -#define GLOGD(...) RdLogPrint::Log(RdLogPrint::Level::LEVEL_DEBUG, LOG_TAG_DOC, __VA_ARGS__) -#define GLOGI(...) RdLogPrint::Log(RdLogPrint::Level::LEVEL_INFO, LOG_TAG_DOC, __VA_ARGS__) -#define GLOGW(...) RdLogPrint::Log(RdLogPrint::Level::LEVEL_WARN, LOG_TAG_DOC, __VA_ARGS__) -#define GLOGE(...) RdLogPrint::Log(RdLogPrint::Level::LEVEL_ERROR, LOG_TAG_DOC, __VA_ARGS__) -#define GLOGF(...) RdLogPrint::Log(RdLogPrint::Level::LEVEL_FATAL, LOG_TAG_DOC, __VA_ARGS__) +#define GLOGD(...) LogPrint::Log(LogPrint::Level::LEVEL_DEBUG, LOG_TAG_DOC, __VA_ARGS__) +#define GLOGI(...) LogPrint::Log(LogPrint::Level::LEVEL_INFO, LOG_TAG_DOC, __VA_ARGS__) +#define GLOGW(...) LogPrint::Log(LogPrint::Level::LEVEL_WARN, LOG_TAG_DOC, __VA_ARGS__) +#define GLOGE(...) LogPrint::Log(LogPrint::Level::LEVEL_ERROR, LOG_TAG_DOC, __VA_ARGS__) +#define GLOGF(...) LogPrint::Log(LogPrint::Level::LEVEL_FATAL, LOG_TAG_DOC, __VA_ARGS__) #endif // LOG_PRINT_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/rd_log_print.cpp b/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/rd_log_print.cpp index 993880acdac..a78fba4d331 100644 --- a/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/rd_log_print.cpp +++ b/frameworks/libs/distributeddb/gaussdb_rd/src/common/src/rd_log_print.cpp @@ -20,28 +20,32 @@ namespace DocumentDB { namespace { -void PrintLog(RdLogPrint::Level level, const char *tag, const std::string &msg) +void PrintLog(LogPrint::Level level, const char *tag, const std::string &msg) { if (msg.empty()) { return; } - const std::string format = "%{public}s"; +#ifdef DB_DEBUG_ENV +#define FORMAT "%s" +#else +#define FORMAT "%{public}s" +#endif OHOS::HiviewDFX::HiLogLabel label = { LOG_CORE, 0xD001631, tag }; // 0xD001631 is identity of the log switch (level) { - case RdLogPrint::Level::LEVEL_DEBUG: - (void)OHOS::HiviewDFX::HiLog::Debug(label, format.c_str(), msg.c_str()); + case LogPrint::Level::LEVEL_DEBUG: + (void)HILOG_IMPL(label.type, LOG_DEBUG, label.domain, label.tag, FORMAT, msg.c_str()); break; - case RdLogPrint::Level::LEVEL_INFO: - (void)OHOS::HiviewDFX::HiLog::Info(label, format.c_str(), msg.c_str()); + case LogPrint::Level::LEVEL_INFO: + (void)HILOG_IMPL(label.type, LOG_INFO, label.domain, label.tag, FORMAT, msg.c_str()); break; - case RdLogPrint::Level::LEVEL_WARN: - (void)OHOS::HiviewDFX::HiLog::Warn(label, format.c_str(), msg.c_str()); + case LogPrint::Level::LEVEL_WARN: + (void)HILOG_IMPL(label.type, LOG_WARN, label.domain, label.tag, FORMAT, msg.c_str()); break; - case RdLogPrint::Level::LEVEL_ERROR: - (void)OHOS::HiviewDFX::HiLog::Error(label, format.c_str(), msg.c_str()); + case LogPrint::Level::LEVEL_ERROR: + (void)HILOG_IMPL(label.type, LOG_ERROR, label.domain, label.tag, FORMAT, msg.c_str()); break; - case RdLogPrint::Level::LEVEL_FATAL: - (void)OHOS::HiviewDFX::HiLog::Fatal(label, format.c_str(), msg.c_str()); + case LogPrint::Level::LEVEL_FATAL: + (void)HILOG_IMPL(label.type, LOG_FATAL, label.domain, label.tag, FORMAT, msg.c_str()); break; default: break; @@ -59,7 +63,7 @@ void PreparePrivateLog(const char *format, std::string &outStrFormat) } } // namespace -void RdLogPrint::Log(Level level, const char *tag, const char *format, ...) +void LogPrint::Log(Level level, const char *tag, const char *format, ...) { static const int maxLogLength = 1024; diff --git a/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_delegate.h b/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_delegate.h index 737a0ba4d13..3e9e4578866 100644 --- a/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_delegate.h +++ b/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_delegate.h @@ -146,7 +146,10 @@ public: return OK; } - DB_API virtual std::pair GetDownloadingAssetsCount() = 0; + DB_API virtual std::pair GetDownloadingAssetsCount() + { + return {OK, 0}; + } protected: virtual DBStatus RemoveDeviceDataInner(const std::string &device, ClearMode mode) = 0; virtual DBStatus CreateDistributedTableInner(const std::string &tableName, TableSyncType type) = 0; diff --git a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_relational_tracker_table_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_relational_tracker_table_test.cpp index 2008b93561c..464199aa86a 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_relational_tracker_table_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_relational_tracker_table_test.cpp @@ -142,8 +142,9 @@ namespace { void CheckExtendAndCursor(uint64_t num, int start, const std::string &tableName, bool addNum = true) { int index = 0; - string querySql = "select json_extract(extend_field, '$.name'), cursor from " + std::string(DBConstant::RELATIONAL_PREFIX) + tableName + - "_log" + " where data_key <= " + std::to_string(num); + string querySql = "select json_extract(extend_field, '$.name'), cursor from " + + std::string(DBConstant::RELATIONAL_PREFIX) + tableName + "_log" + + " where data_key <= " + std::to_string(num); sqlite3_stmt *stmt = nullptr; EXPECT_EQ(SQLiteUtils::GetStatement(g_db, querySql, stmt), E_OK); while (SQLiteUtils::StepWithRetry(stmt) == SQLiteUtils::MapSQLiteErrno(SQLITE_ROW)) { @@ -1844,7 +1845,7 @@ HWTEST_F(DistributedDBInterfacesRelationalTrackerTableTest, ExecuteSql011, TestS * @tc.steps:step2. ExecuteSql concurrently * @tc.expected: step2. Return OK. */ - std::thread readThread([&](){ + std::thread readThread([&]() { SqlCondition condition; std::vector records; condition.readOnly = true; @@ -1853,7 +1854,7 @@ HWTEST_F(DistributedDBInterfacesRelationalTrackerTableTest, ExecuteSql011, TestS EXPECT_EQ(g_delegate->ExecuteSql(condition, records), OK); } }); - std::thread transactionThread([&](){ + std::thread transactionThread([&]() { SqlCondition condition; condition.readOnly = true; std::vector records; @@ -2665,7 +2666,7 @@ HWTEST_F(DistributedDBInterfacesRelationalTrackerTableTest, SchemaStrTest001, Te /** * @tc.name: TrackerTableTest041 - * @tc.desc: Test cursor increases when set tracker table after create distributed table by DEVICE_COOPERATION type + * @tc.desc: Test cursor increases when set tracker table after create distributed table by DEVICE_COOPERATION type * @tc.type: FUNC * @tc.require: * @tc.author: suyue diff --git a/frameworks/libs/distributeddb/test/unittest/common/storage/cloud/distributeddb_cloud_check_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/storage/cloud/distributeddb_cloud_check_sync_test.cpp index efe57233582..c101c79b2cd 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/storage/cloud/distributeddb_cloud_check_sync_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/storage/cloud/distributeddb_cloud_check_sync_test.cpp @@ -1043,7 +1043,7 @@ HWTEST_F(DistributedDBCloudCheckSyncTest, CloudSyncTest008, TestSize.Level0) /** * @tc.name: CloudSyncTest009 - * @tc.desc: reopen database and sync + * @tc.desc: reopen database and sync * @tc.type: FUNC * @tc.require: * @tc.author: wangxiangdong @@ -1097,7 +1097,7 @@ HWTEST_F(DistributedDBCloudCheckSyncTest, CloudSyncTest009, TestSize.Level0) /** * @tc.name: CloudSyncTest010 - * @tc.desc: reopen database, recreate table with less columns and sync + * @tc.desc: reopen database, recreate table with less columns and sync * @tc.type: FUNC * @tc.require: * @tc.author: wangxiangdong diff --git a/frameworks/libs/distributeddb/test/unittest/common/storage/cloud/distributeddb_cloud_save_cloud_data_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/storage/cloud/distributeddb_cloud_save_cloud_data_test.cpp index 8f076089297..4c90e12d2a5 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/storage/cloud/distributeddb_cloud_save_cloud_data_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/storage/cloud/distributeddb_cloud_save_cloud_data_test.cpp @@ -283,7 +283,8 @@ namespace { vBucket[CloudDbConstant::GID_FIELD] = gidStr; DataInfoWithLog dataInfoWithLog; VBucket assetInfo; - EXPECT_EQ(storageProxy->GetInfoByPrimaryKeyOrGid(g_tableName, vBucket, true, dataInfoWithLog, assetInfo), expectCode); + EXPECT_EQ( + storageProxy->GetInfoByPrimaryKeyOrGid(g_tableName, vBucket, true, dataInfoWithLog, assetInfo), expectCode); if (expectCode == E_OK) { if (pkType == PrimaryKeyType::SINGLE_PRIMARY_KEY) { int64_t val = -1; diff --git a/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp index f7dfc105f17..2b1b7ed9f75 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp @@ -424,7 +424,8 @@ HWTEST_F(DistributedDBRDBCollaborationTest, SetSchema006, TestSize.Level0) UnRegisterClientObserver(db_); } -std::string GetTriggerSql(const std::string &tableName, const std::string &triggerTypeName, sqlite3 *db) { +std::string GetTriggerSql(const std::string &tableName, const std::string &triggerTypeName, sqlite3 *db) +{ if (db == nullptr) { return ""; } @@ -748,8 +749,9 @@ HWTEST_F(DistributedDBRDBCollaborationTest, SetSchema015, TestSize.Level0) * @tc.expected: step1.ok */ ASSERT_NO_FATAL_FAILURE(InitDelegate(DistributedTableMode::COLLABORATION)); - std::string createSql = "CREATE TABLE IF NOT EXISTS table_pk_int(integer_field INTEGER PRIMARY KEY AUTOINCREMENT," - "int_field INT, char_field CHARACTER(20) UNIQUE, clob_field CLOB UNIQUE, UNIQUE(char_field, clob_field));"; + std::string createSql = + "CREATE TABLE IF NOT EXISTS table_pk_int(integer_field INTEGER PRIMARY KEY AUTOINCREMENT," + "int_field INT, char_field CHARACTER(20) UNIQUE, clob_field CLOB UNIQUE, UNIQUE(char_field, clob_field));"; ASSERT_EQ(SQLiteUtils::ExecuteRawSQL(db_, createSql), E_OK); EXPECT_EQ(delegate_->CreateDistributedTable("table_pk_int", TableSyncType::DEVICE_COOPERATION), OK); @@ -800,7 +802,8 @@ HWTEST_F(DistributedDBRDBCollaborationTest, SetSchema016, TestSize.Level0) EXPECT_EQ(delegate_->SetDistributedSchema(schema2), SCHEMA_MISMATCH); } -int GetHashKey(sqlite3 *db, const std::string &tableName, std::vector &hashKeys) { +int GetHashKey(sqlite3 *db, const std::string &tableName, std::vector &hashKeys) +{ if (db == nullptr) { return -E_INVALID_DB; } @@ -960,7 +963,6 @@ HWTEST_F(DistributedDBRDBCollaborationTest, SetSchema019, TestSize.Level0) */ HWTEST_F(DistributedDBRDBCollaborationTest, SetSchema020, TestSize.Level0) { - /** * @tc.steps: step1. Prepare db, tableMode is COLLABORATION * @tc.expected: step1.ok diff --git a/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_relational_cloud_syncable_storage_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_relational_cloud_syncable_storage_test.cpp index 8c560037886..c03d95772f7 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_relational_cloud_syncable_storage_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_relational_cloud_syncable_storage_test.cpp @@ -731,7 +731,7 @@ HWTEST_F(DistributedDBRelationalCloudSyncableStorageTest, GetUploadCount004, Tes */ std::thread getUploadCountThread([&]() { for (int i = 0; i < 100; i++) { - if(g_storageProxy->StartTransaction() == E_OK) { + if (g_storageProxy->StartTransaction() == E_OK) { EXPECT_EQ(g_storageProxy->GetUploadCount(g_tableName, g_startTime, false, resCount), E_OK); EXPECT_EQ(resCount, insCount); EXPECT_EQ(g_storageProxy->Commit(), E_OK); @@ -1626,7 +1626,8 @@ HWTEST_F(DistributedDBRelationalCloudSyncableStorageTest, getAsset002, TestSize. gid = "11"; pk = "1"; hashKey.assign(pk.begin(), pk.end()); - EXPECT_EQ(g_storageProxy->GetAssetsByGidOrHashKey(g_tableName, false, gid, hashKey, assets).first, -E_CLOUD_GID_MISMATCH); + EXPECT_EQ( + g_storageProxy->GetAssetsByGidOrHashKey(g_tableName, false, gid, hashKey, assets).first, -E_CLOUD_GID_MISMATCH); CheckGetAsset(assets, static_cast(AssetStatus::NORMAL)); /** diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_async_download_assets_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_async_download_assets_test.cpp index 20526f79a29..8f5fe9d40af 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_async_download_assets_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_async_download_assets_test.cpp @@ -35,7 +35,7 @@ using namespace std; namespace { string g_testDir; -const std::string QUERY_INCONSISTENT_SQL = +const std::string QUERY_INCONSISTENT_SQL = "select count(*) from naturalbase_rdb_aux_AsyncDownloadAssetsTest_log where flag&0x20!=0;"; IRelationalStore *g_store = nullptr; ICloudSyncStorageHook *g_cloudStoreHook = 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 6c5e788df4f..9d35a56d63c 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 @@ -1182,7 +1182,7 @@ HWTEST_F(DistributedDBSingleVerP2PQuerySyncTest, GetQueryLastTimestamp002, TestS ASSERT_EQ(errCode, E_OK); for (auto &pair : idValueMap) { auto &queryId = pair.first; - auto &expectVal = pair.second.second; + auto &expectVal = pair.second.second; EXPECT_EQ(meta.GetQueryLastTimestamp("any", queryId), static_cast(expectVal)); } } -- Gitee