1 /*
2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "components/ui_checkbox.h"
17 #include "test_resource_config.h"
18
19 #include <climits>
20 #include <gtest/gtest.h>
21
22 using namespace testing::ext;
23
24 namespace OHOS {
25 class UICheckBoxTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 static UICheckBox* checkBox_;
30 };
31
32 UICheckBox* UICheckBoxTest::checkBox_ = nullptr;
33
SetUpTestCase()34 void UICheckBoxTest::SetUpTestCase()
35 {
36 if (checkBox_ == nullptr) {
37 checkBox_ = new UICheckBox();
38 }
39 }
40
TearDownTestCase()41 void UICheckBoxTest::TearDownTestCase()
42 {
43 if (checkBox_ != nullptr) {
44 delete checkBox_;
45 checkBox_ = nullptr;
46 }
47 }
48
49 /**
50 * @tc.name: UICheckBoxGetViewType_001
51 * @tc.desc: Verify SetState function, equal.
52 * @tc.type: FUNC
53 * @tc.require: AR000DSMQC
54 */
55 HWTEST_F(UICheckBoxTest, UICheckBoxGetViewType_001, TestSize.Level0)
56 {
57 if (checkBox_ == nullptr) {
58 EXPECT_NE(0, 0);
59 return;
60 }
61 EXPECT_EQ(checkBox_->GetViewType(), UI_CHECK_BOX);
62 }
63
64 /**
65 * @tc.name: UICheckBoxOnClickEvent_001
66 * @tc.desc: Verify OnClickEvent function, equal.
67 * @tc.type: FUNC
68 * @tc.require: AR000EEMQ8
69 */
70 HWTEST_F(UICheckBoxTest, UICheckBoxOnClickEvent_001, TestSize.Level1)
71 {
72 if (checkBox_ == nullptr) {
73 EXPECT_NE(0, 0);
74 return;
75 }
76 ClickEvent event({0, 0});
77 checkBox_->OnClickEvent(event);
78 EXPECT_EQ(checkBox_->GetState(), UICheckBox::SELECTED);
79 }
80
81 /**
82 * @tc.name: UICheckBoxSetState_001
83 * @tc.desc: Verify SetState function, equal.
84 * @tc.type: FUNC
85 * @tc.require: AR000EEMQ8
86 */
87 HWTEST_F(UICheckBoxTest, UICheckBoxSetState_001, TestSize.Level0)
88 {
89 if (checkBox_ == nullptr) {
90 EXPECT_NE(0, 0);
91 return;
92 }
93 checkBox_->SetState(UICheckBox::UICheckBoxState::SELECTED);
94 EXPECT_EQ(checkBox_->GetState(), UICheckBox::UICheckBoxState::SELECTED);
95 checkBox_->SetState(UICheckBox::UICheckBoxState::UNSELECTED);
96 EXPECT_EQ(checkBox_->GetState(), UICheckBox::UICheckBoxState::UNSELECTED);
97 }
98
99 /**
100 * @tc.name: UICheckBoxSetSelectedStateColor_001
101 * @tc.desc: Verify SetSelectedStateColor function, equal.
102 */
103 HWTEST_F(UICheckBoxTest, UICheckBoxSetSelectedStateColor_001, TestSize.Level0)
104 {
105 if (checkBox_ == nullptr) {
106 EXPECT_NE(0, 0);
107 return;
108 }
109 ColorType color = Color::Red();
110 checkBox_->SetSelectedStateColor(color);
111 EXPECT_EQ(checkBox_->GetSelectedStateColor().full, color.full);
112 }
113
114 /**
115 * @tc.name: UICheckBoxOnPreDraw_001
116 * @tc.desc: Verify OnPreDraw function, equal.
117 */
118 HWTEST_F(UICheckBoxTest, UICheckBoxOnPreDraw_001, TestSize.Level0)
119 {
120 if (checkBox_ == nullptr) {
121 EXPECT_NE(0, 0);
122 return;
123 }
124 Rect* invalidatedArea = new Rect();
125 EXPECT_EQ(checkBox_->OnPreDraw(*invalidatedArea), false);
126 delete invalidatedArea;
127 invalidatedArea = nullptr;
128 }
129 } // namespace OHOS
130