1 /*
2 * Copyright (c) 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 "slider_tdd_test.h"
17 #include "acelite_config.h"
18 #include "component_factory.h"
19 #include "js_app_environment.h"
20 #include "root_view.h"
21 #include "slider_component.h"
22 #include "ui_slider.h"
23
24 namespace OHOS {
25 namespace ACELite {
SliderTddTest()26 SliderTddTest::SliderTddTest():BaseTest()
27 {
28 componentNameId_ = KeyParser::ParseKeyId("slider");
29 }
30
ComponentSliderAttributeMinTest001()31 void SliderTddTest::ComponentSliderAttributeMinTest001()
32 {
33 TDD_CASE_BEGIN();
34 /**
35 * @tc.steps: step1. set Slider attribute min value = 0
36 */
37 const int expectMinValue = 0;
38 const char* minStr = "min";
39 jerry_value_t minKey = jerry_create_string(reinterpret_cast<const jerry_char_t *>(minStr));
40 jerry_value_t minValue = jerry_create_number(expectMinValue);
41 jerry_set_property(attrsObj_, minKey, minValue);
42 Component* sliderComponent = reinterpret_cast<SliderComponent *>(GetRenderedComponent(componentNameId_));
43 UISlider* sliderView = reinterpret_cast<UISlider *>(sliderComponent->GetComponentRootView());
44 jerry_release_value(minKey);
45 jerry_release_value(minValue);
46
47 /**
48 * @tc.expected: step2. uikit sliderView minvalue == 0
49 */
50 if (sliderView->GetRangeMin() == expectMinValue) {
51 printf("%s pass\n", __FUNCTION__);
52 } else {
53 printf("%s fail\n", __FUNCTION__);
54 }
55 EXPECT_EQ(sliderView->GetRangeMin(), expectMinValue);
56
57 /* minValue is [-32767,32767], set min value = 32768 */
58 /**
59 * @tc.expected: step4. update min value = 32768, check sliderView.minValue != 32768
60 */
61 const int expectMinValue3 = 32768;
62 UpdateNumAttributeOrStyleValue(sliderComponent, minStr, expectMinValue3, true);
63 if (sliderView->GetRangeMin() != expectMinValue3) {
64 printf("%s update min overflow value pass\n", __FUNCTION__);
65 } else {
66 printf("%s update min overflow value fail\n", __FUNCTION__);
67 }
68 EXPECT_NE(sliderView->GetRangeMin(), expectMinValue3);
69
70 TDD_CASE_END();
71 }
72
ComponentSliderAttributeMaxTest002()73 void SliderTddTest::ComponentSliderAttributeMaxTest002()
74 {
75 TDD_CASE_BEGIN();
76 /**
77 * @tc.steps: step1. set Slider attribute max = 0
78 */
79 const int expectMaxValue = 1;
80 const char* maxStr = "max";
81 jerry_value_t maxKey = jerry_create_string(reinterpret_cast<const jerry_char_t *>(maxStr));
82 jerry_value_t maxValue = jerry_create_number(expectMaxValue);
83 jerry_set_property(attrsObj_, maxKey, maxValue);
84 Component* sliderComponent = reinterpret_cast<SliderComponent *>(GetRenderedComponent(componentNameId_));
85 UISlider* sliderView = reinterpret_cast<UISlider *>(sliderComponent->GetComponentRootView());
86 jerry_release_value(maxKey);
87 jerry_release_value(maxValue);
88 /**
89 * @tc.expected: step2. uikit sliderView maxvalue == 0
90 */
91 if (sliderView->GetRangeMax() == expectMaxValue) {
92 printf("%s set value pass\n", __FUNCTION__);
93 } else {
94 printf("%s set value fail\n", __FUNCTION__);
95 }
96 EXPECT_EQ(sliderView->GetRangeMax(), expectMaxValue);
97
98 /**
99 * @tc.expected: step4. update max value = 32768, check sliderView.maxValue != 32768
100 */
101 const int expectMaxValue3 = 32768;
102 UpdateNumAttributeOrStyleValue(sliderComponent, maxStr, expectMaxValue3, true);
103 if (sliderView->GetRangeMax() != expectMaxValue3) {
104 printf("%s update max overflow value pass\n", __FUNCTION__);
105 } else {
106 printf("%s update max overflow value fail\n", __FUNCTION__);
107 }
108 EXPECT_NE(sliderView->GetRangeMax(), expectMaxValue3);
109
110 TDD_CASE_END();
111 }
112
ComponentSliderAttributeValueTest003()113 void SliderTddTest::ComponentSliderAttributeValueTest003()
114 {
115 TDD_CASE_BEGIN();
116 /**
117 * @tc.steps: step1. set Slider attribute value = 0
118 */
119 const int expectValue = 100;
120 const char* valueStr = "value";
121 jerry_value_t valueKey = jerry_create_string(reinterpret_cast<const jerry_char_t *>(valueStr));
122 jerry_value_t value = jerry_create_number(expectValue);
123 jerry_set_property(attrsObj_, valueKey, value);
124 Component* sliderComponent = reinterpret_cast<SliderComponent *>(GetRenderedComponent(componentNameId_));
125 UISlider* sliderView = reinterpret_cast<UISlider *>(sliderComponent->GetComponentRootView());
126 jerry_release_value(valueKey);
127 jerry_release_value(value);
128 /**
129 * @tc.expected: step2. check uikit sliderView value == 0
130 */
131 if (sliderView->GetValue() == expectValue) {
132 printf("%s pass\n", __FUNCTION__);
133 } else {
134 printf("%s fail\n", __FUNCTION__);
135 }
136 EXPECT_EQ(sliderView->GetValue(), expectValue);
137
138 /**
139 * @tc.expected: step3. update value = 32767, check sliderView.value == 32767
140 */
141 const int expectValue2 = 32767;
142 UpdateNumAttributeOrStyleValue(sliderComponent, valueStr, expectValue2, true);
143 if (sliderView->GetValue() != expectValue2) {
144 printf("%s update value value pass\n", __FUNCTION__);
145 } else {
146 printf("%s update value value fail\n", __FUNCTION__);
147 }
148 EXPECT_NE(sliderView->GetValue(), expectValue2);
149
150 /**
151 * @tc.expected: step4. update value = 32768, check sliderView.value != 32768
152 */
153 const int expectValue3 = 32768;
154 UpdateNumAttributeOrStyleValue(sliderComponent, valueStr, expectValue3, true);
155 if (sliderView->GetValue() != expectValue3) {
156 printf("%s update value overflow value pass\n", __FUNCTION__);
157 } else {
158 printf("%s update value overflow value fail\n", __FUNCTION__);
159 }
160 EXPECT_NE(sliderView->GetValue(), expectValue3);
161
162 TDD_CASE_END();
163 }
164
ComponentSliderStyleSetColorTest004()165 void SliderTddTest::ComponentSliderStyleSetColorTest004()
166 {
167 TDD_CASE_BEGIN();
168 /**
169 * @tc.steps: step1. set text color value = 16711680
170 */
171 const int expectColorValue = 16711680;
172 const char* colorStr = "color";
173 jerry_value_t textKey = jerry_create_string(reinterpret_cast<const jerry_char_t *>(colorStr));
174 jerry_value_t textColorValue = jerry_create_number(expectColorValue);
175 jerry_set_property(styleObj_, textKey, textColorValue);
176 Component* sliderComponent = reinterpret_cast<SliderComponent *>(GetRenderedComponent(componentNameId_));
177 UISlider* uiSliderView = reinterpret_cast<UISlider *>(sliderComponent->GetComponentRootView());
178 jerry_release_value(textKey);
179 jerry_release_value(textColorValue);
180 /**
181 * @tc.expected: step2. check uikit sliderView color = 16711680 (red color)
182 */
183 if (uiSliderView->GetBackgroundStyle(STYLE_BACKGROUND_COLOR) == GetRGBColor(expectColorValue).full) {
184 printf("%s pass\n", __FUNCTION__);
185 } else {
186 printf("%s fail\n", __FUNCTION__);
187 }
188 EXPECT_EQ(uiSliderView->GetBackgroundStyle(STYLE_BACKGROUND_COLOR), GetRGBColor(expectColorValue).full);
189
190 /**
191 * @tc.expected: step3. update color = expectColorValue2, check uikit sliderView color == expectColorValue2
192 */
193 const int32_t expectColorValue2 = 16777215;
194 UpdateNumAttributeOrStyleValue(sliderComponent, colorStr, expectColorValue2, false);
195 if (uiSliderView->GetBackgroundStyle(STYLE_BACKGROUND_COLOR) == GetRGBColor(expectColorValue2).full) {
196 printf("%s update color pass\n", __FUNCTION__);
197 } else {
198 printf("%s update color fail\n", __FUNCTION__);
199 }
200 EXPECT_EQ(uiSliderView->GetBackgroundStyle(STYLE_BACKGROUND_COLOR), GetRGBColor(expectColorValue2).full);
201
202 /**
203 * @tc.expected: step4. update color = expectColorValue3,
204 * check uikit sliderView color == expectColorValue3,
205 */
206 const int32_t expectColorValue3 = 16777216;
207 UpdateNumAttributeOrStyleValue(sliderComponent, colorStr, expectColorValue3, false);
208 if (uiSliderView->GetBackgroundStyle(STYLE_BACKGROUND_COLOR) == GetRGBColor(expectColorValue3).full) {
209 printf("%s update overflow color pass\n", __FUNCTION__);
210 } else {
211 printf("%s update overflow color fail\n", __FUNCTION__);
212 }
213 EXPECT_EQ(uiSliderView->GetBackgroundStyle(STYLE_BACKGROUND_COLOR), GetRGBColor(expectColorValue3).full);
214
215 /**
216 * @tc.expected: step5. set exceptionColorStrValue with exception value "helloWorld",
217 * program keep going
218 */
219 const char* exceptionColorStrValue = "helloWorld";
220 UpdateCharAttributeOrStyleValue(sliderComponent, colorStr, exceptionColorStrValue, false);
221
222 TDD_CASE_END();
223 }
224
ComponentSliderStyleSetSelectColorTest005()225 void SliderTddTest::ComponentSliderStyleSetSelectColorTest005()
226 {
227 TDD_CASE_BEGIN();
228 /**
229 * @tc.steps: step1. set slider selected color value = 16711680
230 */
231 const int expectColorValue = 16711680;
232 const char* selectedColorStr = "selectedColor";
233 jerry_value_t selectedColorKey = jerry_create_string(reinterpret_cast<const jerry_char_t *>(selectedColorStr));
234 jerry_value_t selectedColorValue = jerry_create_number(expectColorValue);
235
236 jerry_set_property(styleObj_, selectedColorKey, selectedColorValue);
237
238 Component* sliderComponent = reinterpret_cast<SliderComponent *>(GetRenderedComponent(componentNameId_));
239 UISlider* uiSliderView = reinterpret_cast<UISlider *>(sliderComponent->GetComponentRootView());
240
241 jerry_release_value(selectedColorKey);
242 jerry_release_value(selectedColorValue);
243
244 /**
245 * @tc.expected: step2. check uikit sliderView select color = 16711680 (red color)
246 */
247 if (uiSliderView->GetForegroundStyle(STYLE_BACKGROUND_COLOR) == GetRGBColor(expectColorValue).full) {
248 printf("%s pass\n", __FUNCTION__);
249 } else {
250 printf("%s fail\n", __FUNCTION__);
251 }
252 EXPECT_EQ(uiSliderView->GetForegroundStyle(STYLE_BACKGROUND_COLOR), GetRGBColor(expectColorValue).full);
253
254 /**
255 * @tc.expected: step3. update slectedcolor = expectColorValue2, check uikit sliderView selectcolor ==
256 * expectColorValue2
257 */
258 const int32_t expectColorValue2 = 16777215;
259 UpdateNumAttributeOrStyleValue(sliderComponent, selectedColorStr, expectColorValue2, false);
260 if (uiSliderView->GetForegroundStyle(STYLE_BACKGROUND_COLOR) == GetRGBColor(expectColorValue2).full) {
261 printf("%s update selectedColor pass\n", __FUNCTION__);
262 } else {
263 printf("%s update selectedColor fail\n", __FUNCTION__);
264 }
265 EXPECT_EQ(uiSliderView->GetForegroundStyle(STYLE_BACKGROUND_COLOR), GetRGBColor(expectColorValue2).full);
266
267 /**
268 * @tc.expected: step4. update selectedcolor with overflow expectColorValue3,
269 * check uikit sliderView color == expectColorValue3,
270 */
271 const int32_t expectColorValue3 = 16777216;
272 UpdateNumAttributeOrStyleValue(sliderComponent, selectedColorStr, expectColorValue3, false);
273 if (uiSliderView->GetForegroundStyle(STYLE_BACKGROUND_COLOR) == GetRGBColor(expectColorValue3).full) {
274 printf("%s update overflow selectedColor pass\n", __FUNCTION__);
275 } else {
276 printf("%s update overflow selectedColor fail\n", __FUNCTION__);
277 }
278 EXPECT_EQ(uiSliderView->GetForegroundStyle(STYLE_BACKGROUND_COLOR), GetRGBColor(expectColorValue3).full);
279
280 /**
281 * @tc.expected: step5. set exceptionColorStrValue with exception value "helloWorld",
282 * program keep going
283 */
284 const char* expectColorStrValue = "helloWorld";
285 UpdateCharAttributeOrStyleValue(sliderComponent, selectedColorStr, expectColorStrValue, false);
286
287 TDD_CASE_END();
288 }
289
RunTests()290 void SliderTddTest::RunTests()
291 {
292 ComponentSliderAttributeMinTest001();
293 ComponentSliderAttributeMaxTest002();
294 ComponentSliderAttributeValueTest003();
295 ComponentSliderStyleSetColorTest004();
296 ComponentSliderStyleSetSelectColorTest005();
297 }
298
299 #ifdef TDD_ASSERTIONS
300 /**
301 * @tc.name:ComponentSliderAttributeMinTest001
302 * @tc.desc: Verify Slider min value can set normally.
303 */
304 HWTEST_F(SliderTddTest, SliderAttr001, TestSize.Level1)
305 {
306 SliderTddTest::ComponentSliderAttributeMinTest001();
307 }
308
309 /**
310 * @tc.name:ComponentSliderAttributeMaxTest002
311 * @tc.desc: Verify Slider max value can set normally.
312 */
313 HWTEST_F(SliderTddTest, SliderAttr002, TestSize.Level1)
314 {
315 SliderTddTest::ComponentSliderAttributeMaxTest002();
316 }
317
318 /**
319 * @tc.name:ComponentSliderAttributeValueTest003
320 * @tc.desc: Verify Slider value value can set normally.
321 */
322 HWTEST_F(SliderTddTest, SliderAttr003, TestSize.Level0)
323 {
324 SliderTddTest::ComponentSliderAttributeValueTest003();
325 }
326
327 /**
328 * @tc.name:ComponentSliderStyleSetColorTest004
329 * @tc.desc: Verify slider color value.
330 */
331 HWTEST_F(SliderTddTest, SliderStyle004, TestSize.Level1)
332 {
333 SliderTddTest::ComponentSliderStyleSetColorTest004();
334 }
335
336 /**
337 * @tc.name:ComponentSliderStyleSetSelectColorTest005
338 * @tc.desc: Verify slider color value.
339 */
340 HWTEST_F(SliderTddTest, SliderStyle005, TestSize.Level1)
341 {
342 SliderTddTest::ComponentSliderStyleSetSelectColorTest005();
343 }
344
345 #endif
346 } // namespace ACELite
347 } // namespace OHOS
348