diff --git a/frameworks/enhance_adapter/src/sec_comp_enhance_adapter.cpp b/frameworks/enhance_adapter/src/sec_comp_enhance_adapter.cpp index 6f3686c32140e63c7d237e53a3676c481499d5e3..b8f18fcdad1d48e2d8c0d01d531fd0d5b9af4768 100644 --- a/frameworks/enhance_adapter/src/sec_comp_enhance_adapter.cpp +++ b/frameworks/enhance_adapter/src/sec_comp_enhance_adapter.cpp @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "sec_comp_enhance_adapter.h" #include diff --git a/frameworks/inner_api/security_component/test/unittest/src/location_button_test.cpp b/frameworks/inner_api/security_component/test/unittest/src/location_button_test.cpp index cac70ecb5f83a64d123455326f00757a2a89e9f8..d0966a8fdf2a9015e4aad1b6d22ce7f9c05e52de 100644 --- a/frameworks/inner_api/security_component/test/unittest/src/location_button_test.cpp +++ b/frameworks/inner_api/security_component/test/unittest/src/location_button_test.cpp @@ -52,11 +52,11 @@ void LocationButtonTest::TearDown() HWTEST_F(LocationButtonTest, FromJson001, TestSize.Level0) { nlohmann::json jsonComponent; - TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton comp; std::string message; bool isClicked = true; + TestCommon::BuildLocationComponentInfo(jsonComponent); ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); } @@ -84,22 +84,25 @@ HWTEST_F(LocationButtonTest, FromJson002, TestSize.Level0) HWTEST_F(LocationButtonTest, FromJson003, TestSize.Level0) { nlohmann::json jsonComponent; - TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton comp; std::string message; bool isClicked = true; + TestCommon::BuildLocationComponentInfo(jsonComponent); ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); jsonComponent[JsonTagConstants::JSON_SC_TYPE] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); - jsonComponent[JsonTagConstants::JSON_SC_TYPE] = 0; + jsonComponent[JsonTagConstants::JSON_SC_TYPE] = UNKNOWN_SC_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + jsonComponent[JsonTagConstants::JSON_SC_TYPE] = MAX_SC_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** * @tc.name: FromJson004 - * @tc.desc: Test location button from wrong rect json + * @tc.desc: Test location button from wrong node id json * @tc.type: FUNC * @tc.require: */ @@ -109,52 +112,101 @@ HWTEST_F(LocationButtonTest, FromJson004, TestSize.Level0) LocationButton comp; std::string message; bool isClicked = true; - jsonComponent[JsonTagConstants::JSON_SC_TYPE] = LOCATION_COMPONENT; - nlohmann::json wrongJson = nlohmann::json::parse("{", nullptr, false); - jsonComponent[JsonTagConstants::JSON_RECT] = wrongJson; + TestCommon::BuildLocationComponentInfo(jsonComponent); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); + + jsonComponent[JsonTagConstants::JSON_NODE_ID] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); +} +/** + * @tc.name: FromJson005 + * @tc.desc: Test location button from wrong wearable info json + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(LocationButtonTest, FromJson005, TestSize.Level0) +{ + nlohmann::json jsonComponent; + LocationButton comp; + std::string message; + bool isClicked = true; TestCommon::BuildLocationComponentInfo(jsonComponent); ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); - auto& rectJson = jsonComponent[JsonTagConstants::JSON_RECT]; - rectJson[JsonTagConstants::JSON_RECT_X] = WRONG_TYPE; + jsonComponent[JsonTagConstants::JSON_IS_WEARABLE] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); +} - rectJson[JsonTagConstants::JSON_RECT_X] = TestCommon::TEST_COORDINATE; - rectJson[JsonTagConstants::JSON_RECT_Y] = WRONG_TYPE; +/** + * @tc.name: FromJson006 + * @tc.desc: Test location button from wrong parent json + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(LocationButtonTest, FromJson006, TestSize.Level0) +{ + nlohmann::json jsonComponent; + LocationButton comp; + std::string message; + bool isClicked = true; + TestCommon::BuildLocationComponentInfo(jsonComponent); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); + + jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); - rectJson[JsonTagConstants::JSON_RECT_Y] = TestCommon::TEST_COORDINATE; - rectJson[JsonTagConstants::JSON_RECT_WIDTH] = WRONG_TYPE; + TestCommon::BuildLocationComponentInfo(jsonComponent); + auto& parentJson = jsonComponent[JsonTagConstants::JSON_PARENT_TAG]; + parentJson[JsonTagConstants::JSON_PARENT_EFFECT_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); - rectJson[JsonTagConstants::JSON_RECT_WIDTH] = TestCommon::TEST_COORDINATE; - rectJson[JsonTagConstants::JSON_RECT_HEIGHT] = WRONG_TYPE; + parentJson[JsonTagConstants::JSON_PARENT_EFFECT_TAG] = false; + parentJson[JsonTagConstants::JSON_IS_CLIPPED_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + parentJson[JsonTagConstants::JSON_IS_CLIPPED_TAG] = false; + parentJson[JsonTagConstants::JSON_TOP_CLIP_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + parentJson[JsonTagConstants::JSON_TOP_CLIP_TAG] = 0.0; + parentJson[JsonTagConstants::JSON_BOTTOM_CLIP_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + parentJson[JsonTagConstants::JSON_BOTTOM_CLIP_TAG] = 0.0; + parentJson[JsonTagConstants::JSON_LEFT_CLIP_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + parentJson[JsonTagConstants::JSON_LEFT_CLIP_TAG] = 0.0; + parentJson[JsonTagConstants::JSON_RIGHT_CLIP_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + int32_t tagIsIntType = 1; + parentJson[JsonTagConstants::JSON_RIGHT_CLIP_TAG] = 0.0; + parentJson[JsonTagConstants::JSON_PARENT_TAG_TAG] = tagIsIntType; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** - * @tc.name: FromJson005 + * @tc.name: FromJson007 * @tc.desc: Test location button from wrong rect json * @tc.type: FUNC * @tc.require: */ -HWTEST_F(LocationButtonTest, FromJson005, TestSize.Level0) +HWTEST_F(LocationButtonTest, FromJson007, TestSize.Level0) { nlohmann::json jsonComponent; LocationButton comp; std::string message; bool isClicked = true; - jsonComponent[JsonTagConstants::JSON_SC_TYPE] = LOCATION_COMPONENT; - nlohmann::json wrongJson = nlohmann::json::parse("{", nullptr, false); - jsonComponent[JsonTagConstants::JSON_WINDOW_RECT] = wrongJson; - ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); - TestCommon::BuildLocationComponentInfo(jsonComponent); ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); - auto& rectJson = jsonComponent[JsonTagConstants::JSON_WINDOW_RECT]; + jsonComponent[JsonTagConstants::JSON_RECT] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + TestCommon::BuildLocationComponentInfo(jsonComponent); + auto& rectJson = jsonComponent[JsonTagConstants::JSON_RECT]; rectJson[JsonTagConstants::JSON_RECT_X] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); @@ -172,12 +224,12 @@ HWTEST_F(LocationButtonTest, FromJson005, TestSize.Level0) } /** - * @tc.name: FromJson006 - * @tc.desc: Test location button from wrong size json + * @tc.name: FromJson008 + * @tc.desc: Test location button from wrong icon&font size json * @tc.type: FUNC * @tc.require: */ -HWTEST_F(LocationButtonTest, FromJson006, TestSize.Level0) +HWTEST_F(LocationButtonTest, FromJson008, TestSize.Level0) { nlohmann::json jsonComponent; LocationButton comp; @@ -186,6 +238,10 @@ HWTEST_F(LocationButtonTest, FromJson006, TestSize.Level0) TestCommon::BuildLocationComponentInfo(jsonComponent); ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); + jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + TestCommon::BuildLocationComponentInfo(jsonComponent); auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; sizeJson[JsonTagConstants::JSON_FONT_SIZE_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); @@ -200,12 +256,12 @@ HWTEST_F(LocationButtonTest, FromJson006, TestSize.Level0) } /** - * @tc.name: FromJson007 - * @tc.desc: Test location button from wrong size json + * @tc.name: FromJson009 + * @tc.desc: Test location button from wrong padding size json * @tc.type: FUNC * @tc.require: */ -HWTEST_F(LocationButtonTest, FromJson007, TestSize.Level0) +HWTEST_F(LocationButtonTest, FromJson009, TestSize.Level0) { nlohmann::json jsonComponent; LocationButton comp; @@ -215,6 +271,10 @@ HWTEST_F(LocationButtonTest, FromJson007, TestSize.Level0) ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; + sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + TestCommon::BuildLocationComponentInfo(jsonComponent); auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; paddingJson[JsonTagConstants::JSON_TOP_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); @@ -222,15 +282,23 @@ HWTEST_F(LocationButtonTest, FromJson007, TestSize.Level0) paddingJson[JsonTagConstants::JSON_TOP_TAG] = TestCommon::TEST_DIMENSION; paddingJson[JsonTagConstants::JSON_RIGHT_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + paddingJson[JsonTagConstants::JSON_RIGHT_TAG] = TestCommon::TEST_DIMENSION; + paddingJson[JsonTagConstants::JSON_BOTTOM_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + paddingJson[JsonTagConstants::JSON_BOTTOM_TAG] = TestCommon::TEST_DIMENSION; + paddingJson[JsonTagConstants::JSON_LEFT_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** - * @tc.name: FromJson008 - * @tc.desc: Test location button from wrong size json + * @tc.name: FromJson010 + * @tc.desc: Test location button from wrong border radius json * @tc.type: FUNC * @tc.require: */ -HWTEST_F(LocationButtonTest, FromJson008, TestSize.Level0) +HWTEST_F(LocationButtonTest, FromJson010, TestSize.Level0) { nlohmann::json jsonComponent; LocationButton comp; @@ -240,22 +308,66 @@ HWTEST_F(LocationButtonTest, FromJson008, TestSize.Level0) ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; - auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; - paddingJson[JsonTagConstants::JSON_BOTTOM_TAG] = WRONG_TYPE; + sizeJson[JsonTagConstants::JSON_BORDER_RADIUS_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); - paddingJson[JsonTagConstants::JSON_BOTTOM_TAG] = TestCommon::TEST_DIMENSION; - paddingJson[JsonTagConstants::JSON_LEFT_TAG] = WRONG_TYPE; + TestCommon::BuildLocationComponentInfo(jsonComponent); + auto& borderRadiusJson = sizeJson[JsonTagConstants::JSON_BORDER_RADIUS_TAG]; + borderRadiusJson[JsonTagConstants::JSON_LEFT_TOP_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + borderRadiusJson[JsonTagConstants::JSON_LEFT_TOP_TAG] = TestCommon::TEST_DIMENSION; + borderRadiusJson[JsonTagConstants::JSON_RIGHT_TOP_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + borderRadiusJson[JsonTagConstants::JSON_RIGHT_TOP_TAG] = TestCommon::TEST_DIMENSION; + borderRadiusJson[JsonTagConstants::JSON_LEFT_BOTTOM_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + borderRadiusJson[JsonTagConstants::JSON_LEFT_BOTTOM_TAG] = TestCommon::TEST_DIMENSION; + borderRadiusJson[JsonTagConstants::JSON_RIGHT_BOTTOM_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** - * @tc.name: FromJson009 - * @tc.desc: Test location button from wrong border and parent json + * @tc.name: FromJson011 + * @tc.desc: Test location button from wrong color params json * @tc.type: FUNC * @tc.require: */ -HWTEST_F(LocationButtonTest, FromJson009, TestSize.Level0) +HWTEST_F(LocationButtonTest, FromJson011, TestSize.Level0) +{ + nlohmann::json jsonComponent; + LocationButton button; + std::string message; + bool isClicked = true; + TestCommon::BuildLocationComponentInfo(jsonComponent); + ASSERT_TRUE(button.FromJson(jsonComponent, message, isClicked)); + + jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = WRONG_TYPE; + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); + + TestCommon::BuildLocationComponentInfo(jsonComponent); + auto& colorJson = jsonComponent[JsonTagConstants::JSON_COLORS_TAG]; + colorJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = WRONG_TYPE; + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); + + colorJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = TestCommon::TEST_COLOR_RED; + colorJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = WRONG_TYPE; + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); + + colorJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = TestCommon::TEST_COLOR_BLUE; + colorJson[JsonTagConstants::JSON_BG_COLOR_TAG] = WRONG_TYPE; + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); +} + +/** + * @tc.name: FromJson012 + * @tc.desc: Test location button from wrong border json + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(LocationButtonTest, FromJson012, TestSize.Level0) { nlohmann::json jsonComponent; LocationButton comp; @@ -264,33 +376,34 @@ HWTEST_F(LocationButtonTest, FromJson009, TestSize.Level0) TestCommon::BuildLocationComponentInfo(jsonComponent); ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); - jsonComponent[JsonTagConstants::JSON_BORDER_TAG] = nlohmann::json { - { JsonTagConstants::JSON_BORDER_WIDTH_TAG, WRONG_TYPE }, - }; + jsonComponent[JsonTagConstants::JSON_BORDER_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); - TestCommon::BuildLocationComponentInfo(jsonComponent); - jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json { - { JsonTagConstants::JSON_PARENT_EFFECT_TAG, WRONG_TYPE }, + jsonComponent[JsonTagConstants::JSON_BORDER_TAG] = nlohmann::json { + { JsonTagConstants::JSON_BORDER_WIDTH_TAG, WRONG_TYPE }, }; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** - * @tc.name: FromJson010 - * @tc.desc: Test location button from wrong type params json + * @tc.name: FromJson013 + * @tc.desc: Test location button from wrong style json * @tc.type: FUNC * @tc.require: */ -HWTEST_F(LocationButtonTest, FromJson010, TestSize.Level0) +HWTEST_F(LocationButtonTest, FromJson013, TestSize.Level0) { nlohmann::json jsonComponent; - TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton button; std::string message; bool isClicked = true; + TestCommon::BuildLocationComponentInfo(jsonComponent); ASSERT_TRUE(button.FromJson(jsonComponent, message, isClicked)); + jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = WRONG_TYPE; + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); + + TestCommon::BuildLocationComponentInfo(jsonComponent); auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; styleJson[JsonTagConstants::JSON_TEXT_TAG] = WRONG_TYPE; ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); @@ -302,75 +415,210 @@ HWTEST_F(LocationButtonTest, FromJson010, TestSize.Level0) styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::LINE_ICON; styleJson[JsonTagConstants::JSON_BG_TAG] = WRONG_TYPE; ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); + + styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE; + styleJson[JsonTagConstants::JSON_TEXT_TAG] = UNKNOWN_TEXT; + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); + + styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::MAX_LABEL_TYPE; + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); + + styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::SELECT_LOCATION; + styleJson[JsonTagConstants::JSON_ICON_TAG] = UNKNOWN_ICON; + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); + + styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::MAX_ICON_TYPE; + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); + + styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::LINE_ICON; + styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::MAX_BG_TYPE; + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); } /** - * @tc.name: FromJson011 - * @tc.desc: Test location button from wrong type params json + * @tc.name: FromJson014 + * @tc.desc: Test location button from wrong rect json * @tc.type: FUNC * @tc.require: */ -HWTEST_F(LocationButtonTest, FromJson011, TestSize.Level0) +HWTEST_F(LocationButtonTest, FromJson014, TestSize.Level0) { nlohmann::json jsonComponent; + LocationButton comp; + std::string message; + bool isClicked = true; TestCommon::BuildLocationComponentInfo(jsonComponent); - LocationButton button; + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); + + jsonComponent[JsonTagConstants::JSON_WINDOW_RECT] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + TestCommon::BuildLocationComponentInfo(jsonComponent); + auto& rectJson = jsonComponent[JsonTagConstants::JSON_WINDOW_RECT]; + rectJson[JsonTagConstants::JSON_RECT_X] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + rectJson[JsonTagConstants::JSON_RECT_X] = TestCommon::TEST_COORDINATE; + rectJson[JsonTagConstants::JSON_RECT_Y] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + rectJson[JsonTagConstants::JSON_RECT_Y] = TestCommon::TEST_COORDINATE; + rectJson[JsonTagConstants::JSON_RECT_WIDTH] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + rectJson[JsonTagConstants::JSON_RECT_WIDTH] = TestCommon::TEST_COORDINATE; + rectJson[JsonTagConstants::JSON_RECT_HEIGHT] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); +} + +/** + * @tc.name: FromJson015 + * @tc.desc: Test location button from wrong window id json + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(LocationButtonTest, FromJson015, TestSize.Level0) +{ + nlohmann::json jsonComponent; + LocationButton comp; std::string message; bool isClicked = true; - ASSERT_TRUE(button.FromJson(jsonComponent, message, isClicked)); + TestCommon::BuildLocationComponentInfo(jsonComponent); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); - auto& colorJson = jsonComponent[JsonTagConstants::JSON_COLORS_TAG]; - colorJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); + jsonComponent[JsonTagConstants::JSON_WINDOW_ID] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); +} - colorJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = TestCommon::TEST_COLOR_RED; - colorJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); +/** + * @tc.name: FromJson016 + * @tc.desc: Test location button from wrong display id json + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(LocationButtonTest, FromJson016, TestSize.Level0) +{ + nlohmann::json jsonComponent; + LocationButton comp; + std::string message; + bool isClicked = true; + TestCommon::BuildLocationComponentInfo(jsonComponent); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); - colorJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = TestCommon::TEST_COLOR_BLUE; - colorJson[JsonTagConstants::JSON_BG_COLOR_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); + jsonComponent[JsonTagConstants::JSON_DISPLAY_ID] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** - * @tc.name: FromJson012 - * @tc.desc: Test location button from wrong value params json + * @tc.name: FromJson017 + * @tc.desc: Test location button from wrong cross axis state json * @tc.type: FUNC * @tc.require: */ -HWTEST_F(LocationButtonTest, FromJson012, TestSize.Level0) +HWTEST_F(LocationButtonTest, FromJson017, TestSize.Level0) { nlohmann::json jsonComponent; + LocationButton comp; + std::string message; + bool isClicked = true; TestCommon::BuildLocationComponentInfo(jsonComponent); - LocationButton button; + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); + + jsonComponent[JsonTagConstants::JSON_CROSS_AXIS_STATE] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + jsonComponent[JsonTagConstants::JSON_CROSS_AXIS_STATE] = static_cast(CrossAxisState::STATE_INVALID) - 1; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + jsonComponent[JsonTagConstants::JSON_CROSS_AXIS_STATE] = static_cast(CrossAxisState::STATE_NO_CROSS) + 1; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); +} + +/** + * @tc.name: FromJson018 + * @tc.desc: Test location button from wrong customize state json + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(LocationButtonTest, FromJson018, TestSize.Level0) +{ + nlohmann::json jsonComponent; + LocationButton comp; std::string message; bool isClicked = true; + TestCommon::BuildLocationComponentInfo(jsonComponent); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); - ASSERT_TRUE(button.FromJson(jsonComponent, message, isClicked)); + jsonComponent[JsonTagConstants::JSON_IS_CUSTOMIZABLE] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); +} - auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; - styleJson[JsonTagConstants::JSON_TEXT_TAG] = UNKNOWN_TEXT; - ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); +/** + * @tc.name: FromJson019 + * @tc.desc: Test location button from wrong tip position json + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(LocationButtonTest, FromJson019, TestSize.Level0) +{ + nlohmann::json jsonComponent; + LocationButton comp; + std::string message; + bool isClicked = true; + TestCommon::BuildLocationComponentInfo(jsonComponent); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); - styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::SELECT_LOCATION; - styleJson[JsonTagConstants::JSON_ICON_TAG] = UNKNOWN_ICON; - ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); + jsonComponent[JsonTagConstants::JSON_TIP_POSITION] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); - styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::LINE_ICON; - styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::UNKNOWN_BG; - ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); + jsonComponent[JsonTagConstants::JSON_TIP_POSITION] = static_cast(TipPosition::ABOVE_BOTTOM) - 1; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); - styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE; - styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::MAX_LABEL_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); + jsonComponent[JsonTagConstants::JSON_TIP_POSITION] = static_cast(TipPosition::BELOW_TOP) + 1; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); +} - styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::SELECT_LOCATION; - styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::MAX_ICON_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); +/** + * @tc.name: FromJson020 + * @tc.desc: Test location button from wrong compatible change json + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(LocationButtonTest, FromJson020, TestSize.Level0) +{ + nlohmann::json jsonComponent; + LocationButton comp; + std::string message; + bool isClicked = true; + TestCommon::BuildLocationComponentInfo(jsonComponent); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); - styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::LINE_ICON; - styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::MAX_BG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); + jsonComponent[JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + jsonComponent[JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG] = true; + jsonComponent[JsonTagConstants::JSON_IS_ICON_EXCEEDED_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + jsonComponent[JsonTagConstants::JSON_IS_ICON_EXCEEDED_TAG] = true; + jsonComponent[JsonTagConstants::JSON_IS_BORDER_COVERED_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + jsonComponent[JsonTagConstants::JSON_IS_BORDER_COVERED_TAG] = true; + jsonComponent[JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + jsonComponent[JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG] = TestCommon::TEST_COORDINATE; + jsonComponent[JsonTagConstants::JSON_FOREGROUND_BLUR_RADIUS_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + jsonComponent[JsonTagConstants::JSON_FOREGROUND_BLUR_RADIUS_TAG] = TestCommon::TEST_COORDINATE; + jsonComponent[JsonTagConstants::JSON_IS_OVERLAY_TEXT_SET_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); + + jsonComponent[JsonTagConstants::JSON_IS_OVERLAY_TEXT_SET_TAG] = true; + jsonComponent[JsonTagConstants::JSON_IS_OVERLAY_NODE_SET_TAG] = WRONG_TYPE; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -382,11 +630,11 @@ HWTEST_F(LocationButtonTest, FromJson012, TestSize.Level0) HWTEST_F(LocationButtonTest, ToJsonStr001, TestSize.Level0) { nlohmann::json jsonComponent; - TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton button; std::string message; bool isClicked = true; + TestCommon::BuildLocationComponentInfo(jsonComponent); ASSERT_TRUE(button.FromJson(jsonComponent, message, isClicked)); ASSERT_EQ(jsonComponent.dump(), button.ToJsonStr()); }