提交 83324abb 编写于 作者: O openharmony_ci 提交者: Gitee

!232 增加Button测试场景化用例

Merge pull request !232 from wangtiantian/checkbox
...@@ -37,6 +37,42 @@ void UITestBUTTON::SetUp() ...@@ -37,6 +37,42 @@ void UITestBUTTON::SetUp()
void UITestBUTTON::TearDown() void UITestBUTTON::TearDown()
{ {
if (checkBoxChangeListener_ != nullptr) {
delete checkBoxChangeListener_;
checkBoxChangeListener_ = nullptr;
}
if (checkBoxChangeListener1_ != nullptr) {
delete checkBoxChangeListener1_;
checkBoxChangeListener1_ = nullptr;
}
if (checkBoxChangeListener2_ != nullptr) {
delete checkBoxChangeListener2_;
checkBoxChangeListener2_ = nullptr;
}
if (radioChangeListener_ != nullptr) {
delete radioChangeListener_;
radioChangeListener_ = nullptr;
}
if (radioChangeListener1_ != nullptr) {
delete radioChangeListener1_;
radioChangeListener1_ = nullptr;
}
if (radioChangeListener2_ != nullptr) {
delete radioChangeListener2_;
radioChangeListener2_ = nullptr;
}
if (toggleChangeListener_ != nullptr) {
delete toggleChangeListener_;
toggleChangeListener_ = nullptr;
}
if (toggleChangeListener1_ != nullptr) {
delete toggleChangeListener1_;
toggleChangeListener1_ = nullptr;
}
if (toggleChangeListener2_ != nullptr) {
delete toggleChangeListener2_;
toggleChangeListener2_ = nullptr;
}
if (clickEnableVisiableListener_ != nullptr) { if (clickEnableVisiableListener_ != nullptr) {
delete clickEnableVisiableListener_; delete clickEnableVisiableListener_;
clickEnableVisiableListener_ = nullptr; clickEnableVisiableListener_ = nullptr;
...@@ -93,18 +129,31 @@ void UITestBUTTON::TearDown() ...@@ -93,18 +129,31 @@ void UITestBUTTON::TearDown()
delete clickSmallListener_; delete clickSmallListener_;
clickSmallListener_ = nullptr; clickSmallListener_ = nullptr;
} }
if (toggleChangeListener_ != nullptr) {
delete toggleChangeListener_;
toggleChangeListener_ = nullptr;
}
if (toggleChangeListener1_ != nullptr) {
delete toggleChangeListener1_;
toggleChangeListener1_ = nullptr;
}
DeleteChildren(container_); DeleteChildren(container_);
container_ = nullptr; container_ = nullptr;
} }
class TestBtnOnStateChangeListener : public OHOS::UICheckBox::OnChangeListener {
public:
explicit TestBtnOnStateChangeListener(UILabel* uiLabel) : uiLabel_(uiLabel) {}
~TestBtnOnStateChangeListener() {}
bool OnChange(UICheckBox::UICheckBoxState state) override
{
if (state == UICheckBox::UICheckBoxState::SELECTED) {
uiLabel_->SetText("ON");
} else {
uiLabel_->SetText("OFF");
}
uiLabel_->Invalidate();
return true;
}
private:
UILabel* uiLabel_;
};
const UIView* UITestBUTTON::GetTestView() const UIView* UITestBUTTON::GetTestView()
{ {
UIKit_Check_Box_Test_001(); UIKit_Check_Box_Test_001();
...@@ -117,7 +166,44 @@ const UIView* UITestBUTTON::GetTestView() ...@@ -117,7 +166,44 @@ const UIView* UITestBUTTON::GetTestView()
return container_; return container_;
} }
void UITestBUTTON::UIKit_Check_Box_Test_001() const UIViewGroup* UITestBUTTON::CreateButtonGroup(int16_t posX, int16_t posY, int16_t width, int16_t height,
UICheckBox::OnChangeListener** listener,
UIViewType type,
const char* name)
{
UIViewGroup* group = new UIViewGroup();
group->SetPosition(posX, posY, 300, 150); // 300: width, 150: height
UILabel* label = new UILabel();
group->Add(label);
label->SetPosition(10, 30, 80, 20); // 10: posX 30 posY 80 width 20 height
label->SetText("State: ");
UILabel* label1 = new UILabel();
group->Add(label1);
label1->SetPosition(70, 30, 40, 20); // 70: posX 30 posY 40 width 20 height
*listener = static_cast<UICheckBox::OnChangeListener*>(new TestBtnOnStateChangeListener(label1));
UICheckBox* checkBox = nullptr;
if (type == UIViewType::UI_TOGGLE_BUTTON) {
checkBox = static_cast<UICheckBox*>(new UIToggleButton());
} else if (type == UIViewType::UI_RADIO_BUTTON) {
checkBox = static_cast<UICheckBox*>(new UIRadioButton(name));
} else {
checkBox = new UICheckBox();
checkBox->SetImages("", "");
}
group->Add(checkBox);
checkBox->SetOnChangeListener(*listener);
checkBox->SetPosition(100, 0, width, height); // 100: posX 0: posY
if (checkBox->GetState() == UICheckBox::SELECTED) {
label1->SetText("ON");
} else {
label1->SetText("OFF");
}
return group;
}
void UITestBUTTON::UIKit_Check_Box_Test_001()
{ {
if (container_ != nullptr) { if (container_ != nullptr) {
UILabel* label = new UILabel(); UILabel* label = new UILabel();
...@@ -126,26 +212,19 @@ void UITestBUTTON::UIKit_Check_Box_Test_001() const ...@@ -126,26 +212,19 @@ void UITestBUTTON::UIKit_Check_Box_Test_001() const
Screen::GetInstance().GetWidth(), TITLE_LABEL_DEFAULT_HEIGHT); Screen::GetInstance().GetWidth(), TITLE_LABEL_DEFAULT_HEIGHT);
label->SetText("checkbox功能"); label->SetText("checkbox功能");
label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
// 40: posX 35 posY 100 width 100 height
UICheckBox* checkbox = new UICheckBox(); UIViewGroup* group = CreateButtonGroup(40, 35, 100, 100, &checkBoxChangeListener_);
checkbox->SetPosition(30, 30, 100, 100); // 30: x-coordinate, 30: y-coordinate, 100 : width, 100 : height // 250: posX 35 posY 100 width 100 height
checkbox->SetImages("", ""); UIViewGroup* group1 = CreateButtonGroup(250, 35, 100, 100, &checkBoxChangeListener1_);
// 500: posX 35 posY 100 width 100 height
UICheckBox* checkbox2 = new UICheckBox(); UIViewGroup* group2 = CreateButtonGroup(500, 35, 100, 100, &checkBoxChangeListener2_);
checkbox2->SetPosition(140, 30, 100, 120); // 140: x-coordinate, 30: y-coordinate, 100 : width, 120 : height container_->Add(group);
checkbox2->SetImages("", ""); container_->Add(group1);
container_->Add(group2);
UICheckBox* checkbox3 = new UICheckBox();
checkbox3->SetImages("", "");
checkbox3->SetPosition(250, 30, 120, 100); // 250: x-coordinate, 30: y-coordinate, 120 : width, 100 : height
container_->Add(checkbox);
container_->Add(checkbox2);
container_->Add(checkbox3);
} }
} }
void UITestBUTTON::UIKit_Radio_Button_Test_001() const void UITestBUTTON::UIKit_Radio_Button_Test_001()
{ {
if (container_ != nullptr) { if (container_ != nullptr) {
UILabel* label = new UILabel(); UILabel* label = new UILabel();
...@@ -155,94 +234,21 @@ void UITestBUTTON::UIKit_Radio_Button_Test_001() const ...@@ -155,94 +234,21 @@ void UITestBUTTON::UIKit_Radio_Button_Test_001() const
TITLE_LABEL_DEFAULT_HEIGHT); TITLE_LABEL_DEFAULT_HEIGHT);
label->SetText("radiobutton功能"); label->SetText("radiobutton功能");
label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
// 40: posX 160 posY 100 width 100 height
UIRadioButton* radioButton = new UIRadioButton("aaa"); UIViewGroup* group = CreateButtonGroup(40, 160, 100, 100, &radioChangeListener_,
radioButton->SetPosition(0, 10); // 0: x-coordinate, 10: y-coordinate UIViewType::UI_RADIO_BUTTON, "bb");
// 250: posX 160 posY 100 width 100 height
UIRadioButton* radioButton2 = new UIRadioButton("aaa"); UIViewGroup* group1 = CreateButtonGroup(250, 160, 100, 100, &radioChangeListener1_,
radioButton2->SetPosition(50, 10); // 50: x-coordinate, 10: y-coordinate UIViewType::UI_RADIO_BUTTON, "bb");
radioButton2->SetWidth(40); // 40: width // 500: posX 160 posY 100 width 100 height
radioButton2->SetHeight(30); // 30: height UIViewGroup* group2 = CreateButtonGroup(500, 160, 100, 100, &radioChangeListener2_,
UIViewType::UI_RADIO_BUTTON, "bb");
UIRadioButton* radioButton3 = new UIRadioButton("aaa"); container_->Add(group);
radioButton3->SetPosition(110, 10); // 110: x-coordinate, 10: y-coordinate container_->Add(group1);
radioButton3->SetWidth(80); // 80: width container_->Add(group2);
radioButton3->SetHeight(60); // 60: height
UIRadioButton* radioButton4 = new UIRadioButton("aaa");
radioButton4->SetPosition(10, 10); // 10: x-coordinate, 10: y-coordinate
radioButton4->SetWidth(70); // 70: width
radioButton4->SetHeight(90); // 90: width
radioButton4->SetState(UICheckBox::SELECTED);
UIRadioButton* radioButton5 = new UIRadioButton("aaa");
radioButton5->SetPosition(110, 10); // 110: x-coordinate, 10: y-coordinate
radioButton5->SetWidth(-1); // -1: width
radioButton5->SetHeight(90); // 90: width
UIRadioButton* radioButton6 = new UIRadioButton("aaa");
radioButton6->SetPosition(130, 10); // 130: x-coordinate, 10: y-coordinate
radioButton6->SetWidth(0); // 0: width
radioButton6->SetHeight(0); // 0: width
UIRadioButton* radioButton7 = new UIRadioButton("aaa");
radioButton7->SetPosition(140, 10); // 140: x-coordinate, 10: y-coordinate
radioButton7->SetWidth(1000); // 1000: width
radioButton7->SetHeight(50); // 50: width
OHOS::UIViewGroup* viewGroup = new UIViewGroup();
viewGroup->SetPosition(30, 150); // 30: x-coordinate, 150: y-coordinate
viewGroup->SetWidth(Screen::GetInstance().GetWidth() / 2); // 2: half width
viewGroup->SetHeight(Screen::GetInstance().GetHeight() / 2); // 2: half height
OHOS::UIViewGroup* viewGroup2 = new UIViewGroup();
// 40, increase width, 2: half width, 150: y-coordinate
viewGroup2->SetPosition(40 + Screen::GetInstance().GetWidth() / 2, 150);
viewGroup2->SetWidth(Screen::GetInstance().GetWidth() / 2); // 2: half width
viewGroup2->SetHeight(Screen::GetInstance().GetHeight() / 2); // 2: half height
viewGroup2->Add(radioButton4);
viewGroup2->Add(radioButton5);
viewGroup2->Add(radioButton6);
viewGroup2->Add(radioButton7);
viewGroup->Add(radioButton);
viewGroup->Add(radioButton2);
viewGroup->Add(radioButton3);
viewGroup->SetStyle(STYLE_BACKGROUND_OPA, 0);
container_->Add(viewGroup);
container_->Add(viewGroup2);
} }
} }
class TestBtnOnStateChangeListener : public OHOS::UICheckBox::OnChangeListener {
public:
explicit TestBtnOnStateChangeListener(UIView* uiView)
{
uiView_ = uiView;
}
~TestBtnOnStateChangeListener() {}
bool OnChange(UICheckBox::UICheckBoxState state) override
{
int16_t xPos = uiView_->GetX();
int16_t yPos = uiView_->GetY();
uiView_->Invalidate();
xPos += 10; // 10: increase xPos
yPos += 10; // 10: increase yPos
uiView_->SetX(xPos);
uiView_->SetY(yPos);
uiView_->Invalidate();
return true;
}
private:
UIView* uiView_;
};
void UITestBUTTON::UIKit_Toggle_Button_Test_001() void UITestBUTTON::UIKit_Toggle_Button_Test_001()
{ {
if (container_ != nullptr) { if (container_ != nullptr) {
...@@ -254,61 +260,18 @@ void UITestBUTTON::UIKit_Toggle_Button_Test_001() ...@@ -254,61 +260,18 @@ void UITestBUTTON::UIKit_Toggle_Button_Test_001()
label->SetText("togglebutton功能"); label->SetText("togglebutton功能");
label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
UIToggleButton* togglebutton = new UIToggleButton(); // 40: posX 300 posY 100 width 100 height
togglebutton->SetPosition(20, 300); // 20: x-coordinate, 300: y-coordinate UIViewGroup* group = CreateButtonGroup(40, 300, 100, 100, &toggleChangeListener_,
togglebutton->SetStyle(STYLE_BACKGROUND_OPA, 0); // 0: opacity UIViewType::UI_TOGGLE_BUTTON);
togglebutton->SetState(false); // 250: posX 300 posY 100 width 100 height
UIViewGroup* group1 = CreateButtonGroup(250, 300, 100, 100, &toggleChangeListener1_,
UIToggleButton* togglebutton2 = new UIToggleButton(); UIViewType::UI_TOGGLE_BUTTON);
togglebutton2->SetPosition(100, 300); // 100: x-coordinate, 300: y-coordinate // 500: posX 300 posY 100 width 100 height
togglebutton2->SetStyle(STYLE_BACKGROUND_OPA, 0); // 0: opacity UIViewGroup* group2 = CreateButtonGroup(500, 300, 100, 100, &toggleChangeListener2_,
togglebutton2->SetState(false); UIViewType::UI_TOGGLE_BUTTON);
togglebutton2->SetWidth(60); // 60: width container_->Add(group);
togglebutton2->SetHeight(40); // 40: height container_->Add(group1);
container_->Add(group2);
UIToggleButton* togglebutton3 = new UIToggleButton();
togglebutton3->SetPosition(190, 300); // 190: x-coordinate, 300: y-coordinate
togglebutton3->SetStyle(STYLE_BACKGROUND_OPA, 0); // 0: opacity
togglebutton3->SetState(false);
togglebutton3->SetWidth(50); // 50: width
togglebutton3->SetHeight(70); // 70: height
UIToggleButton* togglebutton4 = new UIToggleButton();
if (toggleChangeListener_ == nullptr) {
toggleChangeListener_ = static_cast<UICheckBox::OnChangeListener*>(
new TestBtnOnStateChangeListener(reinterpret_cast<UIView*>(togglebutton4)));
}
togglebutton4->SetOnChangeListener(toggleChangeListener_);
togglebutton4->SetPosition(250, 300); // 250: x-coordinate, 300: y-coordinate
togglebutton4->SetStyle(STYLE_BACKGROUND_OPA, 0); // 0: opacity
togglebutton4->SetState(false);
togglebutton4->SetWidth(80); // 80: width
togglebutton4->SetHeight(80); // 80: height
togglebutton4->SetState(true);
UIToggleButton* togglebutton5 = new UIToggleButton();
togglebutton5->SetPosition(340, 300); // 340: x-coordinate, 300: y-coordinate
togglebutton5->SetWidth(-1); // -1: width
togglebutton5->SetHeight(90); // 90: width
UIToggleButton* togglebutton6 = new UIToggleButton();
togglebutton6->SetPosition(350, 300); // 350: x-coordinate, 300: y-coordinate
togglebutton6->SetWidth(0); // 0: width
togglebutton6->SetHeight(0); // 0: width
UIToggleButton* togglebutton7 = new UIToggleButton();
togglebutton7->SetPosition(360, 300); // 360: x-coordinate, 300: y-coordinate
togglebutton7->SetWidth(1000); // 1000: width
togglebutton7->SetHeight(50); // 50: width
container_->Add(togglebutton);
container_->Add(togglebutton2);
container_->Add(togglebutton3);
container_->Add(togglebutton4);
container_->Add(togglebutton5);
container_->Add(togglebutton6);
container_->Add(togglebutton7);
} }
} }
void UITestBUTTON::UIKit_Check_Box_Test_002() const void UITestBUTTON::UIKit_Check_Box_Test_002() const
...@@ -403,11 +366,6 @@ void UITestBUTTON::UIKit_Toggle_Button_Test_002() ...@@ -403,11 +366,6 @@ void UITestBUTTON::UIKit_Toggle_Button_Test_002()
togglebutton->SetImages(BLUE_IMAGE_PATH, YELLOW_IMAGE_PATH); togglebutton->SetImages(BLUE_IMAGE_PATH, YELLOW_IMAGE_PATH);
UIToggleButton* togglebutton2 = new UIToggleButton(); UIToggleButton* togglebutton2 = new UIToggleButton();
if (toggleChangeListener1_ == nullptr) {
toggleChangeListener1_ = static_cast<UICheckBox::OnChangeListener*>(
new TestBtnOnStateChangeListener(reinterpret_cast<UIView*>(togglebutton2)));
}
togglebutton2->SetOnChangeListener(toggleChangeListener1_);
togglebutton2->SetPosition(200, 770); // 200: x-coordinate, 770: y-coordinate togglebutton2->SetPosition(200, 770); // 200: x-coordinate, 770: y-coordinate
togglebutton2->SetStyle(STYLE_BACKGROUND_OPA, 0); // 0: opacity togglebutton2->SetStyle(STYLE_BACKGROUND_OPA, 0); // 0: opacity
togglebutton2->SetState(false); togglebutton2->SetState(false);
......
...@@ -33,7 +33,7 @@ public: ...@@ -33,7 +33,7 @@ public:
/** /**
* @brief Test Checkbox Function * @brief Test Checkbox Function
*/ */
void UIKit_Check_Box_Test_001() const; void UIKit_Check_Box_Test_001();
/** /**
* @brief Test Checkbox's SetImage Function * @brief Test Checkbox's SetImage Function
...@@ -43,7 +43,7 @@ public: ...@@ -43,7 +43,7 @@ public:
/** /**
* @brief Test Radiobutton Function * @brief Test Radiobutton Function
*/ */
void UIKit_Radio_Button_Test_001() const; void UIKit_Radio_Button_Test_001();
/** /**
* @brief Test Radiobutton's SetImage Function * @brief Test Radiobutton's SetImage Function
...@@ -67,11 +67,22 @@ public: ...@@ -67,11 +67,22 @@ public:
private: private:
void UIKit_Button_Test_002(UIScrollView* container, UIButton* button); void UIKit_Button_Test_002(UIScrollView* container, UIButton* button);
UIViewGroup* CreateButtonGroup(int16_t posX, int16_t posY, int16_t width, int16_t height,
UICheckBox::OnChangeListener** listener,
UIViewType type = UI_CHECK_BOX,
const char* name = "aa");
static constexpr int16_t CHANGE_SIZE = 10; static constexpr int16_t CHANGE_SIZE = 10;
UIScrollView* container_ = nullptr; UIScrollView* container_ = nullptr;
UICheckBox::OnChangeListener* checkBoxChangeListener_ = nullptr;
UICheckBox::OnChangeListener* checkBoxChangeListener1_ = nullptr;
UICheckBox::OnChangeListener* checkBoxChangeListener2_ = nullptr;
UICheckBox::OnChangeListener* radioChangeListener_ = nullptr;
UICheckBox::OnChangeListener* radioChangeListener1_ = nullptr;
UICheckBox::OnChangeListener* radioChangeListener2_ = nullptr;
UICheckBox::OnChangeListener* toggleChangeListener_ = nullptr; UICheckBox::OnChangeListener* toggleChangeListener_ = nullptr;
UICheckBox::OnChangeListener* toggleChangeListener1_ = nullptr; UICheckBox::OnChangeListener* toggleChangeListener1_ = nullptr;
UICheckBox::OnChangeListener* toggleChangeListener2_ = nullptr;
UIView::OnClickListener* clickEnableVisiableListener_ = nullptr; UIView::OnClickListener* clickEnableVisiableListener_ = nullptr;
UIView::OnClickListener* clickDisableVisiableListener_ = nullptr; UIView::OnClickListener* clickDisableVisiableListener_ = nullptr;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册