diff --git a/interfaces/inner_api/security_component/src/sec_comp_client.cpp b/interfaces/inner_api/security_component/src/sec_comp_client.cpp index 0e20ceeabdc73b9da67c79848333a199d7dc165b..e7c67f4499e7a79d82e130770e49061e82356efe 100644 --- a/interfaces/inner_api/security_component/src/sec_comp_client.cpp +++ b/interfaces/inner_api/security_component/src/sec_comp_client.cpp @@ -41,10 +41,7 @@ SecCompClient::~SecCompClient() return; } auto remoteObj = proxy_->AsObject(); - if (remoteObj == nullptr) { - return; - } - if (serviceDeathObserver_ != nullptr) { + if ((remoteObj != nullptr) && (serviceDeathObserver_ != nullptr)) { remoteObj->RemoveDeathRecipient(serviceDeathObserver_); } } diff --git a/interfaces/inner_api/security_component/src/sec_comp_proxy.cpp b/interfaces/inner_api/security_component/src/sec_comp_proxy.cpp index 3d8e205bee8a604a1e21dd0f1f0ca2b5a330611f..5b8492db74a7e97e8869340570dcdbb56ffa920c 100644 --- a/interfaces/inner_api/security_component/src/sec_comp_proxy.cpp +++ b/interfaces/inner_api/security_component/src/sec_comp_proxy.cpp @@ -36,16 +36,16 @@ int32_t SecCompProxy::RegisterSecurityComponent(SecCompType type, { MessageParcel data; if (!data.WriteInterfaceToken(SecCompProxy::GetDescriptor())) { - SC_LOG_ERROR(LABEL, "Write descriptor fail"); + SC_LOG_ERROR(LABEL, "Register write descriptor fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (!data.WriteUint32(type)) { - SC_LOG_ERROR(LABEL, "Write Uint32 fail"); + SC_LOG_ERROR(LABEL, "Register write Uint32 fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (!data.WriteString(componentInfo)) { - SC_LOG_ERROR(LABEL, "Write string fail"); + SC_LOG_ERROR(LABEL, "Register write string fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } @@ -53,24 +53,24 @@ int32_t SecCompProxy::RegisterSecurityComponent(SecCompType type, MessageOption option(MessageOption::TF_SYNC); sptr remote = Remote(); if (remote == nullptr) { - SC_LOG_ERROR(LABEL, "Remote service is null"); + SC_LOG_ERROR(LABEL, "Register remote service is null"); return SC_SERVICE_ERROR_IPC_REQUEST_FAIL; } int32_t requestResult = remote->SendRequest( static_cast(SecurityComponentServiceInterfaceCode::REGISTER_SECURITY_COMPONENT), data, reply, option); if (requestResult != SC_OK) { - SC_LOG_ERROR(LABEL, "Request fail, result: %{public}d", requestResult); + SC_LOG_ERROR(LABEL, "Register request fail, result: %{public}d", requestResult); return requestResult; } int32_t res; if (!reply.ReadInt32(res)) { - SC_LOG_ERROR(LABEL, "Read result int32 fail"); + SC_LOG_ERROR(LABEL, "Register read result int32 fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (!reply.ReadInt32(scId)) { - SC_LOG_ERROR(LABEL, "Read scId int32 fail"); + SC_LOG_ERROR(LABEL, "Register read scId int32 fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } return res; @@ -80,16 +80,16 @@ int32_t SecCompProxy::UpdateSecurityComponent(int32_t scId, const std::string& c { MessageParcel data; if (!data.WriteInterfaceToken(SecCompProxy::GetDescriptor())) { - SC_LOG_ERROR(LABEL, "Write descriptor fail"); + SC_LOG_ERROR(LABEL, "Update write descriptor fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (!data.WriteInt32(scId)) { - SC_LOG_ERROR(LABEL, "Write Int32 fail"); + SC_LOG_ERROR(LABEL, "Update write Int32 fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (!data.WriteString(componentInfo)) { - SC_LOG_ERROR(LABEL, "Write string fail"); + SC_LOG_ERROR(LABEL, "Update write string fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } @@ -97,18 +97,18 @@ int32_t SecCompProxy::UpdateSecurityComponent(int32_t scId, const std::string& c MessageOption option(MessageOption::TF_SYNC); sptr remote = Remote(); if (remote == nullptr) { - SC_LOG_ERROR(LABEL, "Remote service is null"); + SC_LOG_ERROR(LABEL, "Update remote update service is null"); return SC_SERVICE_ERROR_IPC_REQUEST_FAIL; } int32_t requestResult = remote->SendRequest( static_cast(SecurityComponentServiceInterfaceCode::UPDATE_SECURITY_COMPONENT), data, reply, option); if (requestResult != SC_OK) { - SC_LOG_ERROR(LABEL, "Request fail, result: %{public}d", requestResult); + SC_LOG_ERROR(LABEL, "Update request fail, result: %{public}d", requestResult); return requestResult; } int32_t res; if (!reply.ReadInt32(res)) { - SC_LOG_ERROR(LABEL, "Read result int32 fail"); + SC_LOG_ERROR(LABEL, "Update read result int32 fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } return res; @@ -118,12 +118,12 @@ int32_t SecCompProxy::UnregisterSecurityComponent(int32_t scId) { MessageParcel data; if (!data.WriteInterfaceToken(SecCompProxy::GetDescriptor())) { - SC_LOG_ERROR(LABEL, "Write descriptor fail"); + SC_LOG_ERROR(LABEL, "Unregister write descriptor fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (!data.WriteInt32(scId)) { - SC_LOG_ERROR(LABEL, "Write Int32 fail"); + SC_LOG_ERROR(LABEL, "Unregister write Int32 fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } @@ -131,19 +131,19 @@ int32_t SecCompProxy::UnregisterSecurityComponent(int32_t scId) MessageOption option(MessageOption::TF_SYNC); sptr remote = Remote(); if (remote == nullptr) { - SC_LOG_ERROR(LABEL, "Remote service is null"); + SC_LOG_ERROR(LABEL, "Unregister remote service is null"); return SC_SERVICE_ERROR_IPC_REQUEST_FAIL; } int32_t requestResult = remote->SendRequest( static_cast(SecurityComponentServiceInterfaceCode::UNREGISTER_SECURITY_COMPONENT), data, reply, option); if (requestResult != SC_OK) { - SC_LOG_ERROR(LABEL, "Request fail, result: %{public}d", requestResult); + SC_LOG_ERROR(LABEL, "Unregister request fail, result: %{public}d", requestResult); return requestResult; } int32_t res; if (!reply.ReadInt32(res)) { - SC_LOG_ERROR(LABEL, "Read int32 fail"); + SC_LOG_ERROR(LABEL, "Unregister read int32 fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } return res; @@ -154,33 +154,33 @@ int32_t SecCompProxy::ReportSecurityComponentClickEvent(int32_t scId, { MessageParcel data; if (!data.WriteInterfaceToken(SecCompProxy::GetDescriptor())) { - SC_LOG_ERROR(LABEL, "Write descriptor fail"); + SC_LOG_ERROR(LABEL, "Report write descriptor fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (!data.WriteInt32(scId)) { - SC_LOG_ERROR(LABEL, "Write Uint32 fail"); + SC_LOG_ERROR(LABEL, "Report write Uint32 fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (!data.WriteString(componentInfo)) { - SC_LOG_ERROR(LABEL, "Write string fail"); + SC_LOG_ERROR(LABEL, "Report write string fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } sptr parcel = new (std::nothrow) SecCompClickEventParcel(); if (parcel == nullptr) { - SC_LOG_ERROR(LABEL, "New click event parcel failed"); + SC_LOG_ERROR(LABEL, "Report new click event parcel failed"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } parcel->touchInfoParams_ = touchInfo; if (!data.WriteParcelable(parcel)) { - SC_LOG_ERROR(LABEL, "Write touchInfo fail"); + SC_LOG_ERROR(LABEL, "Report write touchInfo fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if ((callerToken != nullptr) && !data.WriteRemoteObject(callerToken)) { - SC_LOG_ERROR(LABEL, "Write caller token fail"); + SC_LOG_ERROR(LABEL, "Report write caller token fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } @@ -188,19 +188,19 @@ int32_t SecCompProxy::ReportSecurityComponentClickEvent(int32_t scId, MessageOption option(MessageOption::TF_SYNC); sptr remote = Remote(); if (remote == nullptr) { - SC_LOG_ERROR(LABEL, "Remote service is null"); + SC_LOG_ERROR(LABEL, "Report remote service is null"); return SC_SERVICE_ERROR_IPC_REQUEST_FAIL; } int32_t requestResult = remote->SendRequest( static_cast(SecurityComponentServiceInterfaceCode::REPORT_SECURITY_COMPONENT_CLICK_EVENT), data, reply, option); if (requestResult != SC_OK) { - SC_LOG_ERROR(LABEL, "Request fail, result: %{public}d", requestResult); + SC_LOG_ERROR(LABEL, "Report request fail, result: %{public}d", requestResult); return requestResult; } int32_t res; if (!reply.ReadInt32(res)) { - SC_LOG_ERROR(LABEL, "Read int32 fail"); + SC_LOG_ERROR(LABEL, "Report read int32 fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } return res; @@ -210,12 +210,12 @@ bool SecCompProxy::ReduceAfterVerifySavePermission(AccessToken::AccessTokenID to { MessageParcel data; if (!data.WriteInterfaceToken(SecCompProxy::GetDescriptor())) { - SC_LOG_ERROR(LABEL, "Write descriptor fail"); + SC_LOG_ERROR(LABEL, "Verify write descriptor fail"); return false; } if (!data.WriteUint32(tokenId)) { - SC_LOG_ERROR(LABEL, "Write Uint32 fail"); + SC_LOG_ERROR(LABEL, "Verify write Uint32 fail"); return false; } @@ -223,19 +223,19 @@ bool SecCompProxy::ReduceAfterVerifySavePermission(AccessToken::AccessTokenID to MessageOption option(MessageOption::TF_SYNC); sptr remote = Remote(); if (remote == nullptr) { - SC_LOG_ERROR(LABEL, "Remote service is null"); + SC_LOG_ERROR(LABEL, "Verify remote service is null"); return false; } int32_t requestResult = remote->SendRequest( static_cast(SecurityComponentServiceInterfaceCode::VERIFY_TEMP_SAVE_PERMISSION), data, reply, option); if (requestResult != SC_OK) { - SC_LOG_ERROR(LABEL, "Request fail, result: %{public}d", requestResult); + SC_LOG_ERROR(LABEL, "Verify request fail, result: %{public}d", requestResult); return false; } bool res; if (!reply.ReadBool(res)) { - SC_LOG_ERROR(LABEL, "Read bool fail"); + SC_LOG_ERROR(LABEL, "Verify read bool fail"); return false; } return res; @@ -245,7 +245,7 @@ sptr SecCompProxy::GetEnhanceRemoteObject() { MessageParcel data; if (!data.WriteInterfaceToken(SecCompProxy::GetDescriptor())) { - SC_LOG_ERROR(LABEL, "Write descriptor fail"); + SC_LOG_ERROR(LABEL, "Get enhance write descriptor fail"); return nullptr; } @@ -253,19 +253,19 @@ sptr SecCompProxy::GetEnhanceRemoteObject() MessageOption option(MessageOption::TF_SYNC); sptr remote = Remote(); if (remote == nullptr) { - SC_LOG_ERROR(LABEL, "Remote service is null"); + SC_LOG_ERROR(LABEL, "Get enhance remote service is null"); return nullptr; } int32_t requestResult = remote->SendRequest( static_cast(SecurityComponentServiceInterfaceCode::GET_SECURITY_COMPONENT_ENHANCE_OBJECT), data, reply, option); if (requestResult != SC_OK) { - SC_LOG_ERROR(LABEL, "Request fail, result: %{public}d", requestResult); + SC_LOG_ERROR(LABEL, "Get enhance request fail, result: %{public}d", requestResult); return nullptr; } sptr callback = reply.ReadRemoteObject(); if (callback == nullptr) { - SC_LOG_ERROR(LABEL, "Read remote object fail"); + SC_LOG_ERROR(LABEL, "Get enhance read remote object fail"); } return callback; } diff --git a/interfaces/inner_api/security_component/test/unittest/src/location_button_test.cpp b/interfaces/inner_api/security_component/test/unittest/src/location_button_test.cpp index f4be6317214e49c6307b0f68b4687e0b1da77ac7..263e8701aed919ef5291c7cca511b1f5aa5ba8bf 100644 --- a/interfaces/inner_api/security_component/test/unittest/src/location_button_test.cpp +++ b/interfaces/inner_api/security_component/test/unittest/src/location_button_test.cpp @@ -108,36 +108,20 @@ HWTEST_F(LocationButtonTest, FromJson004, TestSize.Level1) TestCommon::BuildLocationComponentInfo(jsonComponent); ASSERT_TRUE(comp.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_RECT] = nlohmann::json { - {JsonTagConstants::JSON_RECT_X, WRONG_TYPE}, - {JsonTagConstants::JSON_RECT_Y, TestCommon::TEST_COORDINATE}, - {JsonTagConstants::JSON_RECT_WIDTH, TestCommon::TEST_COORDINATE}, - {JsonTagConstants::JSON_RECT_HEIGHT, TestCommon::TEST_COORDINATE} - }; + auto& rectJson = jsonComponent[JsonTagConstants::JSON_RECT]; + rectJson[JsonTagConstants::JSON_RECT_X] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_RECT] = nlohmann::json { - {JsonTagConstants::JSON_RECT_X, TestCommon::TEST_COORDINATE}, - {JsonTagConstants::JSON_RECT_Y, WRONG_TYPE}, - {JsonTagConstants::JSON_RECT_WIDTH, TestCommon::TEST_COORDINATE}, - {JsonTagConstants::JSON_RECT_HEIGHT, TestCommon::TEST_COORDINATE} - }; + rectJson[JsonTagConstants::JSON_RECT_X] = TestCommon::TEST_COORDINATE; + rectJson[JsonTagConstants::JSON_RECT_Y] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_RECT] = nlohmann::json { - {JsonTagConstants::JSON_RECT_X, TestCommon::TEST_COORDINATE}, - {JsonTagConstants::JSON_RECT_Y, TestCommon::TEST_COORDINATE}, - {JsonTagConstants::JSON_RECT_WIDTH, WRONG_TYPE}, - {JsonTagConstants::JSON_RECT_HEIGHT, TestCommon::TEST_COORDINATE} - }; + rectJson[JsonTagConstants::JSON_RECT_Y] = TestCommon::TEST_COORDINATE; + rectJson[JsonTagConstants::JSON_RECT_WIDTH] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_RECT] = nlohmann::json { - {JsonTagConstants::JSON_RECT_X, TestCommon::TEST_COORDINATE}, - {JsonTagConstants::JSON_RECT_Y, TestCommon::TEST_COORDINATE}, - {JsonTagConstants::JSON_RECT_WIDTH, TestCommon::TEST_COORDINATE}, - {JsonTagConstants::JSON_RECT_HEIGHT, WRONG_TYPE} - }; + rectJson[JsonTagConstants::JSON_RECT_WIDTH] = TestCommon::TEST_COORDINATE; + rectJson[JsonTagConstants::JSON_RECT_HEIGHT] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent)); } @@ -154,35 +138,16 @@ HWTEST_F(LocationButtonTest, FromJson005, TestSize.Level1) TestCommon::BuildLocationComponentInfo(jsonComponent); ASSERT_TRUE(comp.FromJson(jsonComponent)); - nlohmann::json jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, TestCommon::TEST_DIMENSION }, - }; - - jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_SIZE_TAG, WRONG_TYPE }, - { JsonTagConstants::JSON_ICON_SIZE_TAG, TestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, TestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, - }; + auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; + sizeJson[JsonTagConstants::JSON_FONT_SIZE_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_SIZE_TAG, TestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_ICON_SIZE_TAG, WRONG_TYPE }, - { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, TestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, - }; + sizeJson[JsonTagConstants::JSON_FONT_SIZE_TAG] = TestCommon::TEST_SIZE; + sizeJson[JsonTagConstants::JSON_ICON_SIZE_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_SIZE_TAG, TestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_ICON_SIZE_TAG, TestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, WRONG_TYPE }, - { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, - }; + sizeJson[JsonTagConstants::JSON_ICON_SIZE_TAG] = TestCommon::TEST_SIZE; + sizeJson[JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent)); } @@ -199,32 +164,13 @@ HWTEST_F(LocationButtonTest, FromJson006, TestSize.Level1) TestCommon::BuildLocationComponentInfo(jsonComponent); ASSERT_TRUE(comp.FromJson(jsonComponent)); - nlohmann::json jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, WRONG_TYPE }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, TestCommon::TEST_DIMENSION }, - }; - jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_SIZE_TAG, TestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_ICON_SIZE_TAG, TestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, TestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, - }; + auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; + auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; + paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent)); - jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, WRONG_TYPE }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, TestCommon::TEST_DIMENSION }, - }; - jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_SIZE_TAG, TestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_ICON_SIZE_TAG, TestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, TestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, - }; + paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = TestCommon::TEST_DIMENSION; + paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent)); } @@ -241,32 +187,13 @@ HWTEST_F(LocationButtonTest, FromJson007, TestSize.Level1) TestCommon::BuildLocationComponentInfo(jsonComponent); ASSERT_TRUE(comp.FromJson(jsonComponent)); - nlohmann::json jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, WRONG_TYPE }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, TestCommon::TEST_DIMENSION }, - }; - jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_SIZE_TAG, TestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_ICON_SIZE_TAG, TestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, TestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, - }; + auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; + auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; + paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent)); - jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, WRONG_TYPE }, - }; - jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_SIZE_TAG, TestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_ICON_SIZE_TAG, TestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, TestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, - }; + paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = TestCommon::TEST_DIMENSION; + paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent)); } @@ -308,25 +235,16 @@ HWTEST_F(LocationButtonTest, FromJson009, TestSize.Level1) LocationButton button; ASSERT_TRUE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, WRONG_TYPE }, - { JsonTagConstants::JSON_ICON_TAG, LocationIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE }, - }; + auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; + styleJson[JsonTagConstants::JSON_TEXT_TAG] = WRONG_TYPE; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, LocationDesc::SELECT_LOCATION }, - { JsonTagConstants::JSON_ICON_TAG, WRONG_TYPE }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE }, - }; + styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::SELECT_LOCATION; + styleJson[JsonTagConstants::JSON_ICON_TAG] = WRONG_TYPE; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, LocationDesc::SELECT_LOCATION }, - { JsonTagConstants::JSON_ICON_TAG, LocationIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, WRONG_TYPE }, - }; + styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::LINE_ICON; + styleJson[JsonTagConstants::JSON_BG_TAG] = WRONG_TYPE; ASSERT_FALSE(button.FromJson(jsonComponent)); } @@ -343,25 +261,16 @@ HWTEST_F(LocationButtonTest, FromJson010, TestSize.Level1) LocationButton button; ASSERT_TRUE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_COLOR_TAG, WRONG_TYPE }, - { JsonTagConstants::JSON_ICON_COLOR_TAG, TestCommon::TEST_COLOR_BLUE }, - { JsonTagConstants::JSON_BG_COLOR_TAG, TestCommon::TEST_COLOR_YELLOW } - }; + auto& colorJson = jsonComponent[JsonTagConstants::JSON_COLORS_TAG]; + colorJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = WRONG_TYPE; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_COLOR_TAG, TestCommon::TEST_COLOR_RED }, - { JsonTagConstants::JSON_ICON_COLOR_TAG, WRONG_TYPE }, - { JsonTagConstants::JSON_BG_COLOR_TAG, TestCommon::TEST_COLOR_YELLOW } - }; + colorJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = TestCommon::TEST_COLOR_RED; + colorJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = WRONG_TYPE; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_COLOR_TAG, TestCommon::TEST_COLOR_RED }, - { JsonTagConstants::JSON_ICON_COLOR_TAG, TestCommon::TEST_COLOR_BLUE }, - { JsonTagConstants::JSON_BG_COLOR_TAG, WRONG_TYPE } - }; + colorJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = TestCommon::TEST_COLOR_BLUE; + colorJson[JsonTagConstants::JSON_BG_COLOR_TAG] = WRONG_TYPE; ASSERT_FALSE(button.FromJson(jsonComponent)); } @@ -379,46 +288,28 @@ HWTEST_F(LocationButtonTest, FromJson011, TestSize.Level1) ASSERT_TRUE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, UNKNOWN_TEXT }, - { JsonTagConstants::JSON_ICON_TAG, LocationIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE }, - }; + auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; + styleJson[JsonTagConstants::JSON_TEXT_TAG] = UNKNOWN_TEXT; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, LocationDesc::SELECT_LOCATION }, - { JsonTagConstants::JSON_ICON_TAG, UNKNOWN_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE }, - }; + styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::SELECT_LOCATION; + styleJson[JsonTagConstants::JSON_ICON_TAG] = UNKNOWN_ICON; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, LocationDesc::SELECT_LOCATION }, - { JsonTagConstants::JSON_ICON_TAG, LocationIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::UNKNOWN_BG }, - }; + styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::LINE_ICON; + styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::UNKNOWN_BG; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, LocationDesc::MAX_LABEL_TYPE }, - { JsonTagConstants::JSON_ICON_TAG, LocationIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE }, - }; + styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE; + styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::MAX_LABEL_TYPE; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, LocationDesc::SELECT_LOCATION }, - { JsonTagConstants::JSON_ICON_TAG, LocationIcon::MAX_ICON_TYPE }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE }, - }; + styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::SELECT_LOCATION; + styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::MAX_ICON_TYPE; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, LocationDesc::SELECT_LOCATION }, - { JsonTagConstants::JSON_ICON_TAG, LocationIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::MAX_BG_TYPE }, - }; + styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::LINE_ICON; + styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::MAX_BG_TYPE; ASSERT_FALSE(button.FromJson(jsonComponent)); } diff --git a/interfaces/inner_api/security_component/test/unittest/src/paste_button_test.cpp b/interfaces/inner_api/security_component/test/unittest/src/paste_button_test.cpp index e724f359ff740d673d9ad8e7b6800b092306d67b..35cb14fc466dad174fbd681fadc89aed25b8a6cc 100644 --- a/interfaces/inner_api/security_component/test/unittest/src/paste_button_test.cpp +++ b/interfaces/inner_api/security_component/test/unittest/src/paste_button_test.cpp @@ -48,7 +48,7 @@ void PasteButtonTest::TearDown() * @tc.type: FUNC * @tc.require: AR000HO9JB */ -HWTEST_F(PasteButtonTest, FromJson010, TestSize.Level1) +HWTEST_F(PasteButtonTest, IsParamValid001, TestSize.Level1) { nlohmann::json jsonComponent; TestCommon::BuildPasteComponentInfo(jsonComponent); @@ -56,46 +56,28 @@ HWTEST_F(PasteButtonTest, FromJson010, TestSize.Level1) ASSERT_TRUE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, UNKNOWN_TEXT }, - { JsonTagConstants::JSON_ICON_TAG, PasteIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE }, - }; + auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; + styleJson[JsonTagConstants::JSON_TEXT_TAG] = UNKNOWN_TEXT; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, PasteDesc::PASTE}, - { JsonTagConstants::JSON_ICON_TAG, UNKNOWN_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE }, - }; + styleJson[JsonTagConstants::JSON_TEXT_TAG] = PasteDesc::PASTE; + styleJson[JsonTagConstants::JSON_ICON_TAG] = UNKNOWN_ICON; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, PasteDesc::PASTE }, - { JsonTagConstants::JSON_ICON_TAG, PasteIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::UNKNOWN_BG }, - }; + styleJson[JsonTagConstants::JSON_ICON_TAG] = PasteIcon::LINE_ICON; + styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::UNKNOWN_BG; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, PasteDesc::MAX_LABEL_TYPE }, - { JsonTagConstants::JSON_ICON_TAG, PasteIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE }, - }; + styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE; + styleJson[JsonTagConstants::JSON_TEXT_TAG] = PasteDesc::MAX_LABEL_TYPE; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, PasteDesc::PASTE }, - { JsonTagConstants::JSON_ICON_TAG, PasteIcon::MAX_ICON_TYPE }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE }, - }; + styleJson[JsonTagConstants::JSON_TEXT_TAG] = PasteDesc::PASTE; + styleJson[JsonTagConstants::JSON_ICON_TAG] = PasteIcon::MAX_ICON_TYPE; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, PasteDesc::PASTE }, - { JsonTagConstants::JSON_ICON_TAG, PasteIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::MAX_BG_TYPE }, - }; + styleJson[JsonTagConstants::JSON_ICON_TAG] = PasteIcon::LINE_ICON; + styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::MAX_BG_TYPE; ASSERT_FALSE(button.FromJson(jsonComponent)); } @@ -146,53 +128,21 @@ HWTEST_F(PasteButtonTest, ComparePasteButton002, TestSize.Level1) ASSERT_TRUE(comp1.FromJson(jsonComponent)); PasteButton comp2 = comp1; - comp1.type_ = LOCATION_COMPONENT; + comp1.type_ = SAVE_COMPONENT; ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); comp1.type_ = PASTE_COMPONENT; - comp1.fontSize_ = DEFAULT_DIMENSION; + comp1.icon_ = static_cast(PasteIcon::FILLED_ICON); ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.fontSize_ = TestCommon::TEST_SIZE; + comp1.icon_ = static_cast(PasteIcon::LINE_ICON); - comp1.iconSize_ = DEFAULT_DIMENSION; + comp1.text_ = static_cast(PasteDesc::MAX_LABEL_TYPE); ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.iconSize_ = TestCommon::TEST_SIZE; + comp1.text_ = static_cast(PasteDesc::PASTE); - comp1.padding_.top = DEFAULT_DIMENSION; + comp1.bg_ = SecCompBackground::NORMAL; ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.padding_.top = TestCommon::TEST_DIMENSION; - - comp1.padding_.right = DEFAULT_DIMENSION; - ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.padding_.right = TestCommon::TEST_DIMENSION; - - comp1.padding_.bottom = DEFAULT_DIMENSION; - ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.padding_.bottom = TestCommon::TEST_DIMENSION; - - comp1.padding_.left = DEFAULT_DIMENSION; - ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.padding_.left = TestCommon::TEST_DIMENSION; - - comp1.textIconSpace_ = DEFAULT_DIMENSION; - ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.textIconSpace_ = TestCommon::TEST_SIZE; - - comp1.borderWidth_ = DEFAULT_DIMENSION; - ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.borderWidth_ = TestCommon::TEST_SIZE; - - comp1.fontColor_.value = TestCommon::TEST_DIFF_COLOR; - ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.fontColor_.value = TestCommon::TEST_COLOR_RED; - - comp1.bgColor_.value = TestCommon::TEST_DIFF_COLOR; - ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.bgColor_.value = TestCommon::TEST_COLOR_YELLOW; - - comp1.iconColor_.value = TestCommon::TEST_DIFF_COLOR; - ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.iconColor_.value = TestCommon::TEST_COLOR_BLUE; + comp1.bg_ = SecCompBackground::CIRCLE; ASSERT_TRUE(comp1.CompareComponentBasicInfo(&comp2, true)); } diff --git a/interfaces/inner_api/security_component/test/unittest/src/save_button_test.cpp b/interfaces/inner_api/security_component/test/unittest/src/save_button_test.cpp index 0c48e62ee9431213197fe2cdddbebfb573c44598..1c57f421fc1c655f275be473bce879ec137b0af5 100644 --- a/interfaces/inner_api/security_component/test/unittest/src/save_button_test.cpp +++ b/interfaces/inner_api/security_component/test/unittest/src/save_button_test.cpp @@ -48,7 +48,7 @@ void SaveButtonTest::TearDown() * @tc.type: FUNC * @tc.require: AR000HO9J7 */ -HWTEST_F(SaveButtonTest, FromJson010, TestSize.Level1) +HWTEST_F(SaveButtonTest, IsParamValid001, TestSize.Level1) { nlohmann::json jsonComponent; TestCommon::BuildSaveComponentInfo(jsonComponent); @@ -56,46 +56,28 @@ HWTEST_F(SaveButtonTest, FromJson010, TestSize.Level1) ASSERT_TRUE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, UNKNOWN_TEXT }, - { JsonTagConstants::JSON_ICON_TAG, SaveIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE }, - }; + auto& stylesJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; + stylesJson[JsonTagConstants::JSON_TEXT_TAG] = UNKNOWN_TEXT; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, SaveDesc::DOWNLOAD}, - { JsonTagConstants::JSON_ICON_TAG, UNKNOWN_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE }, - }; + stylesJson[JsonTagConstants::JSON_TEXT_TAG] = SaveDesc::DOWNLOAD; + stylesJson[JsonTagConstants::JSON_ICON_TAG] = UNKNOWN_ICON; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, SaveDesc::DOWNLOAD }, - { JsonTagConstants::JSON_ICON_TAG, SaveIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::UNKNOWN_BG }, - }; + stylesJson[JsonTagConstants::JSON_ICON_TAG] = SaveIcon::LINE_ICON; + stylesJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::UNKNOWN_BG; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, SaveDesc::MAX_LABEL_TYPE }, - { JsonTagConstants::JSON_ICON_TAG, SaveIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE }, - }; + stylesJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE; + stylesJson[JsonTagConstants::JSON_TEXT_TAG] = SaveDesc::MAX_LABEL_TYPE; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, SaveDesc::DOWNLOAD }, - { JsonTagConstants::JSON_ICON_TAG, SaveIcon::MAX_ICON_TYPE }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE }, - }; + stylesJson[JsonTagConstants::JSON_TEXT_TAG] = SaveDesc::DOWNLOAD; + stylesJson[JsonTagConstants::JSON_ICON_TAG] = SaveIcon::MAX_ICON_TYPE; ASSERT_FALSE(button.FromJson(jsonComponent)); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, SaveDesc::DOWNLOAD }, - { JsonTagConstants::JSON_ICON_TAG, SaveIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::MAX_BG_TYPE }, - }; + stylesJson[JsonTagConstants::JSON_ICON_TAG] = SaveIcon::LINE_ICON; + stylesJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::MAX_BG_TYPE; ASSERT_FALSE(button.FromJson(jsonComponent)); } @@ -150,49 +132,17 @@ HWTEST_F(SaveButtonTest, CompareSaveButton002, TestSize.Level1) ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); comp1.type_ = SAVE_COMPONENT; - comp1.fontSize_ = DEFAULT_DIMENSION; + comp1.icon_ = static_cast(SaveIcon::FILLED_ICON); ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.fontSize_ = TestCommon::TEST_SIZE; + comp1.icon_ = static_cast(SaveIcon::LINE_ICON); - comp1.iconSize_ = DEFAULT_DIMENSION; + comp1.text_ = static_cast(SaveDesc::DOWNLOAD_AND_SHARE); ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.iconSize_ = TestCommon::TEST_SIZE; + comp1.text_ = static_cast(SaveDesc::DOWNLOAD); - comp1.padding_.top = DEFAULT_DIMENSION; + comp1.bg_ = SecCompBackground::CAPSULE; ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.padding_.top = TestCommon::TEST_DIMENSION; - - comp1.padding_.right = DEFAULT_DIMENSION; - ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.padding_.right = TestCommon::TEST_DIMENSION; - - comp1.padding_.bottom = DEFAULT_DIMENSION; - ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.padding_.bottom = TestCommon::TEST_DIMENSION; - - comp1.padding_.left = DEFAULT_DIMENSION; - ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.padding_.left = TestCommon::TEST_DIMENSION; - - comp1.textIconSpace_ = DEFAULT_DIMENSION; - ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.textIconSpace_ = TestCommon::TEST_SIZE; - - comp1.borderWidth_ = DEFAULT_DIMENSION; - ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.borderWidth_ = TestCommon::TEST_SIZE; - - comp1.fontColor_.value = TestCommon::TEST_DIFF_COLOR; - ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.fontColor_.value = TestCommon::TEST_COLOR_RED; - - comp1.bgColor_.value = TestCommon::TEST_DIFF_COLOR; - ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.bgColor_.value = TestCommon::TEST_COLOR_YELLOW; - - comp1.iconColor_.value = TestCommon::TEST_DIFF_COLOR; - ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true)); - comp1.iconColor_.value = TestCommon::TEST_COLOR_BLUE; + comp1.bg_ = SecCompBackground::CIRCLE; ASSERT_TRUE(comp1.CompareComponentBasicInfo(&comp2, true)); } diff --git a/services/security_component_service/sa/sa_main/sec_comp_perm_manager.cpp b/services/security_component_service/sa/sa_main/sec_comp_perm_manager.cpp index 7c10b7adb4f1cc408c581f1d715f674a9aaaf547..e839a56ae92aa0f245922d3be0ba47ed8c0ca6ed 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_perm_manager.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_perm_manager.cpp @@ -14,13 +14,8 @@ */ #include "sec_comp_perm_manager.h" -#include "location_button.h" -#include "paste_button.h" -#include "save_button.h" #include "sec_comp_err.h" #include "sec_comp_log.h" -#include "sec_comp_service.h" -#include "sec_comp_tool.h" namespace OHOS { namespace Security { diff --git a/services/security_component_service/sa/sa_main/sec_comp_service.cpp b/services/security_component_service/sa/sa_main/sec_comp_service.cpp index 40aad2dae403765f53eb9eb108b83f929d133f5a..de0e363e5dce55061be0e41b4fafb19a8c64aa31 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_service.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_service.cpp @@ -167,20 +167,29 @@ bool SecCompService::GetCallerInfo(SecCompCallerInfo& caller) return true; } -int32_t SecCompService::RegisterSecurityComponent(SecCompType type, - const std::string& componentInfo, int32_t& scId) +int32_t SecCompService::ParseParams(const std::string& componentInfo, + SecCompCallerInfo& caller, nlohmann::json& jsonRes) { - StartTrace(HITRACE_TAG_ACCESS_CONTROL, "SecurityComponentRegister"); - SecCompCallerInfo caller; if (!GetCallerInfo(caller)) { SC_LOG_ERROR(LABEL, "Check caller failed"); - FinishTrace(HITRACE_TAG_ACCESS_CONTROL); return SC_SERVICE_ERROR_VALUE_INVALID; } - nlohmann::json jsonRes = nlohmann::json::parse(componentInfo, nullptr, false); + jsonRes = nlohmann::json::parse(componentInfo, nullptr, false); if (jsonRes.is_discarded()) { SC_LOG_ERROR(LABEL, "component info invalid %{public}s", componentInfo.c_str()); + return SC_SERVICE_ERROR_VALUE_INVALID; + } + return SC_OK; +} + +int32_t SecCompService::RegisterSecurityComponent(SecCompType type, + const std::string& componentInfo, int32_t& scId) +{ + StartTrace(HITRACE_TAG_ACCESS_CONTROL, "SecurityComponentRegister"); + SecCompCallerInfo caller; + nlohmann::json jsonRes; + if (ParseParams(componentInfo, caller, jsonRes) != SC_OK) { FinishTrace(HITRACE_TAG_ACCESS_CONTROL); return SC_SERVICE_ERROR_VALUE_INVALID; } @@ -193,14 +202,8 @@ int32_t SecCompService::RegisterSecurityComponent(SecCompType type, int32_t SecCompService::UpdateSecurityComponent(int32_t scId, const std::string& componentInfo) { SecCompCallerInfo caller; - if (!GetCallerInfo(caller)) { - SC_LOG_ERROR(LABEL, "Check caller failed"); - return SC_SERVICE_ERROR_VALUE_INVALID; - } - - nlohmann::json jsonRes = nlohmann::json::parse(componentInfo, nullptr, false); - if (jsonRes.is_discarded()) { - SC_LOG_ERROR(LABEL, "component info invalid %{public}s", componentInfo.c_str()); + nlohmann::json jsonRes; + if (ParseParams(componentInfo, caller, jsonRes) != SC_OK) { return SC_SERVICE_ERROR_VALUE_INVALID; } return SecCompManager::GetInstance().UpdateSecurityComponent(scId, jsonRes, caller); @@ -222,15 +225,8 @@ int32_t SecCompService::ReportSecurityComponentClickEvent(int32_t scId, { StartTrace(HITRACE_TAG_ACCESS_CONTROL, "SecurityComponentClick"); SecCompCallerInfo caller; - if (!GetCallerInfo(caller)) { - SC_LOG_ERROR(LABEL, "Check caller failed"); - FinishTrace(HITRACE_TAG_ACCESS_CONTROL); - return SC_SERVICE_ERROR_VALUE_INVALID; - } - - nlohmann::json jsonRes = nlohmann::json::parse(componentInfo, nullptr, false); - if (jsonRes.is_discarded()) { - SC_LOG_ERROR(LABEL, "component info invalid %{public}s", componentInfo.c_str()); + nlohmann::json jsonRes; + if (ParseParams(componentInfo, caller, jsonRes) != SC_OK) { FinishTrace(HITRACE_TAG_ACCESS_CONTROL); return SC_SERVICE_ERROR_VALUE_INVALID; } diff --git a/services/security_component_service/sa/sa_main/sec_comp_service.h b/services/security_component_service/sa/sa_main/sec_comp_service.h index 99d21f2ba6d0369929f964dc88d7bbf84933266e..85c85bcdf4c3f69d6570e606f36b888865033c35 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_service.h +++ b/services/security_component_service/sa/sa_main/sec_comp_service.h @@ -19,6 +19,7 @@ #include #include "app_state_observer.h" #include "iremote_object.h" +#include "nlohmann/json.hpp" #include "nocopyable.h" #include "sec_comp_manager.h" #include "sec_comp_stub.h" @@ -50,6 +51,7 @@ public: int Dump(int fd, const std::vector& args) override; private: + int32_t ParseParams(const std::string& componentInfo, SecCompCallerInfo& caller, nlohmann::json& jsonRes); bool Initialize() const; bool RegisterAppStateObserver(); void UnregisterAppStateObserver(); diff --git a/services/security_component_service/sa/sa_main/sec_comp_stub.cpp b/services/security_component_service/sa/sa_main/sec_comp_stub.cpp index b91d428b42a613842dc11977352e62d600f7e7ce..3e295fc64285c53c33f0a4c9f82ecc05ca23485e 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_stub.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_stub.cpp @@ -39,11 +39,11 @@ int32_t SecCompStub::OnRemoteRequest( return SC_SERVICE_ERROR_IPC_REQUEST_FAIL; } - auto itFunc = requestFuncMap_.find(code); - if (itFunc != requestFuncMap_.end()) { - auto requestFunc = itFunc->second; - if (requestFunc != nullptr) { - return (this->*requestFunc)(data, reply); + auto funcIter = requestFuncMap_.find(code); + if (funcIter != requestFuncMap_.end()) { + auto func = funcIter->second; + if (func != nullptr) { + return (this->*func)(data, reply); } } return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -53,18 +53,18 @@ int32_t SecCompStub::RegisterSecurityComponentInner(MessageParcel& data, Message { uint32_t type; if (!data.ReadUint32(type)) { - SC_LOG_ERROR(LABEL, "Read component type fail"); + SC_LOG_ERROR(LABEL, "Register read component type fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (type <= UNKNOWN_SC_TYPE || type >= MAX_SC_TYPE) { - SC_LOG_ERROR(LABEL, "Security component type invalid"); + SC_LOG_ERROR(LABEL, "Register security component type invalid"); return SC_SERVICE_ERROR_VALUE_INVALID; } std::string componentInfo; if (!data.ReadString(componentInfo)) { - SC_LOG_ERROR(LABEL, "Read component info fail"); + SC_LOG_ERROR(LABEL, "Register read component info fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } @@ -87,18 +87,18 @@ int32_t SecCompStub::UpdateSecurityComponentInner(MessageParcel& data, MessagePa { int32_t scId; if (!data.ReadInt32(scId)) { - SC_LOG_ERROR(LABEL, "Read component id fail"); + SC_LOG_ERROR(LABEL, "Update read component id fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (scId < 0) { - SC_LOG_ERROR(LABEL, "Security component id invalid"); + SC_LOG_ERROR(LABEL, "Update security component id invalid"); return SC_SERVICE_ERROR_VALUE_INVALID; } std::string componentInfo; if (!data.ReadString(componentInfo)) { - SC_LOG_ERROR(LABEL, "Read component info fail"); + SC_LOG_ERROR(LABEL, "Update read component info fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } @@ -115,12 +115,12 @@ int32_t SecCompStub::UnregisterSecurityComponentInner(MessageParcel& data, Messa { int32_t scId; if (!data.ReadInt32(scId)) { - SC_LOG_ERROR(LABEL, "Read component id fail"); + SC_LOG_ERROR(LABEL, "Unreigster read component id fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (scId < 0) { - SC_LOG_ERROR(LABEL, "Security component id invalid"); + SC_LOG_ERROR(LABEL, "Unreigster security component id invalid"); return SC_SERVICE_ERROR_VALUE_INVALID; } @@ -136,23 +136,23 @@ int32_t SecCompStub::ReportSecurityComponentClickEventInner(MessageParcel& data, { int32_t scId; if (!data.ReadInt32(scId)) { - SC_LOG_ERROR(LABEL, "Read component id fail"); + SC_LOG_ERROR(LABEL, "Report read component id fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (scId < 0) { - SC_LOG_ERROR(LABEL, "Security component id invalid"); + SC_LOG_ERROR(LABEL, "Report security component id invalid"); return SC_SERVICE_ERROR_VALUE_INVALID; } std::string componentInfo; if (!data.ReadString(componentInfo)) { - SC_LOG_ERROR(LABEL, "Read component info fail"); + SC_LOG_ERROR(LABEL, "Report read component info fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } sptr touchInfoParcel = data.ReadParcelable(); if (touchInfoParcel == nullptr) { - SC_LOG_ERROR(LABEL, "Read touchInfo info fail"); + SC_LOG_ERROR(LABEL, "Report read touchInfo info fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } @@ -160,7 +160,7 @@ int32_t SecCompStub::ReportSecurityComponentClickEventInner(MessageParcel& data, int32_t res = this->ReportSecurityComponentClickEvent(scId, componentInfo, touchInfoParcel->touchInfoParams_, callerToken); if (!reply.WriteInt32(res)) { - SC_LOG_ERROR(LABEL, "Register security component result fail"); + SC_LOG_ERROR(LABEL, "Report security component result fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } return SC_OK; @@ -174,18 +174,18 @@ int32_t SecCompStub::ReduceAfterVerifySavePermissionInner(MessageParcel& data, M } uint32_t tokenId; if (!data.ReadUint32(tokenId)) { - SC_LOG_ERROR(LABEL, "Read component id fail"); + SC_LOG_ERROR(LABEL, "Verify read component id fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (tokenId == 0) { - SC_LOG_ERROR(LABEL, "AccessTokenId invalid"); + SC_LOG_ERROR(LABEL, "Verify AccessTokenId invalid"); return SC_SERVICE_ERROR_VALUE_INVALID; } bool res = this->ReduceAfterVerifySavePermission(tokenId); if (!reply.WriteBool(res)) { - SC_LOG_ERROR(LABEL, "verify temp save permission result fail"); + SC_LOG_ERROR(LABEL, "Verify temp save permission result fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } return SC_OK; @@ -195,7 +195,7 @@ int32_t SecCompStub::GetEnhanceRemoteObjectInner(MessageParcel& data, MessagePar { auto res = this->GetEnhanceRemoteObject(); if (!reply.WriteRemoteObject(res)) { - SC_LOG_ERROR(LABEL, "Register security component enhance remote object fail"); + SC_LOG_ERROR(LABEL, "Security component enhance remote object fail"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } return SC_OK; diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp index ddcef69c0d59319501f97f3c7492ed7c407f66ae..64dc4d73c5883a55e1c3d845698624ff0f5b5e0c 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp @@ -124,6 +124,17 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent003, TestSize.Level1) ASSERT_EQ(nullptr, comp); } +static SecCompRect GetDefaultRect(void) +{ + SecCompRect rect = { + .x_ = g_testWidth, + .y_ = g_testHeight, + .width_ = g_testWidth, + .height_ = g_testHeight + }; + return rect; +} + /** * @tc.name: ParseComponent004 * @tc.desc: Test parse component info with invalid rect @@ -132,18 +143,8 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent003, TestSize.Level1) */ HWTEST_F(SecCompInfoHelperTest, ParseComponent004, TestSize.Level1) { - SecCompRect rect = { - .x_ = g_testWidth, - .y_ = g_testHeight, - .width_ = g_testWidth, - .height_ = g_testHeight - }; - SecCompRect windowRect = { - .x_ = g_testWidth, - .y_ = g_testHeight, - .width_ = g_testWidth, - .height_ = g_testHeight - }; + SecCompRect rect = GetDefaultRect(); + SecCompRect windowRect = GetDefaultRect(); ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect)); rect.x_ = ServiceTestCommon::TEST_INVALID_DIMENSION; @@ -172,18 +173,8 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent004, TestSize.Level1) */ HWTEST_F(SecCompInfoHelperTest, ParseComponent005, TestSize.Level1) { - SecCompRect rect = { - .x_ = g_testWidth, - .y_ = g_testHeight, - .width_ = g_testWidth, - .height_ = g_testHeight - }; - SecCompRect windowRect = { - .x_ = g_testWidth, - .y_ = g_testHeight, - .width_ = g_testWidth, - .height_ = g_testHeight - }; + SecCompRect rect = GetDefaultRect(); + SecCompRect windowRect = GetDefaultRect(); ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect)); windowRect.x_ = g_testWidth + 1; @@ -235,51 +226,18 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent007, TestSize.Level1) SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_TRUE(comp->GetValid()); - nlohmann::json jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION }, - }; - - jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_INVALID_DIMENSION }, - { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, - }; + auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; + sizeJson[JsonTagConstants::JSON_FONT_SIZE_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_FALSE(comp->GetValid()); - jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION }, - }; - - jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_INVALID_DIMENSION }, - { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, - }; + sizeJson[JsonTagConstants::JSON_FONT_SIZE_TAG] = ServiceTestCommon::TEST_DIMENSION; + sizeJson[JsonTagConstants::JSON_ICON_SIZE_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_FALSE(comp->GetValid()); - jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION }, - }; - - jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_INVALID_DIMENSION }, - { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, - }; + sizeJson[JsonTagConstants::JSON_ICON_SIZE_TAG] = ServiceTestCommon::TEST_DIMENSION; + sizeJson[JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_FALSE(comp->GetValid()); } @@ -297,35 +255,14 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent008, TestSize.Level1) SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_TRUE(comp->GetValid()); - nlohmann::json jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, ServiceTestCommon::TEST_INVALID_DIMENSION }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION }, - }; - - jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, - }; + auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; + auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; + paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_FALSE(comp->GetValid()); - jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, ServiceTestCommon::TEST_INVALID_DIMENSION }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION }, - }; - - jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, - }; + paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = ServiceTestCommon::TEST_DIMENSION; + paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_FALSE(comp->GetValid()); } @@ -343,35 +280,14 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent009, TestSize.Level1) SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_TRUE(comp->GetValid()); - nlohmann::json jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, ServiceTestCommon::TEST_INVALID_DIMENSION }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION }, - }; - - jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, - }; + auto& sizesJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; + auto& paddingsJson = sizesJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; + paddingsJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_FALSE(comp->GetValid()); - jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, ServiceTestCommon::TEST_INVALID_DIMENSION }, - }; - - jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, - }; + paddingsJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = ServiceTestCommon::TEST_DIMENSION; + paddingsJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_FALSE(comp->GetValid()); } @@ -389,27 +305,18 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent010, TestSize.Level1) SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_TRUE(comp->GetValid()); - jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_COLOR_TAG, ServiceTestCommon::TEST_COLOR_INVALID }, - { JsonTagConstants::JSON_ICON_COLOR_TAG, ServiceTestCommon::TEST_COLOR_BLUE }, - { JsonTagConstants::JSON_BG_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW } - }; + auto& colorJson = jsonComponent[JsonTagConstants::JSON_COLORS_TAG]; + colorJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_INVALID; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_FALSE(comp->GetValid()); - jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_COLOR_TAG, ServiceTestCommon::TEST_COLOR_RED }, - { JsonTagConstants::JSON_ICON_COLOR_TAG, ServiceTestCommon::TEST_COLOR_INVALID }, - { JsonTagConstants::JSON_BG_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW } - }; + colorJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_RED; + colorJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_INVALID; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_FALSE(comp->GetValid()); - jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_COLOR_TAG, ServiceTestCommon::TEST_COLOR_RED }, - { JsonTagConstants::JSON_ICON_COLOR_TAG, ServiceTestCommon::TEST_COLOR_BLUE }, - { JsonTagConstants::JSON_BG_COLOR_TAG, ServiceTestCommon::TEST_COLOR_INVALID } - }; + colorJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_BLUE; + colorJson[JsonTagConstants::JSON_BG_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_INVALID; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_FALSE(comp->GetValid()); } @@ -449,42 +356,18 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent012, TestSize.Level1) SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_TRUE(comp->GetValid()); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, LocationDesc::SELECT_LOCATION }, - { JsonTagConstants::JSON_ICON_TAG, LocationIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE }, - }; - jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW }, - { JsonTagConstants::JSON_ICON_COLOR_TAG, ServiceTestCommon::TEST_COLOR_BLUE }, - { JsonTagConstants::JSON_BG_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW } - }; + auto& colorsJson = jsonComponent[JsonTagConstants::JSON_COLORS_TAG]; + colorsJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_YELLOW; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_FALSE(comp->GetValid()); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, LocationDesc::SELECT_LOCATION }, - { JsonTagConstants::JSON_ICON_TAG, LocationIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE }, - }; - jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_COLOR_TAG, ServiceTestCommon::TEST_COLOR_RED }, - { JsonTagConstants::JSON_ICON_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW }, - { JsonTagConstants::JSON_BG_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW } - }; + colorsJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_RED; + colorsJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_YELLOW; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_FALSE(comp->GetValid()); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, LocationDesc::SELECT_LOCATION }, - { JsonTagConstants::JSON_ICON_TAG, LocationIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::NO_BG_TYPE }, - }; - jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_COLOR_TAG, ServiceTestCommon::TEST_COLOR_RED }, - { JsonTagConstants::JSON_ICON_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW }, - { JsonTagConstants::JSON_BG_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW } - }; + auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; + styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::NO_BG_TYPE; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_FALSE(comp->GetValid()); } @@ -502,40 +385,20 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent013, TestSize.Level1) SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_TRUE(comp->GetValid()); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, LocationDesc::SELECT_LOCATION }, - { JsonTagConstants::JSON_ICON_TAG, LocationIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::NO_BG_TYPE }, - }; - nlohmann::json jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, MIN_PADDING_WITHOUT_BG }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, MIN_PADDING_WITHOUT_BG }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, MIN_PADDING_WITHOUT_BG }, - }; - - jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, - }; + auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; + styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::NO_BG_TYPE; + auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; + auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; + paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = MIN_PADDING_WITHOUT_BG; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_FALSE(comp->GetValid()); - jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, MIN_PADDING_WITHOUT_BG }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, MIN_PADDING_WITHOUT_BG }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, MIN_PADDING_WITHOUT_BG }, - }; - - jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, - }; + paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = ServiceTestCommon::TEST_DIMENSION; + paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = MIN_PADDING_WITHOUT_BG; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_FALSE(comp->GetValid()); } @@ -553,41 +416,21 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent014, TestSize.Level1) SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_TRUE(comp->GetValid()); - jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_TEXT_TAG, LocationDesc::SELECT_LOCATION }, - { JsonTagConstants::JSON_ICON_TAG, LocationIcon::LINE_ICON }, - { JsonTagConstants::JSON_BG_TAG, SecCompBackground::NO_BG_TYPE }, - }; + auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; + styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::NO_BG_TYPE; - nlohmann::json jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, MIN_PADDING_WITHOUT_BG }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, MIN_PADDING_WITHOUT_BG }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, MIN_PADDING_WITHOUT_BG }, - }; - - jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, - }; + auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; + auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; + paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = MIN_PADDING_WITHOUT_BG; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_FALSE(comp->GetValid()); - jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, MIN_PADDING_WITHOUT_BG }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, MIN_PADDING_WITHOUT_BG }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, MIN_PADDING_WITHOUT_BG }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION }, - }; - - jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { - { JsonTagConstants::JSON_FONT_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE }, - { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, - }; + paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = ServiceTestCommon::TEST_DIMENSION; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); ASSERT_FALSE(comp->GetValid()); } diff --git a/test/fuzztest/security_component/getenhanceremoteobjectInner_fuzzer/getenhanceremoteobjectInner_fuzzer.cpp b/test/fuzztest/security_component/getenhanceremoteobjectInner_fuzzer/getenhanceremoteobjectInner_fuzzer.cpp index 48d375e56a93311aa4d5061e5e4e6664b72bae80..c2f7adfaa15b3c2139a51d1b449f1cc26b259e2f 100644 --- a/test/fuzztest/security_component/getenhanceremoteobjectInner_fuzzer/getenhanceremoteobjectInner_fuzzer.cpp +++ b/test/fuzztest/security_component/getenhanceremoteobjectInner_fuzzer/getenhanceremoteobjectInner_fuzzer.cpp @@ -28,7 +28,6 @@ using namespace OHOS::Security::AccessToken; namespace OHOS { static void GetEnhanceRemoteObjectInnerFuzzTest(const uint8_t *data, size_t size) { - uint32_t code = SecurityComponentServiceInterfaceCode::GET_SECURITY_COMPONENT_ENHANCE_OBJECT; MessageParcel datas; datas.WriteInterfaceToken(u"ohos.security.ISecCompService"); datas.WriteBuffer(data, size); @@ -36,6 +35,7 @@ static void GetEnhanceRemoteObjectInnerFuzzTest(const uint8_t *data, size_t size MessageParcel reply; MessageOption option; auto service = std::make_shared(SA_ID_SECURITY_COMPONENT_SERVICE, true); + uint32_t code = SecurityComponentServiceInterfaceCode::GET_SECURITY_COMPONENT_ENHANCE_OBJECT; service->OnRemoteRequest(code, datas, reply, option); } } // namespace OHOS diff --git a/test/fuzztest/security_component/reduceafterverifysavepermissionInner_fuzzer/reduceafterverifysavepermissionInner_fuzzer.cpp b/test/fuzztest/security_component/reduceafterverifysavepermissionInner_fuzzer/reduceafterverifysavepermissionInner_fuzzer.cpp index 5afd4e1204b82cf950d315e66bc2b8e62ec95fd2..785c42c835c0e9e7050a8d40bf85bba4ac31becf 100644 --- a/test/fuzztest/security_component/reduceafterverifysavepermissionInner_fuzzer/reduceafterverifysavepermissionInner_fuzzer.cpp +++ b/test/fuzztest/security_component/reduceafterverifysavepermissionInner_fuzzer/reduceafterverifysavepermissionInner_fuzzer.cpp @@ -27,7 +27,6 @@ using namespace OHOS::Security::AccessToken; namespace OHOS { static void ReduceAfterVerifySavePermissionInnerFuzzTest(const uint8_t *data, size_t size) { - uint32_t code = SecurityComponentServiceInterfaceCode::VERIFY_TEMP_SAVE_PERMISSION; MessageParcel datas; datas.WriteInterfaceToken(u"ohos.security.ISecCompService"); datas.WriteBuffer(data, size); @@ -35,6 +34,7 @@ static void ReduceAfterVerifySavePermissionInnerFuzzTest(const uint8_t *data, si MessageParcel reply; MessageOption option; auto service = std::make_shared(SA_ID_SECURITY_COMPONENT_SERVICE, true); + uint32_t code = SecurityComponentServiceInterfaceCode::VERIFY_TEMP_SAVE_PERMISSION; service->OnRemoteRequest(code, datas, reply, option); } } // namespace OHOS diff --git a/test/fuzztest/security_component/unregistersecuritycomponentInner_fuzzer/unregistersecuritycomponentInner_fuzzer.cpp b/test/fuzztest/security_component/unregistersecuritycomponentInner_fuzzer/unregistersecuritycomponentInner_fuzzer.cpp index 8eddb37a6946477d65e6cbf79a94e489a37e8b2f..d9565b606361ae75ed07c54b030aaa04b928ced8 100644 --- a/test/fuzztest/security_component/unregistersecuritycomponentInner_fuzzer/unregistersecuritycomponentInner_fuzzer.cpp +++ b/test/fuzztest/security_component/unregistersecuritycomponentInner_fuzzer/unregistersecuritycomponentInner_fuzzer.cpp @@ -28,7 +28,6 @@ using namespace OHOS::Security::AccessToken; namespace OHOS { static void UnregisterSecurityComponentInnerFuzzTest(const uint8_t *data, size_t size) { - uint32_t code = SecurityComponentServiceInterfaceCode::UNREGISTER_SECURITY_COMPONENT; MessageParcel datas; datas.WriteInterfaceToken(u"ohos.security.ISecCompService"); datas.WriteBuffer(data, size); @@ -36,6 +35,7 @@ static void UnregisterSecurityComponentInnerFuzzTest(const uint8_t *data, size_t MessageParcel reply; MessageOption option; auto service = std::make_shared(SA_ID_SECURITY_COMPONENT_SERVICE, true); + uint32_t code = SecurityComponentServiceInterfaceCode::UNREGISTER_SECURITY_COMPONENT; service->OnRemoteRequest(code, datas, reply, option); } } // namespace OHOS diff --git a/test/fuzztest/security_component/updatesecuritycomponentInner_fuzzer/updatesecuritycomponentInner_fuzzer.cpp b/test/fuzztest/security_component/updatesecuritycomponentInner_fuzzer/updatesecuritycomponentInner_fuzzer.cpp index 7f1ab9fc6ad74a5604b27d450fab21d9c2bf24ca..e5ce2c077d69dbb13c6d5a49f09e03881d732c3e 100644 --- a/test/fuzztest/security_component/updatesecuritycomponentInner_fuzzer/updatesecuritycomponentInner_fuzzer.cpp +++ b/test/fuzztest/security_component/updatesecuritycomponentInner_fuzzer/updatesecuritycomponentInner_fuzzer.cpp @@ -28,7 +28,6 @@ using namespace OHOS::Security::AccessToken; namespace OHOS { static void UpdateSecurityComponentInnerFuzzTest(const uint8_t *data, size_t size) { - uint32_t code = SecurityComponentServiceInterfaceCode::UPDATE_SECURITY_COMPONENT; MessageParcel datas; datas.WriteInterfaceToken(u"ohos.security.ISecCompService"); datas.WriteBuffer(data, size); @@ -36,6 +35,7 @@ static void UpdateSecurityComponentInnerFuzzTest(const uint8_t *data, size_t siz MessageParcel reply; MessageOption option; auto service = std::make_shared(SA_ID_SECURITY_COMPONENT_SERVICE, true); + uint32_t code = SecurityComponentServiceInterfaceCode::UPDATE_SECURITY_COMPONENT; service->OnRemoteRequest(code, datas, reply, option); } } // namespace OHOS