From 0540486a83bad6d2c09f6943d0b229c34cf9c9d5 Mon Sep 17 00:00:00 2001 From: baoyang Date: Thu, 8 May 2025 18:02:21 +0800 Subject: [PATCH] fix oversize functions Signed-off-by: baoyang --- .../test/unittest/src/test_common.cpp | 119 +++--------------- .../test/unittest/src/test_common.h | 1 + .../security_component/src/sec_comp_base.cpp | 19 ++- .../include/sec_comp_base.h | 2 + 4 files changed, 35 insertions(+), 106 deletions(-) diff --git a/frameworks/inner_api/security_component/test/unittest/src/test_common.cpp b/frameworks/inner_api/security_component/test/unittest/src/test_common.cpp index 9072309..f8b4261 100644 --- a/frameworks/inner_api/security_component/test/unittest/src/test_common.cpp +++ b/frameworks/inner_api/security_component/test/unittest/src/test_common.cpp @@ -17,17 +17,8 @@ namespace OHOS { namespace Security { namespace SecurityComponent { -void TestCommon::BuildLocationComponentInfo(nlohmann::json& jsonComponent) +void TestCommon::BuildComponentCommonInfo(nlohmann::json& jsonComponent) { - jsonComponent[JsonTagConstants::JSON_SC_TYPE] = LOCATION_COMPONENT; - 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, TestCommon::TEST_COORDINATE } - }; - jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0; - jsonComponent[JsonTagConstants::JSON_IS_WEARABLE] = false; jsonComponent[JsonTagConstants::JSON_WINDOW_RECT] = nlohmann::json { {JsonTagConstants::JSON_RECT_X, TestCommon::TEST_COORDINATE }, {JsonTagConstants::JSON_RECT_Y, TestCommon::TEST_COORDINATE }, @@ -74,6 +65,20 @@ void TestCommon::BuildLocationComponentInfo(nlohmann::json& jsonComponent) { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 }, { JsonTagConstants::JSON_PARENT_TAG_TAG, "" }, }; +} + +void TestCommon::BuildLocationComponentInfo(nlohmann::json& jsonComponent) +{ + jsonComponent[JsonTagConstants::JSON_SC_TYPE] = LOCATION_COMPONENT; + 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, TestCommon::TEST_COORDINATE } + }; + jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0; + jsonComponent[JsonTagConstants::JSON_IS_WEARABLE] = false; + BuildComponentCommonInfo(jsonComponent); jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { { JsonTagConstants::JSON_TEXT_TAG, LocationDesc::SELECT_LOCATION }, { JsonTagConstants::JSON_ICON_TAG, LocationIcon::LINE_ICON }, @@ -102,52 +107,7 @@ void TestCommon::BuildSaveComponentInfo(nlohmann::json& jsonComponent) {JsonTagConstants::JSON_RECT_WIDTH, TestCommon::TEST_COORDINATE }, {JsonTagConstants::JSON_RECT_HEIGHT, TestCommon::TEST_COORDINATE } }; - jsonComponent[JsonTagConstants::JSON_WINDOW_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, TestCommon::TEST_COORDINATE } - }; - nlohmann::json jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_TOP_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_RIGHT_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_BOTTOM_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_LEFT_TAG, TestCommon::TEST_DIMENSION }, - }; - - nlohmann::json jsonBorderRadius = nlohmann::json { - { JsonTagConstants::JSON_LEFT_TOP_TAG, TEST_DIMENSION }, - { JsonTagConstants::JSON_RIGHT_TOP_TAG, TEST_DIMENSION }, - { JsonTagConstants::JSON_LEFT_BOTTOM_TAG, TEST_DIMENSION }, - { JsonTagConstants::JSON_RIGHT_BOTTOM_TAG, 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 }, - { JsonTagConstants::JSON_BORDER_RADIUS_TAG, jsonBorderRadius} - }; - - 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, TestCommon::TEST_COLOR_YELLOW } - }; - - jsonComponent[JsonTagConstants::JSON_BORDER_TAG] = nlohmann::json { - { JsonTagConstants::JSON_BORDER_WIDTH_TAG, TestCommon::TEST_SIZE }, - }; - jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json { - { JsonTagConstants::JSON_PARENT_EFFECT_TAG, false }, - { JsonTagConstants::JSON_IS_CLIPPED_TAG, false }, - { JsonTagConstants::JSON_TOP_CLIP_TAG, 0.0 }, - { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, 0.0 }, - { JsonTagConstants::JSON_LEFT_CLIP_TAG, 0.0 }, - { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 }, - { JsonTagConstants::JSON_PARENT_TAG_TAG, "" }, - }; + BuildComponentCommonInfo(jsonComponent); jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { { JsonTagConstants::JSON_TEXT_TAG, SaveDesc::DOWNLOAD }, { JsonTagConstants::JSON_ICON_TAG, SaveIcon::LINE_ICON }, @@ -176,52 +136,7 @@ void TestCommon::BuildPasteComponentInfo(nlohmann::json& jsonComponent) {JsonTagConstants::JSON_RECT_WIDTH, TestCommon::TEST_COORDINATE }, {JsonTagConstants::JSON_RECT_HEIGHT, TestCommon::TEST_COORDINATE } }; - jsonComponent[JsonTagConstants::JSON_WINDOW_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, TestCommon::TEST_COORDINATE } - }; - nlohmann::json jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_TOP_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_RIGHT_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_BOTTOM_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_LEFT_TAG, TestCommon::TEST_DIMENSION }, - }; - - nlohmann::json jsonBorderRadius = nlohmann::json { - { JsonTagConstants::JSON_LEFT_TOP_TAG, TEST_DIMENSION }, - { JsonTagConstants::JSON_RIGHT_TOP_TAG, TEST_DIMENSION }, - { JsonTagConstants::JSON_LEFT_BOTTOM_TAG, TEST_DIMENSION }, - { JsonTagConstants::JSON_RIGHT_BOTTOM_TAG, 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 }, - { JsonTagConstants::JSON_BORDER_RADIUS_TAG, jsonBorderRadius}, - }; - - 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, TestCommon::TEST_COLOR_YELLOW } - }; - - jsonComponent[JsonTagConstants::JSON_BORDER_TAG] = nlohmann::json { - { JsonTagConstants::JSON_BORDER_WIDTH_TAG, TestCommon::TEST_SIZE }, - }; - jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json { - { JsonTagConstants::JSON_PARENT_EFFECT_TAG, false }, - { JsonTagConstants::JSON_IS_CLIPPED_TAG, false }, - { JsonTagConstants::JSON_TOP_CLIP_TAG, 0.0 }, - { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, 0.0 }, - { JsonTagConstants::JSON_LEFT_CLIP_TAG, 0.0 }, - { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 }, - { JsonTagConstants::JSON_PARENT_TAG_TAG, "" }, - }; + BuildComponentCommonInfo(jsonComponent); jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { { JsonTagConstants::JSON_TEXT_TAG, PasteDesc::PASTE }, { JsonTagConstants::JSON_ICON_TAG, PasteIcon::LINE_ICON }, diff --git a/frameworks/inner_api/security_component/test/unittest/src/test_common.h b/frameworks/inner_api/security_component/test/unittest/src/test_common.h index b42b47a..559fa01 100644 --- a/frameworks/inner_api/security_component/test/unittest/src/test_common.h +++ b/frameworks/inner_api/security_component/test/unittest/src/test_common.h @@ -36,6 +36,7 @@ public: static constexpr uint32_t MAX_HMAC_SIZE = 64; static constexpr size_t MAX_CALLER_SIZE = 10; + static void BuildComponentCommonInfo(nlohmann::json& jsonComponent); static void BuildLocationComponentInfo(nlohmann::json& jsonComponent); static void BuildSaveComponentInfo(nlohmann::json& jsonComponent); static void BuildPasteComponentInfo(nlohmann::json& jsonComponent); diff --git a/frameworks/security_component/src/sec_comp_base.cpp b/frameworks/security_component/src/sec_comp_base.cpp index 66b9471..78c87e9 100644 --- a/frameworks/security_component/src/sec_comp_base.cpp +++ b/frameworks/security_component/src/sec_comp_base.cpp @@ -437,11 +437,8 @@ bool SecCompBase::FromJson(const nlohmann::json& jsonSrc, std::string& message, return true; } -void SecCompBase::ToJson(nlohmann::json& jsonRes) const +void SecCompBase::ToJsonRect(nlohmann::json& jsonRes) const { - jsonRes[JsonTagConstants::JSON_SC_TYPE] = type_; - jsonRes[JsonTagConstants::JSON_NODE_ID] = nodeId_; - jsonRes[JsonTagConstants::JSON_IS_WEARABLE] = isWearableDevice_; jsonRes[JsonTagConstants::JSON_RECT] = nlohmann::json { {JsonTagConstants::JSON_RECT_X, rect_.x_}, {JsonTagConstants::JSON_RECT_Y, rect_.y_}, @@ -454,6 +451,10 @@ void SecCompBase::ToJson(nlohmann::json& jsonRes) const {JsonTagConstants::JSON_RECT_WIDTH, windowRect_.width_}, {JsonTagConstants::JSON_RECT_HEIGHT, windowRect_.height_} }; +} + +void SecCompBase::ToJsonSize(nlohmann::json& jsonRes) const +{ nlohmann::json jsonPadding = nlohmann::json { { JsonTagConstants::JSON_TOP_TAG, padding_.top }, { JsonTagConstants::JSON_RIGHT_TAG, padding_.right }, @@ -475,6 +476,16 @@ void SecCompBase::ToJson(nlohmann::json& jsonRes) const { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, { JsonTagConstants::JSON_BORDER_RADIUS_TAG, jsonBorderRadius }, }; +} + +void SecCompBase::ToJson(nlohmann::json& jsonRes) const +{ + jsonRes[JsonTagConstants::JSON_SC_TYPE] = type_; + jsonRes[JsonTagConstants::JSON_NODE_ID] = nodeId_; + jsonRes[JsonTagConstants::JSON_IS_WEARABLE] = isWearableDevice_; + + ToJsonRect(jsonRes); + ToJsonSize(jsonRes); jsonRes[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { { JsonTagConstants::JSON_FONT_COLOR_TAG, fontColor_.value }, diff --git a/interfaces/inner_api/security_component/include/sec_comp_base.h b/interfaces/inner_api/security_component/include/sec_comp_base.h index 5676f63..a1d250e 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_base.h +++ b/interfaces/inner_api/security_component/include/sec_comp_base.h @@ -181,6 +181,8 @@ private: bool ParseDisplayId(const nlohmann::json& json, const std::string& tag); bool ParseCrossAxisState(const nlohmann::json& json, const std::string& tag); bool ParseWearable(const nlohmann::json& json, const std::string& tag); + void ToJsonRect(nlohmann::json& jsonRes) const; + void ToJsonSize(nlohmann::json& jsonRes) const; }; } // namespace SecurityComponent } // namespace Security -- Gitee