diff --git a/test/moduletest/BUILD.gn b/test/moduletest/BUILD.gn index 3161ba06e735c383313582b78e9dd95e02329e33..3c81e50811afcc550417d93872b5d1ad58abada2 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 b4490926194952e358e5ce407f1018596267669a..0bd733d6898be342f2c99e9afc949d959070ac88 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 d8fd1131d1588aa2c078e7113894722c28368a57..afd91bca7acfadffe2df0ba8d49cfdc0fd364614 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 5d190174c84dc3491eded7b33cb172f46f3de7d8..05566e91b2ae99c57edc58f45780bb0ce2f45acf 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 2c746036a49d81a4a0a9d9c68bf9b026f8fca17b..8093d4d422ac89d61cede9723c1c4066a5550102 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 965510d9812259494c976de33ee566981ef01432..772adda7ebd5a7034d4456bc8ed777dca85d9ed5 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 82cb2a1de86dcbbe81b7f9aad2658b087be196de..02bd83ca5ddb98ac835816ee5f1e3c44a5d8a225 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 a6197b7bb989cfe75498b35c06a15a2ee8c6fb6a..6d0465928e350b60fbd04e36395b32084ff70d94 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 76f6c6c462ad5af271f23131913a2ae20234c4d2..3e8ea0e4880aaea4f9679e23a2cb176dbc26a632 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 b59638976588616ce35a4eea9b3865b2149e87ef..6ff5c9bbf8c102c810d771b36b8f604fb721673c 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 be3c9c4a66c6d74b25e2e58daaaa3eec381e1256..2e8d40a8e2de1db492ebe0d46f2551ffa776a50a 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 3d1481bf29740f46aaf112942d1f416c1b58c2ea..4d7bb1cd4d9e62389646a772f3615a83b47f193a 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 51c1ff047189c3d992d38ee95fbda1d8e981673f..69271e2fe6dd856d14533435dad75f3435413065 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 8757e1e182c751a9597fe941e7ef7ada141040cd..a1c7c04ca95ca0f593ccac81e55a59db7d9225d3 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 e1d04cc859261b2dbdcc526826679d0cec394796..51875e02867bcc8af3e261275b5f1ab287c5b358 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 103a35904541dbbec0c24d0fd078b0b6c71ba62f..42c5adb7d3d95b5837a3eeafc04bafbb47352376 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 045ec42a83b1a48eae0f131dacd52d0737ec0e06..a96f458a041bb432ed808f63d5f50e96ecf14c93 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 baa53693076c0d468a4647fcb38f76b18e0f79f6..2a8f478322f558dface4954c8be63a1cf8ee5849 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 755be9065ec246f90d0091914ff0ab6f820a99e7..86eb68adaa8289f46bd8bee766ac0f530e8a929f 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 02ccc39f94bfae4d4f50e562317692959b24a8d0..b865454b7dee0f537b1529ff1d944c904adbc0ad 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 d429c069a805c406a1c207c9e4b42852fb0e6e01..5612e514df8c72d23291897ca54f26e42e961ff7 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 ea88cb70833b1dc153c75a8449ddeaa01d85c014..f73eb1b9c55146b4e2d5208e5099f2892d2a6ceb 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 76e492cf15f1a3dc8e134481ecaf607109010ec5..e10db0db2db2721053d92fbca43c5054e58de948 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 c095171d09468e967402fd526121dfec1e23e50c..1dff9b2b11193a3045b94d4aadc517efd4eca4fb 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 73a3326a352d8c2c12fa1f2e8b6a152cb2f23006..eb360c6e93813505907a73541c9760da205e5dc5 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 42801229395b397b8394cd607cf01f81ff7e4ebb..71772aadcc9478e4cc92c67dce3a1699b268ec22 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 5ba95e059265e77e4f3ab1cebf2d7ccb18463ce5..81b565ef14b34ed23704a31a0ff0337705b2ef6e 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 9aff32eaf103d67099e26975aa0560770803ca2c..13b86f37fcbce2df1c55ae401f06214b30857f9a 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 dd01857b0cd4f4c4f0880c3e0b8db262b2433f43..9cdc8c1ca97b48dd06750550e8a4ceb9a0064890 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 4642c2ac9f2c042c325e9d23e4d0dd908d933973..e2c66ac7c893fd829786c700d9a5c6effe95e30d 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 6bd784b776aecc6881cd42b3f6b1a5f9a67d6f5e..01f544f3a0b9929f0ebabf91d887dccb437f37d9 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 7522b16500de71c37a04d86b78deedf27d50af55..d7ce998940c8eec94bbf12978eae1b5b42f50766 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 da926badd805db9c63b51253c43ff974fdbcfd4f..a73ace4ed7a74e217cd02de54d2ae32a92033080 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 46683c947c6c8ff94bd058cbb20c7a0b984987b1..1b2f5dafea53fd4c46f238edf86c3f3788e8aed2 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 265643796ce9d3918c89f20ea845f5e5609aae3c..71c8e8c9ad850490f57d8154bfb73ce6b46189ef 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 9db58566e5ae24718162e46bcb6c04aff34f6a6f..12d4fde5914d5f9ca964d0d78d4d10cf9b198c1b 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 891969d72a3e67733e68d16af93d1baee100d99f..80f3ad7fc071d4259a86244fab1a7b5978b1926e 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 1a399d3cc53d3ecb5e986d6fa16fa75c30a6d9ca..583e3bbc828ac87528ce13981417a1daf19f4cba 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 bd096fce00e26e265ab5042048a436f35af5e0ed..973516524767b54799367405cf6d314d8e01d6c9 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 087d5d57b38146af3db0f6aa15ffed295f768cb9..8093c24e58a7522bcd327761b6c3d4212d68a2c5 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 ec4b5e6b4b9be3790fa638990b5a25a3775868c3..e2144d9979d5dcb78d74ce5ce697b1a32c51124a 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 642724b8179cbc30aa40f81d78a091996deee606..d326c77672a03b4917a39e952f1d811572d8d18d 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 34307b9758d67f34b6fc64b567987bf2fc61c0fc..df1a445c991159937f5ec54fca2bd9964e5ad72e 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 d451d9ef2a63a1b6807f4f91094c2cdf567fb1e6..8f01abafc5321207beb2de5b542bd8b2b4380bbc 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 f8a09da780541cb1b8fd5d5a5f81652b1d5f4db8..0111fb339d4d93000bbb3c077069f08877ed272d 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 1b43641f6246e76da6c77bc4f80282ccbf9faa92..36d7224ea626a03d06baf67daf5c42d71bd71268 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 b4399a10398b16a04851aba4d483bce6da7dd150..2fac2255aa74778eb2bd56634cfe287c7b53f80f 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 93e063191680770ffeda7de38d8bfd7189604832..72f1f8745297cf1fcbf2570fa58e92a6de5d8a3a 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 d3eb9c00525e1dc4ae4bdd990ce11bb91791b977..f7c053d76fefc35a0d835e4ab4433b4c0b868dc6 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 0baadfbaedab2dd43ad33c44b0ace15b45890149..94a34f34e47362d6350b79277dc3cb07c3c371d2 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 5b4b2f3d5bfe6c44a9500b0d1e07da9d05144733..d2293c7778b0c55d349d0a3bb889b1a68cd85e60 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 4c73807487561cdf50bce221d974d02995211cec..b73febdab9ebac953ead13dcf35bc54efb9f1bd2 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 83f137e6c1d208785d5b1910fe76a51cbc6b7832..ad1f29f40d65c29e0eb80e62b91c929c14e24100 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 f86d59785574d28fa7ae878e2963229cc194a98b..6bb611fd629acb3472c437681426fb994106d00a 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 2b09abb2b66b4f51731a0cadb945c5bd065e82da..18e96be0f92bc59ef31a529139bfc3fd6200444c 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 7ec5e9bc14c9dc1b4910c7fd8499936de82e9514..837bd7927b26da47cd259207254ddb793631e881 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 b1fdcd9108103130b1362d2d9f699a4af443c5c0..78faa4bfef4b6cb436133eb8067b7f38aad18dad 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 62484ae5ad5760cc46a5a7cc07aa4395013a858d..a8314ef4b7c6a8be464aa1c5854f6298fde50da7 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 697a333ccf91a11a283493ab54e1e417895773eb..ce67e1733f784cf9b142ca16fd50f081e6e4be95 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 65cf157481d0459e534fef6f62b94d562fe55880..10b4128009004606281fa0a5f28f62e0ac8cf1f1 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 f5dd91b4c2b932b301e9ecebf7190af6ab2ebded..fda63091c40274a23913337a5428c06bc2eb3017 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 53bcb6ce0817368e3d4be97dff5611705e36e905..0515b3d1679673544be132d083c68b3cba179ed0 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 ad6b0a0c3d9e2fa7cb1ce5ef3d0931962a7b5a4a..06efa28e061a9eabf1f9efe6b19bcedf2b749d2c 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 71428d24e0c18129c70afc5e7ae29fd08e960826..3d73b55cdc4e4b8aca14bc6577ec2b46d3dfba59 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 54d90f68e6697752843351cf9e074d18cb7c8028..1fcae30920fc492c3a3e29f268c1ddc79c2b40a2 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 eb654bbaa19133894a3ebf77c019ef3f99a5b3aa..4166d02a4780da5e2a57cdff459e2240d6a3e370 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",