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_box_progress.h"
17
18 #include <climits>
19 #include <gtest/gtest.h>
20
21 using namespace testing::ext;
22 namespace OHOS {
23 namespace {
24 const int16_t MAX = 500;
25 const int16_t MIN = 100;
26 const int16_t WIDTH = 100;
27 const int16_t HEIGHT = 100;
28 }
29
30 class UIBoxProgressTest : public testing::Test {
31 public:
UIBoxProgressTest()32 UIBoxProgressTest() : boxProgress_(nullptr) {}
~UIBoxProgressTest()33 virtual ~UIBoxProgressTest() {}
34 static void SetUpTestCase();
35 static void TearDownTestCase();
36 void SetUp();
37 void TearDown();
38 UIBoxProgress* boxProgress_;
39 };
40
SetUpTestCase()41 void UIBoxProgressTest::SetUpTestCase()
42 {
43 }
44
TearDownTestCase()45 void UIBoxProgressTest::TearDownTestCase()
46 {
47 }
48
SetUp()49 void UIBoxProgressTest::SetUp()
50 {
51 if (boxProgress_ == nullptr) {
52 boxProgress_ = new UIBoxProgress();
53 }
54 }
55
TearDown()56 void UIBoxProgressTest::TearDown()
57 {
58 if (boxProgress_ != nullptr) {
59 delete boxProgress_;
60 boxProgress_ = nullptr;
61 }
62 }
63
64 /**
65 * @tc.name: UIBoxProgressGetViewType_001
66 * @tc.desc: Verify GetViewType function, equal.
67 * @tc.type: FUNC
68 * @tc.require: AR000DSMQG
69 */
70 HWTEST_F(UIBoxProgressTest, UIBoxProgressGetViewType_001, TestSize.Level1)
71 {
72 if (boxProgress_ == nullptr) {
73 EXPECT_NE(0, 0);
74 return;
75 }
76 EXPECT_EQ(boxProgress_->GetViewType(), UI_BOX_PROGRESS);
77 }
78
79 /**
80 * @tc.name: UIBoxProgressSetDirection_001
81 * @tc.desc: Verify SetDirection function, equal.
82 * @tc.type: FUNC
83 * @tc.require: AR000DSMQG
84 */
85 HWTEST_F(UIBoxProgressTest, UIBoxProgressSetDirection_001, TestSize.Level0)
86 {
87 if (boxProgress_ == nullptr) {
88 EXPECT_NE(0, 0);
89 return;
90 }
91 UIBoxProgress::Direction direction = UIBoxProgress::Direction::DIR_BOTTOM_TO_TOP;
92 boxProgress_->SetDirection(direction);
93 EXPECT_EQ(boxProgress_->GetDirection(), direction);
94 direction = UIBoxProgress::Direction::DIR_LEFT_TO_RIGHT;
95 boxProgress_->SetDirection(direction);
96 EXPECT_EQ(boxProgress_->GetDirection(), direction);
97 direction = UIBoxProgress::Direction::DIR_RIGHT_TO_LEFT;
98 boxProgress_->SetDirection(direction);
99 EXPECT_EQ(boxProgress_->GetDirection(), direction);
100 direction = UIBoxProgress::Direction::DIR_TOP_TO_BOTTOM;
101 boxProgress_->SetDirection(direction);
102 EXPECT_EQ(boxProgress_->GetDirection(), direction);
103 }
104
105 /**
106 * @tc.name: UIBoxProgressSetValidWidth_001
107 * @tc.desc: Verify SetValidWidth function, equal.
108 * @tc.type: FUNC
109 * @tc.require: AR000DSMQG
110 */
111 HWTEST_F(UIBoxProgressTest, UIBoxProgressSetValidWidth_001, TestSize.Level1)
112 {
113 if (boxProgress_ == nullptr) {
114 EXPECT_NE(0, 0);
115 return;
116 }
117 const int16_t valueWidth = 10;
118 boxProgress_->Resize(WIDTH, HEIGHT);
119 EXPECT_EQ(boxProgress_->GetValidWidth(), WIDTH);
120 boxProgress_->SetValidWidth(valueWidth);
121 EXPECT_EQ(boxProgress_->GetValidWidth(), valueWidth);
122 }
123
124 /**
125 * @tc.name: UIBoxProgressSetValidHeight_001
126 * @tc.desc: Verify SetValidHeight function, equal.
127 * @tc.type: FUNC
128 * @tc.require: AR000DSMQG
129 */
130 HWTEST_F(UIBoxProgressTest, UIBoxProgressSetValidHeight_001, TestSize.Level1)
131 {
132 if (boxProgress_ == nullptr) {
133 EXPECT_NE(0, 0);
134 return;
135 }
136 const int16_t valueHeight = 10;
137 boxProgress_->Resize(WIDTH, HEIGHT);
138 EXPECT_EQ(boxProgress_->GetValidHeight(), HEIGHT);
139 boxProgress_->SetValidHeight(valueHeight);
140 EXPECT_EQ(boxProgress_->GetValidHeight(), valueHeight);
141 }
142
143 /**
144 * @tc.name: UIBoxProgressSetValue_001
145 * @tc.desc: Verify SetValue function, equal.
146 * @tc.type: FUNC
147 * @tc.require: AR000DSMQG
148 */
149 HWTEST_F(UIBoxProgressTest, UIBoxProgressSetValue_001, TestSize.Level1)
150 {
151 if (boxProgress_ == nullptr) {
152 EXPECT_NE(0, 0);
153 return;
154 }
155 boxProgress_->SetRange(MAX, MIN);
156
157 int16_t value = MIN - 1;
158 boxProgress_->SetValue(value);
159 EXPECT_EQ(boxProgress_->GetValue(), MIN);
160
161 value = MAX + 1;
162 boxProgress_->SetValue(value);
163 EXPECT_EQ(boxProgress_->GetValue(), MAX);
164 }
165
166 /**
167 * @tc.name: UIBoxProgressSetWidth_001
168 * @tc.desc: Verify SetWidth function, equal.
169 * @tc.type: FUNC
170 * @tc.require: AR000DSMQG
171 */
172 HWTEST_F(UIBoxProgressTest, UIBoxProgressSetWidth_001, TestSize.Level1)
173 {
174 if (boxProgress_ == nullptr) {
175 EXPECT_NE(0, 0);
176 return;
177 }
178
179 boxProgress_->SetWidth(WIDTH);
180 EXPECT_EQ(boxProgress_->GetWidth(), WIDTH);
181 EXPECT_EQ(boxProgress_->GetValidWidth(), WIDTH);
182 }
183
184 /**
185 * @tc.name: UIBoxProgressSetHeight_001
186 * @tc.desc: Verify SetHeight function, equal.
187 * @tc.type: FUNC
188 * @tc.require: AR000DSMQG
189 */
190 HWTEST_F(UIBoxProgressTest, UIBoxProgressSetHeight_001, TestSize.Level1)
191 {
192 if (boxProgress_ == nullptr) {
193 EXPECT_NE(0, 0);
194 return;
195 }
196
197 boxProgress_->SetHeight(HEIGHT);
198 EXPECT_EQ(boxProgress_->GetHeight(), HEIGHT);
199 EXPECT_EQ(boxProgress_->GetValidHeight(), HEIGHT);
200 }
201 } // namespace OHOS
202