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_slider.h"
17 #include <climits>
18 #include <gtest/gtest.h>
19
20 using namespace testing::ext;
21 namespace OHOS {
22 class UISliderTest : public testing::Test {
23 public:
24 static void SetUpTestCase(void);
25 static void TearDownTestCase(void);
26 static UISlider* slider_;
27 };
28
29 UISlider* UISliderTest::slider_ = nullptr;
30
SetUpTestCase(void)31 void UISliderTest::SetUpTestCase(void)
32 {
33 if (slider_ == nullptr) {
34 slider_ = new UISlider();
35 }
36 }
37
TearDownTestCase(void)38 void UISliderTest::TearDownTestCase(void)
39 {
40 if (slider_ != nullptr) {
41 delete slider_;
42 slider_ = nullptr;
43 }
44 }
45
46 /**
47 * @tc.name:UISliderGetViewType_001
48 * @tc.desc: Verify GetViewType function, equal.
49 * @tc.type: FUNC
50 * @tc.require: NA
51 */
52 HWTEST_F(UISliderTest, UISliderGetViewType_001, TestSize.Level1)
53 {
54 if (slider_ == nullptr) {
55 EXPECT_EQ(1, 0);
56 return;
57 }
58 EXPECT_EQ(slider_->GetViewType(), UI_SLIDER);
59 }
60
61 /**
62 * @tc.name:UISliderSetKnobWidth_001
63 * @tc.desc: Verify SetKnobWidth function, equal.
64 * @tc.type: FUNC
65 * @tc.require: NA
66 */
67 HWTEST_F(UISliderTest, UISliderSetKnobWidth_001, TestSize.Level0)
68 {
69 if (slider_ == nullptr) {
70 EXPECT_EQ(1, 0);
71 return;
72 }
73 const int16_t width = 10;
74
75 slider_->SetKnobWidth(width);
76 EXPECT_EQ(slider_->GetKnobWidth(), width);
77 }
78
79 /**
80 * @tc.name:UISliderSetKnobStyle_001
81 * @tc.desc: Verify SetKnobStyle function, equal.
82 * @tc.type: FUNC
83 * @tc.require: NA
84 */
85 HWTEST_F(UISliderTest, UISliderSetKnobStyle_001, TestSize.Level0)
86 {
87 if (slider_ == nullptr) {
88 EXPECT_EQ(1, 0);
89 return;
90 }
91 slider_->SetKnobStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);
92 EXPECT_EQ(slider_->GetKnobStyle().bgColor_.full, Color::Gray().full);
93 }
94 } // namespace OHOS
95