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
18 #include <climits>
19 #include <gtest/gtest.h>
20
21 using namespace testing::ext;
22
23 namespace OHOS {
24 class UICheckBoxTest : public testing::Test {
25 public:
26 static void SetUpTestCase();
27 static void TearDownTestCase();
28 static UICheckBox* checkBox_;
29 };
30
31 UICheckBox* UICheckBoxTest::checkBox_ = nullptr;
32
SetUpTestCase()33 void UICheckBoxTest::SetUpTestCase()
34 {
35 if (checkBox_ == nullptr) {
36 checkBox_ = new UICheckBox();
37 }
38 }
39
TearDownTestCase()40 void UICheckBoxTest::TearDownTestCase()
41 {
42 if (checkBox_ != nullptr) {
43 delete checkBox_;
44 checkBox_ = nullptr;
45 }
46 }
47
48 /**
49 * @tc.name: UICheckBoxGetViewType_001
50 * @tc.desc: Verify SetState function, equal.
51 * @tc.type: FUNC
52 * @tc.require: AR000DSMQC
53 */
54 HWTEST_F(UICheckBoxTest, UICheckBoxGetViewType_001, TestSize.Level0)
55 {
56 if (checkBox_ == nullptr) {
57 EXPECT_NE(0, 0);
58 return;
59 }
60 EXPECT_EQ(checkBox_->GetViewType(), UI_CHECK_BOX);
61 }
62
63 /**
64 * @tc.name: UICheckBoxOnClickEvent_001
65 * @tc.desc: Verify OnClickEvent function, equal.
66 * @tc.type: FUNC
67 * @tc.require: AR000EEMQ8
68 */
69 HWTEST_F(UICheckBoxTest, UICheckBoxOnClickEvent_001, TestSize.Level1)
70 {
71 if (checkBox_ == nullptr) {
72 EXPECT_NE(0, 0);
73 return;
74 }
75 ClickEvent event({0, 0});
76 checkBox_->OnClickEvent(event);
77 EXPECT_EQ(checkBox_->GetState(), UICheckBox::SELECTED);
78 }
79
80 /**
81 * @tc.name: UICheckBoxSetState_001
82 * @tc.desc: Verify SetState function, equal.
83 * @tc.type: FUNC
84 * @tc.require: AR000EEMQ8
85 */
86 HWTEST_F(UICheckBoxTest, UICheckBoxSetState_001, TestSize.Level0)
87 {
88 if (checkBox_ == nullptr) {
89 EXPECT_NE(0, 0);
90 return;
91 }
92 checkBox_->SetState(UICheckBox::UICheckBoxState::SELECTED);
93 EXPECT_EQ(checkBox_->GetState(), UICheckBox::UICheckBoxState::SELECTED);
94 checkBox_->SetState(UICheckBox::UICheckBoxState::UNSELECTED);
95 EXPECT_EQ(checkBox_->GetState(), UICheckBox::UICheckBoxState::UNSELECTED);
96 }
97 } // namespace OHOS