From 91c00500efe378fd52d47c5c1ba4740ab12c14c0 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Tue, 29 Aug 2023 14:02:58 +0800 Subject: [PATCH] refactor:Split test cases Signed-off-by: htt1997 --- CMakeLists.txt | 2 +- data_object/CMakeLists.txt | 5 +- .../src/errorcode_test.cpp | 12 +- .../mediadatashare_test/src/join_test.cpp | 17 +- .../src/mediadatashare_unit_test.cpp | 14 +- .../src/slientaccess_test.cpp | 14 +- .../adapter/CMakeLists.txt | 14 +- .../distributeddataservice/app/CMakeLists.txt | 11 - .../app/src/kvstore_data_service.cpp | 2 + .../framework/CMakeLists.txt | 4 +- .../framework/include/store/auto_cache.h | 2 - .../framework/store/auto_cache.cpp | 40 +++- .../service/CMakeLists.txt | 8 +- .../service/cloud/GetSchema.puml | 35 --- .../service/cloud/sync_manager.cpp | 6 +- .../service/rdb/rdb_service_impl.cpp | 3 - .../service/test/cloud_data_test.cpp | 203 +++++++++++------- .../service/test/mock/adapter_mock.cpp | 56 +++++ .../service/test/mock/cloud_server_mock.cpp | 37 ++++ .../service/test/mock/cloud_server_mock.h | 24 +++ .../service/test/mock/db_store_mock.cpp | 7 + .../service/test/mock/db_store_mock.h | 1 + .../service/test/mock/general_store_mock.cpp | 97 +++++++++ .../service/test/mock/general_store_mock.h | 57 +++++ kv_store/frameworks/CMakeLists.txt | 26 +-- kv_store/frameworks/libs/CMakeLists.txt | 14 +- .../include/extension_ability_info.h | 15 +- mock/src/mock_access_token.cpp | 4 + .../native/unittest/preferences_file_test.cpp | 2 +- .../unittest/preferences_xml_utils_test.cpp | 2 +- relational_store/CMakeLists.txt | 2 +- .../native/rdb/src/rdb_store_impl.cpp | 2 +- .../rdb/unittest/rdb_open_callback_test.cpp | 1 + .../rdb/unittest/rdb_store_config_test.cpp | 1 + test/CMakeLists.txt | 137 +++++++++--- test/test_main.cpp | 3 +- 36 files changed, 638 insertions(+), 242 deletions(-) delete mode 100644 datamgr_service/services/distributeddataservice/service/cloud/GetSchema.puml create mode 100644 datamgr_service/services/distributeddataservice/service/test/mock/adapter_mock.cpp create mode 100644 datamgr_service/services/distributeddataservice/service/test/mock/cloud_server_mock.cpp create mode 100644 datamgr_service/services/distributeddataservice/service/test/mock/cloud_server_mock.h create mode 100644 datamgr_service/services/distributeddataservice/service/test/mock/general_store_mock.cpp create mode 100644 datamgr_service/services/distributeddataservice/service/test/mock/general_store_mock.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a010461..1784ebef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ set(CMAKE_CXX_FLAGS "-std=c++1y -fno-rtti -fvisibility=default -D_GNU_SOURCE") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -fPIC -fpic -ffunction-sections -D_GLIBC_MOCK") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--no-as-needed -ldl") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare -Wimplicit-fallthrough") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=0") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=0 -Wattributes") add_subdirectory(googletest) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/utils_native/base/include) diff --git a/data_object/CMakeLists.txt b/data_object/CMakeLists.txt index a6f21894..bdbc4ee1 100644 --- a/data_object/CMakeLists.txt +++ b/data_object/CMakeLists.txt @@ -23,7 +23,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/frameworks/innerkitsimpl/include include_directories(${CMAKE_CURRENT_SOURCE_DIR}/frameworks/innerkitsimpl/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/frameworks/jskitsimpl/include/adaptor ) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/frameworks/jskitsimpl/include/common ) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/interfaces/innerkits) + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/adapter/include/dfx) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../utils_native/base/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../utils_native/safwk/native/include) @@ -32,4 +32,5 @@ include(${KV_STORE_DIR}/interfaces/CMakeLists.txt OPTIONAL) set(links secure mock adapter distributeddb kvdb) add_library(data_object SHARED ${data_object_src}) -target_link_libraries(data_object ${links}) \ No newline at end of file +target_link_libraries(data_object ${links}) +target_include_directories(data_object PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/innerkits) \ No newline at end of file diff --git a/data_share/test/native/unittest/mediadatashare_test/src/errorcode_test.cpp b/data_share/test/native/unittest/mediadatashare_test/src/errorcode_test.cpp index a5402f36..168c40e1 100644 --- a/data_share/test/native/unittest/mediadatashare_test/src/errorcode_test.cpp +++ b/data_share/test/native/unittest/mediadatashare_test/src/errorcode_test.cpp @@ -28,12 +28,12 @@ namespace DataShare { using namespace testing::ext; using namespace OHOS::Security::AccessToken; constexpr int STORAGE_MANAGER_MANAGER_ID = 5003; -std::string DATA_SHARE_URI = "datashare:///com.acts.errorcodetest"; -std::string SLIENT_ACCESS_URI = "datashare:///com.acts.errorcodetest/entry/DB00/TBL00?Proxy=true"; -std::string TBL_STU_NAME = "name"; -std::string TBL_STU_AGE = "age"; -std::shared_ptr g_slientAccessHelper; -std::shared_ptr dataShareHelper; +static std::string DATA_SHARE_URI = "datashare:///com.acts.errorcodetest"; +static std::string SLIENT_ACCESS_URI = "datashare:///com.acts.errorcodetest/entry/DB00/TBL00?Proxy=true"; +static std::string TBL_STU_NAME = "name"; +static std::string TBL_STU_AGE = "age"; +static std::shared_ptr g_slientAccessHelper; +static std::shared_ptr dataShareHelper; class ErrorCodeTest : public testing::Test { public: diff --git a/data_share/test/native/unittest/mediadatashare_test/src/join_test.cpp b/data_share/test/native/unittest/mediadatashare_test/src/join_test.cpp index 20015ea1..b3c59e69 100644 --- a/data_share/test/native/unittest/mediadatashare_test/src/join_test.cpp +++ b/data_share/test/native/unittest/mediadatashare_test/src/join_test.cpp @@ -29,13 +29,13 @@ namespace DataShare { using namespace testing::ext; using namespace OHOS::Security::AccessToken; constexpr int STORAGE_MANAGER_MANAGER_ID = 5003; -std::string DATA_SHARE_URI = "datashare:///com.acts.datasharetest"; -std::string SLIENT_ACCESS_URI = "datashare:///com.acts.datasharetest?Proxy=true"; -std::string USER_URI = "datashare:///com.acts.datasharetest/entry/DB00/user?Proxy=true"; -std::string BOOK_URI = "datashare:///com.acts.datasharetest/entry/DB00/book?Proxy=true"; -std::string TBL_STU_NAME = "name"; -std::string TBL_STU_AGE = "age"; -std::shared_ptr g_slientAccessHelper; +static std::string DATA_SHARE_URI = "datashare:///com.acts.datasharetest"; +static std::string SLIENT_ACCESS_URI = "datashare:///com.acts.datasharetest?Proxy=true"; +static std::string USER_URI = "datashare:///com.acts.datasharetest/entry/DB00/user?Proxy=true"; +static std::string BOOK_URI = "datashare:///com.acts.datasharetest/entry/DB00/book?Proxy=true"; +static std::string TBL_STU_NAME = "name"; +static std::string TBL_STU_AGE = "age"; +static std::shared_ptr g_slientAccessHelper; class JoinTest : public testing::Test { public: @@ -46,9 +46,10 @@ public: static void InsertUserDates(); static void InsertBookDates(); int ResultSize(std::shared_ptr &resultSet); + static std::shared_ptr CreateDataShareHelper(int32_t systemAbilityId, std::string uri); }; -std::shared_ptr CreateDataShareHelper(int32_t systemAbilityId, std::string uri) +std::shared_ptr JoinTest::CreateDataShareHelper(int32_t systemAbilityId, std::string uri) { LOG_INFO("CreateDataShareHelper start"); auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); diff --git a/data_share/test/native/unittest/mediadatashare_test/src/mediadatashare_unit_test.cpp b/data_share/test/native/unittest/mediadatashare_test/src/mediadatashare_unit_test.cpp index f6600fa1..189ae9d5 100644 --- a/data_share/test/native/unittest/mediadatashare_test/src/mediadatashare_unit_test.cpp +++ b/data_share/test/native/unittest/mediadatashare_test/src/mediadatashare_unit_test.cpp @@ -95,13 +95,13 @@ public: }; constexpr int STORAGE_MANAGER_MANAGER_ID = 5003; -std::string DATA_SHARE_URI = "datashare:///com.acts.datasharetest"; -std::string MEDIALIBRARY_DATA_URI = "datashare:///com.acts.datasharetest"; -std::string MEDIALIBRARY_DATA_URI_ERROR = "test:///com.acts.datasharetest"; -std::string FILE_DATA_URI = "file://com.acts.datasharetest"; -std::string NORMALIZE_URI = "normalize+datashare:///com.acts.datasharetest"; -std::string DENORMALIZE_URI = "denormalize+datashare:///com.acts.datasharetest"; -std::shared_ptr g_dataShareHelper; +static std::string DATA_SHARE_URI = "datashare:///com.acts.datasharetest"; +static std::string MEDIALIBRARY_DATA_URI = "datashare:///com.acts.datasharetest"; +static std::string MEDIALIBRARY_DATA_URI_ERROR = "test:///com.acts.datasharetest"; +static std::string FILE_DATA_URI = "file://com.acts.datasharetest"; +static std::string NORMALIZE_URI = "normalize+datashare:///com.acts.datasharetest"; +static std::string DENORMALIZE_URI = "denormalize+datashare:///com.acts.datasharetest"; +static std::shared_ptr g_dataShareHelper; std::shared_ptr CreateDataShareHelper(int32_t systemAbilityId) { diff --git a/data_share/test/native/unittest/mediadatashare_test/src/slientaccess_test.cpp b/data_share/test/native/unittest/mediadatashare_test/src/slientaccess_test.cpp index b1470258..a007276a 100644 --- a/data_share/test/native/unittest/mediadatashare_test/src/slientaccess_test.cpp +++ b/data_share/test/native/unittest/mediadatashare_test/src/slientaccess_test.cpp @@ -20,7 +20,6 @@ #include "datashare_log.h" #include "hap_token_info.h" #include "iservice_registry.h" -#include "system_ability_definition.h" #include "token_setproc.h" namespace OHOS { @@ -28,11 +27,11 @@ namespace DataShare { using namespace testing::ext; using namespace OHOS::Security::AccessToken; constexpr int STORAGE_MANAGER_MANAGER_ID = 5003; -std::string DATA_SHARE_URI = "datashare:///com.acts.datasharetest"; -std::string SLIENT_ACCESS_URI = "datashare:///com.acts.datasharetest/entry/DB00/TBL00?Proxy=true"; -std::string TBL_STU_NAME = "name"; -std::string TBL_STU_AGE = "age"; -std::shared_ptr g_slientAccessHelper; +static std::string DATA_SHARE_URI = "datashare:///com.acts.datasharetest"; +static std::string SLIENT_ACCESS_URI = "datashare:///com.acts.datasharetest/entry/DB00/TBL00?Proxy=true"; +static std::string TBL_STU_NAME = "name"; +static std::string TBL_STU_AGE = "age"; +static std::shared_ptr g_slientAccessHelper; class SlientAccessTest : public testing::Test { public: @@ -40,9 +39,10 @@ public: static void TearDownTestCase(void); void SetUp(); void TearDown(); + static std::shared_ptr CreateDataShareHelper(int32_t systemAbilityId, std::string uri); }; -std::shared_ptr CreateDataShareHelper(int32_t systemAbilityId, std::string uri) +std::shared_ptr SlientAccessTest::CreateDataShareHelper(int32_t systemAbilityId, std::string uri) { LOG_INFO("CreateDataShareHelper start"); auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); diff --git a/datamgr_service/services/distributeddataservice/adapter/CMakeLists.txt b/datamgr_service/services/distributeddataservice/adapter/CMakeLists.txt index cadc2b8d..214543e3 100644 --- a/datamgr_service/services/distributeddataservice/adapter/CMakeLists.txt +++ b/datamgr_service/services/distributeddataservice/adapter/CMakeLists.txt @@ -30,13 +30,13 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dfx/src/behaviour) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dfx/src/fault) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dfx/src/statistic) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dfx/src) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/account) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/broadcaster) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/communicator) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/dfx) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/permission) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/utils) +#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) +#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/account) +#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/broadcaster) +#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/communicator) +#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/dfx) +#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/permission) +#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/utils) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../../utils_native/base/include) include(${MOCK_DIR}/include/CMakeLists.txt OPTIONAL) include(${KV_STORE_DIR}/interfaces/CMakeLists.txt OPTIONAL) diff --git a/datamgr_service/services/distributeddataservice/app/CMakeLists.txt b/datamgr_service/services/distributeddataservice/app/CMakeLists.txt index 262fa5da..a9e27a44 100644 --- a/datamgr_service/services/distributeddataservice/app/CMakeLists.txt +++ b/datamgr_service/services/distributeddataservice/app/CMakeLists.txt @@ -25,16 +25,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/uninstaller) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/security) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/session_manager) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/checker) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../adapter/include) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../adapter/include/account) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../adapter/include/autils) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../adapter/include/broadcaster) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../adapter/include/communicator) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../adapter/include/dfx) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../adapter/include/log) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../adapter/include/permission) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../adapter/include/security) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../adapter/include/utils) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../service/bootstrap/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../service/config/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../service/crypto/include) @@ -44,7 +34,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../service/kvdb) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../service/matrix/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../service/object) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../service/data_share) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../framework/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../../utils_native/base/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../../utils_native/safwk/native/include) include(${MOCK_DIR}/include/CMakeLists.txt OPTIONAL) diff --git a/datamgr_service/services/distributeddataservice/app/src/kvstore_data_service.cpp b/datamgr_service/services/distributeddataservice/app/src/kvstore_data_service.cpp index 9eb32d47..faec8071 100644 --- a/datamgr_service/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/datamgr_service/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -43,6 +43,7 @@ #include "reporter.h" #include "route_head_handler_impl.h" #include "runtime_config.h" +#include "store/auto_cache.h" #include "string_ex.h" #include "system_ability_definition.h" #include "task_manager.h" @@ -250,6 +251,7 @@ void KvStoreDataService::OnStart() AccountDelegate::GetInstance()->BindExecutor(executors_); AccountDelegate::GetInstance()->RegisterHashFunc(Crypto::Sha256); DmAdapter::GetInstance().Init(executors_); + AutoCache::GetInstance().Bind(executors_); static constexpr int32_t RETRY_TIMES = 50; static constexpr int32_t RETRY_INTERVAL = 500 * 1000; // unit is ms for (BlockInteger retry(RETRY_INTERVAL); retry < RETRY_TIMES; ++retry) { diff --git a/datamgr_service/services/distributeddataservice/framework/CMakeLists.txt b/datamgr_service/services/distributeddataservice/framework/CMakeLists.txt index 7b569a46..761c336f 100644 --- a/datamgr_service/services/distributeddataservice/framework/CMakeLists.txt +++ b/datamgr_service/services/distributeddataservice/framework/CMakeLists.txt @@ -20,14 +20,14 @@ aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/directory svcFwkSrc) aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/store svcFwkSrc) aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/cloud svcFwkSrc) aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/utils svcFwkSrc) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../adapter/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../../utils_native/base/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../../utils_native/safwk/native/include) include(${MOCK_DIR}/include/CMakeLists.txt OPTIONAL) include(${KV_STORE_DIR}/interfaces/CMakeLists.txt OPTIONAL) -set(links secure mock crypto) +set(links secure mock) set(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/../../../../") add_library(svcFwk SHARED ${svcFwkSrc}) target_link_libraries(svcFwk ${links}) +target_include_directories(svcFwk PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/datamgr_service/services/distributeddataservice/framework/include/store/auto_cache.h b/datamgr_service/services/distributeddataservice/framework/include/store/auto_cache.h index 947132c5..e4940b91 100644 --- a/datamgr_service/services/distributeddataservice/framework/include/store/auto_cache.h +++ b/datamgr_service/services/distributeddataservice/framework/include/store/auto_cache.h @@ -44,8 +44,6 @@ public: API_EXPORT void Bind(std::shared_ptr executor); - API_EXPORT bool IsBind(); - API_EXPORT Store GetStore(const StoreMetaData &meta, const Watchers &watchers); API_EXPORT void CloseStore(uint32_t tokenId, const std::string &storeId); diff --git a/datamgr_service/services/distributeddataservice/framework/store/auto_cache.cpp b/datamgr_service/services/distributeddataservice/framework/store/auto_cache.cpp index 69b182d8..3dfd2abd 100644 --- a/datamgr_service/services/distributeddataservice/framework/store/auto_cache.cpp +++ b/datamgr_service/services/distributeddataservice/framework/store/auto_cache.cpp @@ -39,8 +39,6 @@ void AutoCache::Bind(std::shared_ptr executor) return; } executor_ = executor; - taskId_ = executor_->Schedule(std::bind(&AutoCache::GarbageCollect, this, false), std::chrono::minutes(INTERVAL), - std::chrono::minutes(INTERVAL)); } AutoCache::AutoCache() {} @@ -72,11 +70,17 @@ AutoCache::Store AutoCache::GetStore(const StoreMetaData &meta, const Watchers & } auto *dbStore = creators_[meta.storeType](meta); if (dbStore == nullptr || !dbStore->IsValid()) { + ZLOGE("creator failed. storeName:%{public}s, dbStore is %{public}s", meta.GetStoreAlias().c_str(), + dbStore == nullptr ? "null" : "invalid"); return !stores.empty(); } auto result = stores.emplace(std::piecewise_construct, std::forward_as_tuple(meta.storeId), std::forward_as_tuple(dbStore, watchers, atoi(meta.user.c_str()))); store = result.first->second; + if (executor_ != nullptr && taskId_ == Executor::INVALID_TASK_ID) { + taskId_ = executor_->Schedule(std::bind(&AutoCache::GarbageCollect, this, false), + std::chrono::minutes(INTERVAL), std::chrono::minutes(INTERVAL)); + } return !stores.empty(); }); return store; @@ -84,24 +88,35 @@ AutoCache::Store AutoCache::GetStore(const StoreMetaData &meta, const Watchers & void AutoCache::CloseStore(uint32_t tokenId, const std::string &storeId) { - stores_.ComputeIfPresent(tokenId, [&storeId](auto &key, std::map &delegates) { + stores_.ComputeIfPresent(tokenId, [this, &storeId](auto &key, std::map &delegates) { auto it = delegates.find(storeId); if (it != delegates.end()) { it->second.Close(); delegates.erase(it); } + + if (executor_ != nullptr && taskId_ != Executor::INVALID_TASK_ID && stores_.Size() == 1 && delegates.empty()) { + executor_->Remove(taskId_, true); + taskId_ = Executor::INVALID_TASK_ID; + } return !delegates.empty(); }); } void AutoCache::CloseStore(uint32_t tokenId) { - stores_.Erase(tokenId); + stores_.ComputeIfPresent(tokenId, [this](const auto &id, std::map &delegates) { + if (executor_ != nullptr && taskId_ != Executor::INVALID_TASK_ID && stores_.Size() == 1) { + executor_->Remove(taskId_, true); + taskId_ = Executor::INVALID_TASK_ID; + } + return true; + }); } void AutoCache::CloseExcept(const std::set &users) { - stores_.EraseIf([&users](const auto &tokenId, std::map &delegates) { + stores_.EraseIf([this, &users](const auto &tokenId, std::map &delegates) { if (delegates.empty() || users.count(delegates.begin()->second.GetUser()) != 0) { return delegates.empty(); } @@ -114,6 +129,10 @@ void AutoCache::CloseExcept(const std::set &users) it = delegates.erase(it); } } + if (executor_ != nullptr && taskId_ != Executor::INVALID_TASK_ID && stores_.Size() == 1 && delegates.empty()) { + executor_->Remove(taskId_, true); + taskId_ = Executor::INVALID_TASK_ID; + } return delegates.empty(); }); } @@ -134,7 +153,7 @@ void AutoCache::SetObserver(uint32_t tokenId, const std::string &storeId, const void AutoCache::GarbageCollect(bool isForce) { auto current = std::chrono::steady_clock::now(); - stores_.EraseIf([¤t, isForce](auto &key, std::map &delegates) { + stores_.EraseIf([this, ¤t, isForce](auto &key, std::map &delegates) { for (auto it = delegates.begin(); it != delegates.end();) { // if the store is BUSY we wait more INTERVAL minutes again if ((isForce || it->second < current) && it->second.Close()) { @@ -143,15 +162,14 @@ void AutoCache::GarbageCollect(bool isForce) ++it; } } + if (executor_ != nullptr && taskId_ != Executor::INVALID_TASK_ID && stores_.Size() == 1 && delegates.empty()) { + executor_->Remove(taskId_, true); + taskId_ = Executor::INVALID_TASK_ID; + } return delegates.empty(); }); } -bool AutoCache::IsBind() -{ - return executor_ != nullptr; -} - AutoCache::Delegate::Delegate(GeneralStore *delegate, const Watchers &watchers, int32_t user) : store_(delegate), watchers_(watchers), user_(user) { diff --git a/datamgr_service/services/distributeddataservice/service/CMakeLists.txt b/datamgr_service/services/distributeddataservice/service/CMakeLists.txt index fb10301f..bc774dde 100644 --- a/datamgr_service/services/distributeddataservice/service/CMakeLists.txt +++ b/datamgr_service/services/distributeddataservice/service/CMakeLists.txt @@ -51,14 +51,10 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/data_share/strategies/general) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/data_share/strategies) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/data_share/gaussdb_rd/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/data_share/subscriber_managers) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/data_share) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/rdb) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/udmf/lifecycle) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/udmf/permission) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/udmf/preprocess) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/udmf/store) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/udmf) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/kvdb) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../framework/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../app/src) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../../kv_store/frameworks/common) @@ -76,3 +72,7 @@ set(links secure mock kvdb svcFwk adapter data_share udmf document_ut cloud_data set(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/../../../") add_library(service SHARED ${serviceSrc}) target_link_libraries(service ${links}) +target_include_directories(service PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/kvdb) +target_include_directories(service PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/rdb) +target_include_directories(service PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/udmf) +target_include_directories(service PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/data_share) diff --git a/datamgr_service/services/distributeddataservice/service/cloud/GetSchema.puml b/datamgr_service/services/distributeddataservice/service/cloud/GetSchema.puml deleted file mode 100644 index e96955ef..00000000 --- a/datamgr_service/services/distributeddataservice/service/cloud/GetSchema.puml +++ /dev/null @@ -1,35 +0,0 @@ -@startuml -autonumber -actor Actor -entity CloudServiceImpl -entity MetaDataManager -entity CloudServer - -Actor -> CloudServiceImpl:GetScheama -CloudServiceImpl -> CloudServiceImpl:GetSchemaMeta(userId, bundleName, instanceId) -CloudServiceImpl -> MetaDataManager:GetCloudInfo(userId); -CloudServiceImpl <-- MetaDataManager:bool -alt 元数据不存在 -CloudServiceImpl -> CloudServer:GetCloudInfo(userId); -CloudServiceImpl <-- MetaDataManager:bool -end - -CloudServiceImpl -> CloudServiceImpl:CheckCloudInfo -alt CloudInfo invaild -CloudServiceImpl -> CloudServiceImpl:return -end - -CloudServiceImpl -> MetaDataManager:GetSchemaMeta(bundleName, instanceId) -CloudServiceImpl <-- MetaDataManager:bool -alt 找到APP Schema -CloudServiceImpl -> CloudServiceImpl:return -end - -CloudServiceImpl -> MetaDataManager:IsCloud(bundleName) -CloudServiceImpl <-- MetaDataManager:bool -alt false && -CloudServiceImpl -> CloudServiceImpl: 认证接受 -else 某种失败情况 -Bob -> Alice: 请重复 -end -@enduml \ No newline at end of file diff --git a/datamgr_service/services/distributeddataservice/service/cloud/sync_manager.cpp b/datamgr_service/services/distributeddataservice/service/cloud/sync_manager.cpp index 0ae20650..4804b5e4 100644 --- a/datamgr_service/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/datamgr_service/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -133,9 +133,6 @@ SyncManager::~SyncManager() int32_t SyncManager::Bind(std::shared_ptr executor) { executor_ = executor; - if (!AutoCache::GetInstance().IsBind()) { - AutoCache::GetInstance().Bind(executor_); - } return E_OK; } @@ -207,6 +204,9 @@ ExecutorPool::Task SyncManager::GetSyncTask(int32_t times, bool retry, RefCount } for (const auto &database : schema.databases) { + if (!info.tables_.empty() && info.tables_.find(database.name) == info.tables_.end()) { + continue; + } CloudEvent::StoreInfo storeInfo; storeInfo.bundleName = schema.bundleName; storeInfo.user = cloud.user; diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index c3707042..9a2ec41b 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -630,9 +630,6 @@ std::pair RdbServiceImpl::GetInstIndexAndUser(uint32_t tokenId int32_t RdbServiceImpl::OnBind(const BindInfo &bindInfo) { executors_ = bindInfo.executors; - if (!AutoCache::GetInstance().IsBind()) { - AutoCache::GetInstance().Bind(executors_); - } return 0; } diff --git a/datamgr_service/services/distributeddataservice/service/test/cloud_data_test.cpp b/datamgr_service/services/distributeddataservice/service/test/cloud_data_test.cpp index b8500014..fb275826 100644 --- a/datamgr_service/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/datamgr_service/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -14,9 +14,9 @@ */ #define LOG_TAG "CloudDataTest" #include -#include "log_print.h" -#include "ipc_skeleton.h" + #include "account/account_delegate.h" +#include "cloud/change_event.h" #include "cloud/cloud_event.h" #include "cloud/cloud_server.h" #include "cloud/schema_meta.h" @@ -24,20 +24,24 @@ #include "device_matrix.h" #include "eventcenter/event_center.h" #include "feature/feature_system.h" +#include "ipc_skeleton.h" +#include "log_print.h" #include "metadata/meta_data_manager.h" #include "metadata/store_meta_data.h" #include "metadata/store_meta_data_local.h" +#include "mock/cloud_server_mock.h" #include "mock/db_store_mock.h" +#include "mock/general_store_mock.h" +#include "rdb_query.h" #include "rdb_types.h" +#include "store/auto_cache.h" +#include "store/general_store.h" using namespace testing::ext; using namespace OHOS::DistributedData; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; namespace OHOS::Test { namespace DistributedDataTest { -static constexpr const char *TEST_CLOUD_BUNDLE = "test_cloud_bundleName"; -static constexpr const char *TEST_CLOUD_APPID = "test_cloud_appid"; -static constexpr const char *TEST_CLOUD_STORE = "test_cloud_database_name"; class CloudDataTest : public testing::Test { public: static void SetUpTestCase(void); @@ -45,69 +49,62 @@ public: void SetUp(); void TearDown(); - static SchemaMeta schemaMeta_; + static CloudInfo CLOUD_INFO; + static SchemaMeta SCHEMA_META; + protected: - static constexpr const char *TEST_DISTRIBUTEDDATA_BUNDLE = "test_distributeddata"; - static constexpr const char *TEST_DISTRIBUTEDDATA_STORE = "test_service_meta"; + static constexpr uint64_t REMAIN_SPACE = 1000; + static constexpr uint64_t TOTAL_SPACE = 2000; + static constexpr const char *TEST_CLOUD_BUNDLE = "test_cloud_bundleName"; + static constexpr const char *TEST_CLOUD_APPID = "test_cloud_appid"; + static constexpr const char *TEST_CLOUD_STORE = "test_cloud_database_name"; + static constexpr const char *TEST_DISTRIBUTED_DATA_BUNDLE = "test_distributeddata"; + static constexpr const char *TEST_DISTRIBUTED_DATA_STORE = "test_service_meta"; void InitMetaData(); + void InitCloudInfo(); void InitSchemaMeta(); + StoreMetaData GetStoreMetaData(); static std::shared_ptr dbStoreMock_; StoreMetaData metaData_; }; -class CloudServerMock : public CloudServer { -public: - CloudInfo GetServerInfo(int32_t userId) override; - SchemaMeta GetAppSchema(int32_t userId, const std::string &bundleName) override; - virtual ~CloudServerMock() = default; - static constexpr uint64_t REMAINSPACE = 1000; - static constexpr uint64_t TATALSPACE = 2000; -}; - -CloudInfo CloudServerMock::GetServerInfo(int32_t userId) -{ - CloudInfo cloudInfo; - cloudInfo.user = userId; - cloudInfo.id = "test_cloud_id"; - cloudInfo.remainSpace = REMAINSPACE; - cloudInfo.totalSpace = TATALSPACE; - cloudInfo.enableCloud = true; - - CloudInfo::AppInfo appInfo; - appInfo.bundleName = TEST_CLOUD_BUNDLE; - appInfo.appId = TEST_CLOUD_APPID; - appInfo.version = 1; - appInfo.cloudSwitch = true; - - cloudInfo.apps[TEST_CLOUD_BUNDLE] = std::move(appInfo); - return cloudInfo; -} - -SchemaMeta CloudServerMock::GetAppSchema(int32_t userId, const std::string &bundleName) -{ - return CloudDataTest::schemaMeta_; -} - std::shared_ptr CloudDataTest::dbStoreMock_ = std::make_shared(); -SchemaMeta CloudDataTest::schemaMeta_; +CloudInfo CloudDataTest::CLOUD_INFO; +SchemaMeta CloudDataTest::SCHEMA_META; void CloudDataTest::InitMetaData() { metaData_.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; - metaData_.appId = TEST_DISTRIBUTEDDATA_BUNDLE; - metaData_.bundleName = TEST_DISTRIBUTEDDATA_BUNDLE; + metaData_.appId = TEST_DISTRIBUTED_DATA_BUNDLE; + metaData_.bundleName = TEST_DISTRIBUTED_DATA_BUNDLE; metaData_.tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); metaData_.user = std::to_string(DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(metaData_.tokenId)); metaData_.area = OHOS::DistributedKv::EL1; metaData_.instanceId = 0; metaData_.isAutoSync = true; metaData_.storeType = 1; - metaData_.storeId = TEST_DISTRIBUTEDDATA_STORE; + metaData_.storeId = TEST_DISTRIBUTED_DATA_STORE; PolicyValue value; value.type = OHOS::DistributedKv::PolicyType::IMMEDIATE_SYNC_ON_ONLINE; } +void CloudDataTest::InitCloudInfo() +{ + CLOUD_INFO.id = "test_cloud_id"; + CLOUD_INFO.remainSpace = REMAIN_SPACE; + CLOUD_INFO.totalSpace = TOTAL_SPACE; + CLOUD_INFO.enableCloud = true; + + CloudInfo::AppInfo appInfo; + appInfo.bundleName = TEST_CLOUD_BUNDLE; + appInfo.appId = TEST_CLOUD_APPID; + appInfo.version = 1; + appInfo.cloudSwitch = true; + + CLOUD_INFO.apps[TEST_CLOUD_BUNDLE] = std::move(appInfo); +} + void CloudDataTest::InitSchemaMeta() { SchemaMeta::Field field1; @@ -128,19 +125,31 @@ void CloudDataTest::InitSchemaMeta() database.alias = "test_cloud_database_alias"; database.tables.emplace_back(table); - schemaMeta_.version = 1; - schemaMeta_.bundleName = TEST_DISTRIBUTEDDATA_BUNDLE; - schemaMeta_.databases.emplace_back(database); + SCHEMA_META.version = 1; + SCHEMA_META.bundleName = TEST_DISTRIBUTED_DATA_BUNDLE; + SCHEMA_META.databases.emplace_back(database); +} + +StoreMetaData CloudDataTest::GetStoreMetaData() +{ + StoreMetaData storeMetaData; + storeMetaData.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; + storeMetaData.bundleName = TEST_CLOUD_BUNDLE; + storeMetaData.storeId = TEST_CLOUD_STORE; + storeMetaData.instanceId = 0; + storeMetaData.isAutoSync = true; + storeMetaData.storeType = DistributedRdb::RDB_DEVICE_COLLABORATION; + storeMetaData.area = OHOS::DistributedKv::EL1; + storeMetaData.tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); + storeMetaData.user = + std::to_string(DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(storeMetaData.tokenId)); + return storeMetaData; } void CloudDataTest::SetUpTestCase(void) { - MetaDataManager::GetInstance().Initialize(dbStoreMock_, nullptr, [](const auto &, auto) { - DeviceMatrix::GetInstance().OnChanged(DeviceMatrix::META_STORE_MASK); - }); + MetaDataManager::GetInstance().Initialize(dbStoreMock_, nullptr, nullptr); - auto cloudServerMock = new CloudServerMock(); - CloudServer::RegisterCloudInstance(cloudServerMock); FeatureSystem::GetInstance().GetCreator("cloud")(); FeatureSystem::GetInstance().GetCreator("relational_store")(); } @@ -150,49 +159,87 @@ void CloudDataTest::TearDownTestCase() {} void CloudDataTest::SetUp() { InitMetaData(); + InitCloudInfo(); InitSchemaMeta(); MetaDataManager::GetInstance().SaveMeta(metaData_.GetKey(), metaData_); - StoreMetaData storeMetaData; - storeMetaData.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; - storeMetaData.bundleName = TEST_CLOUD_BUNDLE; - storeMetaData.storeId = TEST_CLOUD_STORE; - storeMetaData.instanceId = 0; - storeMetaData.isAutoSync = true; - storeMetaData.storeType = DistributedRdb::RDB_DEVICE_COLLABORATION; - storeMetaData.area = OHOS::DistributedKv::EL1; - storeMetaData.tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); - storeMetaData.user = - std::to_string(DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(storeMetaData.tokenId)); - MetaDataManager::GetInstance().SaveMeta(storeMetaData.GetKey(), storeMetaData); + auto cloudServerMock = new CloudServerMock(CLOUD_INFO, { { TEST_CLOUD_BUNDLE, SCHEMA_META } }); + CloudServer::RegisterCloudInstance(cloudServerMock); } -void CloudDataTest::TearDown() {} +void CloudDataTest::TearDown() +{ + if (dbStoreMock_ != nullptr) { + dbStoreMock_->Reset(); + } +} /** -* @tc.name: GetSchema +* @tc.name: GetSchemaTest001 * @tc.desc: GetSchema from cloud when no schema in meta. * @tc.type: FUNC * @tc.require: * @tc.author: ht */ -HWTEST_F(CloudDataTest, GetSchema, TestSize.Level0) +HWTEST_F(CloudDataTest, GetSchemaTest001, TestSize.Level0) { - ZLOGI("CloudDataTest start"); - auto cloudServerMock = std::make_shared(); - auto cloudInfo = cloudServerMock->GetServerInfo( - DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(OHOS::IPCSkeleton::GetCallingTokenID())); + ZLOGI("GetSchemaTest001 start"); + auto cloudInfo = CLOUD_INFO; ASSERT_TRUE(MetaDataManager::GetInstance().DelMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), true)); SchemaMeta schemaMeta; - ASSERT_FALSE( - MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), schemaMeta, true)); - CloudEvent::StoreInfo storeInfo { OHOS::IPCSkeleton::GetCallingTokenID(), TEST_CLOUD_BUNDLE, TEST_CLOUD_STORE, 0 }; + ASSERT_FALSE(MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), schemaMeta, true)); + CloudEvent::StoreInfo storeInfo{ IPCSkeleton::GetCallingTokenID(), TEST_CLOUD_BUNDLE, TEST_CLOUD_STORE, 0 }; auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo)); EventCenter::GetInstance().PostEvent(move(event)); - ASSERT_TRUE( - MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), schemaMeta, true)); - ASSERT_EQ(to_string(schemaMeta.Marshall()), to_string(schemaMeta_.Marshall())); + ASSERT_TRUE(MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), schemaMeta, true)); + ASSERT_EQ(to_string(schemaMeta.Marshall()), to_string(SCHEMA_META.Marshall())); +} + +/** +* @tc.name: LocalChangeTest001 +* @tc.desc: do cloud sync. +* @tc.type: FUNC +* @tc.require: +* @tc.author: ht +*/ +HWTEST_F(CloudDataTest, LocalChangeTest001, TestSize.Level0) +{ + ZLOGI("LocalChangeTest001 start"); + auto cloudInfo = CLOUD_INFO; + MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true); + auto schemaMeta = SCHEMA_META; + auto keys = cloudInfo.GetSchemaKey(); + for (auto &[bundleName, key] : keys) { + schemaMeta.bundleName = bundleName; + MetaDataManager::GetInstance().SaveMeta(key, schemaMeta, true); + } + using StoreType = DistributedData::StoreMetaData::StoreType; + auto storeMeta = GetStoreMetaData(); + storeMeta.storeType = StoreType::STORE_BUTT - 1; + + AutoCache::GetInstance().RegCreator(storeMeta.storeType, [](const StoreMetaData &metaData) -> GeneralStore* { + return new (std::nothrow) GeneralStoreMock(metaData); + }); + auto process = [this](const Event &event) { + auto &evt = static_cast(event); + auto storeInfo = evt.GetStoreInfo(); + StoreMetaData meta; + meta.storeId = storeInfo.storeName; + meta.bundleName = storeInfo.bundleName; + meta.user = std::to_string(storeInfo.user); + meta.instanceId = storeInfo.instanceId; + meta.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; + ASSERT_TRUE(MetaDataManager::GetInstance().LoadMeta(meta.GetKey(), meta)); + auto store = AutoCache::GetInstance().GetStore(meta, {}); + ASSERT_TRUE(store!= nullptr && store->IsValid()); + }; + EventCenter::GetInstance().Subscribe(CloudEvent::CLOUD_SYNC, process); + CloudEvent::StoreInfo storeInfo{ IPCSkeleton::GetCallingTokenID(), TEST_CLOUD_BUNDLE, TEST_CLOUD_STORE, 0 }; + auto query = std::make_shared(); + auto info = ChangeEvent::EventInfo(GeneralStore::CLOUD_TIME_FIRST, 0, false, query, nullptr); + auto evt = std::make_unique(std::move(storeInfo), std::move(info)); + EventCenter::GetInstance().PostEvent(std::move(evt)); } } // namespace DistributedDataTest } // namespace OHOS::Test diff --git a/datamgr_service/services/distributeddataservice/service/test/mock/adapter_mock.cpp b/datamgr_service/services/distributeddataservice/service/test/mock/adapter_mock.cpp new file mode 100644 index 00000000..66147dfc --- /dev/null +++ b/datamgr_service/services/distributeddataservice/service/test/mock/adapter_mock.cpp @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2023 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. +*/ + +#include "device_manager_adapter.h" + +namespace OHOS { +namespace DistributedData { +DeviceManagerAdapter &DeviceManagerAdapter::GetInstance() +{ + static DeviceManagerAdapter dmAdapter; + return dmAdapter; +} +void DeviceManagerAdapter::Init(std::shared_ptr executors) {} +//Status DeviceManagerAdapter::StartWatchDeviceChange(const AppDeviceChangeListener *observer, const PipeInfo &pipeInfo) +//{ +// +//} +//Status DeviceManagerAdapter::StopWatchDeviceChange(const AppDeviceChangeListener *observer, const PipeInfo &pipeInfo) +//{ +//} +//DeviceInfo DeviceManagerAdapter::GetLocalDevice() {} +//std::vector DeviceManagerAdapter::GetRemoteDevices() {} +//DeviceInfo DeviceManagerAdapter::GetDeviceInfo(const std::string &id) {} +std::string DeviceManagerAdapter::GetUuidByNetworkId(const std::string &networkId) {} +std::string DeviceManagerAdapter::GetUdidByNetworkId(const std::string &networkId) {} +std::string DeviceManagerAdapter::CalcClientUuid(const std::string &appId, const std::string &uuid) {} +std::string DeviceManagerAdapter::ToUUID(const std::string &id) {} +std::string DeviceManagerAdapter::ToUDID(const std::string &id) {} +//static std::vector DeviceManagerAdapter::ToUUID(const std::vector &devices) {} +//static std::vector DeviceManagerAdapter::ToUUID(std::vector devices) {} +std::string DeviceManagerAdapter::ToNetworkID(const std::string &id) {} +void DeviceManagerAdapter::NotifyReadyEvent(const std::string &uuid) {} + +bool DeviceManagerAdapter::IsNetworkAvailable() { + +} + +DeviceManagerAdapter::DeviceManagerAdapter() + : cloudDmInfo({ "cloudDeviceId", "cloudDeviceName", 0, "cloudNetworkId", 0 }) +{ +} + +} // namespace DistributedData +} // namespace OHOS \ No newline at end of file diff --git a/datamgr_service/services/distributeddataservice/service/test/mock/cloud_server_mock.cpp b/datamgr_service/services/distributeddataservice/service/test/mock/cloud_server_mock.cpp new file mode 100644 index 00000000..4c9b95ee --- /dev/null +++ b/datamgr_service/services/distributeddataservice/service/test/mock/cloud_server_mock.cpp @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2023 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. +*/ +#include "cloud_server_mock.h" +#include "store/general_value.h" +namespace OHOS { +namespace DistributedData { +CloudServerMock::CloudServerMock(const CloudInfo &cloudInfo, const std::map &schemaMetas) + : cloudInfo_(cloudInfo), schemaMetas_(schemaMetas) +{ +} + +CloudInfo CloudServerMock::GetServerInfo(int32_t userId) +{ + auto cloudInfo = cloudInfo_; + cloudInfo.user = userId; + return cloudInfo; +} + +SchemaMeta CloudServerMock::GetAppSchema(int32_t userId, const std::string &bundleName) +{ + auto it = schemaMetas_.find(bundleName); + return it != schemaMetas_.end() ? it->second : SchemaMeta(); +} +} // namespace DistributedData +} // namespace OHOS diff --git a/datamgr_service/services/distributeddataservice/service/test/mock/cloud_server_mock.h b/datamgr_service/services/distributeddataservice/service/test/mock/cloud_server_mock.h new file mode 100644 index 00000000..6ada12c9 --- /dev/null +++ b/datamgr_service/services/distributeddataservice/service/test/mock/cloud_server_mock.h @@ -0,0 +1,24 @@ +#ifndef OHOS_DISTRIBUTEDDATA_SERVICE_TEST_CLOUD_SERVER_MOCK_H +#define OHOS_DISTRIBUTEDDATA_SERVICE_TEST_CLOUD_SERVER_MOCK_H + +#include "cloud/cloud_event.h" +#include "cloud/cloud_server.h" +#include "cloud/schema_meta.h" + +namespace OHOS { +namespace DistributedData { +class CloudServerMock : public CloudServer { +public: + CloudServerMock(const CloudInfo& cloudInfo, const std::map& schemaMetas); + CloudInfo GetServerInfo(int32_t userId) override; + SchemaMeta GetAppSchema(int32_t userId, const std::string &bundleName) override; + virtual ~CloudServerMock() = default; + +private: + CloudInfo cloudInfo_; + std::map schemaMetas_; +}; + +} // namespace DistributedData +} // namespace OHOS +#endif //OHOS_DISTRIBUTEDDATA_SERVICE_TEST_CLOUD_SERVER_MOCK_H diff --git a/datamgr_service/services/distributeddataservice/service/test/mock/db_store_mock.cpp b/datamgr_service/services/distributeddataservice/service/test/mock/db_store_mock.cpp index cd1e2df6..df8c3984 100644 --- a/datamgr_service/services/distributeddataservice/service/test/mock/db_store_mock.cpp +++ b/datamgr_service/services/distributeddataservice/service/test/mock/db_store_mock.cpp @@ -310,5 +310,12 @@ DBStatus DBStoreMock::UpdateKey(const UpdateKeyCallback &callback) { return NOT_SUPPORT; } + +void DBStoreMock::Reset() +{ + entries_.Clear(); + localEntries_.Clear(); + observers_.Clear(); +} } // namespace DistributedData } // namespace OHOS \ No newline at end of file diff --git a/datamgr_service/services/distributeddataservice/service/test/mock/db_store_mock.h b/datamgr_service/services/distributeddataservice/service/test/mock/db_store_mock.h index e50def98..74e8342e 100644 --- a/datamgr_service/services/distributeddataservice/service/test/mock/db_store_mock.h +++ b/datamgr_service/services/distributeddataservice/service/test/mock/db_store_mock.h @@ -89,6 +89,7 @@ public: DBStatus GetKeys(const Key &keyPrefix, std::vector &keys) const override; size_t GetSyncDataSize(const std::string &device) const override; DBStatus UpdateKey(const UpdateKeyCallback &callback) override; + void Reset(); private: static const uint32_t DEFAULT_SIZE = 0; diff --git a/datamgr_service/services/distributeddataservice/service/test/mock/general_store_mock.cpp b/datamgr_service/services/distributeddataservice/service/test/mock/general_store_mock.cpp new file mode 100644 index 00000000..80313ce1 --- /dev/null +++ b/datamgr_service/services/distributeddataservice/service/test/mock/general_store_mock.cpp @@ -0,0 +1,97 @@ +/* +* Copyright (c) 2023 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. +*/ +#include "general_store_mock.h" + +namespace OHOS { +namespace DistributedData { + +StoreMetaData GeneralStoreMock::GetStoreMetaData() +{ + return StoreMetaData(); +} +int32_t GeneralStoreMock::Clean(const std::vector &devices, int32_t mode, const std::string &tableName) +{ + return 0; +} +GeneralStoreMock::GeneralStoreMock(const StoreMetaData &meta) {} +GeneralStoreMock::~GeneralStoreMock() {} +bool GeneralStoreMock::IsValid() +{ + return false; +} +int32_t GeneralStoreMock::Bind(const Database &database, GeneralStore::BindInfo bindInfo) +{ + return 0; +} +bool GeneralStoreMock::IsBound() +{ + return false; +} +int32_t GeneralStoreMock::Execute(const std::string &table, const std::string &sql) +{ + return 0; +} +int32_t GeneralStoreMock::SetDistributedTables(const std::vector &tables, int32_t type) +{ + return 0; +} +int32_t GeneralStoreMock::BatchInsert(const std::string &table, VBuckets &&values) +{ + return 0; +} +int32_t GeneralStoreMock::BatchUpdate(const std::string &table, const std::string &sql, VBuckets &&values) +{ + return 0; +} +int32_t GeneralStoreMock::Delete(const std::string &table, const std::string &sql, Values &&args) +{ + return 0; +} +std::shared_ptr GeneralStoreMock::Query(const std::string &table, const std::string &sql, Values &&args) +{ + return std::shared_ptr(); +} +std::shared_ptr GeneralStoreMock::Query(const std::string &table, GenQuery &query) +{ + return std::shared_ptr(); +} +int32_t GeneralStoreMock::Sync(const GeneralStore::Devices &devices, int32_t mode, GenQuery &query, + GeneralStore::DetailAsync async, int32_t wait) +{ + return 0; +} +int32_t GeneralStoreMock::Watch(int32_t origin, GeneralStore::Watcher &watcher) +{ + return 0; +} +int32_t GeneralStoreMock::Unwatch(int32_t origin, GeneralStore::Watcher &watcher) +{ + return 0; +} +int32_t GeneralStoreMock::Close() +{ + return 0; +} +int32_t GeneralStoreMock::AddRef() +{ + return 0; +} +int32_t GeneralStoreMock::Release() +{ + return 0; +} + +} // namespace DistributedData +} // namespace OHOS \ No newline at end of file diff --git a/datamgr_service/services/distributeddataservice/service/test/mock/general_store_mock.h b/datamgr_service/services/distributeddataservice/service/test/mock/general_store_mock.h new file mode 100644 index 00000000..f3ffc4ef --- /dev/null +++ b/datamgr_service/services/distributeddataservice/service/test/mock/general_store_mock.h @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2023 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. +*/ + +#ifndef OHOS_DISTRIBUTEDDATA_SERVICE_TEST_RDB_GENERAL_STORE_H +#define OHOS_DISTRIBUTEDDATA_SERVICE_TEST_RDB_GENERAL_STORE_H +#include +#include +#include + +#include "metadata/store_meta_data.h" +#include "rdb_asset_loader.h" +#include "rdb_cloud.h" +#include "rdb_store.h" +#include "relational_store_delegate.h" +#include "relational_store_manager.h" +#include "store/general_store.h" +#include "store/general_value.h" +namespace OHOS::DistributedData { +class GeneralStoreMock : public DistributedData::GeneralStore { +public: + explicit GeneralStoreMock(const StoreMetaData &meta); + ~GeneralStoreMock(); + bool IsValid() override; + int32_t Bind(const Database &database, BindInfo bindInfo) override; + bool IsBound() override; + int32_t Execute(const std::string &table, const std::string &sql) override; + int32_t SetDistributedTables(const std::vector &tables, int32_t type) override; + int32_t BatchInsert(const std::string &table, VBuckets &&values) override; + int32_t BatchUpdate(const std::string &table, const std::string &sql, VBuckets &&values) override; + int32_t Delete(const std::string &table, const std::string &sql, Values &&args) override; + std::shared_ptr Query(const std::string &table, const std::string &sql, Values &&args) override; + std::shared_ptr Query(const std::string &table, GenQuery &query) override; + int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, DetailAsync async, int32_t wait) override; + int32_t Clean(const std::vector &devices, int32_t mode, const std::string &tableName) override; + int32_t Watch(int32_t origin, Watcher &watcher) override; + int32_t Unwatch(int32_t origin, Watcher &watcher) override; + int32_t Close() override; + int32_t AddRef() override; + int32_t Release() override; + + StoreMetaData GetStoreMetaData(); +private: +}; +} // namespace OHOS::DistributedData +#endif // OHOS_DISTRIBUTEDDATA_SERVICE_TEST_RDB_GENERAL_STORE_H diff --git a/kv_store/frameworks/CMakeLists.txt b/kv_store/frameworks/CMakeLists.txt index 52aa2a46..c0231d19 100644 --- a/kv_store/frameworks/CMakeLists.txt +++ b/kv_store/frameworks/CMakeLists.txt @@ -15,15 +15,7 @@ aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/innerkitsimpl/kvdb/src kvdbSrc) aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/jskitsimpl/distributedkvstore/src jsKVSrc) aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/jskitsimpl/distributeddata/src jsDataSrc) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/innerkitsimpl/distributeddatafwk/include) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/innerkitsimpl/distributeddatafwk/src) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/innerkitsimpl/kvdb/include) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../frameworks/libs/distributeddb/include) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../frameworks/libs/distributeddb/interfaces/include) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../frameworks/libs/distributeddb/interfaces/include/relational) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../data_share/interfaces/inner_api/common/include) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../data_share/interfaces/inner_api/provider/include) + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../utils_native/base/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../utils_native/safwk/native/include) include(${MOCK_DIR}/include/CMakeLists.txt OPTIONAL) @@ -33,8 +25,18 @@ add_library(kvdb SHARED ${kvdbSrc}) add_library(jskvdb SHARED ${jsKVSrc}) add_library(jsolddb SHARED ${jsDataSrc}) target_link_libraries(kvdb ${links}) +target_include_directories(kvdb PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../interfaces/innerkits/distributeddata/include) +target_include_directories(kvdb PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/common) +target_include_directories(kvdb PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/innerkitsimpl/distributeddatafwk/include) +target_include_directories(kvdb PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/innerkitsimpl/distributeddatafwk/src) +target_include_directories(kvdb PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/innerkitsimpl/kvdb/include) + +target_include_directories(kvdb PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../data_share/interfaces/inner_api/common/include/basic) +target_include_directories(kvdb PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../data_share/interfaces/inner_api/common/include) +target_include_directories(kvdb PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../data_share/interfaces/inner_api/consumer/include) +target_include_directories(kvdb PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../data_share/interfaces/inner_api/provider/include) + target_link_libraries(jskvdb ${links} kvdb) target_link_libraries(jsolddb ${links} kvdb) -target_include_directories(kvdb PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../interfaces/innerkits/distributeddata/include) -target_include_directories(jskvdb PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/jskitsimpl/distributedkvstore/include") -target_include_directories(jsolddb PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/jskitsimpl/distributeddata/include") \ No newline at end of file +target_include_directories(jskvdb PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/jskitsimpl/distributedkvstore/include) +target_include_directories(jsolddb PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/jskitsimpl/distributeddata/include) \ No newline at end of file diff --git a/kv_store/frameworks/libs/CMakeLists.txt b/kv_store/frameworks/libs/CMakeLists.txt index 1446bc13..69458e7a 100644 --- a/kv_store/frameworks/libs/CMakeLists.txt +++ b/kv_store/frameworks/libs/CMakeLists.txt @@ -34,13 +34,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/common/src/evloop/ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/common/src) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/communicator/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/communicator/src) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/include/distributeddb) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/include) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/interfaces/include/cloud) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/interfaces/include/relational) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/interfaces/include) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/interfaces/src/relational) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/interfaces/src) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/storage/include/cloud) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/storage/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/storage/src/multiver) @@ -61,3 +54,10 @@ include_directories(${MOCK_DIR}/innerkits/hilog_native/libhilog/include) set(links secure mock jsoncpp crypto) add_library(distributeddb SHARED ${distributeddbSrc}) target_link_libraries(distributeddb ${links}) +target_include_directories(distributeddb PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/interfaces/include/cloud) +target_include_directories(distributeddb PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/interfaces/include/relational) +target_include_directories(distributeddb PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/interfaces/include) +target_include_directories(distributeddb PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/interfaces/src/relational) +target_include_directories(distributeddb PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/interfaces/src) +target_include_directories(distributeddb PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/include/distributeddb) +target_include_directories(distributeddb PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/distributeddb/include) diff --git a/mock/innerkits/appexecfwk_base/include/extension_ability_info.h b/mock/innerkits/appexecfwk_base/include/extension_ability_info.h index 50820a33..adf5917a 100644 --- a/mock/innerkits/appexecfwk_base/include/extension_ability_info.h +++ b/mock/innerkits/appexecfwk_base/include/extension_ability_info.h @@ -73,9 +73,18 @@ struct ExtensionAbilityInfo : public Parcelable { bool enabled = true; std::string process; - bool ReadFromParcel(Parcel &parcel); - virtual bool Marshalling(Parcel &parcel) const override; - static ExtensionAbilityInfo *Unmarshalling(Parcel &parcel); + bool ReadFromParcel(Parcel &parcel) + { + return false; + } + virtual bool Marshalling(Parcel &parcel) const override + { + return false; + } + static ExtensionAbilityInfo *Unmarshalling(Parcel &parcel) + { + return nullptr; + } }; } // namespace AppExecFwk } // namespace OHOS diff --git a/mock/src/mock_access_token.cpp b/mock/src/mock_access_token.cpp index 108332e9..856b1140 100644 --- a/mock/src/mock_access_token.cpp +++ b/mock/src/mock_access_token.cpp @@ -127,6 +127,10 @@ int32_t AccessTokenKit::GetHapDlpFlag(AccessTokenID tokenID) { return 0; } +int32_t AccessTokenKit::ReloadNativeTokenInfo() +{ + return 0; +} } uint64_t GetAccessTokenId(NativeTokenInfoParams *params) diff --git a/preferences/test/native/unittest/preferences_file_test.cpp b/preferences/test/native/unittest/preferences_file_test.cpp index 8addb083..2c3a9f00 100644 --- a/preferences/test/native/unittest/preferences_file_test.cpp +++ b/preferences/test/native/unittest/preferences_file_test.cpp @@ -22,7 +22,7 @@ #include "preferences.h" #include "preferences_errno.h" #include "preferences_helper.h" -#include "preferences_xml_utils.h" +#include "include/preferences_xml_utils.h" using namespace testing::ext; using namespace OHOS::NativePreferences; diff --git a/preferences/test/native/unittest/preferences_xml_utils_test.cpp b/preferences/test/native/unittest/preferences_xml_utils_test.cpp index 011b4ae0..af972ee6 100644 --- a/preferences/test/native/unittest/preferences_xml_utils_test.cpp +++ b/preferences/test/native/unittest/preferences_xml_utils_test.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "preferences_xml_utils.h" +#include "include/preferences_xml_utils.h" #include diff --git a/relational_store/CMakeLists.txt b/relational_store/CMakeLists.txt index 1729baea..0f85ca91 100644 --- a/relational_store/CMakeLists.txt +++ b/relational_store/CMakeLists.txt @@ -46,7 +46,7 @@ include_directories(${MOCK_DIR}/sqlite/include) include_directories(${MOCK_DIR}/filemanagement/file_api/interfaces/kits) include(${KV_STORE_DIR}/interfaces/CMakeLists.txt OPTIONAL) -set(links secure mock adapter distributeddb kvdb) +set(links secure mock distributeddb kvdb) add_library(relational_store SHARED ${relational_store_src} ${rdb_adapter_src}) target_link_libraries(relational_store ${links}) target_include_directories(relational_store PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/inner_api/rdb/include) diff --git a/relational_store/frameworks/native/rdb/src/rdb_store_impl.cpp b/relational_store/frameworks/native/rdb/src/rdb_store_impl.cpp index 62c18e63..827a87e8 100644 --- a/relational_store/frameworks/native/rdb/src/rdb_store_impl.cpp +++ b/relational_store/frameworks/native/rdb/src/rdb_store_impl.cpp @@ -1220,7 +1220,7 @@ void RdbStoreImpl::DoCloudSync(const std::string &table) } auto empty = syncTables_->empty(); if (table.empty()) { - syncTables_->insert(cloudTables_.begin(), cloudTables_.end()); + syncTables_->insert(cloudTables_.begin(), cloudTables_.end()); } else { syncTables_->insert(table); } diff --git a/relational_store/test/native/rdb/unittest/rdb_open_callback_test.cpp b/relational_store/test/native/rdb/unittest/rdb_open_callback_test.cpp index 0c4db7a2..8caf0e33 100644 --- a/relational_store/test/native/rdb/unittest/rdb_open_callback_test.cpp +++ b/relational_store/test/native/rdb/unittest/rdb_open_callback_test.cpp @@ -26,6 +26,7 @@ using namespace testing::ext; using namespace OHOS::NativeRdb; +using namespace OHOS::Rdb; class RdbOpenCallbackTest : public testing::Test { public: diff --git a/relational_store/test/native/rdb/unittest/rdb_store_config_test.cpp b/relational_store/test/native/rdb/unittest/rdb_store_config_test.cpp index 82bcd1cc..8db62591 100644 --- a/relational_store/test/native/rdb/unittest/rdb_store_config_test.cpp +++ b/relational_store/test/native/rdb/unittest/rdb_store_config_test.cpp @@ -26,6 +26,7 @@ using namespace testing::ext; using namespace OHOS::NativeRdb; +using namespace OHOS::Rdb; class RdbStoreConfigTest : public testing::Test { public: diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2958fb95..276b2813 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -7,7 +7,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -fPIC -fpic -ffunction-s set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--no-as-needed -ldl") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=0 -fpermissive") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=deprecated-declarations -Wno-deprecated-declarations") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=deprecated-declarations -Wno-deprecated-declarations -Wattributes") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") include_directories(${CMAKE_SOURCE_DIR}/utils_native/base/include) @@ -17,39 +17,122 @@ set(KV_STORE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../kv_store) include_directories(${MOCK_DIR}/src/) include_directories(${MOCK_DIR}/sqlite/include) include(${MOCK_DIR}/include/CMakeLists.txt OPTIONAL) -include(${KV_STORE_DIR}/interfaces/CMakeLists.txt OPTIONAL) -include(${CMAKE_CURRENT_SOURCE_DIR}/include/CMakeLists.txt OPTIONAL) include_directories(${CMAKE_SOURCE_DIR}/googletest/googletest/include) include_directories(${CMAKE_SOURCE_DIR}/googletest/googlemock/include) aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/ mainSrc) aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/service serviceSrc) aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/client clientSrc) -#aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../data_object/frameworks/innerkitsimpl/test/unittest localTestSrc) -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/innerkitsimpl/kvdb/test remoteTestSrc) -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/common/test remoteTestSrc) -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/innerkitsimpl/distributeddatafwk/test/unittest remoteTestSrc) -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/framework/test localTestSrc) -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/adapter/account/test remoteTestSrc) -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/adapter/communicator/test/unittest remoteTestSrc) -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/test/mock remoteTestSrc) -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/test remoteTestSrc) -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/test/data_share remoteTestSrc) -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../preferences/test/native/unittest localTestSrc) -#aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../relational_store/test/native/dataability/unittest localTestSrc) -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../relational_store/test/native/rdb/unittest localTestSrc) -#aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../relational_store/test/native/rdb_data_share_adapter/unittest localTestSrc) -#aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../udmf/framework/innerkitsimpl/test/unittest remoteTestSrc) - -set(links secure mock relational_store data_share preferences jsoncpp crypto distributeddb data_object app adapter svcFwk kvdb service udmf) +set(links secure mock app adapter svcFwk service) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - enable_testing() -add_executable(LDBTest ${remoteTestSrc} ${localTestSrc} ${mainSrc} ${serviceSrc}) -target_link_libraries(LDBTest ${links} gtest_main gcov) -add_executable(LDBLocalTest ${localTestSrc} ${mainSrc} ${clientSrc}) -target_link_libraries(LDBLocalTest ${links} gtest_main gcov) -#include(GoogleTest) -#gtest_discover_tests(${TEST_BINARY}) \ No newline at end of file +#************************************************KVDBTest start************************************************# +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/innerkitsimpl/kvdb/test KvStoreTestSrc) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/common/test KvStoreTestSrc) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/innerkitsimpl/distributeddatafwk/test/unittest KvStoreTestSrc) +add_executable(KVDBTest ${KvStoreTestSrc} ${mainSrc} ${serviceSrc}) +target_link_libraries(KVDBTest ${links} gtest_main gcov distributeddb kvdb) +target_include_directories(KVDBTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/common) +target_include_directories(KVDBTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/innerkitsimpl/kvdb/include) +target_include_directories(KVDBTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/innerkitsimpl/object/include) +target_include_directories(KVDBTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/innerkitsimpl/distributeddatafwk/include) +target_include_directories(KVDBTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/innerkitsimpl/distributeddatafwk/src) +target_include_directories(KVDBTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/libs/distributeddb/include) +target_include_directories(KVDBTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/libs/distributeddb/interfaces/include) +target_include_directories(KVDBTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/libs/distributeddb/interfaces/include/relational) +target_include_directories(KVDBTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/libs/distributeddb/interfaces/include/cloud) +#************************************************KVDBTest end************************************************# + +#************************************************DataMgrServiceTest start************************************************# +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/framework/test DataMgrTestSrc) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/adapter/account/test DataMgrTestSrc) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/adapter/communicator/test/unittest DataMgrTestSrc) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/test/mock DataMgrTestSrc) +list(REMOVE_ITEM DataMgrTestSrc "${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/test/mock/adapter_mock.cpp") +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/test DataMgrTestSrc) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/test/data_share DataMgrTestSrc) +add_executable(DataMgrServiceTest ${DataMgrTestSrc} ${mainSrc} ${serviceSrc}) +target_link_libraries(DataMgrServiceTest ${links} gtest_main gcov relational_store data_share preferences distributeddb data_object kvdb udmf) +target_include_directories(DataMgrServiceTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/backup/include) +target_include_directories(DataMgrServiceTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/bootstrap/include) +target_include_directories(DataMgrServiceTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/config/include) +target_include_directories(DataMgrServiceTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/crypto/include) +target_include_directories(DataMgrServiceTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/directory/include) +target_include_directories(DataMgrServiceTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/matrix/include) +target_include_directories(DataMgrServiceTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/data_share/common) +target_include_directories(DataMgrServiceTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/data_share/data) +target_include_directories(DataMgrServiceTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/data_share/strategies) +target_include_directories(DataMgrServiceTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/udmf/lifecycle) +target_include_directories(DataMgrServiceTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/udmf/permission) +target_include_directories(DataMgrServiceTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/udmf/preprocess) +target_include_directories(DataMgrServiceTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/udmf/store) +target_include_directories(DataMgrServiceTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/service/crypto/include) +target_include_directories(DataMgrServiceTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/app/src/) + +#************************************************DataMgrServiceTest start************************************************# + +#************************************************RDBTest start************************************************# +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../relational_store/test/native/dataability/unittest RelationalStoreTestSrc) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../relational_store/test/native/rdb/unittest RelationalStoreTestSrc) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../relational_store/test/native/rdb_bms_adapter/unittest RelationalStoreTestSrc) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../relational_store/test/native/rdb_data_ability_adapter/unittest RelationalStoreTestSrc) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../relational_store/test/native/rdb_data_share_adapter/unittest RelationalStoreTestSrc) +add_executable(RDBTest ${RelationalStoreTestSrc} ${mainSrc} ${serviceSrc}) +target_link_libraries(RDBTest ${links} gtest_main gcov relational_store) +target_include_directories(RDBTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../relational_store/frameworks/common/include) +target_include_directories(RDBTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../relational_store/frameworks/js/napi/common/include) +target_include_directories(RDBTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../relational_store/frameworks/js/napi/dataability/include) +target_include_directories(RDBTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../relational_store/frameworks/js/napi/rdb/include) +target_include_directories(RDBTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../relational_store/frameworks/native/dataability/src) +target_include_directories(RDBTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../relational_store/frameworks/native/rdb/include) +target_include_directories(RDBTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../relational_store/frameworks/native/rdb_device_manager_adapter/include) +#************************************************RDBTest end************************************************# + +#************************************************PerferencesTest start************************************************# +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../preferences/test/native/unittest preferencesTestSrc) +add_executable(PerferencesTest ${preferencesTestSrc} ${mainSrc} ${clientSrc}) +target_link_libraries(PerferencesTest ${links} gtest_main gcov preferences kvdb) +target_include_directories(PerferencesTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../preferences/frameworks/native) +target_include_directories(PerferencesTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../preferences/frameworks/common/include) +target_include_directories(PerferencesTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../preferences/frameworks/native/platform/include) +#************************************************PerferencesTest end************************************************# + +#************************************************dataShareTest start************************************************# +file(GLOB_RECURSE dataShareTestSrc ${CMAKE_CURRENT_SOURCE_DIR}/../data_share/test/native/unittest/*.cpp) +add_executable(dataShareTest ${dataShareTestSrc} ${mainSrc} ${serviceSrc}) +target_link_libraries(dataShareTest ${links} gtest_main gcov data_share) +target_include_directories(dataShareTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../data_share/frameworks/native/common/include) +target_include_directories(dataShareTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../data_share/test/native/unittest/mediadatashare_test/include) +target_include_directories(dataShareTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../data_share/frameworks/native/consumer/controller/common) +target_include_directories(dataShareTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../data_share/frameworks/native/consumer/controller/provider/include) +target_include_directories(dataShareTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../data_share/frameworks/native/consumer/controller/service/include) +target_include_directories(dataShareTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../data_share/frameworks/native/consumer/include) +target_include_directories(dataShareTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../data_share/frameworks/native/provider/include) +target_include_directories(dataShareTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../data_share/frameworks/native/proxy/include) +#************************************************dataShareTest end************************************************# + +#************************************************dataObjectTest start************************************************# +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../data_object/frameworks/innerkitsimpl/test/unittest/mock/src dataObjectTestSrc) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../data_object/frameworks/innerkitsimpl/test/unittest/src dataObjectTestSrc) +add_executable(dataObjectTest ${dataObjectTestSrc} ${mainSrc} ${serviceSrc}) +target_link_libraries(dataObjectTest ${links} gtest_main gcov data_object distributeddb) +target_include_directories(dataObjectTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../data_object/frameworks/innerkitsimpl/include/adaptor) +target_include_directories(dataObjectTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../data_object/frameworks/innerkitsimpl/include/common) +target_include_directories(dataObjectTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../data_object/frameworks/innerkitsimpl/include/communicator) +target_include_directories(dataObjectTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../data_object/frameworks/innerkitsimpl/test/unittest/mock/include) +#************************************************dataObjectTest end************************************************# + +#************************************************UdmfTest start************************************************# +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../udmf/framework/innerkitsimpl/test/unittest UdmfTestSrc) +add_executable(UdmfTest ${UdmfTestSrc} ${mainSrc} ${serviceSrc}) +target_link_libraries(UdmfTest ${links} gtest_main gcov udmf) +target_include_directories(UdmfTest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../udmf/framework/common) +#************************************************UdmfTest end************************************************# + +include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/../datamgr_service/services/distributeddataservice/app/src/) +include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/innerkitsimpl/distributeddatafwk/include) +include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/innerkitsimpl/distributeddatafwk/src) +include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/innerkitsimpl/kvdb/include) +include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/../kv_store/frameworks/common) \ No newline at end of file diff --git a/test/test_main.cpp b/test/test_main.cpp index 6e4f8f8d..95aca7eb 100644 --- a/test/test_main.cpp +++ b/test/test_main.cpp @@ -37,8 +37,7 @@ int main(int argc, char *argv[]) sigaction(SIGTERM, &g_action, &g_oldAction); LoadService loadService; MockStarter::Instance()->Start(); - std::string tset; - std::cout << "start" << tset << std::endl; + std::cout << "start" << std::endl; testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } -- Gitee