diff --git a/interfaces/kits/components/ui_axis.h b/interfaces/kits/components/ui_axis.h index e4f357de4dd7bcbbaa08cbd9f76dfcd0cbba1c15..7c158505bfdd7b2adcf9c92af4fcbecc8245f3f4 100644 --- a/interfaces/kits/components/ui_axis.h +++ b/interfaces/kits/components/ui_axis.h @@ -107,6 +107,16 @@ public: enableReverse_ = enable; } + /** + * @brief Obtains the enableReverse_. + * + * @return Returns the enableReverse_. + */ + bool GetEnableReverse() const + { + return enableReverse_; + } + const Point& GetStartPoint() const { return start_; @@ -117,6 +127,16 @@ public: return end_; } + /** + * @brief Sets the markInterval_. + * + * @param Sets the markInterval_. + */ + void SetMarkInterval(float Interval) + { + markInterval_ = Interval; + } + float GetMarkInterval() const { return markInterval_; @@ -237,6 +257,16 @@ public: */ void SetMarkNum(uint16_t count) override; + /** + * @brief Obtains the markDataCount_. + * + * @return Returns the markDataCount_. + */ + uint16_t GetMarkNum() const + { + return markDataCount_; + } + void UpdateAxisPoints() override; private: @@ -305,6 +335,16 @@ public: */ void SetMarkNum(uint16_t count) override; + /** + * @brief Obtains the markDataCount_. + * + * @return Returns the markDataCount_. + */ + uint16_t GetMarkNum() const + { + return markDataCount_; + } + void UpdateAxisPoints() override; private: diff --git a/interfaces/kits/components/ui_button.h b/interfaces/kits/components/ui_button.h index 2b65109b16b55802d038bf4ec90038423ba5bd26..c407065d4a13c8b396ea4328c5fb1e33a087a28b 100644 --- a/interfaces/kits/components/ui_button.h +++ b/interfaces/kits/components/ui_button.h @@ -411,6 +411,17 @@ public: { enableAnimation_ = enable; } + + /** + * @brief Obtains the value of a style. + * + * @param enableAnimation. + * @return Returns enableAnimation_. + */ + bool GetEnableButtonAnimation() const + { + return enableAnimation_; + } #endif protected: diff --git a/interfaces/kits/components/ui_chart.h b/interfaces/kits/components/ui_chart.h index 151d1df2b50c40c37ceb733cb23923f91c47149d..956a048c46307b3d0bd5b476b9d37958ecf5f5fd 100644 --- a/interfaces/kits/components/ui_chart.h +++ b/interfaces/kits/components/ui_chart.h @@ -478,6 +478,16 @@ public: enableHeadPoint_ = enable; } + /** + * @brief enableHeadPoint_. + * + * @return Returns enableHeadPoint_. + */ + bool GetEnableHeadPoint() const + { + return enableHeadPoint_; + } + /** * @brief Enables the feature of drawing the top point of a polyline. If there are multiple top points, * only the first one is drawn. @@ -492,6 +502,16 @@ public: enableTopPoint_ = enable; } + /** + * @brief enableTopPoint_. + * + * @return Returns enableTopPoint_. + */ + bool GetEnableTopPoint() const + { + return enableTopPoint_; + } + /** * @brief Enables the feature of drawing the bottom point of a polyline. If there are multiple bottom points, * only the first one is drawn. @@ -506,6 +526,16 @@ public: enableBottomPoint_ = enable; } + /** + * @brief enableBottomPoint_. + * + * @return Returns enableBottomPoint_. + */ + bool GetEnableBottomPoint() const + { + return enableBottomPoint_; + } + void DrawPoint(BufferInfo& gfxDstBuffer, const Rect& mask); void Refresh(); diff --git a/test/unittest/components/ui_abstract_progress_unit_test.cpp b/test/unittest/components/ui_abstract_progress_unit_test.cpp index 38a3b45cd1acda02cbc92e9e18770d4371454102..116a7ac88603ef44cd6a2655cec7a62fd78de54a 100644 --- a/test/unittest/components/ui_abstract_progress_unit_test.cpp +++ b/test/unittest/components/ui_abstract_progress_unit_test.cpp @@ -26,9 +26,6 @@ namespace { const int16_t MIN_VALUE = 20; const char* foreground = "D:/"; const char* background = "D:/"; - const ImageInfo* foregroundImageInfo; - const ImageInfo* backgroundImageInfo; - const ImageInfo* groundImageInfo; } class UIAbsatrctProgressTest : public testing::Test { public: @@ -256,9 +253,9 @@ HWTEST_F(UIAbsatrctProgressTest, UIAbsatrctProgressSetImage_002, TestSize.Level1 const Image* backgroundImage = new Image(); const Image* foregroundImage = new Image(); const Image* GroundImage = new Image(); - foregroundImageInfo = static_cast(UIMalloc(sizeof(ImageInfo))); - backgroundImageInfo = static_cast(UIMalloc(sizeof(ImageInfo))); - groundImageInfo = static_cast(UIMalloc(sizeof(ImageInfo))); + ImageInfo* foregroundImageInfo = static_cast(UIMalloc(sizeof(ImageInfo))); + ImageInfo* backgroundImageInfo = static_cast(UIMalloc(sizeof(ImageInfo))); + ImageInfo* groundImageInfo = static_cast(UIMalloc(sizeof(ImageInfo))); abstractProgress_->SetImage(foregroundImageInfo, backgroundImageInfo); if (foregroundImageInfo == nullptr && GroundImage->GetImageInfo() == nullptr) { EXPECT_EQ(foregroundImage->GetSrcType(), 2); // 0 : IMG_SRC_VARIABLE 1 : IMG_SRC_FILE 2 : IMG_SRC_UNKNOWN @@ -280,8 +277,11 @@ HWTEST_F(UIAbsatrctProgressTest, UIAbsatrctProgressSetImage_002, TestSize.Level1 GroundImage = nullptr; delete foregroundImage; foregroundImage = nullptr; - UIFree(&foregroundImageInfo); - UIFree(&backgroundImageInfo); - UIFree(&groundImageInfo); + UIFree(foregroundImageInfo); + foregroundImageInfo = nullptr; + UIFree(backgroundImageInfo); + backgroundImageInfo = nullptr; + UIFree(groundImageInfo); + groundImageInfo = nullptr; } } // namespace OHOS diff --git a/test/unittest/components/ui_axis_unit_test.cpp b/test/unittest/components/ui_axis_unit_test.cpp index cb62d55eca9f74c3378821ee087cb72b89135c2a..b1a58a344888bff6f43846d2cfcbce52dc24c7b0 100644 --- a/test/unittest/components/ui_axis_unit_test.cpp +++ b/test/unittest/components/ui_axis_unit_test.cpp @@ -24,6 +24,7 @@ namespace OHOS { namespace { const int16_t LARGER_VALUE = 10; const int16_t SMALLER_VALUE = 2; + const bool ENABLE = true; } class UIAxisTest : public testing::Test { public: @@ -146,4 +147,199 @@ HWTEST_F(UIAxisTest, UIYAxisSetDataRange_002, TestSize.Level1) } EXPECT_EQ(axisY_->SetDataRange(LARGER_VALUE, SMALLER_VALUE), false); } + +/** + * @tc.name: UIYAxisSetMarkNum_001 + * @tc.desc: Verify SetMarkNum function, equal. + */ +HWTEST_F(UIAxisTest, UIXAxisSetMarkNum_001, TestSize.Level1) +{ + if (axisY_ == nullptr) { + EXPECT_EQ(1, 0); + return; + } + int16_t COUNT = 1; + axisX_->SetMarkNum(COUNT); + EXPECT_EQ(axisX_->GetMarkNum(), COUNT); +} + +/** + * @tc.name: UIYAxisSetMarkNum_001 + * @tc.desc: Verify SetMarkNum function, equal. + */ +HWTEST_F(UIAxisTest, UIYAxisSetMarkNum_001, TestSize.Level1) +{ + if (axisY_ == nullptr) { + EXPECT_EQ(1, 0); + return; + } + int16_t COUNT = 1; + axisY_->SetMarkNum(COUNT); + EXPECT_EQ(axisY_->GetMarkNum(), COUNT); + COUNT = 2; + axisY_->SetMarkNum(COUNT); + axisY_->UpdateAxis(); + EXPECT_EQ(axisY_->GetMarkNum(), COUNT); +} + +/** + * @tc.name: UIAxisEnableReverse_001 + * @tc.desc: Verify EnableReverse function, equal. + */ +HWTEST_F(UIAxisTest, UIAxisEnableReverse_001, TestSize.Level1) +{ + if (axisX_ == nullptr) { + EXPECT_EQ(1, 0); + return; + } + axisX_->EnableReverse(ENABLE); + EXPECT_EQ(axisX_->GetEnableReverse(), ENABLE); +} + +/** + * @tc.name: UIAxisGetStartPoint_001 + * @tc.desc: Verify GetStartPoint function, equal. + */ +HWTEST_F(UIAxisTest, UIAxisGetStartPoint_001, TestSize.Level1) +{ + if (axisX_ == nullptr) { + EXPECT_EQ(1, 0); + return; + } + Point start_ = {0, 0}; + EXPECT_EQ(axisX_->GetStartPoint().x, start_.x); + EXPECT_EQ(axisX_->GetStartPoint().y, start_.y); +} + +/** + * @tc.name: UIAxisGetEndPoint_001 + * @tc.desc: Verify GetEndPoint function, equal. + */ +HWTEST_F(UIAxisTest, UIAxisGetEndPoint_001, TestSize.Level1) +{ + if (axisX_ == nullptr) { + EXPECT_EQ(1, 0); + return; + } + Point end_ = {0, 0}; + EXPECT_EQ(axisX_->GetEndPoint().x, end_.x); + EXPECT_EQ(axisX_->GetEndPoint().y, end_.y); +} + +/** + * @tc.name: UIAxisGetMarkInterval_001 + * @tc.desc: Verify GetMarkInterval function, equal. + */ +HWTEST_F(UIAxisTest, UIAxisGetMarkInterval_001, TestSize.Level1) +{ + if (axisX_ == nullptr) { + EXPECT_EQ(1, 0); + return; + } + float markInterval = 0; + axisX_->SetMarkInterval(markInterval); + EXPECT_EQ(axisX_->GetMarkInterval(), markInterval); +} + +/** + * @tc.name: UIAxisOnPreDraw_001 + * @tc.desc: Verify OnPreDraw function, equal. + */ +HWTEST_F(UIAxisTest, UIAxisOnPreDraw_001, TestSize.Level1) +{ + if (axisX_ == nullptr) { + EXPECT_EQ(1, 0); + return; + } + Rect* invalidatedArea = new Rect(); + EXPECT_EQ(axisX_->OnPreDraw(*invalidatedArea), false); + delete invalidatedArea; + invalidatedArea = nullptr; +} + +/** + * @tc.name: UIAxisUpdateAxisPoints_001 + * @tc.desc: Verify UpdateAxisPoints function, equal. + */ +HWTEST_F(UIAxisTest, UIAxisUpdateAxisPoints_001, TestSize.Level1) +{ + if (axisX_ == nullptr) { + EXPECT_EQ(1, 0); + return; + } + axisX_->UpdateAxisPoints(); + Point endx = axisX_->GetEndPoint(); + Point startx = axisX_->GetStartPoint(); + EXPECT_EQ(endx.y, startx.y); +} + +/** + * @tc.name: UIAxisUpdateAxisPoints_002 + * @tc.desc: Verify UpdateAxisPoints function, equal. + */ +HWTEST_F(UIAxisTest, UIAxisUpdateAxisPoints_002, TestSize.Level1) +{ + if (axisY_ == nullptr) { + EXPECT_EQ(1, 0); + return; + } + axisY_->UpdateAxisPoints(); + Point endx = axisY_->GetEndPoint(); + Point startx = axisY_->GetStartPoint(); + EXPECT_EQ(endx.x, startx.x); +} + +/** + * @tc.name: UIAxisTranslateToPixel_001 + * @tc.desc: Verify TranslateToPixel function, equal. + */ +HWTEST_F(UIAxisTest, UIAxisTranslateToPixel_001, TestSize.Level1) +{ + if (axisX_ == nullptr) { + EXPECT_EQ(1, 0); + return; + } + int16_t value = 2; + float minXStep = 0; + Point startx = axisX_->GetStartPoint(); + axisX_->TranslateToPixel(value); + int16_t value2 = startx.x + static_cast((value - 0) * minXStep); + EXPECT_EQ(value, value2); +} + +/** + * @tc.name: UIAxisTranslateToPixel_002 + * @tc.desc: Verify TranslateToPixel function, equal. + */ +HWTEST_F(UIAxisTest, UIAxisTranslateToPixel_002, TestSize.Level1) +{ + if (axisY_ == nullptr) { + EXPECT_EQ(1, 0); + return; + } + int16_t value = 2; + float minYStep = 0; + Point starty = axisY_->GetStartPoint(); + axisX_->TranslateToPixel(value); + int16_t value2 = starty.y + static_cast((0 - value + 0) * minYStep); + EXPECT_EQ(value, value2); +} + +/** + * @tc.name: UIAxisTranslateToPixel_003 + * @tc.desc: Verify TranslateToPixel function, equal. + */ +HWTEST_F(UIAxisTest, UIAxisTranslateToPixel_003, TestSize.Level1) +{ + if (axisY_ == nullptr) { + EXPECT_EQ(1, 0); + return; + } + int16_t value = 2; + float minYStep = 0; + Point starty = axisY_->GetStartPoint(); + axisY_->TranslateToPixel(value); + int16_t value2 = starty.y - static_cast((value - 0) * minYStep); + EXPECT_EQ(value, value2); +} } // namespace OHOS diff --git a/test/unittest/components/ui_button_unit_test.cpp b/test/unittest/components/ui_button_unit_test.cpp index 85893db61871a69f102e7c9fafc563293b3a47a8..7ce717ecc2d16897ad47c9b3c30d3863057b7ce0 100644 --- a/test/unittest/components/ui_button_unit_test.cpp +++ b/test/unittest/components/ui_button_unit_test.cpp @@ -18,6 +18,7 @@ #include #include #include "test_resource_config.h" +#include "draw/draw_utils.h" using namespace testing::ext; @@ -337,4 +338,40 @@ HWTEST_F(UIButtonTest, UIButtonSetStateForStyle_001, TestSize.Level1) button_->SetStateForStyle(UIButton::ButtonState::PRESSED); EXPECT_EQ(button_->GetStyle(STYLE_BACKGROUND_COLOR), Color::Green().full); } + +/** + * @tc.name: UIButtonSetImageSrc_002 + * @tc.desc: Verify SetImageSrc function. + */ +HWTEST_F(UIButtonTest, UIButtonSetImageSrc_002, TestSize.Level0) +{ + if (button_ == nullptr) { + EXPECT_NE(0, 0); + return; + } + ImageInfo* defaultImgSrc = static_cast(UIMalloc(sizeof(ImageInfo))); + ImageInfo* triggeredImgSrc = static_cast(UIMalloc(sizeof(ImageInfo))); + button_->SetImageSrc(defaultImgSrc, triggeredImgSrc); + ASSERT_TRUE(button_->GetCurImageSrc()); + EXPECT_EQ(button_->GetCurImageSrc()->GetSrcType(), IMG_SRC_VARIABLE); + UIFree(triggeredImgSrc); + triggeredImgSrc = nullptr; + UIFree(defaultImgSrc); + defaultImgSrc = nullptr; +} + +/** + * @tc.name: UIButtonEnableButtonAnimation_001 + * @tc.desc: Verify EnableButtonAnimation function. + */ +HWTEST_F(UIButtonTest, UIButtonEnableButtonAnimation_001, TestSize.Level0) +{ + if (button_ == nullptr) { + EXPECT_NE(0, 0); + return; + } + bool enable = true; + button_->EnableButtonAnimation(enable); + EXPECT_EQ(button_->GetEnableButtonAnimation(), enable); +} } // namespace OHOS diff --git a/test/unittest/components/ui_canvas_unit_test.cpp b/test/unittest/components/ui_canvas_unit_test.cpp index d1038e619a2dc4ab448ad241b8718c74445cf252..8d1c50788b94bc0caee105a11135ac44090f9912 100644 --- a/test/unittest/components/ui_canvas_unit_test.cpp +++ b/test/unittest/components/ui_canvas_unit_test.cpp @@ -1850,6 +1850,7 @@ HWTEST_F(UICanvasTest, UICanvasShadowColor_001, TestSize.Level1) ColorType color = Color::Red(); paint_->SetShadowColor(color); EXPECT_EQ(paint_->GetShadowColor().full, color.full); + EXPECT_EQ(paint_->HaveShadow(), true); } HWTEST_F(UICanvasTest, UICanvasShadowColor_002, TestSize.Level0) { @@ -1940,6 +1941,7 @@ HWTEST_F(UICanvasTest, UICanvasCreateLinearGradient_001, TestSize.Level1) EXPECT_EQ(paint_->GetLinearGradientPoint().y0, START_Y); EXPECT_EQ(paint_->GetLinearGradientPoint().x1, END_X); EXPECT_EQ(paint_->GetLinearGradientPoint().y1, END_Y); + EXPECT_EQ(paint_->GetGradient(), Paint::Gradient::Linear); } HWTEST_F(UICanvasTest, UICanvasCreateLinearGradient_002, TestSize.Level0) @@ -2140,4 +2142,52 @@ HWTEST_F(UICanvasTest, UICanvasSetRotate_002, TestSize.Level1) EXPECT_EQ(fontStyle.letterSpace, LETTER_SPACE); EXPECT_EQ(paint_->GetRotateAngle(), ROTATE); } + +/** + * @tc.name: UICanvasInitDash_001 + * @tc.desc: Verify InitDash function, equal. + * @tc.type: FUNC + */ +HWTEST_F(UICanvasTest, UICanvasInitDash_001, TestSize.Level0) +{ + if (canvas_ == nullptr) { + EXPECT_EQ(1, 0); + return; + } + + if (paint_ == nullptr) { + EXPECT_EQ(1, 0); + return; + } +#if GRAPHIC_ENABLE_DASH_GENERATE_FLAG + Paint* paint3 = new Paint(); + paint_->InitDash(*paint3); + EXPECT_EQ(paint_->GetLineDash(), nullptr); + delete paint3; + paint3 = nullptr; +#endif + Paint* paint1 = new Paint(); + paint1->Init(*paint_); + EXPECT_EQ(paint1->GetChangeFlag(), false); + + ColorType color = Color::Red(); + paint1->SetStrokeStyle(color); + EXPECT_EQ(paint1->GetStrokeColor().full, color.full); + color = Color::Yellow(); + paint1->SetFillStyle(color); + EXPECT_EQ(paint1->GetFillColor().full, color.full); + + paint1->SetStrokeStyle(Paint::PaintStyle::GRADIENT); + EXPECT_EQ(paint1->GetStyle(), Paint::PaintStyle::GRADIENT); + paint1->SetFillStyle(Paint::PaintStyle::STROKE_FILL_STYLE); + EXPECT_EQ(paint1->GetStyle(), Paint::PaintStyle::STROKE_FILL_STYLE); + + paint1->GetTransAffine(); + paint1->SetUICanvas(canvas_); + EXPECT_EQ(paint1->GetUICanvas(), canvas_); + + EXPECT_EQ(paint1->HaveComposite(), false); + delete paint1; + paint1 = nullptr; +} } // namespace OHOS diff --git a/test/unittest/components/ui_chart_unit_test.cpp b/test/unittest/components/ui_chart_unit_test.cpp index b0e9d394660b39900badc7a5d79589b6b77b56dc..490e37404c1d9c1b57a198ee22ee2f27d0aa61bb 100644 --- a/test/unittest/components/ui_chart_unit_test.cpp +++ b/test/unittest/components/ui_chart_unit_test.cpp @@ -488,4 +488,35 @@ HWTEST_F(UIChartDataSerialTest, UIChartClearDataSerial_001, TestSize.Level1) ret = chart_->DeleteDataSerial(chartDataSerial_); EXPECT_EQ(ret, false); } + +/** + * @tc.name: UIChartGetValleyData_001 + * @tc.desc: Verify GetValleyData function, equal. + */ +HWTEST_F(UIChartDataSerialTest, UIChartGetValleyData_001, TestSize.Level1) +{ + if (chart_ == nullptr) { + EXPECT_EQ(1, 0); + return; + } + UIChart* chart = static_cast(chart_); + chartDataSerial_->BindToChart(chart); + bool flag = true; + chartDataSerial_->EnableHeadPoint(flag); + chartDataSerial_->EnableTopPoint(flag); + chartDataSerial_->EnableBottomPoint(flag); + EXPECT_EQ(chartDataSerial_->GetEnableHeadPoint(), flag); + EXPECT_EQ(chartDataSerial_->GetEnableTopPoint(), flag); + EXPECT_EQ(chartDataSerial_->GetEnableBottomPoint(), flag); + + BufferInfo* gfxDstBuffer = new BufferInfo(); + Rect* mask = new Rect(); + chartDataSerial_->DrawPoint(*gfxDstBuffer, *mask); + chartDataSerial_->Refresh(); + EXPECT_EQ(chartDataSerial_->GetValleyData(), 0); + delete gfxDstBuffer; + gfxDstBuffer = nullptr; + delete mask; + mask = nullptr; +} } diff --git a/test/unittest/components/ui_checkbox_unit_test.cpp b/test/unittest/components/ui_checkbox_unit_test.cpp index bc6b586bde50cf84bc003ed32c672c68a123a164..89b6d6b4da7f9df359f0281992dbd4bb97ce75d6 100644 --- a/test/unittest/components/ui_checkbox_unit_test.cpp +++ b/test/unittest/components/ui_checkbox_unit_test.cpp @@ -14,6 +14,7 @@ */ #include "components/ui_checkbox.h" +#include "test_resource_config.h" #include #include @@ -94,4 +95,35 @@ HWTEST_F(UICheckBoxTest, UICheckBoxSetState_001, TestSize.Level0) checkBox_->SetState(UICheckBox::UICheckBoxState::UNSELECTED); EXPECT_EQ(checkBox_->GetState(), UICheckBox::UICheckBoxState::UNSELECTED); } + +/** + * @tc.name: UICheckBoxSetSelectedStateColor_001 + * @tc.desc: Verify SetSelectedStateColor function, equal. + */ +HWTEST_F(UICheckBoxTest, UICheckBoxSetSelectedStateColor_001, TestSize.Level0) +{ + if (checkBox_ == nullptr) { + EXPECT_NE(0, 0); + return; + } + ColorType color = Color::Red(); + checkBox_->SetSelectedStateColor(color); + EXPECT_EQ(checkBox_->GetSelectedStateColor().full, color.full); +} + +/** + * @tc.name: UICheckBoxOnPreDraw_001 + * @tc.desc: Verify OnPreDraw function, equal. + */ +HWTEST_F(UICheckBoxTest, UICheckBoxOnPreDraw_001, TestSize.Level0) +{ + if (checkBox_ == nullptr) { + EXPECT_NE(0, 0); + return; + } + Rect* invalidatedArea = new Rect(); + EXPECT_EQ(checkBox_->OnPreDraw(*invalidatedArea), false); + delete invalidatedArea; + invalidatedArea = nullptr; +} } // namespace OHOS