From f2e223b3a7274f0cb3ddc9b885c39bba9034509d Mon Sep 17 00:00:00 2001 From: 13776621730 Date: Wed, 28 May 2025 17:41:11 +0800 Subject: [PATCH] =?UTF-8?q?json=E7=BB=9F=E4=B8=80=E4=B8=BAcJSON=E7=9A=84un?= =?UTF-8?q?ittest=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 13776621730 Change-Id: Ia2c57d0256ffc6b1f69d2fb2b26b0e41b2d6cb2f --- test/moduletest/BUILD.gn | 2 - test/moduletest/ability_test/BUILD.gn | 8 - test/moduletest/call_module_test/BUILD.gn | 1 - test/moduletest/common/ams/BUILD.gn | 1 - .../specified_ability_service_test.cpp | 1 - .../mock/src/ui_service_mgr_client_mock.cpp | 19 +- .../running_infos_module_test.cpp | 1 - .../BUILD.gn | 3 +- test/unittest/BUILD.gn | 2 - .../BUILD.gn | 1 + .../BUILD.gn | 1 - .../ability_debug_response_stub_test/BUILD.gn | 1 - .../ability_extension_config_test.cpp | 103 ++++++++--- .../ability_manager_service_dialog_test.cpp | 7 +- .../BUILD.gn | 2 + .../BUILD.gn | 1 - .../BUILD.gn | 1 + .../ability_manager_service_second_test.cpp | 1 - .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../ability_manager_service_third_test.cpp | 3 +- .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../ability_permission_util_test/BUILD.gn | 1 - .../ability_stage_context_test/BUILD.gn | 1 - .../ams_app_state_callback_test/BUILD.gn | 1 - .../BUILD.gn | 4 + .../app_exit_reason_data_manager_new_test.cpp | 27 ++- .../BUILD.gn | 3 + .../BUILD.gn | 1 - .../app_mgr_service_inner_sixth_test/BUILD.gn | 1 - .../BUILD.gn | 1 - test/unittest/app_spawn_client_test/BUILD.gn | 1 + .../BUILD.gn | 2 + .../BUILD.gn | 4 +- .../cj_test_runner_object_test/BUILD.gn | 1 - test/unittest/cj_test_runner_test/BUILD.gn | 1 - .../deeplink_reserve_config_test/BUILD.gn | 1 + .../deeplink_reserve_config_test.cpp | 6 +- .../dfr_test/appfreeze_inner_test/BUILD.gn | 1 - .../dfr_test/appfreeze_manager_test/BUILD.gn | 1 - .../dfr_test/appfreeze_state_test/BUILD.gn | 1 - test/unittest/dfr_test/watchdog_test/BUILD.gn | 1 - test/unittest/dump_utils_test/BUILD.gn | 1 - .../mock/mock_extension_config.cpp | 22 +-- .../extension_record_factory_test/BUILD.gn | 1 - .../BUILD.gn | 7 +- .../extract_insight_intent_profile_test.cpp | 21 ++- .../pac_map_test.cpp | 84 ++++++--- .../BUILD.gn | 9 +- .../startup_manager_test.cpp | 167 ++++++++++++------ .../startup_utils_test.cpp | 5 +- .../BUILD.gn | 2 + .../BUILD.gn | 2 + .../insight_intent_profile_test/BUILD.gn | 5 +- .../BUILD.gn | 2 + .../js_auto_fill_extension_test/BUILD.gn | 1 - .../js_service_extension_test/BUILD.gn | 1 - test/unittest/keep_alive_utils_test/BUILD.gn | 1 - .../js_runtime_lite_test.cpp | 10 +- .../service_router_mgr_service_test/BUILD.gn | 1 + .../status_bar_delegate_manager_test/BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../want_agent_helper_test.cpp | 35 ++-- .../window_options_utils_test/BUILD.gn | 1 - 66 files changed, 392 insertions(+), 212 deletions(-) diff --git a/test/moduletest/BUILD.gn b/test/moduletest/BUILD.gn index 3161ba06e73..3c81e50811a 100644 --- a/test/moduletest/BUILD.gn +++ b/test/moduletest/BUILD.gn @@ -26,7 +26,6 @@ config("aafwk_module_test_config") { include_dirs = [ "${ability_runtime_test_path}/moduletest/mock/include", - "//third_party/jsoncpp/include", ] } @@ -73,7 +72,6 @@ group("moduletest") { external_deps = [ "icu:shared_icuuc", - "jsoncpp:jsoncpp", ] } } diff --git a/test/moduletest/ability_test/BUILD.gn b/test/moduletest/ability_test/BUILD.gn index b4490926194..0bd733d6898 100644 --- a/test/moduletest/ability_test/BUILD.gn +++ b/test/moduletest/ability_test/BUILD.gn @@ -81,7 +81,6 @@ ohos_moduletest("ability_moduletest") { "init:libbegetutil", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", "jsoncpp:jsoncpp", "napi:ace_napi", "relational_store:native_appdatafwk", @@ -142,8 +141,6 @@ ohos_moduletest("ability_conetxt_test") { "init:libbegetutil", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", - "jsoncpp:jsoncpp", "napi:ace_napi", "relational_store:native_appdatafwk", "relational_store:native_dataability", @@ -184,7 +181,6 @@ ohos_moduletest("ability_thread_call_request_module_test") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_napi", - "json:nlohmann_json_static", "napi:ace_napi", "samgr:samgr_proxy", ] @@ -231,8 +227,6 @@ ohos_moduletest("data_ability_operation_moduletest") { "image_framework:image_native", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", - "jsoncpp:jsoncpp", "napi:ace_napi", "relational_store:native_appdatafwk", "relational_store:native_dataability", @@ -289,7 +283,6 @@ ohos_moduletest("data_ability_helper_module_test") { "hilog:libhilog", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", "napi:ace_napi", "relational_store:native_appdatafwk", "relational_store:native_dataability", @@ -336,7 +329,6 @@ ohos_moduletest("ability_post_event_timeout_test") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", - "json:nlohmann_json_static", "napi:ace_napi", "relational_store:native_appdatafwk", "relational_store:native_dataability", diff --git a/test/moduletest/call_module_test/BUILD.gn b/test/moduletest/call_module_test/BUILD.gn index d8fd1131d15..afd91bca7ac 100644 --- a/test/moduletest/call_module_test/BUILD.gn +++ b/test/moduletest/call_module_test/BUILD.gn @@ -45,7 +45,6 @@ ohos_moduletest("call_ability_service_module_test") { "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_core", - "jsoncpp:jsoncpp", "safwk:api_cache_manager", ] diff --git a/test/moduletest/common/ams/BUILD.gn b/test/moduletest/common/ams/BUILD.gn index 5d190174c84..05566e91b2a 100644 --- a/test/moduletest/common/ams/BUILD.gn +++ b/test/moduletest/common/ams/BUILD.gn @@ -64,7 +64,6 @@ ohos_source_set("appmgr_mst_source") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", ] public_external_deps = [ diff --git a/test/moduletest/common/ams/specified_ability_service_test/specified_ability_service_test.cpp b/test/moduletest/common/ams/specified_ability_service_test/specified_ability_service_test.cpp index 2c746036a49..8093d4d422a 100644 --- a/test/moduletest/common/ams/specified_ability_service_test/specified_ability_service_test.cpp +++ b/test/moduletest/common/ams/specified_ability_service_test/specified_ability_service_test.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include diff --git a/test/moduletest/mock/src/ui_service_mgr_client_mock.cpp b/test/moduletest/mock/src/ui_service_mgr_client_mock.cpp index 965510d9812..772adda7ebd 100644 --- a/test/moduletest/mock/src/ui_service_mgr_client_mock.cpp +++ b/test/moduletest/mock/src/ui_service_mgr_client_mock.cpp @@ -88,13 +88,18 @@ ErrCode UIServiceMgrClient::ShowDialog(const std::string& name, const std::strin isCallBack_ = false; if (code_ == EVENT_MULT_APP_CHOOSE) { params_ = params; - auto jsonObj = nlohmann::json::parse(params, nullptr, false); - auto hapListObj = nlohmann::json::array(); - hapListObj = jsonObj["hapList"]; - auto aObj = hapListObj[0]; - std::string callbackParams = aObj["bundle"].dump() + ";" + aObj["ability"].dump(); - callback(0, EVENT_CHOOSE_CODE, callbackParams); - return ERR_OK; + cJSON *jsonObj = cJSON_Parse(params.c_str()); + cJSON *hapListObj = cJSON_GetObjectItem(jsonObj, "hapList"); + if (cJSON_GetArraySize > 0) { + cJSON *aObj = cJSON_GetArrayItem(hapListObj, 0); + cJSON *bundleItem = cJSON_GetObjectItem(aObj, "bundle"); + cJSON *abilityItem = cJSON_GetObjectItem(aObj, "ability"); + std::string bundle = bundleItem->valuestring; + std::string ability = abilityItem->valuestring; + std::string callbackParams = bundle + ";" + ability; + callback(0, EVENT_CHOOSE_CODE, callbackParams); + return ERR_OK; + } } if (code_ == EVENT_MULT_APP_CLOSE) { diff --git a/test/moduletest/running_infos_module_test/running_infos_module_test.cpp b/test/moduletest/running_infos_module_test/running_infos_module_test.cpp index 82cb2a1de86..02bd83ca5dd 100644 --- a/test/moduletest/running_infos_module_test/running_infos_module_test.cpp +++ b/test/moduletest/running_infos_module_test/running_infos_module_test.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include diff --git a/test/moduletest/start_ability_implicit_module_test/BUILD.gn b/test/moduletest/start_ability_implicit_module_test/BUILD.gn index a6197b7bb98..6d0465928e3 100644 --- a/test/moduletest/start_ability_implicit_module_test/BUILD.gn +++ b/test/moduletest/start_ability_implicit_module_test/BUILD.gn @@ -27,7 +27,6 @@ ohos_moduletest("start_ability_implicit_module_test") { "${ace_engine_path}/adapter/ohos/services/uiservice/include", "${windowmanager_path}/interfaces/innerkits", "${multimodalinput_path}/interfaces/native/innerkits/event/include", - "//third_party/jsoncpp/include", ] sources = [ "start_ability_implicit_module_test.cpp" ] @@ -60,7 +59,6 @@ ohos_moduletest("start_ability_implicit_module_test") { "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", "//third_party/icu/icu4c:shared_icuuc", - "//third_party/jsoncpp:jsoncpp", ] if (ability_runtime_graphics) { @@ -91,6 +89,7 @@ ohos_moduletest("start_ability_implicit_module_test") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", + "jsoncpp:jsoncpp", "napi:ace_napi", "relational_store:native_appdatafwk", "relational_store:native_dataability", diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 76f6c6c462a..3e8ea0e4880 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -79,7 +79,6 @@ ohos_source_set("appmgr_test_source") { "hitrace:hitrace_meter", "i18n:intl_util", "ipc:ipc_core", - "json:nlohmann_json_static", "kv_store:distributeddata_inner", "kv_store:distributeddata_mgr", "samgr:samgr_proxy", @@ -259,7 +258,6 @@ ohos_source_set("abilityms_test_source") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "jsoncpp:jsoncpp", "kv_store:distributeddata_inner", "relational_store:native_appdatafwk", "relational_store:native_dataability", diff --git a/test/unittest/ability_bundle_event_callback_test/BUILD.gn b/test/unittest/ability_bundle_event_callback_test/BUILD.gn index b5963897658..6ff5c9bbf8c 100644 --- a/test/unittest/ability_bundle_event_callback_test/BUILD.gn +++ b/test/unittest/ability_bundle_event_callback_test/BUILD.gn @@ -37,6 +37,7 @@ ohos_unittest("ability_bundle_event_callback_test") { "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_data_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_db_cache.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/extract_insight_intent_profile.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_event_mgr.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", diff --git a/test/unittest/ability_debug_response_proxy_test/BUILD.gn b/test/unittest/ability_debug_response_proxy_test/BUILD.gn index be3c9c4a66c..2e8d40a8e2d 100644 --- a/test/unittest/ability_debug_response_proxy_test/BUILD.gn +++ b/test/unittest/ability_debug_response_proxy_test/BUILD.gn @@ -43,7 +43,6 @@ ohos_unittest("ability_debug_response_proxy_test") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", - "jsoncpp:jsoncpp", ] } diff --git a/test/unittest/ability_debug_response_stub_test/BUILD.gn b/test/unittest/ability_debug_response_stub_test/BUILD.gn index 3d1481bf297..4d7bb1cd4d9 100644 --- a/test/unittest/ability_debug_response_stub_test/BUILD.gn +++ b/test/unittest/ability_debug_response_stub_test/BUILD.gn @@ -48,7 +48,6 @@ ohos_unittest("ability_debug_response_stub_test") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", - "jsoncpp:jsoncpp", ] } diff --git a/test/unittest/ability_extension_config_test/ability_extension_config_test.cpp b/test/unittest/ability_extension_config_test/ability_extension_config_test.cpp index 51c1ff04718..69271e2fe6d 100644 --- a/test/unittest/ability_extension_config_test/ability_extension_config_test.cpp +++ b/test/unittest/ability_extension_config_test/ability_extension_config_test.cpp @@ -24,7 +24,6 @@ using namespace testing; using namespace testing::ext; -using json = nlohmann::json; namespace { constexpr const char* EXTENSION_CONFIG_NAME = "extension_config_name"; constexpr const char* EXTENSION_TYPE_NAME = "extension_type_name"; @@ -66,8 +65,9 @@ void AbilityExtensionConfigTest::TearDown() void AbilityExtensionConfigTest::LoadTestConfig(const std::string &configStr) { - nlohmann::json jsonConfig = nlohmann::json::parse(configStr); + cJSON *jsonConfig = cJSON_Parse(configStr.c_str()); extensionConfig_->LoadExtensionConfig(jsonConfig); + cJSON_Delete(jsonConfig); } /* @@ -92,15 +92,30 @@ HWTEST_F(AbilityExtensionConfigTest, GetExtensionConfigPath_001, TestSize.Level1 */ HWTEST_F(AbilityExtensionConfigTest, LoadExtensionServiceBlockedList_001, TestSize.Level1) { - json jsOnFile; + cJSON *jsOnFile = cJSON_CreateObject(); extensionConfig_->LoadExtensionServiceBlockedList(jsOnFile, "aa"); - jsOnFile[EXTENSION_SERVICE_STARTUP_ENABLE_FLAG] = false; + + cJSON_AddBoolToObject(jsOnFile, EXTENSION_SERVICE_STARTUP_ENABLE_FLAG, false); extensionConfig_->LoadExtensionServiceBlockedList(jsOnFile, "aa"); - jsOnFile[EXTENSION_SERVICE_STARTUP_ENABLE_FLAG] = true; + + cJSON *item = cJSON_GetObjectItem(jsOnFile, EXTENSION_SERVICE_STARTUP_ENABLE_FLAG); + if (item != nullptr) { + cJSON_DetachItemViaPointer(jsOnFile, item); + cJSON_Delete(item); + } + cJSON_AddBoolToObject(jsOnFile, EXTENSION_SERVICE_STARTUP_ENABLE_FLAG, true); extensionConfig_->LoadExtensionServiceBlockedList(jsOnFile, "aa"); - jsOnFile[EXTENSION_SERVICE_BLOCKED_LIST_NAME] = {"aa", "bb"}; + + cJSON *arraysItem = cJSON_CreateArray(); + cJSON *array1Item = cJSON_CreateString("aa"); + cJSON *array2Item = cJSON_CreateString("bb"); + cJSON_AddItemToArray(arraysItem, array1Item); + cJSON_AddItemToArray(arraysItem, array2Item); + cJSON_AddItemToObject(jsOnFile, EXTENSION_SERVICE_BLOCKED_LIST_NAME, arraysItem); extensionConfig_->LoadExtensionServiceBlockedList(jsOnFile, "aa"); + EXPECT_TRUE(extensionConfig_ != nullptr); + cJSON_Delete(jsOnFile); } /* @@ -110,14 +125,23 @@ HWTEST_F(AbilityExtensionConfigTest, LoadExtensionServiceBlockedList_001, TestSi */ HWTEST_F(AbilityExtensionConfigTest, LoadExtensionThirdPartyAppBlockedList_001, TestSize.Level1) { - json jsOnFile; + cJSON *jsOnFile = cJSON_CreateObject(); std::string extensionTypeName = "aa"; extensionConfig_->LoadExtensionThirdPartyAppBlockedList(jsOnFile, extensionTypeName); - jsOnFile[EXTENSION_THIRD_PARTY_APP_BLOCKED_FLAG_NAME] = false; + + cJSON_AddBoolToObject(jsOnFile, EXTENSION_THIRD_PARTY_APP_BLOCKED_FLAG_NAME, false); extensionConfig_->LoadExtensionThirdPartyAppBlockedList(jsOnFile, extensionTypeName); - jsOnFile[EXTENSION_THIRD_PARTY_APP_BLOCKED_FLAG_NAME] = true; + + cJSON *item = cJSON_GetObjectItem(jsOnFile, EXTENSION_THIRD_PARTY_APP_BLOCKED_FLAG_NAME); + if (item != nullptr) { + cJSON_DetachItemViaPointer(jsOnFile, item); + cJSON_Delete(item); + } + cJSON_AddBoolToObject(jsOnFile, EXTENSION_THIRD_PARTY_APP_BLOCKED_FLAG_NAME, true); extensionConfig_->LoadExtensionThirdPartyAppBlockedList(jsOnFile, extensionTypeName); + EXPECT_TRUE(extensionConfig_ != nullptr); + cJSON_Delete(jsOnFile); } /* @@ -127,12 +151,16 @@ HWTEST_F(AbilityExtensionConfigTest, LoadExtensionThirdPartyAppBlockedList_001, */ HWTEST_F(AbilityExtensionConfigTest, LoadExtensionAutoDisconnectTime_001, TestSize.Level1) { - json jsOnFile; + cJSON *jsOnFile = cJSON_CreateObject(); + std::string extensionTypeName = "aa"; extensionConfig_->LoadExtensionAutoDisconnectTime(jsOnFile, extensionTypeName); - jsOnFile[EXTENSION_AUTO_DISCONNECT_TIME] = 100; + + cJSON_AddNumberToObject(jsOnFile, EXTENSION_AUTO_DISCONNECT_TIME, 100); extensionConfig_->LoadExtensionAutoDisconnectTime(jsOnFile, extensionTypeName); + EXPECT_TRUE(extensionConfig_ != nullptr); + cJSON_Delete(jsOnFile); } /* @@ -142,15 +170,25 @@ HWTEST_F(AbilityExtensionConfigTest, LoadExtensionAutoDisconnectTime_001, TestSi */ HWTEST_F(AbilityExtensionConfigTest, LoadExtensionConfig_001, TestSize.Level1) { - json jsOnFile; - json jsOnItem; - json jsOnItem2; + cJSON *jsOnFile = cJSON_CreateObject(); + + cJSON *jsOnItems = cJSON_CreateArray(); + cJSON *jsOnItem = cJSON_CreateObject(); + cJSON *jsOnItem2 = cJSON_CreateObject(); + cJSON *jsOnItem3 = cJSON_CreateObject(); extensionConfig_->LoadExtensionConfig(jsOnFile); - jsOnItem[EXTENSION_TYPE_NAME] = "aa"; - jsOnItem2[EXTENSION_TYPE_NAME] = "bb"; - jsOnFile[EXTENSION_CONFIG_NAME] = {jsOnItem, jsOnItem2, "cc"}; + + cJSON_AddStringToObject(jsOnItem, EXTENSION_TYPE_NAME, "aa"); + cJSON_AddStringToObject(jsOnItem2, EXTENSION_TYPE_NAME, "bb"); + cJSON_AddStringToObject(jsOnItem3, EXTENSION_TYPE_NAME, "cc"); + cJSON_AddItemToArray(jsOnItems, jsOnItem); + cJSON_AddItemToArray(jsOnItems, jsOnItem2); + cJSON_AddItemToArray(jsOnItems, jsOnItem3); + cJSON_AddItemToObject(jsOnFile, EXTENSION_CONFIG_NAME, jsOnItems); extensionConfig_->LoadExtensionConfig(jsOnFile); + EXPECT_TRUE(extensionConfig_ != nullptr); + cJSON_Delete(jsOnFile); } /* @@ -190,14 +228,22 @@ HWTEST_F(AbilityExtensionConfigTest, IsExtensionStartServiceEnable_002, TestSize */ HWTEST_F(AbilityExtensionConfigTest, IsExtensionStartServiceEnable_003, TestSize.Level1) { - json jsOnFile; + cJSON *jsOnFile = cJSON_CreateObject(); auto extType = "form"; - jsOnFile[EXTENSION_SERVICE_STARTUP_ENABLE_FLAG] = true; - jsOnFile[EXTENSION_SERVICE_BLOCKED_LIST_NAME] = {"aa", "bb", "/bundle/module/ability"}; + cJSON_AddBoolToObject(jsOnFile, EXTENSION_SERVICE_STARTUP_ENABLE_FLAG, true); + cJSON *items = cJSON_CreateArray(); + cJSON *item1 = cJSON_CreateString("aa"); + cJSON *item2 = cJSON_CreateString("bb"); + cJSON *item3 = cJSON_CreateString("/bundle/module/ability"); + cJSON_AddItemToArray(items, item1); + cJSON_AddItemToArray(items, item2); + cJSON_AddItemToArray(items, item3); + cJSON_AddItemToObject(jsOnFile, EXTENSION_SERVICE_BLOCKED_LIST_NAME, items); extensionConfig_->LoadExtensionServiceBlockedList(jsOnFile, extType); // uri not valid bool enable = extensionConfig_->IsExtensionStartServiceEnable(extType, "bb"); EXPECT_EQ(enable, true); + cJSON_Delete(jsOnFile); } /* @@ -207,14 +253,22 @@ HWTEST_F(AbilityExtensionConfigTest, IsExtensionStartServiceEnable_003, TestSize */ HWTEST_F(AbilityExtensionConfigTest, IsExtensionStartServiceEnable_004, TestSize.Level1) { - json jsOnFile; + cJSON *jsOnFile = cJSON_CreateObject(); auto extType = "form"; - jsOnFile[EXTENSION_SERVICE_STARTUP_ENABLE_FLAG] = true; - jsOnFile[EXTENSION_SERVICE_BLOCKED_LIST_NAME] = {"aa", "bb", "/bundle/module/ability"}; + cJSON_AddBoolToObject(jsOnFile, EXTENSION_SERVICE_STARTUP_ENABLE_FLAG, true); + cJSON *items = cJSON_CreateArray(); + cJSON *item1 = cJSON_CreateString("aa"); + cJSON *item2 = cJSON_CreateString("bb"); + cJSON *item3 = cJSON_CreateString("/bundle/module/ability"); + cJSON_AddItemToArray(items, item1); + cJSON_AddItemToArray(items, item2); + cJSON_AddItemToArray(items, item3); + cJSON_AddItemToObject(jsOnFile, EXTENSION_SERVICE_BLOCKED_LIST_NAME, items); extensionConfig_->LoadExtensionServiceBlockedList(jsOnFile, extType); // uri is valid bool enable = extensionConfig_->IsExtensionStartServiceEnable(extType, "/bundle/module/ability"); EXPECT_EQ(enable, false); + cJSON_Delete(jsOnFile); } /* @@ -224,9 +278,10 @@ HWTEST_F(AbilityExtensionConfigTest, IsExtensionStartServiceEnable_004, TestSize */ HWTEST_F(AbilityExtensionConfigTest, ReadFileInfoJson_001, TestSize.Level1) { - nlohmann::json jsOne; + cJSON *jsOne = nullptr; auto result = extensionConfig_->ReadFileInfoJson("d://dddd", jsOne); EXPECT_EQ(result, false); + cJSON_Delete(jsOne); } /* diff --git a/test/unittest/ability_manager_service_dialog_test/ability_manager_service_dialog_test.cpp b/test/unittest/ability_manager_service_dialog_test/ability_manager_service_dialog_test.cpp index 8757e1e182c..a1c7c04ca95 100644 --- a/test/unittest/ability_manager_service_dialog_test/ability_manager_service_dialog_test.cpp +++ b/test/unittest/ability_manager_service_dialog_test/ability_manager_service_dialog_test.cpp @@ -153,8 +153,11 @@ HWTEST_F(AbilityMgrServiceDialogTest, AbilityMgrServiceDialog_0500, TestSize.Lev }; std::vector dialogAppInfos = { dialogAppInfo }; auto params = systemDialogScheduler_->GetSelectorParams(dialogAppInfos); - nlohmann::json jsonObj = nlohmann::json::parse(params); - EXPECT_EQ(jsonObj["hapList"].size(), 1); + cJSON *jsonObj = cJSON_Parse(params.c_str()); + cJSON *hapListItem = cJSON_GetObjectItem(jsonObj, "hapList"); + EXPECT_TRUE(hapListItem != nullptr && cJSON_IsArray(hapListItem)); + EXPECT_EQ(cJSON_GetArraySize(hapListItem), 1); + cJSON_Delete(jsonObj); TAG_LOGI(AAFwkTag::TEST, "AbilityMgrServiceDialog_0500 end"); } diff --git a/test/unittest/ability_manager_service_fourth_test/BUILD.gn b/test/unittest/ability_manager_service_fourth_test/BUILD.gn index e1d04cc8592..51875e02867 100644 --- a/test/unittest/ability_manager_service_fourth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_fourth_test/BUILD.gn @@ -49,6 +49,7 @@ ohos_unittest("ability_manager_service_fourth_test") { "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_data_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_db_cache.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/extract_insight_intent_profile.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_event_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_connect_callback_stub.cpp", @@ -107,6 +108,7 @@ ohos_unittest("ability_manager_service_fourth_test") { "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_core", + "jsoncpp:jsoncpp", "kv_store:distributeddata_inner", "relational_store:native_dataability", "safwk:api_cache_manager", diff --git a/test/unittest/ability_manager_service_mock_test/BUILD.gn b/test/unittest/ability_manager_service_mock_test/BUILD.gn index 103a3590454..42c5adb7d3d 100644 --- a/test/unittest/ability_manager_service_mock_test/BUILD.gn +++ b/test/unittest/ability_manager_service_mock_test/BUILD.gn @@ -111,7 +111,6 @@ ohos_unittest("ability_manager_service_mock_test") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "kv_store:distributeddata_inner", "os_account:os_account_innerkits", "qos_manager:concurrent_task_client", diff --git a/test/unittest/ability_manager_service_second_test/BUILD.gn b/test/unittest/ability_manager_service_second_test/BUILD.gn index 045ec42a83b..a96f458a041 100644 --- a/test/unittest/ability_manager_service_second_test/BUILD.gn +++ b/test/unittest/ability_manager_service_second_test/BUILD.gn @@ -69,6 +69,7 @@ ohos_unittest("ability_manager_service_second_test") { "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_core", + "jsoncpp:jsoncpp", "safwk:api_cache_manager", "selinux_adapter:librestorecon", ] diff --git a/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp b/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp index baa53693076..2a8f478322f 100644 --- a/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp +++ b/test/unittest/ability_manager_service_second_test/ability_manager_service_second_test.cpp @@ -1818,7 +1818,6 @@ HWTEST_F(AbilityManagerServiceSecondTest, ParseJsonFromBoot_001, TestSize.Level1 TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest ParseJsonFromBoot_001 start"); auto abilityMs_ = std::make_shared(); const std::string file = "/etc/efficiency_manager/prevent_startability_whitelist.json"; - nlohmann::json whiteListJsonObj; abilityMs_->ParseJsonFromBoot(file); EXPECT_TRUE(abilityMs_ != nullptr); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSecondTest ParseJsonFromBoot_001 end"); diff --git a/test/unittest/ability_manager_service_tenth_test/BUILD.gn b/test/unittest/ability_manager_service_tenth_test/BUILD.gn index 755be9065ec..86eb68adaa8 100644 --- a/test/unittest/ability_manager_service_tenth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_tenth_test/BUILD.gn @@ -75,6 +75,7 @@ ohos_unittest("ability_manager_service_tenth_test") { "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_core", + "jsoncpp:jsoncpp", "kv_store:distributeddata_inner", "safwk:api_cache_manager", "selinux_adapter:librestorecon", diff --git a/test/unittest/ability_manager_service_third_test/BUILD.gn b/test/unittest/ability_manager_service_third_test/BUILD.gn index 02ccc39f94b..b865454b7de 100644 --- a/test/unittest/ability_manager_service_third_test/BUILD.gn +++ b/test/unittest/ability_manager_service_third_test/BUILD.gn @@ -47,6 +47,7 @@ ohos_unittest("ability_manager_service_third_test") { "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_data_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_db_cache.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/extract_insight_intent_profile.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_event_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_cache_manager.cpp", diff --git a/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp b/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp index d429c069a80..5612e514df8 100644 --- a/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp +++ b/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp @@ -2425,8 +2425,9 @@ HWTEST_F(AbilityManagerServiceThirdTest, ParseJsonValueFromFile_001, TestSize.Le EXPECT_NE(abilityMs_, nullptr); std::string filePath = "hello"; - nlohmann::json value; + cJSON *value = nullptr; abilityMs_->ParseJsonValueFromFile(value, filePath); + cJSON_Delete(value); } /* diff --git a/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn b/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn index ea88cb70833..f73eb1b9c55 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn @@ -126,6 +126,7 @@ ohos_unittest("ability_manager_service_thirteenth_test") { "${ability_runtime_services_path}/abilitymgr/src/inner_mission_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_execute_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_execute_result.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_profile.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_utils.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/hmsf_utils.cpp", diff --git a/test/unittest/ability_manager_service_twelfth_test/BUILD.gn b/test/unittest/ability_manager_service_twelfth_test/BUILD.gn index 76e492cf15f..e10db0db2db 100644 --- a/test/unittest/ability_manager_service_twelfth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_twelfth_test/BUILD.gn @@ -107,6 +107,7 @@ ohos_unittest("ability_manager_service_twelfth_test") { "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_core", + "jsoncpp:jsoncpp", "kv_store:distributeddata_inner", "relational_store:native_dataability", "safwk:api_cache_manager", diff --git a/test/unittest/ability_permission_util_test/BUILD.gn b/test/unittest/ability_permission_util_test/BUILD.gn index c095171d094..1dff9b2b111 100644 --- a/test/unittest/ability_permission_util_test/BUILD.gn +++ b/test/unittest/ability_permission_util_test/BUILD.gn @@ -74,7 +74,6 @@ ohos_unittest("ability_permission_util_test") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "jsoncpp:jsoncpp", "kv_store:distributeddata_mgr", "memory_utils:libmeminfo", diff --git a/test/unittest/ability_stage_context_test/BUILD.gn b/test/unittest/ability_stage_context_test/BUILD.gn index 73a3326a352..eb360c6e938 100644 --- a/test/unittest/ability_stage_context_test/BUILD.gn +++ b/test/unittest/ability_stage_context_test/BUILD.gn @@ -60,7 +60,6 @@ ohos_unittest("ability_stage_context_test") { "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "napi:ace_napi", "resource_management:global_resmgr", "samgr:samgr_proxy", diff --git a/test/unittest/ams_app_state_callback_test/BUILD.gn b/test/unittest/ams_app_state_callback_test/BUILD.gn index 42801229395..71772aadcc9 100644 --- a/test/unittest/ams_app_state_callback_test/BUILD.gn +++ b/test/unittest/ams_app_state_callback_test/BUILD.gn @@ -43,7 +43,6 @@ ohos_unittest("AmsAppStateCallbackTest") { "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", - "json:nlohmann_json_static", ] } diff --git a/test/unittest/app_exit_reason_data_manager_new_test/BUILD.gn b/test/unittest/app_exit_reason_data_manager_new_test/BUILD.gn index 5ba95e05926..81b565ef14b 100644 --- a/test/unittest/app_exit_reason_data_manager_new_test/BUILD.gn +++ b/test/unittest/app_exit_reason_data_manager_new_test/BUILD.gn @@ -34,6 +34,8 @@ ohos_unittest("app_exit_reason_data_manager_new_test") { sources = [ "${ability_runtime_services_path}/abilitymgr/src/app_exit_reason_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/exit_info_data_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", "app_exit_reason_data_manager_new_test.cpp", ] @@ -47,6 +49,8 @@ ohos_unittest("app_exit_reason_data_manager_new_test") { external_deps = [ "access_token:libaccesstoken_sdk", "c_utils:utils", + "cJSON:cjson", + "config_policy:configpolicy_util", "googletest:gmock_main", "googletest:gtest_main", "hilog:libhilog", diff --git a/test/unittest/app_exit_reason_data_manager_new_test/app_exit_reason_data_manager_new_test.cpp b/test/unittest/app_exit_reason_data_manager_new_test/app_exit_reason_data_manager_new_test.cpp index 9aff32eaf10..13b86f37fcb 100644 --- a/test/unittest/app_exit_reason_data_manager_new_test/app_exit_reason_data_manager_new_test.cpp +++ b/test/unittest/app_exit_reason_data_manager_new_test/app_exit_reason_data_manager_new_test.cpp @@ -17,6 +17,7 @@ #include "gmock/gmock.h" #include #include +#include "cJSON.h" #define private public #define protected public #include "app_exit_reason_data_manager.h" @@ -205,10 +206,12 @@ HWTEST_F(AppExitReasonDataManagerTest, AppExitReasonDataManager_ConvertReasonFro { bool withKillMsg = false; std::string killMsg = "test_value"; - nlohmann::json jsonObject = nlohmann::json{{ "kill_msg", killMsg }}; + cJSON *jsonObject = cJSON_CreateObject(); + cJSON_AddStringToObject(jsonObject, "kill_msg", killMsg.c_str()); AAFwk::ExitReason exitReason = {AAFwk::REASON_JS_ERROR, "Js Error."}; DelayedSingleton::GetInstance()->ConvertReasonFromValue(jsonObject, exitReason, withKillMsg); + cJSON_Delete(jsonObject); EXPECT_EQ(withKillMsg, true); } @@ -384,11 +387,13 @@ HWTEST_F(AppExitReasonDataManagerTest, AppExitReasonDataManager_SetAppExitReason HWTEST_F(AppExitReasonDataManagerTest, AppExitReasonDataManager_ConvertReasonFromValue_002, TestSize.Level1) { bool withKillMsg = false; - nlohmann::json jsonObject = nlohmann::json{{ JSON_KEY_REASON, AAFwk::Reason::REASON_NORMAL }}; + cJSON *jsonObject = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_REASON.c_str(), AAFwk::Reason::REASON_NORMAL); AAFwk::ExitReason exitReason; DelayedSingleton::GetInstance()->ConvertReasonFromValue(jsonObject, exitReason, withKillMsg); EXPECT_EQ(exitReason.reason, AAFwk::Reason::REASON_NORMAL); + cJSON_Delete(jsonObject); } /* * @@ -399,12 +404,14 @@ HWTEST_F(AppExitReasonDataManagerTest, AppExitReasonDataManager_ConvertReasonFro HWTEST_F(AppExitReasonDataManagerTest, AppExitReasonDataManager_ConvertReasonFromValue_003, TestSize.Level1) { bool withKillMsg = false; - nlohmann::json jsonObject = nlohmann::json{{ JSON_KEY_SUB_KILL_REASON, 0 }}; + cJSON *jsonObject = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObject, JSON_KEY_SUB_KILL_REASON.c_str(), 0); AAFwk::ExitReason exitReason; exitReason.subReason = -1; DelayedSingleton::GetInstance()->ConvertReasonFromValue(jsonObject, exitReason, withKillMsg); EXPECT_EQ(exitReason.subReason, 0); + cJSON_Delete(jsonObject); } /* * @@ -415,11 +422,13 @@ HWTEST_F(AppExitReasonDataManagerTest, AppExitReasonDataManager_ConvertReasonFro HWTEST_F(AppExitReasonDataManagerTest, AppExitReasonDataManager_ConvertReasonFromValue_004, TestSize.Level1) { bool withKillMsg = false; - nlohmann::json jsonObject = nlohmann::json{{ JSON_KEY_EXIT_MSG, "exitMsg" }}; + cJSON *jsonObject = cJSON_CreateObject(); + cJSON_AddStringToObject(jsonObject, JSON_KEY_EXIT_MSG.c_str(), "exitMsg"); AAFwk::ExitReason exitReason; DelayedSingleton::GetInstance()->ConvertReasonFromValue(jsonObject, exitReason, withKillMsg); EXPECT_EQ(exitReason.exitMsg, "exitMsg"); + cJSON_Delete(jsonObject); } /* * @@ -514,17 +523,17 @@ HWTEST_F(AppExitReasonDataManagerTest, AppExitReasonDataManager_ConvertAppExitRe { std::string extensionListName = "testExtensionListName"; bool withKillMsg = true; - nlohmann::json jsonObject = nlohmann::json{{ JSON_KEY_REASON, AAFwk::Reason::REASON_NORMAL }}; AAFwk::ExitReason exitReason; exitReason.exitMsg = "exitMsg"; AppExecFwk::RunningProcessInfo processInfo; auto result = DelayedSingleton::GetInstance() ->ConvertAppExitReasonInfoToValueOfExtensionName(extensionListName, exitReason, processInfo, withKillMsg); std::string jsonString = result.ToString(); - jsonObject = nlohmann::json::parse(jsonString); - ASSERT_TRUE(jsonObject.contains(JSON_KEY_EXIT_MSG)); - ASSERT_TRUE(jsonObject[JSON_KEY_EXIT_MSG].is_string()); - auto exitMsg = jsonObject.at(JSON_KEY_EXIT_MSG).get(); + cJSON *jsonObject = cJSON_Parse(jsonString.c_str()); + cJSON *exitMsgItem = cJSON_GetObjectItem(jsonObject, JSON_KEY_EXIT_MSG.c_str()); + ASSERT_TRUE(exitMsgItem != nullptr); + ASSERT_TRUE(cJSON_IsString(exitMsgItem) && exitMsgItem->type == cJSON_String); + std::string exitMsg = exitMsgItem->valuestring; EXPECT_EQ(exitMsg, exitReason.exitMsg); } } // namespace AbilityRuntime diff --git a/test/unittest/app_exit_reason_data_manager_second_test/BUILD.gn b/test/unittest/app_exit_reason_data_manager_second_test/BUILD.gn index dd01857b0cd..9cdc8c1ca97 100644 --- a/test/unittest/app_exit_reason_data_manager_second_test/BUILD.gn +++ b/test/unittest/app_exit_reason_data_manager_second_test/BUILD.gn @@ -34,6 +34,8 @@ ohos_unittest("app_exit_reason_data_manager_second_test") { sources = [ "${ability_runtime_services_path}/abilitymgr/src/app_exit_reason_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/exit_info_data_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", "app_exit_reason_data_manager_second_test.cpp", ] @@ -47,6 +49,7 @@ ohos_unittest("app_exit_reason_data_manager_second_test") { external_deps = [ "access_token:libaccesstoken_sdk", "c_utils:utils", + "config_policy:configpolicy_util", "googletest:gmock_main", "googletest:gtest_main", "hilog:libhilog", diff --git a/test/unittest/app_mgr_service_inner_second_test/BUILD.gn b/test/unittest/app_mgr_service_inner_second_test/BUILD.gn index 4642c2ac9f2..e2c66ac7c89 100644 --- a/test/unittest/app_mgr_service_inner_second_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_second_test/BUILD.gn @@ -88,7 +88,6 @@ ohos_unittest("AppMgrServiceInnerSecondTest") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "jsoncpp:jsoncpp", "kv_store:distributeddata_mgr", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/unittest/app_mgr_service_inner_sixth_test/BUILD.gn b/test/unittest/app_mgr_service_inner_sixth_test/BUILD.gn index 6bd784b776a..01f544f3a0b 100644 --- a/test/unittest/app_mgr_service_inner_sixth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_sixth_test/BUILD.gn @@ -80,7 +80,6 @@ ohos_unittest("app_mgr_service_inner_sixth_test") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "jsoncpp:jsoncpp", "kv_store:distributeddata_mgr", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/unittest/app_mgr_service_inner_tdd_third_test/BUILD.gn b/test/unittest/app_mgr_service_inner_tdd_third_test/BUILD.gn index 7522b16500d..d7ce998940c 100644 --- a/test/unittest/app_mgr_service_inner_tdd_third_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_tdd_third_test/BUILD.gn @@ -70,7 +70,6 @@ ohos_unittest("app_mgr_service_inner_tdd_third_test") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "jsoncpp:jsoncpp", "kv_store:distributeddata_mgr", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/unittest/app_spawn_client_test/BUILD.gn b/test/unittest/app_spawn_client_test/BUILD.gn index da926badd80..a73ace4ed7a 100644 --- a/test/unittest/app_spawn_client_test/BUILD.gn +++ b/test/unittest/app_spawn_client_test/BUILD.gn @@ -30,6 +30,7 @@ ohos_unittest("AppSpawnClientTest") { deps = [ "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", ] diff --git a/test/unittest/assert_fault_callback_death_mgr_test/BUILD.gn b/test/unittest/assert_fault_callback_death_mgr_test/BUILD.gn index 46683c947c6..1b2f5dafea5 100644 --- a/test/unittest/assert_fault_callback_death_mgr_test/BUILD.gn +++ b/test/unittest/assert_fault_callback_death_mgr_test/BUILD.gn @@ -37,6 +37,7 @@ ohos_unittest("assert_fault_callback_death_mgr_test") { "${ability_runtime_services_path}/abilitymgr/src/assert_fault_callback_death_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/assert_fault_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/state_utils.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", "assert_fault_callback_death_mgr_test.cpp", ] @@ -74,6 +75,7 @@ ohos_unittest("assert_fault_callback_death_mgr_test") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", + "config_policy:configpolicy_util", "eventhandler:libeventhandler", "ffrt:libffrt", "googletest:gmock_main", diff --git a/test/unittest/cache_process_manager_second_test/BUILD.gn b/test/unittest/cache_process_manager_second_test/BUILD.gn index 265643796ce..71c8e8c9ad8 100644 --- a/test/unittest/cache_process_manager_second_test/BUILD.gn +++ b/test/unittest/cache_process_manager_second_test/BUILD.gn @@ -142,8 +142,8 @@ ohos_unittest("cache_process_manager_second_test") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", - "jsoncpp:jsoncpp", + # "json:nlohmann_json_static", + # "jsoncpp:jsoncpp", "kv_store:distributeddata_inner", "memmgr:memmgrclient", "memory_utils:libmeminfo", diff --git a/test/unittest/cj_test_runner_object_test/BUILD.gn b/test/unittest/cj_test_runner_object_test/BUILD.gn index 9db58566e5a..12d4fde5914 100644 --- a/test/unittest/cj_test_runner_object_test/BUILD.gn +++ b/test/unittest/cj_test_runner_object_test/BUILD.gn @@ -58,7 +58,6 @@ ohos_unittest("cj_test_runner_object_test") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", - "json:nlohmann_json_static", "napi:ace_napi", "resource_management:global_resmgr", ] diff --git a/test/unittest/cj_test_runner_test/BUILD.gn b/test/unittest/cj_test_runner_test/BUILD.gn index 891969d72a3..80f3ad7fc07 100644 --- a/test/unittest/cj_test_runner_test/BUILD.gn +++ b/test/unittest/cj_test_runner_test/BUILD.gn @@ -92,7 +92,6 @@ ohos_unittest("cj_test_runner_test") { "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "napi:ace_napi", "napi:cj_bind_native", "resource_management:global_resmgr", diff --git a/test/unittest/deeplink_reserve_config_test/BUILD.gn b/test/unittest/deeplink_reserve_config_test/BUILD.gn index 1a399d3cc53..583e3bbc828 100644 --- a/test/unittest/deeplink_reserve_config_test/BUILD.gn +++ b/test/unittest/deeplink_reserve_config_test/BUILD.gn @@ -30,6 +30,7 @@ ohos_unittest("deeplink_reserve_config_test") { external_deps = [ "c_utils:utils", + "cJSON:cjson", "googletest:gmock_main", ] } diff --git a/test/unittest/deeplink_reserve_config_test/deeplink_reserve_config_test.cpp b/test/unittest/deeplink_reserve_config_test/deeplink_reserve_config_test.cpp index bd096fce00e..97351652476 100644 --- a/test/unittest/deeplink_reserve_config_test/deeplink_reserve_config_test.cpp +++ b/test/unittest/deeplink_reserve_config_test/deeplink_reserve_config_test.cpp @@ -56,7 +56,7 @@ HWTEST_F(DeepLinkReserveConfigTest, AaFwk_DeepLinkReserveConfigTest_0200, TestSi { GTEST_LOG_(INFO) << "AaFwk_DeepLinkReserveConfigTest_0200 start"; DeepLinkReserveConfig deepLinkReserveConfig; - const nlohmann::json DEFAULT_CONFIG = R"( + const std::string jsonStr = R"( { "deepLinkReservedUri": [ { @@ -76,12 +76,14 @@ HWTEST_F(DeepLinkReserveConfigTest, AaFwk_DeepLinkReserveConfigTest_0200, TestSi } ] } - )"_json; + )"; + cJSON *DEFAULT_CONFIG = cJSON_Parse(jsonStr.c_str()); deepLinkReserveConfig.LoadReservedUriList(DEFAULT_CONFIG); std::string linkString = "http://www.xxx.com:80/pathRegex"; std::string bundleName = "just a test"; auto ans = deepLinkReserveConfig.IsLinkReserved(linkString, bundleName); EXPECT_EQ(ans, true); + cJSON_Delete(DEFAULT_CONFIG); GTEST_LOG_(INFO) << "AaFwk_DeepLinkReserveConfigTest_0200 end"; } diff --git a/test/unittest/dfr_test/appfreeze_inner_test/BUILD.gn b/test/unittest/dfr_test/appfreeze_inner_test/BUILD.gn index 087d5d57b38..8093c24e58a 100644 --- a/test/unittest/dfr_test/appfreeze_inner_test/BUILD.gn +++ b/test/unittest/dfr_test/appfreeze_inner_test/BUILD.gn @@ -101,7 +101,6 @@ ohos_unittest("appfreeze_inner_test") { "init:libbegetutil", "input:libmmi-client", "ipc:ipc_core", - "json:nlohmann_json_static", "napi:ace_napi", "resource_management:global_resmgr", "safwk:system_ability_fwk", diff --git a/test/unittest/dfr_test/appfreeze_manager_test/BUILD.gn b/test/unittest/dfr_test/appfreeze_manager_test/BUILD.gn index ec4b5e6b4b9..e2144d9979d 100644 --- a/test/unittest/dfr_test/appfreeze_manager_test/BUILD.gn +++ b/test/unittest/dfr_test/appfreeze_manager_test/BUILD.gn @@ -85,7 +85,6 @@ ohos_unittest("appfreeze_manager_test") { "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", - "json:nlohmann_json_static", ] } diff --git a/test/unittest/dfr_test/appfreeze_state_test/BUILD.gn b/test/unittest/dfr_test/appfreeze_state_test/BUILD.gn index 642724b8179..d326c77672a 100644 --- a/test/unittest/dfr_test/appfreeze_state_test/BUILD.gn +++ b/test/unittest/dfr_test/appfreeze_state_test/BUILD.gn @@ -98,7 +98,6 @@ ohos_unittest("appfreeze_state_test") { "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "napi:ace_napi", ] diff --git a/test/unittest/dfr_test/watchdog_test/BUILD.gn b/test/unittest/dfr_test/watchdog_test/BUILD.gn index 34307b9758d..df1a445c991 100644 --- a/test/unittest/dfr_test/watchdog_test/BUILD.gn +++ b/test/unittest/dfr_test/watchdog_test/BUILD.gn @@ -81,7 +81,6 @@ ohos_unittest("watchdog_test") { "hilog:libhilog", "image_framework:image_native", "ipc:ipc_core", - "json:nlohmann_json_static", "jsoncpp:jsoncpp", "napi:ace_napi", ] diff --git a/test/unittest/dump_utils_test/BUILD.gn b/test/unittest/dump_utils_test/BUILD.gn index d451d9ef2a6..8f01abafc53 100644 --- a/test/unittest/dump_utils_test/BUILD.gn +++ b/test/unittest/dump_utils_test/BUILD.gn @@ -60,7 +60,6 @@ ohos_unittest("dump_utils_test") { "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", - "json:nlohmann_json_static", "jsoncpp:jsoncpp", "window_manager:libdm", "window_manager:libwsutils", diff --git a/test/unittest/extension_control_interceptor_test/mock/mock_extension_config.cpp b/test/unittest/extension_control_interceptor_test/mock/mock_extension_config.cpp index f8a09da7805..0111fb339d4 100644 --- a/test/unittest/extension_control_interceptor_test/mock/mock_extension_config.cpp +++ b/test/unittest/extension_control_interceptor_test/mock/mock_extension_config.cpp @@ -74,29 +74,27 @@ bool ExtensionConfig::IsExtensionStartServiceEnable(const std::string &extension return StatusSingleton::GetInstance().isExtensionStartServiceEnable_; } -void ExtensionConfig::LoadExtensionConfig(const nlohmann::json &object) +void ExtensionConfig::LoadExtensionConfig(const cJSON *object) { return; } -void ExtensionConfig::LoadExtensionAutoDisconnectTime(const nlohmann::json &object, - const std::string &extensionTypeName) +void ExtensionConfig::LoadExtensionAutoDisconnectTime(const cJSON *object, const std::string &extensionTypeName) { return; } -void ExtensionConfig::LoadExtensionThirdPartyAppBlockedList(const nlohmann::json &object, - std::string extensionTypeName) +void ExtensionConfig::LoadExtensionThirdPartyAppBlockedList(const cJSON *object, std::string extensionTypeName) { return; } -void ExtensionConfig::LoadExtensionServiceBlockedList(const nlohmann::json &object, std::string extensionTypeName) +void ExtensionConfig::LoadExtensionServiceBlockedList(const cJSON *object, std::string extensionTypeName) { return; } -bool ExtensionConfig::LoadExtensionAbilityAccess(const nlohmann::json &object, const std::string &extensionTypeName) +bool ExtensionConfig::LoadExtensionAbilityAccess(const cJSON *object, const std::string &extensionTypeName) { return true; } @@ -109,20 +107,18 @@ std::string ExtensionConfig::FormatAccessFlag(const std::optional &flag) return flag.value() ? "true" : "false"; } -void ExtensionConfig::LoadExtensionAllowOrBlockedList(const nlohmann::json &object, const std::string &key, +void ExtensionConfig::LoadExtensionAllowOrBlockedList(const cJSON *object, const std::string &key, std::unordered_set &list) { return; } -void ExtensionConfig::LoadExtensionNetworkEnable(const nlohmann::json &object, - const std::string &extensionTypeName) +void ExtensionConfig::LoadExtensionNetworkEnable(const cJSON *object, const std::string &extensionTypeName) { return; } -void ExtensionConfig::LoadExtensionSAEnable(const nlohmann::json &object, - const std::string &extensionTypeName) +void ExtensionConfig::LoadExtensionSAEnable(const cJSON *object, const std::string &extensionTypeName) { return; } @@ -194,7 +190,7 @@ bool ExtensionConfig::IsExtensionSAEnable(const std::string &extensionTypeName) return EXTENSION_SA_ENABLE_FLAG_DEFAULT; } -bool ExtensionConfig::ReadFileInfoJson(const std::string &filePath, nlohmann::json &jsonBuf) +bool ExtensionConfig::ReadFileInfoJson(const std::string &filePath, cJSON *jsonBuf) { return true; } diff --git a/test/unittest/extension_record_factory_test/BUILD.gn b/test/unittest/extension_record_factory_test/BUILD.gn index 1b43641f624..36d7224ea62 100644 --- a/test/unittest/extension_record_factory_test/BUILD.gn +++ b/test/unittest/extension_record_factory_test/BUILD.gn @@ -94,7 +94,6 @@ ohos_unittest("extension_record_factory_test") { "i18n:intl_util", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "jsoncpp:jsoncpp", "kv_store:distributeddata_inner", "napi:ace_napi", diff --git a/test/unittest/extract_insight_intent_profile_test/BUILD.gn b/test/unittest/extract_insight_intent_profile_test/BUILD.gn index b4399a10398..2fac2255aa7 100644 --- a/test/unittest/extract_insight_intent_profile_test/BUILD.gn +++ b/test/unittest/extract_insight_intent_profile_test/BUILD.gn @@ -31,7 +31,11 @@ ohos_unittest("extract_insight_intent_profile_test") { "${ability_runtime_services_path}/abilitymgr:abilityms", ] - sources = [ "extract_insight_intent_profile_test.cpp" ] + sources = [ + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", + "extract_insight_intent_profile_test.cpp", + ] deps = [ "${ability_runtime_abilitymgr_path}/:abilityms" ] @@ -43,6 +47,7 @@ ohos_unittest("extract_insight_intent_profile_test") { "bundle_framework:libappexecfwk_common", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "config_policy:configpolicy_util", "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", diff --git a/test/unittest/extract_insight_intent_profile_test/extract_insight_intent_profile_test.cpp b/test/unittest/extract_insight_intent_profile_test/extract_insight_intent_profile_test.cpp index 93e06319168..72f1f874529 100644 --- a/test/unittest/extract_insight_intent_profile_test/extract_insight_intent_profile_test.cpp +++ b/test/unittest/extract_insight_intent_profile_test/extract_insight_intent_profile_test.cpp @@ -348,29 +348,38 @@ HWTEST_F(ExtractInsightIntentProfileTest, TransformTo_0200, TestSize.Level0) EXPECT_EQ(profileInfos.insightIntents[1].example, "exampleBBB"); EXPECT_NE(profileInfos.insightIntents[1].result, ""); - nlohmann::json jsonObject1; + cJSON *jsonObject1 = nullptr; result = ExtractInsightIntentProfile::ToJson(profileInfos.insightIntents[0], jsonObject1); EXPECT_EQ(result, true); ExtractInsightIntentProfileInfoVec profileInfos1; - result = ExtractInsightIntentProfile::TransformTo(jsonObject1.dump(), profileInfos1); + char *str1 = cJSON_PrintUnformatted(jsonObject1); + std::string jsonStr1 = (str1 == nullptr) ? "" : str1; + cJSON_free(str1); + result = ExtractInsightIntentProfile::TransformTo(jsonStr1, profileInfos1); EXPECT_EQ(result, true); - TAG_LOGI(AAFwkTag::TEST, "jsonObject1 dump: %{public}s", jsonObject1.dump().c_str()); + TAG_LOGI(AAFwkTag::TEST, "jsonObject1 dump: %{public}s", jsonStr1.c_str()); EXPECT_EQ(profileInfos1.insightIntents.size(), 1); EXPECT_EQ(profileInfos1.insightIntents[0].decoratorType, "@InsightIntentLink"); EXPECT_EQ(profileInfos1.insightIntents[0].intentName, "123"); EXPECT_EQ(profileInfos1.insightIntents[0].example, "exampleAAA"); + cJSON_Delete(jsonObject1); - nlohmann::json jsonObject2; + + cJSON *jsonObject2 = nullptr; result = ExtractInsightIntentProfile::ToJson(profileInfos.insightIntents[1], jsonObject2); EXPECT_EQ(result, true); ExtractInsightIntentProfileInfoVec profileInfos2; - result = ExtractInsightIntentProfile::TransformTo(jsonObject2.dump(), profileInfos2); + char *str2 = cJSON_PrintUnformatted(jsonObject1); + std::string jsonStr2 = (str2 == nullptr) ? "" : str2; + cJSON_free(str2); + result = ExtractInsightIntentProfile::TransformTo(jsonStr2, profileInfos2); EXPECT_EQ(result, true); - TAG_LOGI(AAFwkTag::TEST, "jsonObject2 dump: %{public}s", jsonObject2.dump().c_str()); + TAG_LOGI(AAFwkTag::TEST, "jsonObject2 dump: %{public}s", jsonStr2.c_str()); EXPECT_EQ(profileInfos2.insightIntents.size(), 1); EXPECT_EQ(profileInfos2.insightIntents[0].decoratorType, "@InsightIntentLink"); EXPECT_EQ(profileInfos2.insightIntents[0].intentName, "InsightIntent2"); EXPECT_EQ(profileInfos2.insightIntents[0].example, "exampleBBB"); + cJSON_Delete(jsonObject2); ExtractInsightIntentInfo info1; result = ExtractInsightIntentProfile::ProfileInfoFormat(profileInfos1.insightIntents[0], info1); diff --git a/test/unittest/frameworks_kits_ability_native_test/pac_map_test.cpp b/test/unittest/frameworks_kits_ability_native_test/pac_map_test.cpp index d3eb9c00525..f7c053d76fe 100644 --- a/test/unittest/frameworks_kits_ability_native_test/pac_map_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/pac_map_test.cpp @@ -1443,9 +1443,10 @@ HWTEST_F(PacMapTest, AppExecFwk_PacMap_ToJsonArrayShort_0100, Function | MediumT GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayShort_0100 start"; std::vector array; - Json::Value item; + cJSON *item = nullptr; int type = 1; bool result = pacmap_->ToJsonArrayShort(array, item, type); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayShort_0100 end"; @@ -1462,9 +1463,10 @@ HWTEST_F(PacMapTest, AppExecFwk_PacMap_ToJsonArrayInt_0100, Function | MediumTes GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayInt_0100 start"; std::vector array; - Json::Value item; + cJSON *item = nullptr; int type = 1; bool result = pacmap_->ToJsonArrayInt(array, item, type); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayInt_0100 end"; @@ -1481,9 +1483,10 @@ HWTEST_F(PacMapTest, AppExecFwk_PacMap_ToJsonArrayLong_0100, Function | MediumTe GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayLong_0100 start"; std::vector array; - Json::Value item; + cJSON *item = nullptr; int type = 1; bool result = pacmap_->ToJsonArrayLong(array, item, type); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayLong_0100 end"; @@ -1500,9 +1503,10 @@ HWTEST_F(PacMapTest, AppExecFwk_PacMap_ToJsonArrayByte_0100, Function | MediumTe GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayByte_0100 start"; std::vector array; - Json::Value item; + cJSON *item = nullptr; int type = 1; bool result = pacmap_->ToJsonArrayByte(array, item, type); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayByte_0100 end"; @@ -1519,9 +1523,10 @@ HWTEST_F(PacMapTest, AppExecFwk_PacMap_ToJsonArrayBoolean_0100, Function | Mediu GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayBoolean_0100 start"; std::vector array; - Json::Value item; + cJSON *item = nullptr; int type = 1; bool result = pacmap_->ToJsonArrayBoolean(array, item, type); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayBoolean_0100 end"; @@ -1538,9 +1543,10 @@ HWTEST_F(PacMapTest, AppExecFwk_PacMap_ToJsonArrayFloat_0100, Function | MediumT GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayFloat_0100 start"; std::vector array; - Json::Value item; + cJSON *item = nullptr; int type = 1; bool result = pacmap_->ToJsonArrayFloat(array, item, type); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayFloat_0100 end"; @@ -1557,9 +1563,10 @@ HWTEST_F(PacMapTest, AppExecFwk_PacMap_ToJsonArrayDouble_0100, Function | Medium GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayDouble_0100 start"; std::vector array; - Json::Value item; + cJSON *item = nullptr; int type = 1; bool result = pacmap_->ToJsonArrayDouble(array, item, type); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayDouble_0100 end"; @@ -1576,9 +1583,10 @@ HWTEST_F(PacMapTest, AppExecFwk_PacMap_ToJsonArrayString_0100, Function | Medium GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayString_0100 start"; std::vector array; - Json::Value item; + cJSON *item = nullptr; int type = 1; bool result = pacmap_->ToJsonArrayString(array, item, type); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ToJsonArrayString_0100 end"; @@ -1594,9 +1602,10 @@ HWTEST_F(PacMapTest, AppExecFwk_PacMap_ParseJson_0100, Function | MediumTest | L { GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ParseJson_0100 start"; - Json::Value data; + cJSON *data = nullptr; PacMapList mapList; bool result = pacmap_->ParseJson(data, mapList); + cJSON_Delete(data); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_PacMap_ParseJson_0100 end"; @@ -1614,8 +1623,9 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayShort_0100, Function | MediumT PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->ParseJsonItemArrayShort(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayShort_0100 end"; @@ -1633,8 +1643,9 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayInteger_0100, Function | Mediu PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->ParseJsonItemArrayInteger(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayInteger_0100 end"; @@ -1652,8 +1663,9 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayLong_0100, Function | MediumTe PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->ParseJsonItemArrayLong(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayLong_0100 end"; @@ -1671,8 +1683,9 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayChar_0100, Function | MediumTe PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->ParseJsonItemArrayChar(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayChar_0100 end"; @@ -1690,19 +1703,25 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayChar_0200, Function | MediumTe PacMapList mapList; std::string key = "this is key"; - Json::Value item; - item["data"] = "test"; + cJSON *item = cJSON_CreateObject(); + cJSON_AddStringToObject(item, "data", "test"); auto result = pacmap_->ParseJsonItemArrayChar(mapList, key, item); EXPECT_EQ(result, true); - Json::Value courses(Json::arrayValue); - courses.append('a'); - courses.append(1); - courses.append("first"); - courses.append("second"); - courses.append("third"); - item["data"] = courses; + cJSON *courses = cJSON_CreateArray(); + cJSON *courses1 = cJSON_CreateNumber(static_cast('a')); + cJSON *courses2 = cJSON_CreateNumber(static_cast(1)); + cJSON *courses3 = cJSON_CreateString("first"); + cJSON *courses4 = cJSON_CreateString("second"); + cJSON *courses5 = cJSON_CreateString("third"); + cJSON_AddItemToArray(courses, courses1); + cJSON_AddItemToArray(courses, courses2); + cJSON_AddItemToArray(courses, courses3); + cJSON_AddItemToArray(courses, courses4); + cJSON_AddItemToArray(courses, courses5); + cJSON_AddItemToObject(item, "data", courses); result = pacmap_->ParseJsonItemArrayChar(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayChar_0200 end"; @@ -1720,8 +1739,9 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayByte_0100, Function | MediumTe PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->ParseJsonItemArrayByte(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayByte_0100 end"; @@ -1739,8 +1759,9 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayBoolean_0100, Function | Mediu PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->ParseJsonItemArrayBoolean(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayBoolean_0100 end"; @@ -1758,8 +1779,9 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayFloat_0100, Function | MediumT PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->ParseJsonItemArrayFloat(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayFloat_0100 end"; @@ -1777,8 +1799,9 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayDouble_0100, Function | Medium PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->ParseJsonItemArrayDouble(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayDouble_0100 end"; @@ -1796,8 +1819,9 @@ HWTEST_F(PacMapTest, AppExecFwk_ParseJsonItemArrayString_0100, Function | Medium PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->ParseJsonItemArrayString(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, true); GTEST_LOG_(INFO) << "AppExecFwk_ParseJsonItemArrayString_0100 end"; @@ -1815,8 +1839,9 @@ HWTEST_F(PacMapTest, AppExecFwk_InnerPutObjectValue_0100, Function | MediumTest PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->InnerPutObjectValue(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_InnerPutObjectValue_0100 end"; @@ -1834,8 +1859,9 @@ HWTEST_F(PacMapTest, AppExecFwk_InnerPutPacMapValue_0100, Function | MediumTest PacMapList mapList; std::string key = "this is key"; - Json::Value item; + cJSON *item = nullptr; bool result = pacmap_->InnerPutPacMapValue(mapList, key, item); + cJSON_Delete(item); EXPECT_EQ(result, false); GTEST_LOG_(INFO) << "AppExecFwk_InnerPutPacMapValue_0100 end"; diff --git a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn index 0baadfbaeda..94a34f34e47 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn @@ -1022,6 +1022,7 @@ ohos_unittest("idle_time_test") { "graphic_2d:librender_service_client", "hilog:libhilog", "ipc:ipc_core", + # "json:nlohmann_json_static", "napi:ace_napi", ] } @@ -1057,7 +1058,6 @@ ohos_unittest("dump_runtime_helper_second_test") { "hilog:libhilog", "init:libbegetutil", "ipc:ipc_core", - "jsoncpp:jsoncpp", "napi:ace_napi", "ffrt:libffrt", "storage_service:storage_manager_acl", @@ -1096,7 +1096,6 @@ ohos_unittest("native_lib_util_test") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", - "jsoncpp:jsoncpp", "napi:ace_napi", ] } @@ -1125,6 +1124,7 @@ ohos_unittest("startup_manager_test") { "${ability_runtime_native_path}/appkit/app_startup/startup_manager.cpp", "${ability_runtime_native_path}/appkit/app_startup/startup_task.cpp", "${ability_runtime_native_path}/appkit/app_startup/startup_utils.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", "app_startup_task_matcher_test.cpp", "startup_manager_test.cpp", "startup_utils_test.cpp", @@ -1144,6 +1144,7 @@ ohos_unittest("startup_manager_test") { "ability_base:zuri", "ability_runtime:runtime", "c_utils:utils", + "config_policy:configpolicy_util", "eventhandler:libeventhandler", "faultloggerd:libfaultloggerd", "googletest:gtest_main", @@ -1151,7 +1152,6 @@ ohos_unittest("startup_manager_test") { "hisysevent:libhisysevent", "hitrace:hitrace_meter", "ipc:ipc_core", - "jsoncpp:jsoncpp", "napi:ace_napi", ] } @@ -1185,6 +1185,7 @@ ohos_unittest("startup_manager_mock_test") { "${ability_runtime_native_path}/appkit/app_startup/startup_listener.cpp", "${ability_runtime_native_path}/appkit/app_startup/startup_manager.cpp", "${ability_runtime_native_path}/appkit/app_startup/startup_task.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", "${ability_runtime_test_path}/mock/start_up_and_intent/src/mock_extractor.cpp", "${ability_runtime_test_path}/mock/start_up_and_intent/src/mock_native_module_manager.cpp", "startup_manager_mock_test.cpp", @@ -1203,6 +1204,7 @@ ohos_unittest("startup_manager_mock_test") { "ability_base:zuri", "ability_runtime:runtime", "c_utils:utils", + "config_policy:configpolicy_util", "eventhandler:libeventhandler", "faultloggerd:libfaultloggerd", "googletest:gtest_main", @@ -1210,7 +1212,6 @@ ohos_unittest("startup_manager_mock_test") { "hisysevent:libhisysevent", "hitrace:hitrace_meter", "ipc:ipc_core", - "jsoncpp:jsoncpp", "napi:ace_napi", ] } diff --git a/test/unittest/frameworks_kits_appkit_native_test/startup_manager_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/startup_manager_test.cpp index 5b4b2f3d5bf..d2293c7778b 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/startup_manager_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/startup_manager_test.cpp @@ -618,7 +618,7 @@ HWTEST_F(StartupManagerTest, AnalyzeStartupConfig_0100, Function | MediumTest | ret = startupManager->AnalyzeStartupConfig(info, startupConfig, preloadSoStartupTasks, pendingStartupTaskInfos, pendingConfigEntry); EXPECT_EQ(ret, false); - const nlohmann::json startupConfig_json = R"( + std::string jsonStr = R"( { "startupConfig" : [ { @@ -627,22 +627,39 @@ HWTEST_F(StartupManagerTest, AnalyzeStartupConfig_0100, Function | MediumTest | } ] } - )"_json; - startupConfig = startupConfig_json.dump(); + )"; + cJSON *startupConfig_json = cJSON_Parse(jsonStr.c_str()); + char *str = cJSON_PrintUnformatted(startupConfig_json); + startupConfig = (str == nullptr) ? "" : str; ret = startupManager->AnalyzeStartupConfig(info, startupConfig, preloadSoStartupTasks, pendingStartupTaskInfos, pendingConfigEntry); EXPECT_EQ(ret, true); + cJSON_Delete(startupConfig_json); + cJSON_free(str); info.moduleType_ = AppExecFwk::ModuleType::ENTRY; - nlohmann::json startupConfigJson = { - {"startupConfig", { - {"configEntry", "test_configEntry"} - }} - }; - startupConfig = startupConfigJson.dump(); + /* + { + "startupConfig" : [ + "configEntry", + "test_configEntry" + ] + } + */ + cJSON *item1 = cJSON_CreateObject(); + cJSON *item2 = cJSON_CreateArray(); + cJSON *array1 = cJSON_CreateString("configEntry"); + cJSON *array2 = cJSON_CreateString("test_configEntry"); + cJSON_AddItemToArray(item2, array1); + cJSON_AddItemToArray(item2, array2); + cJSON_AddItemToObject(item1, "startupConfig", item2); + char *str1 = cJSON_PrintUnformatted(item1); + startupConfig = (str1 == nullptr) ? "" : str1; ret = startupManager->AnalyzeStartupConfig(info, startupConfig, preloadSoStartupTasks, pendingStartupTaskInfos, pendingConfigEntry); EXPECT_EQ(ret, false); + cJSON_Delete(item1); + cJSON_free(str1); GTEST_LOG_(INFO) << "StartupManagerTest AnalyzeStartupConfig_0100 end"; } @@ -659,14 +676,16 @@ HWTEST_F(StartupManagerTest, AnalyzeAppStartupTask_0100, Function | MediumTest | std::string name = "test_name"; ModuleStartupConfigInfo info(name, "", "", AppExecFwk::ModuleType::UNKNOWN, false); std::vector pendingStartupTaskInfos; - nlohmann::json startupTasksJson = R"( + const std::string jsonStr = R"( { } - )"_json; + )"; + cJSON *startupTasksJson = cJSON_Parse(jsonStr.c_str()); bool ret = startupManager->AnalyzeAppStartupTask(info, startupTasksJson, pendingStartupTaskInfos); EXPECT_EQ(ret, true); + cJSON_Delete(startupTasksJson); - nlohmann::json startupTasksJson2 = R"( + const std::string jsonStr2 = R"( { "startupTasks": [ { @@ -675,11 +694,13 @@ HWTEST_F(StartupManagerTest, AnalyzeAppStartupTask_0100, Function | MediumTest | } ] } - )"_json; + )"; + cJSON *startupTasksJson2 = cJSON_Parse(jsonStr2.c_str()); ret = startupManager->AnalyzeAppStartupTask(info, startupTasksJson2, pendingStartupTaskInfos); EXPECT_EQ(ret, true); + cJSON_Delete(startupTasksJson2); - nlohmann::json startupTasksJson3 = R"( + const std::string jsonStr3 = R"( { "startupTasks": [ { @@ -687,9 +708,11 @@ HWTEST_F(StartupManagerTest, AnalyzeAppStartupTask_0100, Function | MediumTest | } ] } - )"_json; + )"; + cJSON *startupTasksJson3 = cJSON_Parse(jsonStr3.c_str()); ret = startupManager->AnalyzeAppStartupTask(info, startupTasksJson3, pendingStartupTaskInfos); EXPECT_EQ(ret, false); + cJSON_Delete(startupTasksJson3); GTEST_LOG_(INFO) << "StartupManagerTest AnalyzeAppStartupTask_0100 end"; } @@ -706,7 +729,7 @@ HWTEST_F(StartupManagerTest, AnalyzeAppStartupTask_0200, Function | MediumTest | std::string name = "test_name"; ModuleStartupConfigInfo info(name, "", "", AppExecFwk::ModuleType::UNKNOWN, false); std::vector pendingStartupTaskInfos; - nlohmann::json startupTasksJson = R"( + const std::string jsonStr = R"( { "startupTasks": [ { @@ -714,11 +737,13 @@ HWTEST_F(StartupManagerTest, AnalyzeAppStartupTask_0200, Function | MediumTest | } ] } - )"_json; + )"; + cJSON *startupTasksJson = cJSON_Parse(jsonStr.c_str()); bool ret = startupManager->AnalyzeAppStartupTask(info, startupTasksJson, pendingStartupTaskInfos); EXPECT_EQ(ret, false); + cJSON_Delete(startupTasksJson); - nlohmann::json startupTasksJson2 = R"( + const std::string jsonStr2 = R"( { "startupTasks": [ { @@ -727,7 +752,8 @@ HWTEST_F(StartupManagerTest, AnalyzeAppStartupTask_0200, Function | MediumTest | } ] } - )"_json; + )"; + cJSON *startupTasksJson2 = cJSON_Parse(jsonStr2.c_str()); ret = startupManager->AnalyzeAppStartupTask(info, startupTasksJson2, pendingStartupTaskInfos); EXPECT_EQ(ret, false); GTEST_LOG_(INFO) << "StartupManagerTest AnalyzeAppStartupTask_0200 end"; @@ -746,14 +772,16 @@ HWTEST_F(StartupManagerTest, AnalyzePreloadSoStartupTask_0100, Function | Medium std::string name = "test_name"; ModuleStartupConfigInfo info(name, "", "", AppExecFwk::ModuleType::UNKNOWN, false); std::map> preloadSoStartupTasks; - nlohmann::json preloadHintStartupTasksJson = R"( + const std::string jsonStr = R"( { } - )"_json; + )"; + cJSON *preloadHintStartupTasksJson = cJSON_Parse(jsonStr.c_str()); bool ret = startupManager->AnalyzePreloadSoStartupTask(info, preloadHintStartupTasksJson, preloadSoStartupTasks); EXPECT_EQ(ret, true); + cJSON_Delete(preloadHintStartupTasksJson); - nlohmann::json preloadHintStartupTasksJson2 = R"( + const std::string jsonStr2 = R"( { "appPreloadHintStartupTasks": [ { @@ -762,11 +790,13 @@ HWTEST_F(StartupManagerTest, AnalyzePreloadSoStartupTask_0100, Function | Medium } ] } - )"_json; + )"; + cJSON *preloadHintStartupTasksJson2 = cJSON_Parse(jsonStr2.c_str()); ret = startupManager->AnalyzePreloadSoStartupTask(info, preloadHintStartupTasksJson2, preloadSoStartupTasks); EXPECT_EQ(ret, false); + cJSON_Delete(preloadHintStartupTasksJson2); - nlohmann::json preloadHintStartupTasksJson3 = R"( + const std::string jsonStr3 = R"( { "appPreloadHintStartupTasks": [ { @@ -774,9 +804,11 @@ HWTEST_F(StartupManagerTest, AnalyzePreloadSoStartupTask_0100, Function | Medium } ] } - )"_json; + )"; + cJSON *preloadHintStartupTasksJson3 = cJSON_Parse(jsonStr3.c_str()); ret = startupManager->AnalyzePreloadSoStartupTask(info, preloadHintStartupTasksJson3, preloadSoStartupTasks); EXPECT_EQ(ret, false); + cJSON_Delete(preloadHintStartupTasksJson3); GTEST_LOG_(INFO) << "StartupManagerTest AnalyzePreloadSoStartupTask_0100 end"; } @@ -793,7 +825,7 @@ HWTEST_F(StartupManagerTest, AnalyzePreloadSoStartupTask_0200, Function | Medium std::string name = "test_name"; ModuleStartupConfigInfo info(name, "", "", AppExecFwk::ModuleType::UNKNOWN, false); std::map> preloadSoStartupTasks; - nlohmann::json preloadHintStartupTasksJson = R"( + const std::string jsonStr = R"( { "appPreloadHintStartupTasks": [ { @@ -801,11 +833,13 @@ HWTEST_F(StartupManagerTest, AnalyzePreloadSoStartupTask_0200, Function | Medium } ] } - )"_json; + )"; + cJSON *preloadHintStartupTasksJson = cJSON_Parse(jsonStr.c_str()); bool ret = startupManager->AnalyzePreloadSoStartupTask(info, preloadHintStartupTasksJson, preloadSoStartupTasks); EXPECT_EQ(ret, false); + cJSON_Delete(preloadHintStartupTasksJson); - nlohmann::json preloadHintStartupTasksJson2 = R"( + const std::string jsonStr2 = R"( { "appPreloadHintStartupTasks": [ { @@ -814,9 +848,11 @@ HWTEST_F(StartupManagerTest, AnalyzePreloadSoStartupTask_0200, Function | Medium } ] } - )"_json; + )"; + cJSON *preloadHintStartupTasksJson2 = cJSON_Parse(jsonStr2.c_str()); ret = startupManager->AnalyzePreloadSoStartupTask(info, preloadHintStartupTasksJson2, preloadSoStartupTasks); EXPECT_EQ(ret, false); + cJSON_Delete(preloadHintStartupTasksJson2); GTEST_LOG_(INFO) << "StartupManagerTest AnalyzePreloadSoStartupTask_0200 end"; } @@ -833,36 +869,45 @@ HWTEST_F(StartupManagerTest, AnalyzeAppStartupTaskInner_0100, Function | MediumT std::string name = "test_name"; ModuleStartupConfigInfo info(name, "", "", AppExecFwk::ModuleType::UNKNOWN, false); std::vector pendingStartupTaskInfos; - nlohmann::json appStartupTaskInnerJson = R"( + const std::string jsonStr = R"( { } - )"_json; + )"; + cJSON *appStartupTaskInnerJson = cJSON_Parse(jsonStr.c_str()); bool ret = startupManager->AnalyzeAppStartupTaskInner(info, appStartupTaskInnerJson, pendingStartupTaskInfos); EXPECT_EQ(ret, false); + cJSON_Delete(appStartupTaskInnerJson); - nlohmann::json appStartupTaskInnerJson1 = R"( + const std::string jsonStr1 = R"( { "srcEntry": "test_entry", "name": "test_name" } - )"_json; + )"; + cJSON *appStartupTaskInnerJson1 = cJSON_Parse(jsonStr1.c_str()); ret = startupManager->AnalyzeAppStartupTaskInner(info, appStartupTaskInnerJson1, pendingStartupTaskInfos); EXPECT_EQ(ret, true); + cJSON_Delete(appStartupTaskInnerJson1); - nlohmann::json appStartupTaskInnerJson2 = R"( + const std::string jsonStr2 = R"( { "srcEntry": [] } - )"_json; + )"; + cJSON *appStartupTaskInnerJson2 = cJSON_Parse(jsonStr2.c_str()); ret = startupManager->AnalyzeAppStartupTaskInner(info, appStartupTaskInnerJson2, pendingStartupTaskInfos); EXPECT_EQ(ret, false); - nlohmann::json appStartupTaskInnerJson3 = R"( + cJSON_Delete(appStartupTaskInnerJson2); + + const std::string jsonStr3 = R"( { "srcEntry": "test_entry" } - )"_json; + )"; + cJSON *appStartupTaskInnerJson3 = cJSON_Parse(jsonStr3.c_str()); ret = startupManager->AnalyzeAppStartupTaskInner(info, appStartupTaskInnerJson3, pendingStartupTaskInfos); EXPECT_EQ(ret, false); + cJSON_Delete(appStartupTaskInnerJson3); GTEST_LOG_(INFO) << "StartupManagerTest AnalyzeAppStartupTaskInner_0100 end"; } @@ -879,32 +924,38 @@ HWTEST_F(StartupManagerTest, AnalyzeAppStartupTaskInner_0200, Function | MediumT std::string name = "test_name"; ModuleStartupConfigInfo info(name, "", "", AppExecFwk::ModuleType::UNKNOWN, false); std::vector pendingStartupTaskInfos; - nlohmann::json appStartupTaskInnerJson = R"( + const std::string jsonStr = R"( { "srcEntry": "test_entry", "name": [] } - )"_json; + )"; + cJSON *appStartupTaskInnerJson = cJSON_Parse(jsonStr.c_str()); bool ret = startupManager->AnalyzeAppStartupTaskInner(info, appStartupTaskInnerJson, pendingStartupTaskInfos); EXPECT_EQ(ret, false); + cJSON_Delete(appStartupTaskInnerJson); - nlohmann::json appStartupTaskInnerJson2 = R"( + const std::string jsonStr2 = R"( { "srcEntry": "", "name": "test_name" } - )"_json; + )"; + cJSON *appStartupTaskInnerJson2 = cJSON_Parse(jsonStr2.c_str()); ret = startupManager->AnalyzeAppStartupTaskInner(info, appStartupTaskInnerJson2, pendingStartupTaskInfos); EXPECT_EQ(ret, false); + cJSON_Delete(appStartupTaskInnerJson2); - nlohmann::json appStartupTaskInnerJson3 = R"( + const std::string jsonStr3 = R"( { "srcEntry": "test_entry", "name": "" } - )"_json; + )"; + cJSON *appStartupTaskInnerJson3 = cJSON_Parse(jsonStr3.c_str()); ret = startupManager->AnalyzeAppStartupTaskInner(info, appStartupTaskInnerJson3, pendingStartupTaskInfos); EXPECT_EQ(ret, false); + cJSON_Delete(appStartupTaskInnerJson3); GTEST_LOG_(INFO) << "StartupManagerTest AnalyzeAppStartupTaskInner_0200 end"; } @@ -921,32 +972,38 @@ HWTEST_F(StartupManagerTest, AnalyzePreloadSoStartupTaskInner_0100, Function | M std::string name = "test_name"; ModuleStartupConfigInfo info(name, "", "", AppExecFwk::ModuleType::UNKNOWN, false); std::map> preloadSoStartupTasks; - nlohmann::json preloadSoStartupTaskInnerJson = R"( + const std::string jsonStr = R"( { } - )"_json; + )"; + cJSON *preloadSoStartupTaskInnerJson = cJSON_Parse(jsonStr.c_str()); bool ret = startupManager->AnalyzePreloadSoStartupTaskInner(info, preloadSoStartupTaskInnerJson, preloadSoStartupTasks); EXPECT_EQ(ret, false); + cJSON_Delete(preloadSoStartupTaskInnerJson); - nlohmann::json preloadSoStartupTaskInnerJson1 = R"( + const std::string jsonStr1 = R"( { "ohmurl": "test_ohmurl", "name": "test_name" } - )"_json; + )"; + cJSON *preloadSoStartupTaskInnerJson1 = cJSON_Parse(jsonStr1.c_str()); ret = startupManager->AnalyzePreloadSoStartupTaskInner(info, preloadSoStartupTaskInnerJson1, preloadSoStartupTasks); EXPECT_EQ(ret, true); + cJSON_Delete(preloadSoStartupTaskInnerJson1); - nlohmann::json preloadSoStartupTaskInnerJson2 = R"( + const std::string jsonStr2 = R"( { "ohmurl": [] } - )"_json; + )"; + cJSON *preloadSoStartupTaskInnerJson2 = cJSON_Parse(jsonStr2.c_str()); ret = startupManager->AnalyzePreloadSoStartupTaskInner(info, preloadSoStartupTaskInnerJson2, preloadSoStartupTasks); EXPECT_EQ(ret, false); + cJSON_Delete(preloadSoStartupTaskInnerJson2); GTEST_LOG_(INFO) << "StartupManagerTest AnalyzePreloadSoStartupTaskInner_0100 end"; } @@ -963,24 +1020,28 @@ HWTEST_F(StartupManagerTest, AnalyzePreloadSoStartupTaskInner_0200, Function | M std::string name = "test_name"; ModuleStartupConfigInfo info(name, "", "", AppExecFwk::ModuleType::UNKNOWN, false); std::map> preloadSoStartupTasks; - nlohmann::json preloadSoStartupTaskInnerJson = R"( + const std::string jsonStr = R"( { "ohmurl": "test_ohmurl" } - )"_json; + )"; + cJSON *preloadSoStartupTaskInnerJson = cJSON_Parse(jsonStr.c_str()); bool ret = startupManager->AnalyzePreloadSoStartupTaskInner(info, preloadSoStartupTaskInnerJson, preloadSoStartupTasks); EXPECT_EQ(ret, false); + cJSON_Delete(preloadSoStartupTaskInnerJson); - nlohmann::json preloadSoStartupTaskInnerJson2 = R"( + const std::string jsonStr2 = R"( { "ohmurl": "test_ohmurl", "name": [] } - )"_json; + )"; + cJSON *preloadSoStartupTaskInnerJson2 = cJSON_Parse(jsonStr2.c_str()); ret = startupManager->AnalyzePreloadSoStartupTaskInner(info, preloadSoStartupTaskInnerJson2, preloadSoStartupTasks); EXPECT_EQ(ret, false); + cJSON_Delete(preloadSoStartupTaskInnerJson2); GTEST_LOG_(INFO) << "StartupManagerTest AnalyzePreloadSoStartupTaskInner_0200 end"; } diff --git a/test/unittest/frameworks_kits_appkit_native_test/startup_utils_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/startup_utils_test.cpp index 4c738074875..b73febdab9e 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/startup_utils_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/startup_utils_test.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ #include -#include #include "startup_utils.h" @@ -60,7 +59,7 @@ HWTEST_F(StartupUtilsTest, ParseJsonStringArray_001, TestSize.Level1) "nonArray" : "nonArray", "nonString": [1] })"; - nlohmann::json json = nlohmann::json::parse(jsonStr); + cJSON *json = cJSON_Parse(jsonStr.c_str()); std::vector arr; StartupUtils::ParseJsonStringArray(json, "nonExist", arr); @@ -78,6 +77,8 @@ HWTEST_F(StartupUtilsTest, ParseJsonStringArray_001, TestSize.Level1) StartupUtils::ParseJsonStringArray(json, "actions", arr3); EXPECT_EQ(arr3.size(), 2); GTEST_LOG_(INFO) << "ParseJsonStringArray_001 end"; + + cJSON_Delete(json); } } } \ No newline at end of file diff --git a/test/unittest/insight_intent/insight_intent_execute_manager_second_test/BUILD.gn b/test/unittest/insight_intent/insight_intent_execute_manager_second_test/BUILD.gn index 83f137e6c1d..ad1f29f40d6 100644 --- a/test/unittest/insight_intent/insight_intent_execute_manager_second_test/BUILD.gn +++ b/test/unittest/insight_intent/insight_intent_execute_manager_second_test/BUILD.gn @@ -35,6 +35,7 @@ ohos_unittest("insight_intent_execute_manager_second_test") { "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_data_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/hmsf_utils.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", "insight_intent_execute_manager_mock.cpp", "insight_intent_execute_manager_second_test.cpp", ] @@ -61,6 +62,7 @@ ohos_unittest("insight_intent_execute_manager_second_test") { "ability_runtime:ability_manager", "bundle_framework:libappexecfwk_common", "c_utils:utils", + "config_policy:configpolicy_util", "ffrt:libffrt", "googletest:gmock_main", "googletest:gtest_main", diff --git a/test/unittest/insight_intent/insight_intent_execute_manager_test/BUILD.gn b/test/unittest/insight_intent/insight_intent_execute_manager_test/BUILD.gn index f86d5978557..6bb611fd629 100644 --- a/test/unittest/insight_intent/insight_intent_execute_manager_test/BUILD.gn +++ b/test/unittest/insight_intent/insight_intent_execute_manager_test/BUILD.gn @@ -31,6 +31,7 @@ ohos_unittest("insight_intent_execute_manager_test") { "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_data_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/hmsf_utils.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", "insight_intent_execute_manager_test.cpp", "insight_intent_utils_mock.cpp", ] @@ -54,6 +55,7 @@ ohos_unittest("insight_intent_execute_manager_test") { "ability_runtime:ability_manager", "bundle_framework:libappexecfwk_common", "c_utils:utils", + "config_policy:configpolicy_util", "ffrt:libffrt", "googletest:gmock_main", "googletest:gtest_main", diff --git a/test/unittest/insight_intent_profile_test/BUILD.gn b/test/unittest/insight_intent_profile_test/BUILD.gn index 2b09abb2b66..18e96be0f92 100644 --- a/test/unittest/insight_intent_profile_test/BUILD.gn +++ b/test/unittest/insight_intent_profile_test/BUILD.gn @@ -30,7 +30,10 @@ ohos_unittest("insight_intent_profile_test") { "${ability_runtime_abilitymgr_path}/src", ] - sources = [ "insight_intent_profile_test.cpp" ] + sources = [ + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", + "insight_intent_profile_test.cpp", + ] deps = [ "${ability_runtime_abilitymgr_path}/:abilityms" ] diff --git a/test/unittest/insight_intent_rdb_storage_mgr_test/BUILD.gn b/test/unittest/insight_intent_rdb_storage_mgr_test/BUILD.gn index 7ec5e9bc14c..837bd7927b2 100644 --- a/test/unittest/insight_intent_rdb_storage_mgr_test/BUILD.gn +++ b/test/unittest/insight_intent_rdb_storage_mgr_test/BUILD.gn @@ -34,6 +34,7 @@ ohos_unittest("insight_intent_rdb_storage_mgr_test") { sources = [ "${ability_runtime_services_path}/abilitymgr/src/insight_intent/extract_insight_intent_profile.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_rdb_storage_mgr.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", "insight_intent_rdb_storage_mgr_test.cpp", "mock_insight_intent_rdb_data_mgr.cpp", ] @@ -48,6 +49,7 @@ ohos_unittest("insight_intent_rdb_storage_mgr_test") { "bundle_framework:libappexecfwk_common", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "config_policy:configpolicy_util", "ffrt:libffrt", "googletest:gmock_main", "googletest:gtest_main", diff --git a/test/unittest/js_auto_fill_extension_test/BUILD.gn b/test/unittest/js_auto_fill_extension_test/BUILD.gn index b1fdcd91081..78faa4bfef4 100644 --- a/test/unittest/js_auto_fill_extension_test/BUILD.gn +++ b/test/unittest/js_auto_fill_extension_test/BUILD.gn @@ -61,7 +61,6 @@ ohos_unittest("js_auto_fill_extension_test") { "init:libbegetutil", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", "napi:ace_napi", "resource_management:global_resmgr", ] diff --git a/test/unittest/js_service_extension_test/BUILD.gn b/test/unittest/js_service_extension_test/BUILD.gn index 62484ae5ad5..a8314ef4b7c 100644 --- a/test/unittest/js_service_extension_test/BUILD.gn +++ b/test/unittest/js_service_extension_test/BUILD.gn @@ -62,7 +62,6 @@ ohos_unittest("js_service_extension_test") { "init:libbegetutil", "ipc:ipc_core", "ipc:ipc_napi", - "json:nlohmann_json_static", "napi:ace_napi", "resource_management:global_resmgr", ] diff --git a/test/unittest/keep_alive_utils_test/BUILD.gn b/test/unittest/keep_alive_utils_test/BUILD.gn index 697a333ccf9..ce67e1733f7 100644 --- a/test/unittest/keep_alive_utils_test/BUILD.gn +++ b/test/unittest/keep_alive_utils_test/BUILD.gn @@ -70,7 +70,6 @@ ohos_unittest("keep_alive_utils_test") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "jsoncpp:jsoncpp", "kv_store:distributeddata_mgr", "memory_utils:libmeminfo", diff --git a/test/unittest/native_runtime_test/js_runtime_lite_test.cpp b/test/unittest/native_runtime_test/js_runtime_lite_test.cpp index 65cf157481d..10b41280090 100644 --- a/test/unittest/native_runtime_test/js_runtime_lite_test.cpp +++ b/test/unittest/native_runtime_test/js_runtime_lite_test.cpp @@ -288,13 +288,14 @@ HWTEST_F(JsRuntimeLiteTest, InitLoop_0100, TestSize.Level1) */ HWTEST_F(JsRuntimeLiteTest, ParsePkgContextInfoJsonString_0100, TestSize.Level1) { - nlohmann::json itemObject; - itemObject["key"] = "value"; + cJSON *itemObject = cJSON_CreateObject(); + cJSON_AddStringToObject(itemObject, "key", "value"); std::string key = "key"; std::vector items = {}; JsRuntimeLite::GetInstance().ParsePkgContextInfoJsonString(itemObject, key, items); auto rBeginIt = items.rbegin(); EXPECT_EQ(*rBeginIt, "value"); + cJSON_Delete(itemObject); } /** @@ -304,13 +305,14 @@ HWTEST_F(JsRuntimeLiteTest, ParsePkgContextInfoJsonString_0100, TestSize.Level1) */ HWTEST_F(JsRuntimeLiteTest, ParsePkgContextInfoJsonString_0200, TestSize.Level1) { - nlohmann::json itemObject; - itemObject["key"] = "value"; + cJSON *itemObject = cJSON_CreateObject(); + cJSON_AddStringToObject(itemObject, "key", "value"); std::string key = "FakeKey"; std::vector items = {}; JsRuntimeLite::GetInstance().ParsePkgContextInfoJsonString(itemObject, key, items); auto rBeginIt = items.rbegin(); EXPECT_EQ(*rBeginIt, ""); + cJSON_Delete(itemObject); } } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/service_router_mgr_service_test/BUILD.gn b/test/unittest/service_router_mgr_service_test/BUILD.gn index f5dd91b4c2b..fda63091c40 100644 --- a/test/unittest/service_router_mgr_service_test/BUILD.gn +++ b/test/unittest/service_router_mgr_service_test/BUILD.gn @@ -44,6 +44,7 @@ ohos_unittest("service_router_mgr_service_test") { "googletest:gtest_main", "hilog:libhilog", "ipc:ipc_core", + # "json:nlohmann_json_static", "safwk:api_cache_manager", ] } diff --git a/test/unittest/status_bar_delegate_manager_test/BUILD.gn b/test/unittest/status_bar_delegate_manager_test/BUILD.gn index 53bcb6ce081..0515b3d1679 100644 --- a/test/unittest/status_bar_delegate_manager_test/BUILD.gn +++ b/test/unittest/status_bar_delegate_manager_test/BUILD.gn @@ -37,6 +37,7 @@ ohos_unittest("status_bar_delegate_manager_test") { "${ability_runtime_services_path}/abilitymgr/src/app_exit_reason_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/exit_info_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/extension_config.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/scene_board/status_bar_delegate_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/timeout_state_utils.cpp", diff --git a/test/unittest/ui_ability_lifecycle_manager_second_test/BUILD.gn b/test/unittest/ui_ability_lifecycle_manager_second_test/BUILD.gn index ad6b0a0c3d9..06efa28e061 100644 --- a/test/unittest/ui_ability_lifecycle_manager_second_test/BUILD.gn +++ b/test/unittest/ui_ability_lifecycle_manager_second_test/BUILD.gn @@ -45,6 +45,7 @@ ohos_unittest("ui_ability_lifecycle_manager_second_test") { "${ability_runtime_services_path}/abilitymgr/src/exit_info_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/extension_config.cpp", "${ability_runtime_services_path}/abilitymgr/src/hidden_start_observer_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/scene_board/status_bar_delegate_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/utils/timeout_state_utils.cpp", diff --git a/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn b/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn index 71428d24e0c..3d73b55cdc4 100644 --- a/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn +++ b/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn @@ -40,6 +40,7 @@ ohos_unittest("ui_ability_lifecycle_manager_test") { "${ability_runtime_services_path}/abilitymgr/src/app_exit_reason_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/exit_info_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/extension_config.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent/insight_intent_json_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/hidden_start_observer_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/scene_board/status_bar_delegate_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp", diff --git a/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp b/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp index 54d90f68e66..1fcae30920f 100644 --- a/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp +++ b/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp @@ -770,46 +770,57 @@ HWTEST_F(WantAgentHelperTest, WantAgentHelper_3500, Function | MediumTest | Leve HWTEST_F(WantAgentHelperTest, WantAgentHelper_3600, Function | MediumTest | Level1) { std::vector flagsVec; - nlohmann::json jsonObject; - jsonObject["flags"] = -1; + cJSON *jsonObject = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObject, "flags", static_cast(-1)); flagsVec = WantAgentHelper::ParseFlags(jsonObject); EXPECT_EQ(flagsVec.size(), 0); + cJSON_Delete(jsonObject); + jsonObject = nullptr; - jsonObject.clear(); - jsonObject["flags"] = 1111000000; + jsonObject = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObject, "flags", static_cast(1111000000)); flagsVec = WantAgentHelper::ParseFlags(jsonObject); std::vector::iterator oneTimeIt = std::find(flagsVec.begin(), flagsVec.end(), WantAgentConstant::Flags::ONE_TIME_FLAG); EXPECT_EQ(oneTimeIt != flagsVec.end(), true); + cJSON_Delete(jsonObject); + jsonObject = nullptr; - jsonObject.clear(); - jsonObject["flags"] = 111100000000000; + jsonObject = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObject, "flags", static_cast(111100000000000)); flagsVec = WantAgentHelper::ParseFlags(jsonObject); std::vector::iterator cancelPresentIt = std::find(flagsVec.begin(), flagsVec.end(), WantAgentConstant::Flags::CANCEL_PRESENT_FLAG); EXPECT_EQ(cancelPresentIt != flagsVec.end(), true); + cJSON_Delete(jsonObject); + jsonObject = nullptr; - jsonObject.clear(); - jsonObject["flags"] = 111100000000000; + jsonObject = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObject, "flags", static_cast(111100000000000)); flagsVec = WantAgentHelper::ParseFlags(jsonObject); std::vector::iterator updateResentIt = std::find(flagsVec.begin(), flagsVec.end(), WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); EXPECT_EQ(updateResentIt != flagsVec.end(), true); + cJSON_Delete(jsonObject); + jsonObject = nullptr; - jsonObject.clear(); - jsonObject["flags"] = 111100000000000; + jsonObject = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObject, "flags", static_cast(111100000000000)); flagsVec = WantAgentHelper::ParseFlags(jsonObject); std::vector::iterator constantIt = std::find(flagsVec.begin(), flagsVec.end(), WantAgentConstant::Flags::CONSTANT_FLAG); EXPECT_EQ(constantIt != flagsVec.end(), true); + cJSON_Delete(jsonObject); + jsonObject = nullptr; - jsonObject.clear(); - jsonObject["flags"] = 1000000000; + jsonObject = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObject, "flags", static_cast(1000000000)); flagsVec = WantAgentHelper::ParseFlags(jsonObject); std::vector::iterator noBuildIt = std::find(flagsVec.begin(), flagsVec.end(), WantAgentConstant::Flags::NO_BUILD_FLAG); EXPECT_EQ(noBuildIt != flagsVec.end(), true); + cJSON_Delete(jsonObject); } /* diff --git a/test/unittest/window_options_utils_test/BUILD.gn b/test/unittest/window_options_utils_test/BUILD.gn index eb654bbaa19..4166d02a478 100644 --- a/test/unittest/window_options_utils_test/BUILD.gn +++ b/test/unittest/window_options_utils_test/BUILD.gn @@ -61,7 +61,6 @@ ohos_unittest("window_options_utils_test") { "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", - "json:nlohmann_json_static", "jsoncpp:jsoncpp", "window_manager:libdm", "window_manager:libwsutils", -- Gitee