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_toggle_button.h"
17
18 #include <climits>
19 #include <gtest/gtest.h>
20
21 using namespace testing::ext;
22 namespace OHOS {
23 class UIToggleButtonTest : public testing::Test {
24 public:
25 static void SetUpTestCase(void);
26 static void TearDownTestCase(void);
27 static UIToggleButton* toggleBtn_;
28 };
29
30 UIToggleButton* UIToggleButtonTest::toggleBtn_ = nullptr;
31
SetUpTestCase(void)32 void UIToggleButtonTest::SetUpTestCase(void)
33 {
34 if (toggleBtn_ == nullptr) {
35 toggleBtn_ = new UIToggleButton();
36 }
37 }
38
TearDownTestCase(void)39 void UIToggleButtonTest::TearDownTestCase(void)
40 {
41 if (toggleBtn_ != nullptr) {
42 delete toggleBtn_;
43 toggleBtn_ = nullptr;
44 }
45 }
46
47 /**
48 * @tc.name: UIToggleButtonGetViewType_001
49 * @tc.desc: Verify GetViewType function.
50 * @tc.type: FUNC
51 * @tc.require: AR000DSMQA
52 */
53 HWTEST_F(UIToggleButtonTest, UIToggleButtonGetViewType_001, TestSize.Level1)
54 {
55 if (toggleBtn_ == nullptr) {
56 EXPECT_NE(0, 0);
57 return;
58 }
59 EXPECT_EQ(toggleBtn_->GetViewType(), UI_TOGGLE_BUTTON);
60 }
61
62 /**
63 * @tc.name: UIToggleButtonSetState_001
64 * @tc.desc: Verify SetState function.
65 * @tc.type: FUNC
66 * @tc.require: AR000F4E5H
67 */
68 HWTEST_F(UIToggleButtonTest, UIToggleButtonSetState_001, TestSize.Level0)
69 {
70 if (toggleBtn_ == nullptr) {
71 EXPECT_NE(0, 0);
72 return;
73 }
74 toggleBtn_->SetState(true);
75 EXPECT_EQ(toggleBtn_->GetState(), true);
76
77 toggleBtn_->SetState(false);
78 EXPECT_EQ(toggleBtn_->GetState(), false);
79 }
80 } // namespace OHOS
81