From 2e37d040300ed96f93af64ceaaee867465e7ecd9 Mon Sep 17 00:00:00 2001 From: bjd Date: Tue, 8 Jul 2025 16:29:35 +0800 Subject: [PATCH 01/14] =?UTF-8?q?cjson=E4=BB=A3=E7=A0=81=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bjd --- bundle.json | 2 +- .../adapter/communicator/BUILD.gn | 2 +- .../adapter/communicator/test/BUILD.gn | 2 +- services/distributeddataservice/app/BUILD.gn | 2 +- .../distributeddataservice/app/test/BUILD.gn | 8 +- .../distributeddataservice/framework/BUILD.gn | 2 +- .../include/serializable/serializable.h | 117 +-- .../framework/serializable/serializable.cpp | 911 +----------------- .../framework/test/BUILD.gn | 12 +- .../framework/test/cloud_test.cpp | 6 +- .../framework/test/meta_data_test.cpp | 6 +- .../framework/test/serializable_test.cpp | 400 ++++---- .../framework/test/subscription_test.cpp | 16 +- .../rust/extension/BUILD.gn | 2 +- .../service/backup/BUILD.gn | 2 +- .../service/bootstrap/BUILD.gn | 2 +- .../service/cloud/BUILD.gn | 2 +- .../service/config/BUILD.gn | 2 +- .../config/src/model/component_config.cpp | 2 +- .../service/data_share/BUILD.gn | 2 +- .../service/dumper/BUILD.gn | 2 +- .../service/kvdb/BUILD.gn | 2 +- .../service/matrix/BUILD.gn | 2 +- .../service/permission/BUILD.gn | 2 +- .../service/test/BUILD.gn | 30 +- .../service/test/config_factory_test.cpp | 2 +- .../test/data_share_profile_config_test.cpp | 4 +- .../objectservicestub_fuzzer/BUILD.gn | 2 +- 28 files changed, 277 insertions(+), 1269 deletions(-) diff --git a/bundle.json b/bundle.json index 3a22c1c14..f726ee71c 100644 --- a/bundle.json +++ b/bundle.json @@ -92,7 +92,7 @@ "app_file_service", "file_api", "openssl", - "cJSON", + "json", "dmsfwk", "data_object", "init" diff --git a/services/distributeddataservice/adapter/communicator/BUILD.gn b/services/distributeddataservice/adapter/communicator/BUILD.gn index c46ff0ade..9cb388498 100755 --- a/services/distributeddataservice/adapter/communicator/BUILD.gn +++ b/services/distributeddataservice/adapter/communicator/BUILD.gn @@ -64,7 +64,7 @@ ohos_source_set("distributeddata_communicator") { "dsoftbus:softbus_client", "hilog:libhilog", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:datamgr_common", "kv_store:distributeddb", ] diff --git a/services/distributeddataservice/adapter/communicator/test/BUILD.gn b/services/distributeddataservice/adapter/communicator/test/BUILD.gn index a41f0430c..93d24695f 100755 --- a/services/distributeddataservice/adapter/communicator/test/BUILD.gn +++ b/services/distributeddataservice/adapter/communicator/test/BUILD.gn @@ -218,7 +218,7 @@ ohos_unittest("SoftbusAdapterStandardTest") { "dsoftbus:softbus_client", "hilog:libhilog", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:datamgr_common", "kv_store:distributeddata_inner", "kv_store:distributeddb", diff --git a/services/distributeddataservice/app/BUILD.gn b/services/distributeddataservice/app/BUILD.gn index 8263d7234..9368b28c5 100644 --- a/services/distributeddataservice/app/BUILD.gn +++ b/services/distributeddataservice/app/BUILD.gn @@ -144,7 +144,7 @@ ohos_shared_library("distributeddataservice") { "hitrace:hitrace_meter", "hitrace:libhitracechain", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:datamgr_common", "kv_store:distributeddata_mgr", "kv_store:distributeddb", diff --git a/services/distributeddataservice/app/test/BUILD.gn b/services/distributeddataservice/app/test/BUILD.gn index 9fc966e3c..3d9a2e9d2 100644 --- a/services/distributeddataservice/app/test/BUILD.gn +++ b/services/distributeddataservice/app/test/BUILD.gn @@ -250,7 +250,7 @@ ohos_unittest("SessionManagerTest") { "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddata_mgr", "kv_store:distributeddb", @@ -325,7 +325,7 @@ ohos_unittest("KvStoreDataServiceClearTest") { "hitrace:hitrace_meter", "hitrace:libhitracechain", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddata_mgr", "kv_store:distributeddb", @@ -445,7 +445,7 @@ ohos_unittest("UpgradeManagerTest") { "c_utils:utils", "googletest:gtest_main", "hilog:libhilog", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", ] @@ -515,7 +515,7 @@ ohos_unittest("RouteHeadHandlerImplTest") { "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddata_mgr", "kv_store:distributeddb", diff --git a/services/distributeddataservice/framework/BUILD.gn b/services/distributeddataservice/framework/BUILD.gn index 3857df595..c02ccc84c 100644 --- a/services/distributeddataservice/framework/BUILD.gn +++ b/services/distributeddataservice/framework/BUILD.gn @@ -137,7 +137,7 @@ ohos_shared_library("distributeddatasvcfwk") { "common_event_service:cesfwk_innerkits", "hilog:libhilog", "huks:libhukssdk", - "cJSON:cjson", + "json:nlohmann_json_static", "openssl:libcrypto_shared", "kv_store:datamgr_common", "kv_store:distributeddb", diff --git a/services/distributeddataservice/framework/include/serializable/serializable.h b/services/distributeddataservice/framework/include/serializable/serializable.h index a69eec77d..93f887544 100644 --- a/services/distributeddataservice/framework/include/serializable/serializable.h +++ b/services/distributeddataservice/framework/include/serializable/serializable.h @@ -15,16 +15,14 @@ #ifndef OHOS_DISTRIBUTED_DATA_FRAMEWORKS_COMMON_SERIALIZABLE_H #define OHOS_DISTRIBUTED_DATA_FRAMEWORKS_COMMON_SERIALIZABLE_H -#include #include #include -#include #include "visibility.h" #ifndef JSON_NOEXCEPTION #define JSON_NOEXCEPTION #endif #include -struct cJSON; +#include namespace OHOS { namespace DistributedData { #ifndef GET_NAME @@ -32,103 +30,9 @@ namespace DistributedData { #endif struct Serializable { public: - class iterator; - class JSONWrapper final { - public: - friend iterator; - enum class Type : uint8_t { - ARRAY, - OBJECT, - }; - API_EXPORT JSONWrapper(); - API_EXPORT JSONWrapper(cJSON *json, cJSON *root, const std::string &key = ""); - API_EXPORT JSONWrapper(const std::string &jsonStr); - API_EXPORT JSONWrapper(JSONWrapper &&jsonWrapper); - - API_EXPORT operator std::string() const; - API_EXPORT bool operator==(int32_t value) const; - API_EXPORT bool operator==(const std::string &value) const; - - API_EXPORT JSONWrapper &operator=(JSONWrapper &&jsonWrapper); - API_EXPORT JSONWrapper &operator=(JSONWrapper::Type type); - API_EXPORT JSONWrapper &operator=(bool value); - API_EXPORT JSONWrapper &operator=(int32_t value); - API_EXPORT JSONWrapper &operator=(uint32_t value); - API_EXPORT JSONWrapper &operator=(int64_t value); - API_EXPORT JSONWrapper &operator=(uint64_t value); - API_EXPORT JSONWrapper &operator=(double value); - API_EXPORT JSONWrapper &operator=(const char *value); - API_EXPORT JSONWrapper &operator=(const std::string &value); - API_EXPORT JSONWrapper &operator=(const std::vector &value); - API_EXPORT JSONWrapper &operator[](const std::string &key); - API_EXPORT JSONWrapper &operator[](size_t index); - API_EXPORT JSONWrapper &operator[](size_t index) const; - - API_EXPORT bool is_null() const; - API_EXPORT bool is_boolean() const; - API_EXPORT bool is_number_integer() const; - API_EXPORT bool is_number_unsigned() const; - API_EXPORT bool is_number_float() const; - API_EXPORT bool is_string() const; - API_EXPORT bool is_array() const; - API_EXPORT bool is_object() const; - API_EXPORT bool is_discarded() const; - API_EXPORT bool get_to(bool &values) const; - API_EXPORT bool get_to(int16_t &values) const; - API_EXPORT bool get_to(uint16_t &values) const; - API_EXPORT bool get_to(int32_t &values) const; - API_EXPORT bool get_to(uint32_t &values) const; - API_EXPORT bool get_to(int64_t &values) const; - API_EXPORT bool get_to(uint64_t &values) const; - API_EXPORT bool get_to(double &values) const; - API_EXPORT bool get_to(std::string &values) const; - API_EXPORT bool get_to(std::vector &values) const; - API_EXPORT size_t size() const; - API_EXPORT std::string dump() const; - API_EXPORT iterator find(const std::string &key) const; - API_EXPORT iterator begin() const; - API_EXPORT iterator end() const; - API_EXPORT ~JSONWrapper(); - API_EXPORT static JSONWrapper parse(const std::string &str); - API_EXPORT static bool accept(const std::string &str); - - API_EXPORT static JSONWrapper array(); - API_EXPORT void push_back(const JSONWrapper &value); - API_EXPORT static std::string to_string(const JSONWrapper &jsonWrapper); - API_EXPORT bool operator==(const std::map& value) const; - API_EXPORT bool operator==(const std::map& value) const; - API_EXPORT bool operator==(const std::vector& value) const; - API_EXPORT bool empty() const; - API_EXPORT JSONWrapper& operator=(const std::map& value); - API_EXPORT JSONWrapper& operator=(const std::map& value); - API_EXPORT bool erase(const std::string& key); - API_EXPORT bool erase(int index); - private: - void AddToRoot(); - JSONWrapper(const JSONWrapper& jsonWrapper) = delete; - JSONWrapper &operator=(const JSONWrapper &jsonWrapper) = delete; - bool ReplaceNode(cJSON *node); - void SyncChildren() const; - cJSON *json_ = nullptr; - cJSON *root_ = nullptr; - std::string key_; - bool needDel_ = false; - mutable std::vector> children_; - }; - class iterator { - public: - API_EXPORT iterator(std::vector>::iterator it); - API_EXPORT iterator &operator++(); - API_EXPORT bool operator==(const iterator &iter) const; - API_EXPORT bool operator!=(const iterator &iter) const; - API_EXPORT const JSONWrapper &operator*() const; - API_EXPORT std::string key() const; - API_EXPORT const JSONWrapper &value() const; - - private: - std::vector>::iterator node_; - }; - using json = JSONWrapper; + using json = nlohmann::json; + using size_type = nlohmann::json::size_type; + using error_handler_t = nlohmann::detail::error_handler_t; API_EXPORT json Marshall() const; template @@ -136,7 +40,7 @@ public: { json root; SetValue(root, values); - return root.dump(); + return root.dump(-1, ' ', false, error_handler_t::replace); } API_EXPORT bool Unmarshall(const std::string &jsonStr); @@ -225,9 +129,8 @@ bool Serializable::GetValue(const json &node, const std::string &name, std::vect return false; } bool result = true; - auto size = subNode.size(); - values.resize(size); - for (size_t i = 0; i < size; ++i) { + values.resize(subNode.size()); + for (size_type i = 0; i < subNode.size(); ++i) { result = GetValue(subNode[i], "", values[i]) && result; } return result; @@ -237,8 +140,8 @@ template bool Serializable::SetValue(json &node, const std::vector &values) { bool result = true; - size_t i = 0; - node = JSONWrapper::Type::ARRAY; + size_type i = 0; + node = json::value_t::array; for (const auto &value : values) { result = SetValue(node[i], value) && result; i++; @@ -264,7 +167,7 @@ template bool Serializable::SetValue(json &node, const std::map &values) { bool result = true; - node = JSONWrapper::Type::OBJECT; + node = json::value_t::object; for (const auto &[key, value] : values) { result = SetValue(node[key], value) && result; } diff --git a/services/distributeddataservice/framework/serializable/serializable.cpp b/services/distributeddataservice/framework/serializable/serializable.cpp index e3b10b4ec..0a82b14e4 100644 --- a/services/distributeddataservice/framework/serializable/serializable.cpp +++ b/services/distributeddataservice/framework/serializable/serializable.cpp @@ -13,11 +13,7 @@ * limitations under the License. */ -#define LOG_TAG "serializable" -#include "log_print.h" #include "serializable/serializable.h" - -#include namespace OHOS { namespace DistributedData { Serializable::json Serializable::Marshall() const @@ -29,13 +25,13 @@ Serializable::json Serializable::Marshall() const bool Serializable::Unmarshall(const std::string &jsonStr) { - json jsonObj = json::parse(jsonStr); + json jsonObj = json::parse(jsonStr, nullptr, false); if (jsonObj.is_discarded()) { // if the string size is less than 1, means the string is invalid. if (jsonStr.empty()) { return false; } - jsonObj = json::parse(jsonStr.substr(1)); // drop first char to adapt A's value; + jsonObj = json::parse(jsonStr.substr(1), nullptr, false); // drop first char to adapt A's value; if (jsonObj.is_discarded()) { return false; } @@ -45,13 +41,13 @@ bool Serializable::Unmarshall(const std::string &jsonStr) Serializable::json Serializable::ToJson(const std::string &jsonStr) { - json jsonObj = json::parse(jsonStr); + json jsonObj = json::parse(jsonStr, nullptr, false); if (jsonObj.is_discarded()) { // if the string size is less than 1, means the string is invalid. if (jsonStr.empty()) { return {}; } - jsonObj = json::parse(jsonStr.substr(1)); // drop first char to adapt A's value; + jsonObj = json::parse(jsonStr.substr(1), nullptr, false); // drop first char to adapt A's value; if (jsonObj.is_discarded()) { return {}; } @@ -62,7 +58,7 @@ Serializable::json Serializable::ToJson(const std::string &jsonStr) bool Serializable::IsJson(const std::string &jsonStr) { if (!json::accept(jsonStr)) { - return json::accept(jsonStr.substr(1)); + return json::accept(jsonStr.begin() + 1, jsonStr.end()); } return true; } @@ -73,7 +69,8 @@ bool Serializable::GetValue(const json &node, const std::string &name, std::stri if (subNode.is_null() || !subNode.is_string()) { return false; } - return subNode.get_to(value); + value = subNode; + return true; } bool Serializable::GetValue(const json &node, const std::string &name, uint32_t &value) @@ -144,33 +141,33 @@ bool Serializable::GetValue(const json &node, const std::string &name, bool &val return false; } -bool Serializable::GetValue(const json &node, const std::string &name, std::vector &value) +bool Serializable::GetValue(const json &node, const std::string &name, double &value) { auto &subNode = GetSubNode(node, name); - if (subNode.is_null() || !subNode.is_array()) { + if (subNode.is_null() || !subNode.is_number_float()) { return false; } - - return subNode.get_to(value); + subNode.get_to(value); + return true; } -bool Serializable::GetValue(const json &node, const std::string &name, Serializable &value) +bool Serializable::GetValue(const json &node, const std::string &name, std::vector &value) { auto &subNode = GetSubNode(node, name); - if (subNode.is_null() || !subNode.is_object()) { + if (subNode.is_null() || !subNode.is_array()) { return false; } - return value.Unmarshal(subNode); + value = std::vector(subNode); + return true; } -bool Serializable::GetValue(const json &node, const std::string &name, double &value) +bool Serializable::GetValue(const json &node, const std::string &name, Serializable &value) { auto &subNode = GetSubNode(node, name); - if (subNode.is_null() || !subNode.is_number_integer()) { + if (subNode.is_null() || !subNode.is_object()) { return false; } - subNode.get_to(value); - return true; + return value.Unmarshal(subNode); } bool Serializable::SetValue(json &node, const std::string &value) @@ -228,7 +225,7 @@ bool Serializable::SetValue(json &node, const Serializable &value) const Serializable::json &Serializable::GetSubNode(const json &node, const std::string &name) { - static const json jsonNull; + static const json jsonNull = json::value_t::null; if (node.is_discarded() || node.is_null()) { return jsonNull; } @@ -243,875 +240,5 @@ const Serializable::json &Serializable::GetSubNode(const json &node, const std:: } return *it; } - -Serializable::JSONWrapper::JSONWrapper() : root_(nullptr) -{ - json_ = cJSON_CreateNull(); - needDel_ = true; -} - -Serializable::JSONWrapper::JSONWrapper(cJSON *json, cJSON *root, const std::string &key) - : json_(json), root_(root), key_(key), needDel_(root == nullptr) -{ -} - -Serializable::JSONWrapper::JSONWrapper(const std::string &jsonStr) : root_(nullptr), needDel_(true) -{ - json_ = cJSON_Parse(jsonStr.c_str()); -} - -Serializable::JSONWrapper::JSONWrapper(JSONWrapper &&jsonWrapper) -{ - json_ = std::move(jsonWrapper.json_); - jsonWrapper.json_ = nullptr; - root_ = jsonWrapper.root_; - jsonWrapper.root_ = nullptr; - key_ = std::move(jsonWrapper.key_); - children_ = std::move(jsonWrapper.children_); - needDel_ = jsonWrapper.needDel_; -} - -Serializable::JSONWrapper::operator std::string() const -{ - return dump(); -} - -Serializable::JSONWrapper &Serializable::JSONWrapper::operator=(JSONWrapper &&jsonWrapper) -{ - if (this == &jsonWrapper) { - return *this; - } - if (root_ == nullptr) { - cJSON_Delete(json_); - json_ = nullptr; - } - json_ = std::move(jsonWrapper.json_); - jsonWrapper.json_ = nullptr; - root_ = jsonWrapper.root_; - jsonWrapper.root_ = nullptr; - key_ = std::move(jsonWrapper.key_); - children_ = std::move(jsonWrapper.children_); - needDel_ = jsonWrapper.needDel_; - return *this; -} - -Serializable::JSONWrapper &Serializable::JSONWrapper::operator=(Serializable::JSONWrapper::Type type) -{ - if (json_ != nullptr) { - ZLOGE("cannot use operator[]"); - return *this; - } - switch (type) { - case Type::ARRAY: - json_ = cJSON_CreateArray(); - break; - case Type::OBJECT: - json_ = cJSON_CreateObject(); - } - if (json_ == nullptr || root_ == nullptr) { - return *this; - } - AddToRoot(); - return *this; -} - -Serializable::JSONWrapper &Serializable::JSONWrapper::operator=(bool value) -{ - if (root_ == nullptr && cJSON_IsNull(json_)) { - cJSON_Delete(json_); - json_ = nullptr; - } - if (json_ == nullptr) { - json_ = cJSON_CreateBool(value); - if (json_ == nullptr || root_ == nullptr) { - return *this; - } - AddToRoot(); - } - if (json_ == nullptr) { - return *this; - } - if (cJSON_IsBool(json_)) { - cJSON_SetBoolValue(json_, value); - return *this; - } - cJSON *node = cJSON_CreateBool(value); - if (node == nullptr) { - return *this; - } - if (!ReplaceNode(node)) { - cJSON_Delete(node); - } - return *this; -} - -Serializable::JSONWrapper &Serializable::JSONWrapper::operator=(int32_t value) -{ - if (root_ == nullptr && cJSON_IsNull(json_)) { - cJSON_Delete(json_); - json_ = nullptr; - } - if (json_ == nullptr) { - json_ = cJSON_CreateNumber(value); - if (json_ == nullptr || root_ == nullptr) { - return *this; - } - AddToRoot(); - } - if (json_ == nullptr) { - return *this; - } - if (cJSON_IsNumber(json_)) { - cJSON_SetNumberValue(json_, value); - return *this; - } - cJSON *node = cJSON_CreateNumber(value); - if (node == nullptr) { - return *this; - } - if (!ReplaceNode(node)) { - cJSON_Delete(node); - } - return *this; -} - -Serializable::JSONWrapper &Serializable::JSONWrapper::operator=(uint32_t value) -{ - if (root_ == nullptr && cJSON_IsNull(json_)) { - cJSON_Delete(json_); - json_ = nullptr; - } - if (json_ == nullptr) { - json_ = cJSON_CreateNumber(static_cast(value)); - if (json_ == nullptr || root_ == nullptr) { - return *this; - } - AddToRoot(); - } - if (json_ == nullptr) { - return *this; - } - if (cJSON_IsNumber(json_)) { - cJSON_SetNumberValue(json_, static_cast(value)); - return *this; - } - cJSON *node = cJSON_CreateNumber(static_cast(value)); - if (node == nullptr) { - return *this; - } - if (!ReplaceNode(node)) { - ZLOGE("replace node failed."); - cJSON_Delete(node); - } - return *this; -} - -Serializable::JSONWrapper &Serializable::JSONWrapper::operator=(int64_t value) -{ - if (root_ == nullptr && cJSON_IsNull(json_)) { - cJSON_Delete(json_); - json_ = nullptr; - } - if (json_ == nullptr) { - json_ = cJSON_CreateNumber(value); - if (json_ == nullptr || root_ == nullptr) { - return *this; - } - AddToRoot(); - } - if (json_ == nullptr) { - return *this; - } - if (cJSON_IsNumber(json_)) { - cJSON_SetNumberValue(json_, value); - return *this; - } - cJSON *node = cJSON_CreateNumber(value); - if (node == nullptr) { - return *this; - } - if (!ReplaceNode(node)) { - cJSON_Delete(node); - } - return *this; -} - -Serializable::JSONWrapper &Serializable::JSONWrapper::operator=(uint64_t value) -{ - int64_t number = static_cast(value); - return operator=(number); -} - -Serializable::JSONWrapper &Serializable::JSONWrapper::operator=(double value) -{ - if (root_ == nullptr && cJSON_IsNull(json_)) { - cJSON_Delete(json_); - json_ = nullptr; - } - if (json_ == nullptr) { - json_ = cJSON_CreateNumber(value); - if (json_ == nullptr || root_ == nullptr) { - return *this; - } - AddToRoot(); - } - if (json_ == nullptr) { - return *this; - } - if (cJSON_IsNumber(json_)) { - cJSON_SetNumberValue(json_, value); - return *this; - } - cJSON *node = cJSON_CreateNumber(value); - if (node == nullptr) { - return *this; - } - if (!ReplaceNode(node)) { - cJSON_Delete(node); - } - return *this; -} - -Serializable::JSONWrapper &Serializable::JSONWrapper::operator=(const char *value) -{ - if (root_ == nullptr && cJSON_IsNull(json_)) { - cJSON_Delete(json_); - json_ = nullptr; - } - - if (json_ == nullptr) { - json_ = cJSON_CreateString(value); - if (json_ == nullptr || root_ == nullptr) { - return *this; - } - AddToRoot(); - } - if (cJSON_IsString(json_)) { - cJSON_SetValuestring(json_, value); - return *this; - } - - cJSON *node = cJSON_CreateString(value); - if (node == nullptr) { - return *this; - } - if (!ReplaceNode(node)) { - cJSON_Delete(node); - } - return *this; -} - -Serializable::JSONWrapper &Serializable::JSONWrapper::operator=(const std::string &value) -{ - return operator=(value.c_str()); -} - -Serializable::JSONWrapper &Serializable::JSONWrapper::operator=(const std::vector &value) -{ - if (root_ == nullptr && cJSON_IsNull(json_)) { - cJSON_Delete(json_); - json_ = nullptr; - } - if (json_ != nullptr) { - return *this; - } - json_ = cJSON_CreateArray(); - children_.clear(); - for (size_t i = 0; json_ && (i < value.size()); i++) { - auto node = cJSON_CreateNumber(value[i]); - if (!node || !cJSON_AddItemToArray(json_, node)) { - cJSON_Delete(json_); - cJSON_Delete(node); - json_ = nullptr; - children_.clear(); - return *this; - } - children_.push_back(std::make_shared(node, json_)); - } - if (json_ == nullptr || root_ == nullptr) { - return *this; - } - AddToRoot(); - return *this; -} - -bool Serializable::JSONWrapper::ReplaceNode(cJSON *node) -{ - if (root_ == nullptr) { - cJSON_Delete(json_); - json_ = node; - return true; - } - - bool success = false; - if (key_.empty()) { - success = cJSON_ReplaceItemViaPointer(root_, json_, node); - } else { - success = cJSON_ReplaceItemInObject(root_, key_.c_str(), node); - } - - if (success) { - json_ = node; - children_.clear(); - } - return success; -} - -Serializable::JSONWrapper &Serializable::JSONWrapper::operator[](const std::string &key) -{ - if (root_ == nullptr && cJSON_IsNull(json_)) { - cJSON_Delete(json_); - json_ = nullptr; - } - if (json_ == nullptr) { - json_ = cJSON_CreateObject(); - if (json_ != nullptr && root_ != nullptr) { - AddToRoot(); - } - } - if (!is_object()) { - ZLOGE("cannot use operator[]."); - } - auto it = children_.begin(); - while (it != children_.end()) { - if ((*it)->key_ == key) { - return **it; - } - ++it; - } - auto item = cJSON_GetObjectItem(json_, key.c_str()); - auto res = std::make_shared(item, json_, key); - children_.push_back(res); - return *res; -} - -Serializable::JSONWrapper &Serializable::JSONWrapper::operator[](size_t index) -{ - if (root_ == nullptr && cJSON_IsNull(json_)) { - cJSON_Delete(json_); - json_ = nullptr; - } - if (json_ == nullptr) { - json_ = cJSON_CreateArray(); - if (json_ != nullptr && root_ != nullptr) { - AddToRoot(); - } - } - if (!is_array()) { - ZLOGE("cannot use operator[]."); - } - int rawSize = cJSON_GetArraySize(json_); - size_t size = (rawSize < 0) ? 0 : static_cast(rawSize); - auto len = children_.size(); - while (len < size) { - auto item = cJSON_GetArrayItem(json_, len); - children_.push_back(std::make_shared(item, json_)); - len++; - } - if (index > len) { - ZLOGE("index over limit."); - } - while (len <= index) { - auto item = cJSON_GetArrayItem(json_, len); - children_.push_back(std::make_shared(item, json_)); - len++; - } - return *children_[index]; -} - -Serializable::JSONWrapper &Serializable::JSONWrapper::operator[](size_t index) const -{ - if (!is_array()) { - ZLOGE("invalid args."); - } - int rawSize = cJSON_GetArraySize(json_); - size_t size = (rawSize < 0) ? 0 : static_cast(rawSize); - if (index >= size) { - ZLOGE("invalid args."); - } - auto len = children_.size(); - while (len < size) { - auto item = cJSON_GetArrayItem(json_, len); - children_.push_back(std::make_shared(item, json_)); - len++; - } - if (index > len) { - ZLOGE("index over limit."); - } - while (len <= index) { - auto item = cJSON_GetArrayItem(json_, len); - children_.push_back(std::make_shared(item, json_)); - len++; - } - return *children_[index]; -} - -bool Serializable::JSONWrapper::is_null() const -{ - return cJSON_IsNull(json_); -} - -bool Serializable::JSONWrapper::is_boolean() const -{ - return cJSON_IsBool(json_); -} - -bool Serializable::JSONWrapper::is_number_integer() const -{ - return cJSON_IsNumber(json_); -} - -bool Serializable::JSONWrapper::is_number_unsigned() const -{ - return cJSON_IsNumber(json_) && cJSON_GetNumberValue(json_) >= 0; -} - -bool Serializable::JSONWrapper::is_number_float() const -{ - return cJSON_IsNumber(json_); -} - -bool Serializable::JSONWrapper::is_string() const -{ - return cJSON_IsString(json_); -} - -bool Serializable::JSONWrapper::is_array() const -{ - return cJSON_IsArray(json_); -} - -bool Serializable::JSONWrapper::is_object() const -{ - return cJSON_IsObject(json_); -} - -bool Serializable::JSONWrapper::is_discarded() const -{ - return json_ == nullptr; -} - -bool Serializable::JSONWrapper::accept(const std::string &str) -{ - cJSON *json = cJSON_Parse(str.c_str()); - if (json == nullptr) { - return false; - } - - cJSON_Delete(json); - return true; -} - -bool Serializable::JSONWrapper::get_to(bool &values) const -{ - if (json_ == nullptr || !is_boolean()) { - return false; - } - - values = cJSON_IsTrue(json_) ? true : false; - return true; -} - -bool Serializable::JSONWrapper::get_to(int16_t &values) const -{ - if (json_ == nullptr || !is_number_integer()) { - return false; - } - values = json_->valueint; - return true; -} - -bool Serializable::JSONWrapper::get_to(uint16_t &values) const -{ - if (json_ == nullptr || !is_number_unsigned()) { - return false; - } - values = json_->valueint; - return true; -} - -bool Serializable::JSONWrapper::get_to(int32_t &values) const -{ - if (json_ == nullptr || !is_number_integer()) { - return false; - } - values = json_->valueint; - return true; -} - -bool Serializable::JSONWrapper::get_to(uint32_t &values) const -{ - if (json_ == nullptr || !is_number_unsigned()) { - return false; - } - double num = cJSON_GetNumberValue(json_); - values = static_cast(num); - return true; -} - -bool Serializable::JSONWrapper::get_to(int64_t &values) const -{ - if (json_ == nullptr || !is_number_integer()) { - return false; - } - double num = cJSON_GetNumberValue(json_); - values = static_cast(num); - return true; -} - -bool Serializable::JSONWrapper::get_to(uint64_t &values) const -{ - if (json_ == nullptr || !is_number_unsigned()) { - return false; - } - double num = cJSON_GetNumberValue(json_); - values = static_cast(num); - return true; -} - -bool Serializable::JSONWrapper::get_to(double &values) const -{ - if (json_ == nullptr || !is_number_integer()) { - return false; - } - values = cJSON_GetNumberValue(json_); - return true; -} - -bool Serializable::JSONWrapper::get_to(std::string &values) const -{ - if (json_ == nullptr || !is_string()) { - return false; - } - values = cJSON_GetStringValue(json_); - return true; -} - -bool Serializable::JSONWrapper::get_to(std::vector &values) const -{ - if (json_ == nullptr || !is_array()) { - return false; - } - auto size = cJSON_GetArraySize(json_); - values.clear(); - values.reserve(size); - for (auto i = 0; i < size; i++) { - auto item = cJSON_GetArrayItem(json_, i); - if (item) { - values.push_back(cJSON_GetNumberValue(item)); - } - } - return true; -} - -bool Serializable::JSONWrapper::empty() const -{ - if (json_ == nullptr) { - return true; - } - if (cJSON_IsNull(json_)) { - return true; - } - if (cJSON_IsArray(json_) || cJSON_IsObject(json_)) { - return cJSON_GetArraySize(json_) == 0; - } - return false; -} - -size_t Serializable::JSONWrapper::size() const -{ - if (!cJSON_IsArray(json_) && !cJSON_IsObject(json_)) { - return 0; - } - return cJSON_GetArraySize(json_); -} - -std::string Serializable::JSONWrapper::dump() const -{ - if (json_ == nullptr) { - return ""; - } - char *str = cJSON_PrintUnformatted(json_); - std::string res(str); - cJSON_free(str); - return res; -} - -Serializable::iterator Serializable::JSONWrapper::find(const std::string &key) const -{ - SyncChildren(); - auto it = children_.begin(); - while (it != children_.end()) { - if ((*it)->key_ == key) { - return it; - } - ++it; - } - return it; -} - -Serializable::iterator Serializable::JSONWrapper::begin() const -{ - if (json_ == nullptr || (!is_array() && !is_object())) { - ZLOGE("not support."); - } - SyncChildren(); - return children_.begin(); -} - -Serializable::iterator Serializable::JSONWrapper::end() const -{ - if (json_ == nullptr || json_->child == nullptr || (!is_array() && !is_object())) { - ZLOGE("not support."); - } - SyncChildren(); - return children_.end(); -} - -void Serializable::JSONWrapper::SyncChildren() const -{ - int rawSize = cJSON_GetArraySize(json_); - size_t size = (rawSize < 0) ? 0 : static_cast(rawSize); - auto len = children_.size(); - if (len != size) { - children_.clear(); - for (int i = 0; i < size; i++) { - auto item = cJSON_GetArrayItem(json_, i); - children_.push_back(std::make_shared(item, json_, is_object() ? item->string:"")); - } - } -} - -Serializable::JSONWrapper::~JSONWrapper() -{ - if (needDel_ && root_ == nullptr && json_ != nullptr) { - cJSON_Delete(json_); - } -} - -Serializable::JSONWrapper Serializable::JSONWrapper::parse(const std::string &str) -{ - return Serializable::JSONWrapper(cJSON_Parse(str.c_str()), nullptr); -} - -bool Serializable::JSONWrapper::operator==(int32_t value) const -{ - return value == cJSON_GetNumberValue(json_); -} - -bool Serializable::JSONWrapper::operator==(const std::string &value) const -{ - return value == cJSON_GetStringValue(json_); -} - -void Serializable::JSONWrapper::AddToRoot() -{ - if (!key_.empty()) { - if (!cJSON_AddItemToObject(root_, key_.c_str(), json_)) { - cJSON_Delete(json_); - json_ = nullptr; - } else { - needDel_ = false; - } - } else { - if (!cJSON_AddItemToArray(root_, json_)) { - cJSON_Delete(json_); - json_ = nullptr; - } else { - needDel_ = false; - } - } -} - -Serializable::iterator::iterator(std::vector>::iterator it) : node_(it) {} - -Serializable::iterator &Serializable::iterator::operator++() -{ - node_++; - return *this; -} - -bool Serializable::iterator::operator==(const Serializable::iterator &iter) const -{ - return node_ == iter.node_; -} - -bool Serializable::iterator::operator!=(const Serializable::iterator &iter) const -{ - return !operator==(iter); -} - -const Serializable::JSONWrapper &Serializable::iterator::operator*() const -{ - return **node_; -} - -std::string Serializable::iterator::key() const -{ - return (*node_)->key_; -} - -const Serializable::JSONWrapper &Serializable::iterator::value() const -{ - return operator*(); -} - -Serializable::JSONWrapper Serializable::JSONWrapper::array() -{ - cJSON* json = cJSON_CreateArray(); - return Serializable::JSONWrapper(json, nullptr, ""); -} - -void Serializable::JSONWrapper::push_back(const JSONWrapper &value) -{ - if (is_array()) { - cJSON *newJson = cJSON_Duplicate(value.json_, 1); - cJSON_AddItemToArray(json_, newJson); - children_.push_back(std::make_shared(newJson, json_)); - } -} - -std::string Serializable::JSONWrapper::to_string(const JSONWrapper &jsonWrapper) -{ - return jsonWrapper.dump(); -} - -bool Serializable::JSONWrapper::operator==(const std::map& value) const -{ - if (!is_object()) { - return false; - } - int rawSize = cJSON_GetArraySize(json_); - size_t size = (rawSize < 0) ? 0 : static_cast(rawSize); - if (size != value.size()) { - return false; - } - for (const auto& pair : value) { - auto item = cJSON_GetObjectItem(json_, pair.first.c_str()); - if (item == nullptr || std::string(cJSON_GetStringValue(item)) != pair.second) { - return false; - } - } - return true; -} - -bool Serializable::JSONWrapper::operator==(const std::map& value) const -{ - if (!is_object()) { - return false; - } - int rawSize = cJSON_GetArraySize(json_); - size_t size = (rawSize < 0) ? 0 : static_cast(rawSize); - if (size != value.size()) { - return false; - } - for (const auto& pair : value) { - auto item = cJSON_GetObjectItem(json_, pair.first.c_str()); - if (item == nullptr || cJSON_GetNumberValue(item) != pair.second) { - return false; - } - } - return true; -} - -bool Serializable::JSONWrapper::operator==(const std::vector& value) const -{ - if (!is_array()) { - return false; - } - int rawSize = cJSON_GetArraySize(json_); - size_t size = (rawSize < 0) ? 0 : static_cast(rawSize); - if (size != value.size()) { - return false; - } - for (size_t i = 0; i < value.size(); ++i) { - auto item = cJSON_GetArrayItem(json_, i); - if (item == nullptr || std::string(cJSON_GetStringValue(item)) != value[i]) { - return false; - } - } - return true; -} - -Serializable::JSONWrapper& Serializable::JSONWrapper::operator=(const std::map& value) -{ - if (json_) { - cJSON_Delete(json_); - json_ = nullptr; - } - json_ = cJSON_CreateObject(); - for (const auto& pair : value) { - cJSON* num = cJSON_CreateNumber(pair.second); - if (!cJSON_AddItemToObject(json_, pair.first.c_str(), num)) { - cJSON_Delete(num); - } - } - children_.clear(); - return *this; -} - -Serializable::JSONWrapper& Serializable::JSONWrapper::operator=(const std::map& value) -{ - if (json_) { - cJSON_Delete(json_); - json_ = nullptr; - } - json_ = cJSON_CreateObject(); - for (const auto& pair : value) { - cJSON* str = cJSON_CreateString(pair.second.c_str()); - if (!cJSON_AddItemToObject(json_, pair.first.c_str(), str)) { - cJSON_Delete(str); - } - } - children_.clear(); - return *this; -} - -bool Serializable::JSONWrapper::erase(const std::string& key) -{ - if (!json_ || !is_object()) { - return false; - } - - auto it = children_.begin(); - while (it != children_.end()) { - if ((*it)->key_ == key) { - it = children_.erase(it); - } else { - ++it; - } - } - - cJSON_DeleteItemFromObject(json_, key.c_str()); - return true; -} - -bool Serializable::JSONWrapper::erase(int index) -{ - if (!json_ || !is_array()) { - return false; - } - - int rawSize = cJSON_GetArraySize(json_); - size_t size = (rawSize < 0) ? 0 : static_cast(rawSize); - auto len = children_.size(); - while (len < size) { - auto item = cJSON_GetArrayItem(json_, len); - children_.push_back(std::make_shared(item, json_)); - len++; - } - - if (index < 0 || index >= size) { - return false; - } - - if (index < children_.size()) { - children_.erase(children_.begin() + index); - } - - cJSON_DeleteItemFromArray(json_, index); - return true; -} - } // namespace DistributedData } // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/framework/test/BUILD.gn b/services/distributeddataservice/framework/test/BUILD.gn index 89d48976e..ee5db04f2 100644 --- a/services/distributeddataservice/framework/test/BUILD.gn +++ b/services/distributeddataservice/framework/test/BUILD.gn @@ -121,7 +121,7 @@ ohos_unittest("ServiceUtilsTest") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:datamgr_common", ] @@ -213,7 +213,7 @@ ohos_unittest("CloudInfoTest") { deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] external_deps = [ - "cJSON:cjson", + "json:nlohmann_json_static", "c_utils:utils", "kv_store:datamgr_common", ] @@ -247,7 +247,7 @@ ohos_unittest("SubscriptionTest") { configs = [ ":module_private_config" ] deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] external_deps = [ - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:datamgr_common", ] } @@ -275,7 +275,7 @@ ohos_unittest("MetaDataManagerTest") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:datamgr_common", "kv_store:distributeddb", "kv_store:distributeddata_inner", @@ -294,7 +294,7 @@ ohos_unittest("StoreMetaDataLocalTest") { deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] external_deps = [ - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:datamgr_common", "kv_store:distributeddb", "kv_store:distributeddata_inner", @@ -355,7 +355,7 @@ ohos_unittest("ServiceMetaDataTest") { "hitrace:hitrace_meter", "hitrace:libhitracechain", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddata_mgr", "kv_store:distributeddb", diff --git a/services/distributeddataservice/framework/test/cloud_test.cpp b/services/distributeddataservice/framework/test/cloud_test.cpp index 3a178e1d5..57e4ab7ec 100644 --- a/services/distributeddataservice/framework/test/cloud_test.cpp +++ b/services/distributeddataservice/framework/test/cloud_test.cpp @@ -248,7 +248,7 @@ HWTEST_F(CloudInfoTest, CloudInfoTest001, TestSize.Level0) Serializable::json node1; cloudInfo1.Marshal(node1); - EXPECT_EQ(Serializable::Marshall(cloudInfo1), Serializable::JSONWrapper::to_string(node1)); + EXPECT_EQ(Serializable::Marshall(cloudInfo1), to_string(node1)); CloudInfo cloudInfo2; cloudInfo2.Unmarshal(node1); @@ -273,7 +273,7 @@ HWTEST_F(CloudInfoTest, AppInfoTest, TestSize.Level0) Serializable::json node1; cloudInfoAppInfo1.Marshal(node1); - EXPECT_EQ(Serializable::Marshall(cloudInfoAppInfo1), Serializable::JSONWrapper::to_string(node1)); + EXPECT_EQ(Serializable::Marshall(cloudInfoAppInfo1), to_string(node1)); CloudInfo::AppInfo cloudInfoAppInfo2; cloudInfoAppInfo2.Unmarshal(node1); @@ -303,7 +303,7 @@ HWTEST_F(CloudInfoTest, TableTest, TestSize.Level0) table1.fields.push_back(field1); Serializable::json node1; table1.Marshal(node1); - EXPECT_EQ(Serializable::Marshall(table1), Serializable::JSONWrapper::to_string(node1)); + EXPECT_EQ(Serializable::Marshall(table1), to_string(node1)); Table table2; table2.Unmarshal(node1); diff --git a/services/distributeddataservice/framework/test/meta_data_test.cpp b/services/distributeddataservice/framework/test/meta_data_test.cpp index 053aabaae..8ff4f7229 100644 --- a/services/distributeddataservice/framework/test/meta_data_test.cpp +++ b/services/distributeddataservice/framework/test/meta_data_test.cpp @@ -35,7 +35,7 @@ #include "metadata/device_meta_data.h" #include "utils/constant.h" #include "gtest/gtest.h" -#include "serializable/serializable.h" +#include using namespace testing::ext; using namespace OHOS; using namespace OHOS::DistributedKv; @@ -781,9 +781,7 @@ HWTEST_F(ServiceMetaDataTest, UserMetaData, TestSize.Level1) Serializable::json node2; userStatus.Marshal(node2); - bool ret; - node2["isActive"].get_to(ret); - EXPECT_EQ(ret, true); + EXPECT_EQ(node2["isActive"], true); EXPECT_EQ(node2["id"], USER_ID2); UserStatus userUnmarshal; diff --git a/services/distributeddataservice/framework/test/serializable_test.cpp b/services/distributeddataservice/framework/test/serializable_test.cpp index 913c745b6..dd162afff 100644 --- a/services/distributeddataservice/framework/test/serializable_test.cpp +++ b/services/distributeddataservice/framework/test/serializable_test.cpp @@ -129,7 +129,7 @@ HWTEST_F(SerializableTest, GetNormalVal, TestSize.Level2) normal.isClear = true; normal.cols = {"adfasdfas"}; auto json = normal.Marshall(); - auto jstr = Serializable::JSONWrapper::to_string(json); + auto jstr = to_string(normal.Marshall()); Normal normal1; normal1.Unmarshall(jstr); ASSERT_TRUE(normal == normal1) << normal1.name; @@ -166,7 +166,7 @@ HWTEST_F(SerializableTest, GetMutilVal, TestSize.Level2) NormalEx normalEx; normalEx.normals = {Normal()}; normalEx.name = "normalEx"; - auto jstr = Serializable::JSONWrapper::to_string(normalEx.Marshall()); + auto jstr = to_string(normalEx.Marshall()); NormalEx normal1; normal1.Unmarshall(jstr); ASSERT_TRUE(normalEx == normal1) << normal1.name; @@ -301,12 +301,192 @@ HWTEST_F(SerializableTest, SetPointerValue, TestSize.Level2) in.value = new int64_t(-100); in.status = new uint32_t(110); in.isClear = new bool(true); - auto json = Serializable::JSONWrapper::to_string(in.Marshall()); + auto json = to_string(in.Marshall()); Test out; out.Unmarshall(json); ASSERT_TRUE(in == out) << in.count; } +/** +* @tc.name: IsJson +* @tc.desc: is json. +* @tc.type: FUNC +*/ +HWTEST_F(SerializableTest, IsJson, TestSize.Level1) +{ + std::string str = "test"; + std::string jsonStr = "\"test\""; + ASSERT_FALSE(Serializable::IsJson(str)); + ASSERT_TRUE(Serializable::IsJson(jsonStr)); +} + +/** +* @tc.name: ToJson_01 +* @tc.desc: to json. +* @tc.type: FUNC +*/ +HWTEST_F(SerializableTest, ToJson_01, TestSize.Level1) +{ + std::string jsonStr = "{\"key\":\"value\"}"; + Serializable::json result = Serializable::ToJson(jsonStr); + ASSERT_FALSE(result.is_discarded()); +} + +/** +* @tc.name: ToJson_02 +* @tc.desc: to json. +* @tc.type: FUNC +*/ +HWTEST_F(SerializableTest, ToJson_02, TestSize.Level1) +{ + std::string jsonStr = "invalid_json"; + Serializable::json result = Serializable::ToJson(jsonStr); + ASSERT_FALSE(result.is_discarded()); +} + +/** +* @tc.name: ToJson_03 +* @tc.desc: to json. +* @tc.type: FUNC +*/ +HWTEST_F(SerializableTest, ToJson_03, TestSize.Level1) +{ + std::string jsonStr = ""; + Serializable::json result = Serializable::ToJson(jsonStr); + ASSERT_TRUE(result.empty()); +} + +/** +* @tc.name: ToJson_04 +* @tc.desc: to json. +* @tc.type: FUNC +*/ +HWTEST_F(SerializableTest, ToJson_04, TestSize.Level1) +{ + std::string jsonStr = "{invalid_json}"; + Serializable::json result = Serializable::ToJson(jsonStr); + ASSERT_FALSE(result.is_discarded()); +} + +/** +* @tc.name: ToJson_05 +* @tc.desc: test string to json of value with numeric type. +* @tc.type: FUNC +*/ +HWTEST_F(SerializableTest, ToJson_05, TestSize.Level1) +{ + std::string jsonStr = "{\"key\": 10}"; + Serializable::json result = Serializable::ToJson(jsonStr); + uint64_t uint64Value; + bool ret = Serializable::GetValue(result, "key", uint64Value); + ASSERT_TRUE(ret); + + std::string jsonStr2 = "{\"key\": 10.0}"; + Serializable::json result2 = Serializable::ToJson(jsonStr2); + double doubleValue; + ret = Serializable::GetValue(result2, "key", doubleValue); + ASSERT_TRUE(ret); +} + +/** +* @tc.name: GetValueTest001 +* @tc.desc: Test to json when type not match. +* @tc.type: FUNC +*/ +HWTEST_F(SerializableTest, GetValueTest001, TestSize.Level1) +{ + std::string jsonStr = "{\"key\": 10}"; + Serializable::json result = Serializable::ToJson(jsonStr); + + std::string value; + bool ret = Serializable::GetValue(result, "key", value); + ASSERT_FALSE(ret); + ret = Serializable::GetValue(result, "notExist", value); + ASSERT_FALSE(ret); + + std::string jsonStr2 = "{\"key\": \"str\"}"; + Serializable::json strResult = Serializable::ToJson(jsonStr2); + int32_t intValue; + ret = Serializable::GetValue(strResult, "key", intValue); + ASSERT_FALSE(ret); + ret = Serializable::GetValue(strResult, "notExist", intValue); + ASSERT_FALSE(ret); + + uint32_t uintValue; + ret = Serializable::GetValue(strResult, "key", uintValue); + ASSERT_FALSE(ret); + ret = Serializable::GetValue(strResult, "notExist", uintValue); + ASSERT_FALSE(ret); + + uint64_t uint64Value; + ret = Serializable::GetValue(strResult, "key", uint64Value); + ASSERT_FALSE(ret); + ret = Serializable::GetValue(strResult, "notExist", uint64Value); + ASSERT_FALSE(ret); + + int64_t int64Value; + ret = Serializable::GetValue(strResult, "key", int64Value); + ASSERT_FALSE(ret); + ret = Serializable::GetValue(strResult, "notExist", int64Value); + ASSERT_FALSE(ret); + + bool boolValue; + ret = Serializable::GetValue(strResult, "key", boolValue); + ASSERT_FALSE(ret); + ret = Serializable::GetValue(strResult, "notExist", boolValue); + ASSERT_FALSE(ret); + + double doubleValue; + ret = Serializable::GetValue(strResult, "key", doubleValue); + ASSERT_FALSE(ret); + ret = Serializable::GetValue(strResult, "notExist", doubleValue); + ASSERT_FALSE(ret); + + std::vector arrayValue; + ret = Serializable::GetValue(strResult, "key", arrayValue); + ASSERT_FALSE(ret); + ret = Serializable::GetValue(strResult, "notExist", arrayValue); + ASSERT_FALSE(ret); +} + +/** +* @tc.name: SetUintValue +* @tc.desc: set value with uint param. +* @tc.type: FUNC +*/ +HWTEST_F(SerializableTest, SetUintValue, TestSize.Level2) +{ + struct TestUint final : public Serializable { + public: + std::vector testBytes = { 0x01, 0x02, 0x03, 0x04 }; + bool Marshal(json &node) const override + { + SetValue(node[GET_NAME(testBytes)], testBytes); + return true; + } + + bool Unmarshal(const json &node) override + { + bool success = true; + success = GetValue(node, GET_NAME(testBytes), testBytes) && success; + return success; + } + + bool operator==(const TestUint &other) const + { + return testBytes == other.testBytes; + } + }; + + std::string jsonStr2 = "{\"key\": \"str\"}"; + Serializable::json strResult = Serializable::ToJson(jsonStr2); + TestUint serialValue; + bool ret = Serializable::GetValue(strResult, "key", serialValue); + ASSERT_FALSE(ret); + ret = Serializable::GetValue(strResult, "notExist", serialValue); + ASSERT_FALSE(ret); +} + /** * @tc.name: SetStringMapValue * @tc.desc: set map value with string param. @@ -339,7 +519,7 @@ HWTEST_F(SerializableTest, SetStringMapValue, TestSize.Level2) TestStringMap in; in.testMap["name"] = "New York"; in.testMap["email"] = "john@sample.com"; - auto json = Serializable::JSONWrapper::to_string(in.Marshall()); + auto json = to_string(in.Marshall()); TestStringMap out; out.Unmarshall(json); ASSERT_TRUE(in == out); @@ -376,176 +556,12 @@ HWTEST_F(SerializableTest, SetMapValue, TestSize.Level2) TestMap in; in.testMap["version"] = 552; - auto json = Serializable::JSONWrapper::to_string(in.Marshall()); - + auto json = to_string(in.Marshall()); TestMap out; out.Unmarshall(json); ASSERT_TRUE(in == out); } - -/** -* @tc.name: IsJson -* @tc.desc: is json. -* @tc.type: FUNC -*/ -HWTEST_F(SerializableTest, IsJson, TestSize.Level1) -{ - std::string str = "test"; - std::string jsonStr = "\"test\""; - ASSERT_FALSE(Serializable::IsJson(str)); - ASSERT_TRUE(Serializable::IsJson(jsonStr)); -} - -/** -* @tc.name: ToString -* @tc.desc: string. -* @tc.type: FUNC -*/ -HWTEST_F(SerializableTest, ToString, TestSize.Level1) -{ - Serializable::JSONWrapper wrapper; - wrapper["name"] = "Alice"; - wrapper["age"] = 30; - wrapper["height"] = 1.75; - wrapper["is_student"] = false; - std::string result = wrapper; - EXPECT_EQ(result, "{\"name\":\"Alice\",\"age\":30,\"height\":1.75,\"is_student\":false}"); - std::map testUintMap = { - {"id", 123456}, - {"version", 42} - }; - std::map testStringMap = { - {"name", "John"}, - {"email", "john@example.com"} - }; - wrapper["testUintMap"] = testUintMap; - wrapper["testStringMap"] = testStringMap; - EXPECT_TRUE(wrapper["name"].is_string()); - EXPECT_TRUE(wrapper["age"].is_number_float()); - EXPECT_TRUE(wrapper["is_student"].is_boolean()); -} - -/** -* @tc.name: OperatorTest -* @tc.desc: test operator. -* @tc.type: FUNC -*/ -HWTEST_F(SerializableTest, OperatorTest, TestSize.Level1) -{ - std::string name = "Alice"; - int32_t count = -30; - uint32_t status = 1; - uint64_t type = 5; - int64_t value = 2; - double test = 1.75; - bool isStudent = false; - Serializable::JSONWrapper wrapper; - wrapper["name"] = name; - wrapper["count"] = count; - wrapper["status"] = status; - wrapper["type"] = type; - wrapper["value"] = value; - wrapper["test"] = test; - wrapper["isStudent"] = isStudent; - EXPECT_TRUE(wrapper["name"].is_string()); - EXPECT_TRUE(wrapper["test"].is_number_float()); - EXPECT_TRUE(wrapper["count"].is_number_integer()); - EXPECT_TRUE(wrapper["status"].is_number_unsigned()); - EXPECT_TRUE(wrapper["isStudent"].is_boolean()); - std::string result = wrapper; - EXPECT_EQ(result, "{\"name\":\"Alice\",\"count\":-30,\"status\":1,\"type\":" - "5,\"value\":2,\"test\":1.75,\"isStudent\":false}"); - wrapper["name"] = isStudent; - EXPECT_TRUE(wrapper["name"].is_boolean()); - wrapper["count"] = status; - EXPECT_TRUE(wrapper["count"].is_number_unsigned()); - wrapper["status"] = count; - EXPECT_TRUE(wrapper["status"].is_number_integer()); - wrapper["isStudent"] = test; - result = wrapper; - EXPECT_EQ(result, "{\"name\":false,\"count\":1,\"status\":-30,\"type\":5," - "\"value\":2,\"test\":1.75,\"isStudent\":1.75}"); -} - -/** -* @tc.name: EraseTest -* @tc.desc: test erase. -* @tc.type: FUNC -*/ -HWTEST_F(SerializableTest, EraseTest, TestSize.Level2) -{ - Serializable::JSONWrapper wrapper; - wrapper = std::map{ - {"name", "John"}, {"age", "30"}, {"city", "New York"}}; - std::string res = wrapper.dump(); - EXPECT_EQ(res, "{\"age\":\"30\",\"city\":\"New York\",\"name\":\"John\"}"); - bool result = wrapper.erase("age"); - ASSERT_TRUE(result); - res = wrapper.dump(); - EXPECT_EQ(res, "{\"city\":\"New York\",\"name\":\"John\"}"); -} - -/** -* @tc.name: CompareUint -* @tc.desc: test compare. -* @tc.type: FUNC -*/ -HWTEST_F(SerializableTest, CompareUint, TestSize.Level2) -{ - Serializable::JSONWrapper wrapper; - wrapper = std::map{ - {"key1", 100}, - {"key2", 200}, - {"key3", 300} - }; - - std::map testMap1 = { - {"key1", 100}, - {"key2", 200} - }; - - bool result = wrapper == testMap1; - ASSERT_FALSE(result); - std::map testMap2 = { - {"key1", 100}, - {"key2", 200}, - {"key3", 300} - }; - result = wrapper == testMap2; - ASSERT_TRUE(result); -} - -/** -* @tc.name: CompareStringMap -* @tc.desc: test compare. -* @tc.type: FUNC -*/ -HWTEST_F(SerializableTest, CompareStringMap, TestSize.Level2) -{ - Serializable::JSONWrapper wrapper; - wrapper = std::map{ - {"name", "Bob"}, - {"age", "25"}, - {"job", "Engineer"} - }; - std::map testMap1 = { - {"name", "Bob"}, - {"age", "25"} - }; - - bool result = wrapper == testMap1; - ASSERT_FALSE(result); - - std::map testMap2 = { - {"name", "Bob"}, - {"age", "25"}, - {"job", "Engineer"} - }; - result = wrapper == testMap2; - ASSERT_TRUE(result); -} - /** * @tc.name: BoundaryTest * @tc.desc: test boundary. @@ -579,56 +595,26 @@ HWTEST_F(SerializableTest, BoundaryTest, TestSize.Level1) TestBoundary in, out; in.int32Val = INT32_MIN; in.uint32Val = 0; - in.int64Val = -(1LL << 53) + 2; + in.int64Val = INT64_MIN; in.uint64Val = 0; - - auto json = Serializable::JSONWrapper::to_string(in.Marshall()); + + auto json = to_string(in.Marshall()); out.Unmarshall(json); EXPECT_EQ(out.int32Val, in.int32Val); EXPECT_EQ(out.uint32Val, in.uint32Val); EXPECT_EQ(out.int64Val, in.int64Val); EXPECT_EQ(out.uint64Val, in.uint64Val); - + in.int32Val = INT32_MAX; in.uint32Val = UINT32_MAX; - in.int64Val = (1LL << 53) - 2; - in.uint64Val = (1LL << 53) - 2; - - json = Serializable::JSONWrapper::to_string(in.Marshall()); + in.int64Val = INT64_MAX; + in.uint64Val = UINT64_MAX; + + json = to_string(in.Marshall()); out.Unmarshall(json); EXPECT_EQ(out.int32Val, in.int32Val); EXPECT_EQ(out.uint32Val, in.uint32Val); EXPECT_EQ(out.int64Val, in.int64Val); EXPECT_EQ(out.uint64Val, in.uint64Val); } - - -HWTEST_F(SerializableTest, ArrayTest, TestSize.Level1) -{ - struct TestBoundary : public Serializable { - std::vector vectorVal = {10, 20, 30, 40, 50}; - - bool Marshal(json &node) const override - { - SetValue(node[GET_NAME(vectorVal)], vectorVal); - return true; - } - - bool Unmarshal(const json &node) override - { - bool success = true; - success = GetValue(node, GET_NAME(vectorVal), vectorVal) && success; - return success; - } - }; - - TestBoundary in; - Serializable::JSONWrapper wrapper; - wrapper = in.Marshall(); - EXPECT_EQ(wrapper["vectorVal"][0].dump(), "10"); - EXPECT_EQ(wrapper["vectorVal"][1].dump(), "20"); - EXPECT_EQ(wrapper["vectorVal"][4].dump(), "50"); - EXPECT_EQ(wrapper["vectorVal"][5].dump(), ""); - EXPECT_EQ(wrapper["vectorVal"][10].dump(), ""); -} } // namespace OHOS::Test \ No newline at end of file diff --git a/services/distributeddataservice/framework/test/subscription_test.cpp b/services/distributeddataservice/framework/test/subscription_test.cpp index f729d878e..00cffdd43 100644 --- a/services/distributeddataservice/framework/test/subscription_test.cpp +++ b/services/distributeddataservice/framework/test/subscription_test.cpp @@ -55,12 +55,10 @@ HWTEST_F(SubscriptionTest, RelationMarshal, TestSize.Level1) */ HWTEST_F(SubscriptionTest, RelationUnmarshal, TestSize.Level1) { - Subscription::Relation relationOri; - relationOri.id = "testId"; - relationOri.bundleName = "testBundleName"; - relationOri.relations = testRelation; Subscription::json node; - relationOri.Marshal(node); + node["id"] = "testId"; + node["bundleName"] = "testBundleName"; + node["relations"] = testRelation; Subscription::Relation relation; relation.Unmarshal(node); ASSERT_EQ(relation.id, "testId"); @@ -93,12 +91,10 @@ HWTEST_F(SubscriptionTest, Marshal, TestSize.Level1) */ HWTEST_F(SubscriptionTest, Unmarshal, TestSize.Level1) { - Subscription subscriptionOri; - subscriptionOri.userId = 100; - subscriptionOri.id = "testId"; - subscriptionOri.expiresTime = testExpiresTime; Subscription::json node; - subscriptionOri.Marshal(node); + node["userId"] = 100; + node["id"] = "testId"; + node["expiresTime"] = testExpiresTime; Subscription subscription; subscription.Unmarshal(node); ASSERT_EQ(subscription.userId, 100); diff --git a/services/distributeddataservice/rust/extension/BUILD.gn b/services/distributeddataservice/rust/extension/BUILD.gn index 45246570d..92cd41b85 100644 --- a/services/distributeddataservice/rust/extension/BUILD.gn +++ b/services/distributeddataservice/rust/extension/BUILD.gn @@ -60,7 +60,7 @@ ohos_shared_library("opencloudextension") { external_deps = [ "access_token:libaccesstoken_sdk", "hilog:libhilog", - "cJSON:cjson", + "json:nlohmann_json_static", "c_utils:utils", "kv_store:datamgr_common", ] diff --git a/services/distributeddataservice/service/backup/BUILD.gn b/services/distributeddataservice/service/backup/BUILD.gn index 9b7398de3..194f7a03c 100755 --- a/services/distributeddataservice/service/backup/BUILD.gn +++ b/services/distributeddataservice/service/backup/BUILD.gn @@ -55,7 +55,7 @@ ohos_source_set("distributeddata_backup") { external_deps = [ "device_manager:devicemanagersdk", "hilog:libhilog", - "cJSON:cjson", + "json:nlohmann_json_static", "c_utils:utils", "kv_store:datamgr_common", ] diff --git a/services/distributeddataservice/service/bootstrap/BUILD.gn b/services/distributeddataservice/service/bootstrap/BUILD.gn index 9226e02b2..f79f3c0c1 100644 --- a/services/distributeddataservice/service/bootstrap/BUILD.gn +++ b/services/distributeddataservice/service/bootstrap/BUILD.gn @@ -53,7 +53,7 @@ ohos_source_set("distributeddata_bootstrap") { external_deps = [ "hilog:libhilog", - "cJSON:cjson", + "json:nlohmann_json_static", "c_utils:utils", "kv_store:datamgr_common", ] diff --git a/services/distributeddataservice/service/cloud/BUILD.gn b/services/distributeddataservice/service/cloud/BUILD.gn index 7cb2ea5ce..a0772df87 100755 --- a/services/distributeddataservice/service/cloud/BUILD.gn +++ b/services/distributeddataservice/service/cloud/BUILD.gn @@ -73,7 +73,7 @@ ohos_source_set("distributeddata_cloud") { "hicollie:libhicollie", "hilog:libhilog", "ipc:ipc_single", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:datamgr_common", "kv_store:distributeddb", "relational_store:cloud_data_inner", diff --git a/services/distributeddataservice/service/config/BUILD.gn b/services/distributeddataservice/service/config/BUILD.gn index ac8f98861..99550fc4a 100644 --- a/services/distributeddataservice/service/config/BUILD.gn +++ b/services/distributeddataservice/service/config/BUILD.gn @@ -60,7 +60,7 @@ ohos_source_set("distributeddata_config") { deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] external_deps = [ "hilog:libhilog", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:datamgr_common", ] subsystem_name = "distributeddatamgr" diff --git a/services/distributeddataservice/service/config/src/model/component_config.cpp b/services/distributeddataservice/service/config/src/model/component_config.cpp index 9195e7dc8..3810ece2b 100644 --- a/services/distributeddataservice/service/config/src/model/component_config.cpp +++ b/services/distributeddataservice/service/config/src/model/component_config.cpp @@ -36,7 +36,7 @@ bool ComponentConfig::Unmarshal(const json &node) GetValue(node, GET_NAME(destructor), destructor); const auto &subNode = GetSubNode(node, GET_NAME(params)); if (!subNode.is_null()) { - params = Serializable::JSONWrapper::to_string(subNode); + params = to_string(subNode); } return true; } diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index 68e54c60c..01d7396bd 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -132,7 +132,7 @@ ohos_source_set("data_share_service") { "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:datamgr_common", "kv_store:distributeddb", "qos_manager:concurrent_task_client", diff --git a/services/distributeddataservice/service/dumper/BUILD.gn b/services/distributeddataservice/service/dumper/BUILD.gn index 813707ad5..72b194d79 100644 --- a/services/distributeddataservice/service/dumper/BUILD.gn +++ b/services/distributeddataservice/service/dumper/BUILD.gn @@ -42,7 +42,7 @@ ohos_source_set("distributeddata_dumper") { deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] external_deps = [ "hilog:libhilog", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:datamgr_common", "kv_store:distributeddb", ] diff --git a/services/distributeddataservice/service/kvdb/BUILD.gn b/services/distributeddataservice/service/kvdb/BUILD.gn index 011ace89b..874dc361c 100644 --- a/services/distributeddataservice/service/kvdb/BUILD.gn +++ b/services/distributeddataservice/service/kvdb/BUILD.gn @@ -78,7 +78,7 @@ ohos_source_set("distributeddata_kvdb") { "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:datamgr_common", "kv_store:distributeddb", "kv_store:kvdb_inner_lite", diff --git a/services/distributeddataservice/service/matrix/BUILD.gn b/services/distributeddataservice/service/matrix/BUILD.gn index 65d3b4e66..88c1d03a4 100755 --- a/services/distributeddataservice/service/matrix/BUILD.gn +++ b/services/distributeddataservice/service/matrix/BUILD.gn @@ -58,7 +58,7 @@ ohos_source_set("distributeddata_matrix") { external_deps = [ "device_manager:devicemanagersdk", "hilog:libhilog", - "cJSON:cjson", + "json:nlohmann_json_static", "c_utils:utils", "kv_store:datamgr_common", ] diff --git a/services/distributeddataservice/service/permission/BUILD.gn b/services/distributeddataservice/service/permission/BUILD.gn index 3849f82ea..c6a4e1f1c 100644 --- a/services/distributeddataservice/service/permission/BUILD.gn +++ b/services/distributeddataservice/service/permission/BUILD.gn @@ -61,7 +61,7 @@ ohos_source_set("distributeddata_permit") { "device_auth:deviceauth_sdk", "device_manager:devicemanagersdk", "hilog:libhilog", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:datamgr_common", "kv_store:distributeddb", ] diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index c93164adb..de6d9a966 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -85,7 +85,7 @@ ohos_unittest("CloudDataTest") { "googletest:gmock", "googletest:gtest", "ipc:ipc_single", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddb", "relational_store:native_rdb", @@ -136,7 +136,7 @@ ohos_unittest("CloudServiceImplTest") { external_deps = [ "access_token:libaccesstoken_sdk", "access_token:libtoken_setproc", - "cJSON:cjson", + "json:nlohmann_json_static", "c_utils:utils", "device_manager:devicemanagersdk", "googletest:gmock", @@ -444,7 +444,7 @@ ohos_unittest("KVDBGeneralStoreAbnormalTest") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddb", "relational_store:native_rdb", @@ -713,7 +713,7 @@ ohos_unittest("ObjectAssetLoaderTest") { "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", ] @@ -747,7 +747,7 @@ ohos_unittest("ObjectAssetMachineTest") { "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", ] @@ -843,7 +843,7 @@ ohos_unittest("ObjectManagerTest") { "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddata_mgr", "kv_store:distributeddb", @@ -882,7 +882,7 @@ ohos_unittest("ObjectSnapshotTest") { "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "relational_store:native_rdb", ] @@ -927,7 +927,7 @@ ohos_unittest("MetaDataTest") { "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddata_mgr", "kv_store:distributeddb", @@ -1126,7 +1126,7 @@ ohos_unittest("DataShareServiceImplTest") { "huks:libhukssdk", "init:libbegetutil", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddb", "kv_store:distributeddb", @@ -1414,7 +1414,7 @@ ohos_unittest("UdmfServiceImplMockTest") { "googletest:gtest_main", "hilog:libhilog", "hisysevent:libhisysevent", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddb", "kv_store:distributeddata_mgr", @@ -1810,7 +1810,7 @@ ohos_unittest("PermitDelegateMockTest") { "googletest:gmock_main", "googletest:gtest_main", "hilog:libhilog", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddb", ] @@ -1912,7 +1912,7 @@ ohos_unittest("QueryHelperUnitTest") { "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:datamgr_common", "kv_store:distributeddb", "kv_store:kvdb_inner_lite", @@ -1942,7 +1942,7 @@ ohos_unittest("AuthDelegateMockTest") { "googletest:gmock_main", "googletest:gtest_main", "hilog:libhilog", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", ] @@ -1993,7 +1993,7 @@ ohos_unittest("UpgradeMockTest") { "googletest:gtest_main", "hilog:libhilog", "huks:libhukssdk", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:datamgr_common", "kv_store:distributeddb", ] @@ -2040,7 +2040,7 @@ ohos_unittest("UserDelegateMockTest") { "googletest:gmock_main", "googletest:gtest_main", "hilog:libhilog", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:datamgr_common", "kv_store:distributeddb", ] diff --git a/services/distributeddataservice/service/test/config_factory_test.cpp b/services/distributeddataservice/service/test/config_factory_test.cpp index 4077c2acd..fde209259 100644 --- a/services/distributeddataservice/service/test/config_factory_test.cpp +++ b/services/distributeddataservice/service/test/config_factory_test.cpp @@ -60,7 +60,7 @@ HWTEST_F(ConfigFactoryTest, ComponentConfig, TestSize.Level0) ASSERT_EQ(config.lib, "libconfigdemo.z.so"); ASSERT_EQ(config.constructor, ""); ASSERT_EQ(config.destructor, ""); - ASSERT_EQ(config.params, "{\"key\":\"value\",\"count\":1}"); + ASSERT_EQ(config.params, "{\"count\":1,\"key\":\"value\"}"); } /** diff --git a/services/distributeddataservice/service/test/data_share_profile_config_test.cpp b/services/distributeddataservice/service/test/data_share_profile_config_test.cpp index c7d227241..55f5a31b9 100644 --- a/services/distributeddataservice/service/test/data_share_profile_config_test.cpp +++ b/services/distributeddataservice/service/test/data_share_profile_config_test.cpp @@ -113,9 +113,7 @@ HWTEST_F(DataShareProfileConfigTest, ProfileInfo001, TestSize.Level1) Serializable::json node; info.Marshal(node); - bool ret; - node["isSilentProxyEnable"].get_to(ret); - EXPECT_EQ(ret, true); + EXPECT_EQ(node["isSilentProxyEnable"], true); EXPECT_EQ(node["path"], "storeName/tableName"); EXPECT_EQ(node["scope"], "module"); EXPECT_EQ(node["type"], "rdb"); diff --git a/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn index 39050c67f..e1185088f 100755 --- a/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn @@ -102,7 +102,7 @@ ohos_fuzztest("ObjectServiceStubFuzzTest") { "hisysevent:libhisysevent", "huks:libhukssdk", "ipc:ipc_core", - "cJSON:cjson", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddata_mgr", "kv_store:distributeddb", -- Gitee From bb88ff5703befb3f2c813535ac2e6a47cefe9055 Mon Sep 17 00:00:00 2001 From: bjd Date: Tue, 8 Jul 2025 16:54:36 +0800 Subject: [PATCH 02/14] =?UTF-8?q?cjson=E4=BB=A3=E7=A0=81=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bjd --- services/distributeddataservice/service/test/mock/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/service/test/mock/BUILD.gn b/services/distributeddataservice/service/test/mock/BUILD.gn index ce0a05278..639214a12 100644 --- a/services/distributeddataservice/service/test/mock/BUILD.gn +++ b/services/distributeddataservice/service/test/mock/BUILD.gn @@ -56,6 +56,7 @@ ohos_static_library("distributeddata_mock_static") { "device_manager:devicemanagersdk", "googletest:gmock", "googletest:gtest", + "json:nlohmann_json_static", "kv_store:distributeddata_mgr", "kv_store:distributeddb", "relational_store:native_rdb", -- Gitee From 57d5c94974da217625881fd8888d15b85c0b0903 Mon Sep 17 00:00:00 2001 From: bjd Date: Tue, 8 Jul 2025 17:10:30 +0800 Subject: [PATCH 03/14] =?UTF-8?q?cjson=E4=BB=A3=E7=A0=81=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bjd --- .../framework/test/fuzztest/storedebuginfo_fuzzer/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/BUILD.gn b/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/BUILD.gn index fd6c2367f..a44f574a0 100644 --- a/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/BUILD.gn +++ b/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/BUILD.gn @@ -42,6 +42,7 @@ ohos_fuzztest("StoreDebugInfoFuzzTest") { external_deps = [ "c_utils:utils", "hilog:libhilog", + "json:nlohmann_json_static", "kv_store:datamgr_common", ] } -- Gitee From bd3439f4b699d284f5bddfe0b4f629fa5be689cd Mon Sep 17 00:00:00 2001 From: bjd Date: Tue, 8 Jul 2025 17:41:55 +0800 Subject: [PATCH 04/14] =?UTF-8?q?cjson=E4=BB=A3=E7=A0=81=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bjd --- services/distributeddataservice/rust/test/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/rust/test/BUILD.gn b/services/distributeddataservice/rust/test/BUILD.gn index ade7f57f2..42c092395 100644 --- a/services/distributeddataservice/rust/test/BUILD.gn +++ b/services/distributeddataservice/rust/test/BUILD.gn @@ -46,6 +46,7 @@ ohos_unittest("ExtensionUtilTest") { ] external_deps = [ "hilog:libhilog", + "json:nlohmann_json_static", "kv_store:datamgr_common", ] -- Gitee From 3774ca99ab2b1e81cc614ce275c9db0ddabc4c23 Mon Sep 17 00:00:00 2001 From: bjd Date: Tue, 8 Jul 2025 19:10:22 +0800 Subject: [PATCH 05/14] =?UTF-8?q?cjson=E4=BB=A3=E7=A0=81=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bjd --- .../service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn index fcc9489e4..1be915e1e 100644 --- a/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn @@ -53,6 +53,7 @@ ohos_fuzztest("SyncStrategiesFuzzTest") { "access_token:libtokenid_sdk", "c_utils:utils", "hilog:libhilog", + "json:nlohmann_json_static", "kv_store:datamgr_common", ] } -- Gitee From 15aec967dc14a0cab828b63c6ef3d8dd4746fcab Mon Sep 17 00:00:00 2001 From: bjd Date: Tue, 8 Jul 2025 19:43:58 +0800 Subject: [PATCH 06/14] =?UTF-8?q?cjson=E4=BB=A3=E7=A0=81=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bjd --- services/distributeddataservice/framework/test/BUILD.gn | 6 ------ .../framework/test/fuzztest/storedebuginfo_fuzzer/BUILD.gn | 1 - services/distributeddataservice/service/test/BUILD.gn | 1 + services/distributeddataservice/service/test/mock/BUILD.gn | 1 - 4 files changed, 1 insertion(+), 8 deletions(-) diff --git a/services/distributeddataservice/framework/test/BUILD.gn b/services/distributeddataservice/framework/test/BUILD.gn index ee5db04f2..b4b2b558d 100644 --- a/services/distributeddataservice/framework/test/BUILD.gn +++ b/services/distributeddataservice/framework/test/BUILD.gn @@ -121,7 +121,6 @@ ohos_unittest("ServiceUtilsTest") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", - "json:nlohmann_json_static", "kv_store:datamgr_common", ] @@ -213,7 +212,6 @@ ohos_unittest("CloudInfoTest") { deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] external_deps = [ - "json:nlohmann_json_static", "c_utils:utils", "kv_store:datamgr_common", ] @@ -247,7 +245,6 @@ ohos_unittest("SubscriptionTest") { configs = [ ":module_private_config" ] deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] external_deps = [ - "json:nlohmann_json_static", "kv_store:datamgr_common", ] } @@ -275,7 +272,6 @@ ohos_unittest("MetaDataManagerTest") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", - "json:nlohmann_json_static", "kv_store:datamgr_common", "kv_store:distributeddb", "kv_store:distributeddata_inner", @@ -294,7 +290,6 @@ ohos_unittest("StoreMetaDataLocalTest") { deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] external_deps = [ - "json:nlohmann_json_static", "kv_store:datamgr_common", "kv_store:distributeddb", "kv_store:distributeddata_inner", @@ -355,7 +350,6 @@ ohos_unittest("ServiceMetaDataTest") { "hitrace:hitrace_meter", "hitrace:libhitracechain", "ipc:ipc_core", - "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddata_mgr", "kv_store:distributeddb", diff --git a/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/BUILD.gn b/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/BUILD.gn index a44f574a0..fd6c2367f 100644 --- a/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/BUILD.gn +++ b/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/BUILD.gn @@ -42,7 +42,6 @@ ohos_fuzztest("StoreDebugInfoFuzzTest") { external_deps = [ "c_utils:utils", "hilog:libhilog", - "json:nlohmann_json_static", "kv_store:datamgr_common", ] } diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index de6d9a966..29beaa0a3 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -1255,6 +1255,7 @@ ohos_unittest("KvdbServiceImplTest") { "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_core", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddata_mgr", "kv_store:distributeddb", diff --git a/services/distributeddataservice/service/test/mock/BUILD.gn b/services/distributeddataservice/service/test/mock/BUILD.gn index 639214a12..ce0a05278 100644 --- a/services/distributeddataservice/service/test/mock/BUILD.gn +++ b/services/distributeddataservice/service/test/mock/BUILD.gn @@ -56,7 +56,6 @@ ohos_static_library("distributeddata_mock_static") { "device_manager:devicemanagersdk", "googletest:gmock", "googletest:gtest", - "json:nlohmann_json_static", "kv_store:distributeddata_mgr", "kv_store:distributeddb", "relational_store:native_rdb", -- Gitee From eff6c648934bd5e755df3f232f760e419e7b549f Mon Sep 17 00:00:00 2001 From: bjd Date: Tue, 8 Jul 2025 19:52:39 +0800 Subject: [PATCH 07/14] =?UTF-8?q?cjson=E4=BB=A3=E7=A0=81=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bjd --- services/distributeddataservice/app/test/BUILD.gn | 2 -- services/distributeddataservice/rust/test/BUILD.gn | 1 - .../service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn | 1 - 3 files changed, 4 deletions(-) diff --git a/services/distributeddataservice/app/test/BUILD.gn b/services/distributeddataservice/app/test/BUILD.gn index 3d9a2e9d2..f8680bb60 100644 --- a/services/distributeddataservice/app/test/BUILD.gn +++ b/services/distributeddataservice/app/test/BUILD.gn @@ -250,7 +250,6 @@ ohos_unittest("SessionManagerTest") { "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_core", - "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddata_mgr", "kv_store:distributeddb", @@ -325,7 +324,6 @@ ohos_unittest("KvStoreDataServiceClearTest") { "hitrace:hitrace_meter", "hitrace:libhitracechain", "ipc:ipc_core", - "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddata_mgr", "kv_store:distributeddb", diff --git a/services/distributeddataservice/rust/test/BUILD.gn b/services/distributeddataservice/rust/test/BUILD.gn index 42c092395..ade7f57f2 100644 --- a/services/distributeddataservice/rust/test/BUILD.gn +++ b/services/distributeddataservice/rust/test/BUILD.gn @@ -46,7 +46,6 @@ ohos_unittest("ExtensionUtilTest") { ] external_deps = [ "hilog:libhilog", - "json:nlohmann_json_static", "kv_store:datamgr_common", ] diff --git a/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn index 1be915e1e..fcc9489e4 100644 --- a/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn @@ -53,7 +53,6 @@ ohos_fuzztest("SyncStrategiesFuzzTest") { "access_token:libtokenid_sdk", "c_utils:utils", "hilog:libhilog", - "json:nlohmann_json_static", "kv_store:datamgr_common", ] } -- Gitee From 4bd8923a7630efb904c905c2e9d7ce272c9c7346 Mon Sep 17 00:00:00 2001 From: bjd Date: Tue, 8 Jul 2025 20:03:51 +0800 Subject: [PATCH 08/14] =?UTF-8?q?cjson=E4=BB=A3=E7=A0=81=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bjd --- services/distributeddataservice/service/test/mock/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/service/test/mock/BUILD.gn b/services/distributeddataservice/service/test/mock/BUILD.gn index ce0a05278..639214a12 100644 --- a/services/distributeddataservice/service/test/mock/BUILD.gn +++ b/services/distributeddataservice/service/test/mock/BUILD.gn @@ -56,6 +56,7 @@ ohos_static_library("distributeddata_mock_static") { "device_manager:devicemanagersdk", "googletest:gmock", "googletest:gtest", + "json:nlohmann_json_static", "kv_store:distributeddata_mgr", "kv_store:distributeddb", "relational_store:native_rdb", -- Gitee From 580bf9627c94150cb856559b69f486edadbe40d1 Mon Sep 17 00:00:00 2001 From: bjd Date: Tue, 8 Jul 2025 22:43:15 +0800 Subject: [PATCH 09/14] =?UTF-8?q?cjson=E4=BB=A3=E7=A0=81=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bjd --- services/distributeddataservice/app/test/BUILD.gn | 2 ++ services/distributeddataservice/framework/test/BUILD.gn | 6 ++++++ .../framework/test/fuzztest/storedebuginfo_fuzzer/BUILD.gn | 1 + services/distributeddataservice/rust/test/BUILD.gn | 1 + .../service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn | 1 + 5 files changed, 11 insertions(+) diff --git a/services/distributeddataservice/app/test/BUILD.gn b/services/distributeddataservice/app/test/BUILD.gn index f8680bb60..3d9a2e9d2 100644 --- a/services/distributeddataservice/app/test/BUILD.gn +++ b/services/distributeddataservice/app/test/BUILD.gn @@ -250,6 +250,7 @@ ohos_unittest("SessionManagerTest") { "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_core", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddata_mgr", "kv_store:distributeddb", @@ -324,6 +325,7 @@ ohos_unittest("KvStoreDataServiceClearTest") { "hitrace:hitrace_meter", "hitrace:libhitracechain", "ipc:ipc_core", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddata_mgr", "kv_store:distributeddb", diff --git a/services/distributeddataservice/framework/test/BUILD.gn b/services/distributeddataservice/framework/test/BUILD.gn index b4b2b558d..37a5bafdd 100644 --- a/services/distributeddataservice/framework/test/BUILD.gn +++ b/services/distributeddataservice/framework/test/BUILD.gn @@ -121,6 +121,7 @@ ohos_unittest("ServiceUtilsTest") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", + "json:nlohmann_json_static", "kv_store:datamgr_common", ] @@ -213,6 +214,7 @@ ohos_unittest("CloudInfoTest") { external_deps = [ "c_utils:utils", + "json:nlohmann_json_static", "kv_store:datamgr_common", ] } @@ -245,6 +247,7 @@ ohos_unittest("SubscriptionTest") { configs = [ ":module_private_config" ] deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] external_deps = [ + "json:nlohmann_json_static", "kv_store:datamgr_common", ] } @@ -272,6 +275,7 @@ ohos_unittest("MetaDataManagerTest") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", + "json:nlohmann_json_static", "kv_store:datamgr_common", "kv_store:distributeddb", "kv_store:distributeddata_inner", @@ -290,6 +294,7 @@ ohos_unittest("StoreMetaDataLocalTest") { deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] external_deps = [ + "json:nlohmann_json_static", "kv_store:datamgr_common", "kv_store:distributeddb", "kv_store:distributeddata_inner", @@ -350,6 +355,7 @@ ohos_unittest("ServiceMetaDataTest") { "hitrace:hitrace_meter", "hitrace:libhitracechain", "ipc:ipc_core", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddata_mgr", "kv_store:distributeddb", diff --git a/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/BUILD.gn b/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/BUILD.gn index fd6c2367f..a44f574a0 100644 --- a/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/BUILD.gn +++ b/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/BUILD.gn @@ -42,6 +42,7 @@ ohos_fuzztest("StoreDebugInfoFuzzTest") { external_deps = [ "c_utils:utils", "hilog:libhilog", + "json:nlohmann_json_static", "kv_store:datamgr_common", ] } diff --git a/services/distributeddataservice/rust/test/BUILD.gn b/services/distributeddataservice/rust/test/BUILD.gn index ade7f57f2..42c092395 100644 --- a/services/distributeddataservice/rust/test/BUILD.gn +++ b/services/distributeddataservice/rust/test/BUILD.gn @@ -46,6 +46,7 @@ ohos_unittest("ExtensionUtilTest") { ] external_deps = [ "hilog:libhilog", + "json:nlohmann_json_static", "kv_store:datamgr_common", ] diff --git a/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn index fcc9489e4..1be915e1e 100644 --- a/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn @@ -53,6 +53,7 @@ ohos_fuzztest("SyncStrategiesFuzzTest") { "access_token:libtokenid_sdk", "c_utils:utils", "hilog:libhilog", + "json:nlohmann_json_static", "kv_store:datamgr_common", ] } -- Gitee From cf56bc4c057b666af431773480eb6a74ae5cdbe3 Mon Sep 17 00:00:00 2001 From: bjd Date: Wed, 9 Jul 2025 09:02:22 +0800 Subject: [PATCH 10/14] =?UTF-8?q?cjson=E4=BB=A3=E7=A0=81=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bjd --- services/distributeddataservice/service/test/BUILD.gn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 29beaa0a3..eed6fcd87 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -1189,6 +1189,7 @@ ohos_unittest("KvdbServicePasswordTest") { "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_core", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddata_mgr", "kv_store:distributeddb", @@ -1293,6 +1294,7 @@ ohos_unittest("DumpHelperTest") { "c_utils:utils", "googletest:gtest_main", "hilog:libhilog", + "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddb", "relational_store:native_rdb", -- Gitee From 0329c6c27be2b3f10fb3468abdb1950cb3553f1f Mon Sep 17 00:00:00 2001 From: bjd Date: Wed, 9 Jul 2025 21:10:17 +0800 Subject: [PATCH 11/14] =?UTF-8?q?cjson=E4=BB=A3=E7=A0=81=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bjd --- BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/BUILD.gn b/BUILD.gn index 4bffdf862..291b57a0b 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -15,6 +15,7 @@ import("//build/ohos.gni") group("build_native_test") { testonly = true deps = [ + "services/distributeddataservice/adapter/test:unittest", "services/distributeddataservice/app/test:unittest", "services/distributeddataservice/framework/test:unittest", -- Gitee From e44210601901da7041796d1ffdb9bbd994a8bff7 Mon Sep 17 00:00:00 2001 From: bjd Date: Wed, 9 Jul 2025 21:10:33 +0800 Subject: [PATCH 12/14] =?UTF-8?q?cjson=E4=BB=A3=E7=A0=81=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bjd --- BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/BUILD.gn b/BUILD.gn index 291b57a0b..4bffdf862 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -15,7 +15,6 @@ import("//build/ohos.gni") group("build_native_test") { testonly = true deps = [ - "services/distributeddataservice/adapter/test:unittest", "services/distributeddataservice/app/test:unittest", "services/distributeddataservice/framework/test:unittest", -- Gitee From 47570ff3e667013995187aa42ec49e61e3cd5bd7 Mon Sep 17 00:00:00 2001 From: baijidong Date: Thu, 10 Jul 2025 20:34:20 +0800 Subject: [PATCH 13/14] =?UTF-8?q?cjson=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: baijidong --- .../framework/serializable/serializable.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/framework/serializable/serializable.cpp b/services/distributeddataservice/framework/serializable/serializable.cpp index 0a82b14e4..9eec3a301 100644 --- a/services/distributeddataservice/framework/serializable/serializable.cpp +++ b/services/distributeddataservice/framework/serializable/serializable.cpp @@ -240,5 +240,6 @@ const Serializable::json &Serializable::GetSubNode(const json &node, const std:: } return *it; } + } // namespace DistributedData } // namespace OHOS \ No newline at end of file -- Gitee From 38b0daeb547412b09ca885ff1615536906854a60 Mon Sep 17 00:00:00 2001 From: baijidong Date: Sat, 12 Jul 2025 12:02:49 +0800 Subject: [PATCH 14/14] =?UTF-8?q?cjson=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: baijidong --- .../distributeddataservice/framework/test/meta_data_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/framework/test/meta_data_test.cpp b/services/distributeddataservice/framework/test/meta_data_test.cpp index 8ff4f7229..47f7bf777 100644 --- a/services/distributeddataservice/framework/test/meta_data_test.cpp +++ b/services/distributeddataservice/framework/test/meta_data_test.cpp @@ -35,7 +35,7 @@ #include "metadata/device_meta_data.h" #include "utils/constant.h" #include "gtest/gtest.h" -#include +#include "serializable/serializable.h" using namespace testing::ext; using namespace OHOS; using namespace OHOS::DistributedKv; -- Gitee