1 /*
2 * Copyright (c) 2023 iSoftStone Information Technology (Group) 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 #include "gmock/gmock.h"
16 #include "gtest/gtest.h"
17
18 #include "base/utils/utils.h"
19 #define protected public
20 #define private public
21 #include "test/mock/core/pipeline/mock_pipeline_context.h"
22
23 #include "core/common/ace_application_info.h"
24 #include "core/components_ng/render/render_property.h"
25
26 #undef private
27 #undef protected
28
29 using namespace testing;
30 using namespace testing::ext;
31
32 namespace OHOS::Ace {
33 namespace {
34 const NG::InspectorFilter filter;
35 const std::string ZERO_STRING = "0.0px";
36 const std::string SRC_IMAGES = "images/mmm.jpg";
37 const std::string BACKGROUND_IMAGES = "images/mmm.jpg, ImageRepeat.NoRepeat";
38 constexpr char SHADOW_TEST[] = "shadow";
39
40 const Dimension POSITION_X { 10.0, DimensionUnit::PX };
41 const Dimension POSITION_Y { 20.0, DimensionUnit::PX };
42 const Dimension OFFSET_X { 40.0, DimensionUnit::PX };
43 const Dimension OFFSET_Y { 80.0, DimensionUnit::PX };
44 const Dimension ANCHOR_X { 100.0, DimensionUnit::PX };
45 const Dimension ANCHOR_Y { 200.0, DimensionUnit::PX };
46 const InvertVariant invert = 0.0f;
47 const float DYNAMIC_DIMMING = 0.5f;
48
49 const float VALUE_TEST = 720.0f;
50 const Color WHITE = Color(0xffffffff);
51 const Offset OFFSETS { 2.0, 2.0 };
52
53 const NG::VectorF VECTOR_TEST = { 10.0, 20.0 };
54 const NG::Vector5F VECTOR_5F_TEST = { 20.0f, 40.0f, 60.0f, 80.0f, 0.0f };
55 const NG::TranslateOptions PTTION_TEST = { OFFSET_X, OFFSET_Y, POSITION_X };
56 const NG::OffsetT<Dimension> POSITION = { POSITION_X, POSITION_Y };
57 const NG::OffsetT<Dimension> OFFSET_TEST = { OFFSET_X, OFFSET_Y };
58 const NG::OffsetT<Dimension> ANCHOR = { ANCHOR_X, ANCHOR_Y };
59
60 const BackgroundImageSize BACKGROUND_SIZE { BackgroundImageSizeType::COVER, 1.0 };
61 const BackgroundImagePosition BACKGROUND_POSITION { BackgroundImagePositionType::PERCENT, -1.0,
62 BackgroundImagePositionType::PERCENT, 0.0 };
63
MakeGraphicsProperty(NG::GraphicsProperty & graphicsProperty)64 void MakeGraphicsProperty(NG::GraphicsProperty& graphicsProperty)
65 {
66 graphicsProperty.propFrontGrayScale = POSITION_X;
67 graphicsProperty.propFrontBrightness = POSITION_X;
68 graphicsProperty.propDynamicDimDegree = DYNAMIC_DIMMING;
69 graphicsProperty.propFrontSaturate = POSITION_X;
70 graphicsProperty.propFrontContrast = POSITION_X;
71 graphicsProperty.propFrontInvert = invert;
72 graphicsProperty.propFrontSepia = POSITION_X;
73 graphicsProperty.propFrontHueRotate = VALUE_TEST;
74 graphicsProperty.propFrontColorBlend = WHITE;
75 };
76 } // namespace
77
78 class RenderPropertyTestNg : public testing::Test {
79 public:
80 void SetUp() override;
81 void TearDown() override;
82 };
83
SetUp()84 void RenderPropertyTestNg::SetUp()
85 {
86 NG::MockPipelineContext::SetUp();
87 }
88
TearDown()89 void RenderPropertyTestNg::TearDown()
90 {
91 NG::MockPipelineContext::TearDown();
92 }
93
94 /**
95 * @tc.name: RenderPositionPropertyTest001
96 * @tc.desc: Test cast to RenderPropertyTestNg
97 * @tc.type: FUNC
98 */
99 HWTEST_F(RenderPropertyTestNg, RenderPositionPropertyTest001, TestSize.Level1)
100 {
101 /**
102 * @tc.steps: step1. Build a object renderPositionProperty.
103 */
104 NG::RenderPositionProperty renderPositionProperty;
105 auto json = JsonUtil::Create(true);
106
107 /**
108 * @tc.steps: step2. call ToJsonValue.The propPosition propOffset propMarkAnchor is null.
109 */
110 renderPositionProperty.ToJsonValue(json, filter);
111
112 /**
113 * @tc.expected: Return expected results.
114 */
115 EXPECT_EQ(json->GetValue("position")->GetString("x"), "");
116 EXPECT_EQ(json->GetValue("position")->GetString("y"), "");
117 EXPECT_EQ(json->GetValue("offset")->GetString("x"), ZERO_STRING);
118 EXPECT_EQ(json->GetValue("offset")->GetString("y"), ZERO_STRING);
119 EXPECT_EQ(json->GetValue("markAnchor")->GetString("x"), ZERO_STRING);
120 EXPECT_EQ(json->GetValue("markAnchor")->GetString("y"), ZERO_STRING);
121
122 /**
123 * @tc.steps: step3. Build a object renderPosition.
124 */
125 NG::RenderPositionProperty renderPosition;
126 auto jsonTest = JsonUtil::Create(true);
127
128 /**
129 * @tc.steps: step4. call ToJsonValue.The propPosition propOffset propMarkAnchor is not null.
130 */
131 renderPosition.propPosition = POSITION;
132 renderPosition.propOffset = OFFSET_TEST;
133 renderPosition.propAnchor = ANCHOR;
134 renderPosition.ToJsonValue(jsonTest, filter);
135
136 /**
137 * @tc.expected: Return expected results.
138 */
139 EXPECT_EQ(jsonTest->GetValue("position")->GetString("x"), "10.00px");
140 EXPECT_EQ(jsonTest->GetValue("position")->GetString("y"), "20.00px");
141 EXPECT_EQ(jsonTest->GetValue("offset")->GetString("x"), "40.00px");
142 EXPECT_EQ(jsonTest->GetValue("offset")->GetString("y"), "80.00px");
143 EXPECT_EQ(jsonTest->GetValue("markAnchor")->GetString("x"), "100.00px");
144 EXPECT_EQ(jsonTest->GetValue("markAnchor")->GetString("y"), "200.00px");
145 }
146
147 /**
148 * @tc.name: GraphicsPropertyTest001
149 * @tc.desc: Test cast to RenderPropertyTestNg
150 * @tc.type: FUNC
151 */
152 HWTEST_F(RenderPropertyTestNg, GraphicsPropertyTest001, TestSize.Level1)
153 {
154 /**
155 * @tc.steps: step1. Build a object graphicsProperty.
156 */
157 NG::GraphicsProperty graphicsProperty;
158 auto json = JsonUtil::Create(true);
159
160 /**
161 * @tc.steps: step2. call ToJsonValue.The propBackShadow is null, propFrontColorBlend = WHITE;
162 */
163 MakeGraphicsProperty(graphicsProperty);
164 graphicsProperty.ToJsonValue(json, filter);
165
166 /**
167 * @tc.expected: Return expected results.
168 */
169 EXPECT_EQ(json->GetString("colorBlend"), "#FFFFFFFF");
170 EXPECT_EQ(json->GetValue(SHADOW_TEST)->GetString("radius"), "0.000000");
171 EXPECT_EQ(json->GetValue(SHADOW_TEST)->GetString("color"), "#FF000000");
172 EXPECT_EQ(json->GetValue(SHADOW_TEST)->GetString("offsetX"), "0.000000");
173 EXPECT_EQ(json->GetValue(SHADOW_TEST)->GetString("offsetY"), "0.000000");
174 EXPECT_EQ(json->GetDouble("dynamicDimming"), 0.5);
175 }
176
177 /**
178 * @tc.name: GraphicsPropertyTest002
179 * @tc.desc: Test cast to RenderPropertyTestNg
180 * @tc.type: FUNC
181 */
182 HWTEST_F(RenderPropertyTestNg, GraphicsPropertyTest002, TestSize.Level1)
183 {
184 /**
185 * @tc.steps: step1. Build a object graphicsProperty.
186 */
187 NG::GraphicsProperty graphicsProperty;
188 auto json = JsonUtil::Create(true);
189 Shadow shadow(VALUE_TEST, OFFSETS, WHITE, ShadowStyle::None);
190
191 /**
192 * @tc.steps: step2. call ToJsonValue.push propBackShadow style_ == ShadowStyle::OuterDefaultXS.
193 * @tc.expected: Return expected results.
194 */
195 shadow.style_ = ShadowStyle::OuterDefaultXS;
196 graphicsProperty.propBackShadow = shadow;
197 graphicsProperty.ToJsonValue(json, filter);
198 EXPECT_EQ(json->GetString(SHADOW_TEST), "ShadowStyle.OuterDefaultXS");
199 json->Delete(SHADOW_TEST);
200
201 /**
202 * @tc.steps: step3. call ToJsonValue.push propBackShadow style_ == ShadowStyle::OuterDefaultSM.
203 * @tc.expected: Return expected results.
204 */
205 shadow.style_ = ShadowStyle::OuterDefaultSM;
206 graphicsProperty.propBackShadow = shadow;
207 graphicsProperty.ToJsonValue(json, filter);
208 EXPECT_EQ(json->GetString(SHADOW_TEST), "ShadowStyle.OuterDefaultSM");
209 json->Delete(SHADOW_TEST);
210 /**
211 * @tc.steps: step4. call ToJsonValue.push propBackShadow style_ == ShadowStyle::OuterDefaultMD.
212 * @tc.expected: Return expected results.
213 */
214 shadow.style_ = ShadowStyle::OuterDefaultMD;
215 graphicsProperty.propBackShadow = shadow;
216 graphicsProperty.ToJsonValue(json, filter);
217 EXPECT_EQ(json->GetString(SHADOW_TEST), "ShadowStyle.OuterDefaultMD");
218 json->Delete(SHADOW_TEST);
219
220 /**
221 * @tc.steps: step5. call ToJsonValue.push propBackShadow style_ == ShadowStyle::OuterDefaultLG.
222 * @tc.expected: Return expected results.
223 */
224 shadow.style_ = ShadowStyle::OuterDefaultLG;
225 graphicsProperty.propBackShadow = shadow;
226 graphicsProperty.ToJsonValue(json, filter);
227 EXPECT_EQ(json->GetString(SHADOW_TEST), "ShadowStyle.OuterDefaultLG");
228 json->Delete(SHADOW_TEST);
229
230 /**
231 * @tc.steps: step6. call ToJsonValue.push propBackShadow style_ == ShadowStyle::OuterFloatingSM.
232 * @tc.expected: Return expected results.
233 */
234 shadow.style_ = ShadowStyle::OuterFloatingSM;
235 graphicsProperty.propBackShadow = shadow;
236 graphicsProperty.ToJsonValue(json, filter);
237 EXPECT_EQ(json->GetString(SHADOW_TEST), "ShadowStyle.OuterFloatingSM");
238 json->Delete(SHADOW_TEST);
239
240 /**
241 * @tc.steps: step7. call ToJsonValue.push propBackShadow style_ == ShadowStyle::OuterFloatingMD.
242 * @tc.expected: Return expected results.
243 */
244 shadow.style_ = ShadowStyle::OuterFloatingMD;
245 graphicsProperty.propBackShadow = shadow;
246 graphicsProperty.ToJsonValue(json, filter);
247 EXPECT_EQ(json->GetString(SHADOW_TEST), "ShadowStyle.OuterFloatingMD");
248 json->Delete(SHADOW_TEST);
249 }
250
251 /**
252 * @tc.name: GraphicsPropertyTest003
253 * @tc.desc: Test cast to RenderPropertyTestNg
254 * @tc.type: FUNC
255 */
256 HWTEST_F(RenderPropertyTestNg, GraphicsPropertyTest003, TestSize.Level1)
257 {
258 /**
259 * @tc.steps: step1. Build a object graphicsProperty.
260 */
261 NG::GraphicsProperty graphicsProperty;
262 auto json = JsonUtil::Create(true);
263 Shadow shadow(VALUE_TEST, OFFSETS, WHITE, ShadowStyle::None);
264
265 /**
266 * @tc.steps: step2. call ToJsonValue.push propBackShadow colorStrategy_ == ShadowColorStrategy::AVERAGE.
267 * @tc.expected: Return expected results.
268 */
269 shadow.colorStrategy_ = ShadowColorStrategy::AVERAGE;
270 graphicsProperty.propBackShadow = shadow;
271 graphicsProperty.ToJsonValue(json, filter);
272 EXPECT_EQ(json->GetValue(SHADOW_TEST)->GetString("color"), "ColoringStrategy.AVERAGE");
273 json->Delete(SHADOW_TEST);
274
275 /**
276 * @tc.steps: step3. call ToJsonValue.push propBackShadow colorStrategy_ == ShadowColorStrategy::PRIMARY.
277 * @tc.expected: Return expected results.
278 */
279 shadow.colorStrategy_ = ShadowColorStrategy::PRIMARY;
280 graphicsProperty.propBackShadow = shadow;
281 graphicsProperty.ToJsonValue(json, filter);
282 EXPECT_EQ(json->GetValue(SHADOW_TEST)->GetString("color"), "ColoringStrategy.PRIMARY");
283 }
284
285 /**
286 * @tc.name: BackgroundPropertyTest001
287 * @tc.desc: Test cast to RenderPropertyTestNg
288 * @tc.type: FUNC
289 */
290 HWTEST_F(RenderPropertyTestNg, BackgroundPropertyTest001, TestSize.Level1)
291 {
292 /**
293 * @tc.steps: step1. Build a object backgroundProperty.
294 */
295 NG::BackgroundProperty backgroundProperty;
296 auto json = JsonUtil::Create(true);
297
298 /**
299 * @tc.steps: step2. call ToJsonValue.push propBackgroundImage is null.
300 * @tc.steps: step2. push propBackgroundImageSize is null.
301 * @tc.steps: step2. push propBackgroundImagePosition is null.
302 */
303 backgroundProperty.ToJsonValue(json, filter);
304
305 /**
306 * @tc.expected: Return expected results.
307 */
308 EXPECT_EQ(json->GetString("backgroundImage"), "NONE");
309 EXPECT_EQ(json->GetString("backgroundImageSize"), "ImageSize.Auto");
310 EXPECT_EQ(json->GetString("backgroundImagePosition"), "");
311 }
312
313 /**
314 * @tc.name: BackgroundPropertyTest002
315 * @tc.desc: Test cast to RenderPropertyTestNg
316 * @tc.type: FUNC
317 */
318 HWTEST_F(RenderPropertyTestNg, BackgroundPropertyTest002, TestSize.Level1)
319 {
320 /**
321 * @tc.steps: step1. Build a object backgroundProperty.
322 */
323 NG::BackgroundProperty backgroundProperty;
324 auto json = JsonUtil::Create(true);
325
326 /**
327 * @tc.steps: step2. call ToJsonValue.push propBackgroundImage is imageSourceInfo.
328 * @tc.steps: step2. push propBackgroundImageSize is BACKGROUND_SIZE.
329 * @tc.steps: step2. push propBackgroundImagePosition is BACKGROUND_POSITION.
330 */
331 ImageSourceInfo imageSourceInfo;
332 imageSourceInfo.src_ = SRC_IMAGES;
333 backgroundProperty.propBackgroundImage = imageSourceInfo;
334 backgroundProperty.propBackgroundImageSize = BACKGROUND_SIZE;
335 backgroundProperty.propBackgroundImagePosition = BACKGROUND_POSITION;
336 backgroundProperty.ToJsonValue(json, filter);
337
338 /**
339 * @tc.expected: Return expected results.
340 */
341 EXPECT_EQ(json->GetString("backgroundImage"), BACKGROUND_IMAGES);
342 EXPECT_EQ(json->GetString("backgroundImageSize"), "ImageSize.Cover");
343 EXPECT_EQ(json->GetString("backgroundImagePosition"), "Alignment.TopEnd");
344 }
345
346 /**
347 * @tc.name: ClipPropertytyTest001
348 * @tc.desc: Test cast to RenderPropertyTestNg
349 * @tc.type: FUNC
350 */
351 HWTEST_F(RenderPropertyTestNg, ClipPropertytyTest001, TestSize.Level1)
352 {
353 /**
354 * @tc.steps: step1. Build a object backgroundProperty.
355 */
356 NG::ClipProperty clipProperty;
357 auto json = JsonUtil::Create(true);
358
359 /**
360 * @tc.steps: step2. call ToJsonValue.push propClipShape is null.
361 * @tc.steps: step2. push propClipMask is null.
362 */
363 clipProperty.ToJsonValue(json, filter);
364
365 /**
366 * @tc.expected: Return expected results.
367 */
368 EXPECT_EQ(json->GetString("clip"), "false");
369 EXPECT_EQ(json->GetValue("mask")->GetString("shape"), "");
370 json->Delete("clip");
371 json->Delete("mask");
372
373 /**
374 * @tc.steps: step3. call ToJsonValue.push propClipShape is not null.
375 * @tc.steps: step3. push propClipMask is not null.
376 */
377 clipProperty.propClipShape = AceType::MakeRefPtr<BasicShape>();
378 clipProperty.propClipMask = AceType::MakeRefPtr<BasicShape>();
379 clipProperty.ToJsonValue(json, filter);
380
381 /**
382 * @tc.expected: Return expected results.
383 */
384 EXPECT_EQ(json->GetString("clip"), "{\"shape\":\"None\"}");
385 EXPECT_EQ(json->GetValue("mask")->GetString("shape"), "None");
386 }
387
388 /**
389 * @tc.name: GradientPropertyTest001
390 * @tc.desc: Test cast to RenderPropertyTestNg
391 * @tc.type: FUNC
392 */
393 HWTEST_F(RenderPropertyTestNg, GradientPropertyTest001, TestSize.Level1)
394 {
395 /**
396 * @tc.steps: step1. Build a object backgroundProperty.
397 */
398 NG::GradientProperty gradientProperty;
399 auto json = JsonUtil::Create(true);
400
401 /**
402 * @tc.steps: step2. call ToJsonValue.push propClipShape is null.
403 * @tc.steps: step2. push propClipMask is null.
404 */
405 gradientProperty.ToJsonValue(json, filter);
406
407 /**
408 * @tc.expected: Return expected results.
409 */
410
411 EXPECT_EQ(json->GetString("linearGradient"), "");
412 EXPECT_EQ(json->GetString("sweepGradient"), "");
413 EXPECT_EQ(json->GetString("radialGradient"), "");
414 json->Delete("linearGradient");
415 json->Delete("sweepGradient");
416 json->Delete("radialGradient");
417
418 /**
419 * @tc.steps: step3. call ToJsonValue.push propLinearGradient is not null.
420 * @tc.steps: step3. push propSweepGradient is not null.
421 * @tc.steps: step3. push propRadialGradient is not null.
422 */
423 NG::Gradient gradient;
424 gradientProperty.propLinearGradient = gradient;
425 gradientProperty.propSweepGradient = gradient;
426 gradientProperty.propRadialGradient = gradient;
427 gradientProperty.ToJsonValue(json, filter);
428
429 /**
430 * @tc.expected: Return expected results.
431 */
432 EXPECT_TRUE(gradientProperty.propLinearGradient.has_value());
433 EXPECT_TRUE(gradientProperty.propSweepGradient.has_value());
434 EXPECT_TRUE(gradientProperty.propRadialGradient.has_value());
435 }
436
437 /**
438 * @tc.name: TransformPropertyTest001
439 * @tc.desc: Test cast to RenderPropertyTestNg
440 * @tc.type: FUNC
441 */
442 HWTEST_F(RenderPropertyTestNg, TransformPropertyTest001, TestSize.Level1)
443 {
444 /**
445 * @tc.steps: step1. Build a object backgroundProperty.
446 */
447 NG::TransformProperty transformProperty;
448 auto json = JsonUtil::Create(true);
449
450 /**
451 * @tc.steps: step2. call ToJsonValue.push transformProperty is null.
452 */
453 transformProperty.ToJsonValue(json, filter);
454
455 /**
456 * @tc.expected: Return expected results.
457 */
458 EXPECT_EQ(json->GetString("rotate"), "");
459 EXPECT_EQ(json->GetString("scale"), "");
460 EXPECT_EQ(json->GetString("translate"), "");
461 json->Delete("rotate");
462 json->Delete("scale");
463 json->Delete("translate");
464
465 /**
466 * @tc.steps: step3. call ToJsonValue. push propTransformRotate is VECTOR_5F_TEST.
467 * @tc.steps: step3. push propTransformScale is VECTOR_TEST.
468 * @tc.steps: step3. push propTransformTranslate is PTTION_TEST.
469 */
470 transformProperty.propTransformRotate = VECTOR_5F_TEST;
471 transformProperty.propTransformScale = VECTOR_TEST;
472 transformProperty.propTransformTranslate = PTTION_TEST;
473 transformProperty.ToJsonValue(json, filter);
474
475 /**
476 * @tc.expected: Return expected results.
477 */
478 EXPECT_EQ(json->GetValue("rotate")->GetString("x"), "20.000000");
479 EXPECT_EQ(json->GetValue("rotate")->GetString("y"), "40.000000");
480 EXPECT_EQ(json->GetValue("rotate")->GetString("z"), "60.000000");
481 EXPECT_EQ(json->GetValue("rotate")->GetString("angle"), "80.000000");
482
483 EXPECT_EQ(json->GetValue("scale")->GetString("centerX"), "5000.00%");
484 EXPECT_EQ(json->GetValue("scale")->GetString("centerY"), "5000.00%");
485
486 EXPECT_EQ(json->GetValue("translate")->GetString("x"), "40.00px");
487 EXPECT_EQ(json->GetValue("translate")->GetString("y"), "80.00px");
488 EXPECT_EQ(json->GetValue("translate")->GetString("z"), "10.00px");
489 }
490
491 /**
492 * @tc.name: RenderPropertyTest001
493 * @tc.desc: Test cast to RenderPropertyTestNg
494 * @tc.type: FUNC
495 */
496 HWTEST_F(RenderPropertyTestNg, RenderPropertyTest001, TestSize.Level1)
497 {
498 /**
499 * @tc.steps: step1. Build a object renderPositionProperty.
500 */
501 NG::RenderPositionProperty renderPositionProperty;
502 NG::InspectorFilter testFilter;
503 auto jsonValue = JsonUtil::Create(true);
504 auto offset = NG::OffsetT<Dimension>(Dimension(1), Dimension(1));
505 renderPositionProperty.propOffset = offset;
506
507 /**
508 * @tc.steps: step2. call ToJsonValue.
509 */
510 auto context = PipelineContext::GetCurrentContext();
511 int32_t tempVersion = static_cast<int32_t>(context->GetMinPlatformVersion());
512 context->SetMinPlatformVersion(static_cast<int32_t>(PlatformVersion::VERSION_TEN));
513 renderPositionProperty.ToJsonValue(jsonValue, testFilter);
514 context->SetMinPlatformVersion(tempVersion);
515 EXPECT_EQ(jsonValue->GetValue("offset")->GetString("x"), "1.00px");
516 testFilter.AddFilterAttr("focusable");
517 renderPositionProperty.ToJsonValue(jsonValue, testFilter);
518 EXPECT_EQ(jsonValue->GetValue("offset")->GetString("x"), "1.00px");
519 }
520
521 /**
522 * @tc.name: RenderPropertyTest002
523 * @tc.desc: Test cast to RenderPropertyTestNg
524 * @tc.type: FUNC
525 */
526 HWTEST_F(RenderPropertyTestNg, RenderPropertyTest002, TestSize.Level1)
527 {
528 /**
529 * @tc.steps: step1. Build a object graphicsProperty.
530 */
531 NG::GraphicsProperty graphicsProperty;
532 NG::InspectorFilter testFilter;
533 auto jsonValue = JsonUtil::Create(true);
534 Shadow shadow(VALUE_TEST, OFFSETS, WHITE, ShadowStyle::None);
535 shadow.colorStrategy_ = ShadowColorStrategy::AVERAGE;
536 graphicsProperty.propBackShadow = shadow;
537 InvertOption option;
538 option.low_ = 1.0f;
539 option.high_ = 1.0f;
540 InvertVariant testInvert = option;
541 graphicsProperty.propFrontInvert = testInvert;
542 std::vector<std::pair<float, float>> fractionStops;
543 fractionStops.push_back(std::pair<float, float>(0.0f, 1.0f));
544 CalcDimension dimensionRadius(0.0);
545 NG::LinearGradientBlurPara blurPara(dimensionRadius, fractionStops, NG::GradientDirection::LEFT);
546 graphicsProperty.propLinearGradientBlur = blurPara;
547
548 /**
549 * @tc.steps: step2. call ToJsonValue.
550 */
551 graphicsProperty.ToJsonValue(jsonValue, testFilter);
552 EXPECT_EQ(jsonValue->GetValue(SHADOW_TEST)->GetString("color"), "ColoringStrategy.AVERAGE");
553 blurPara.direction_ = static_cast<NG::GradientDirection>(11); // 11 is not a valid GradientDirection.
554 graphicsProperty.propLinearGradientBlur = blurPara;
555 graphicsProperty.ToJsonValue(jsonValue, testFilter);
556 EXPECT_EQ(jsonValue->GetValue(SHADOW_TEST)->GetString("color"), "ColoringStrategy.AVERAGE");
557 testFilter.AddFilterAttr("focusable");
558 graphicsProperty.ToJsonValue(jsonValue, testFilter);
559 EXPECT_EQ(jsonValue->GetValue(SHADOW_TEST)->GetString("color"), "ColoringStrategy.AVERAGE");
560 }
561
562 /**
563 * @tc.name: RenderPropertyTest003
564 * @tc.desc: Test cast to RenderPropertyTestNg
565 * @tc.type: FUNC
566 */
567 HWTEST_F(RenderPropertyTestNg, RenderPropertyTest003, TestSize.Level1)
568 {
569 /**
570 * @tc.steps: step1. Build a object backgroundProperty.
571 */
572 NG::BackgroundProperty backgroundProperty;
573 NG::InspectorFilter testFilter;
574 auto jsonValue = JsonUtil::Create(true);
575 ImageSourceInfo imageSourceInfo;
576 imageSourceInfo.src_ = SRC_IMAGES;
577 backgroundProperty.propBackgroundImage = imageSourceInfo;
578 backgroundProperty.propBackgroundImageSize = BACKGROUND_SIZE;
579 backgroundProperty.propBackgroundImagePosition = BACKGROUND_POSITION;
580 backgroundProperty.propBackgroundImageRepeat = static_cast<ImageRepeat>(4); // 4 is not a valid ImageRepeat.
581
582 /**
583 * @tc.steps: step2. call ToJsonValue.
584 */
585 backgroundProperty.ToJsonValue(jsonValue, testFilter);
586 EXPECT_EQ(jsonValue->GetString("backgroundImage"), BACKGROUND_IMAGES);
587 EXPECT_EQ(jsonValue->GetString("backgroundImageSize"), "ImageSize.Cover");
588 EXPECT_EQ(jsonValue->GetString("backgroundImagePosition"), "Alignment.TopEnd");
589 testFilter.AddFilterAttr("focusable");
590 backgroundProperty.ToJsonValue(jsonValue, testFilter);
591 EXPECT_EQ(jsonValue->GetString("backgroundImage"), BACKGROUND_IMAGES);
592 EXPECT_EQ(jsonValue->GetString("backgroundImageSize"), "ImageSize.Cover");
593 EXPECT_EQ(jsonValue->GetString("backgroundImagePosition"), "Alignment.TopEnd");
594 }
595
596 /**
597 * @tc.name: RenderPropertyTest004
598 * @tc.desc: Test cast to RenderPropertyTestNg
599 * @tc.type: FUNC
600 */
601 HWTEST_F(RenderPropertyTestNg, RenderPropertyTest004, TestSize.Level1)
602 {
603 /**
604 * @tc.steps: step1. Build a object customBackgroundProperty.
605 */
606 NG::CustomBackgroundProperty customBackgroundProperty;
607 NG::InspectorFilter testFilter;
608 auto jsonValue = JsonUtil::Create(true);
609 customBackgroundProperty.propBackgroundAlign = Alignment::BOTTOM_RIGHT;
610
611 /**
612 * @tc.steps: step2. call ToJsonValue.
613 */
614 customBackgroundProperty.ToJsonValue(jsonValue, testFilter);
615 void* voidPtr = static_cast<void*>(new char[0]);
616 RefPtr<PixelMap> pixelMap = PixelMap::CreatePixelMap(voidPtr);
617 customBackgroundProperty.propBackgroundPixelMap = pixelMap;
618 customBackgroundProperty.ToJsonValue(jsonValue, testFilter);
619 EXPECT_EQ(jsonValue->GetString("backgroundAlign"), "Alignment (1.0, 1.0)");
620 testFilter.AddFilterAttr("focusable");
621 customBackgroundProperty.ToJsonValue(jsonValue, testFilter);
622 EXPECT_EQ(jsonValue->GetString("backgroundAlign"), "Alignment (1.0, 1.0)");
623 }
624
625 /**
626 * @tc.name: RenderPropertyTest005
627 * @tc.desc: Test cast to RenderPropertyTestNg
628 * @tc.type: FUNC
629 */
630 HWTEST_F(RenderPropertyTestNg, RenderPropertyTest005, TestSize.Level1)
631 {
632 /**
633 * @tc.steps: step1. Build a object foregroundProperty.
634 */
635 NG::ForegroundProperty foregroundProperty;
636 NG::InspectorFilter testFilter;
637 auto jsonValue = JsonUtil::Create(true);
638 MotionBlurOption motionBlurOption;
639 motionBlurOption.radius = 1.0;
640 motionBlurOption.anchor.x = 1.0;
641 motionBlurOption.anchor.y = 1.0;
642 foregroundProperty.propMotionBlur = motionBlurOption;
643 foregroundProperty.propForegroundEffect = 1.0f;
644
645 /**
646 * @tc.steps: step2. call ToJsonValue.
647 */
648 foregroundProperty.ToJsonValue(jsonValue, testFilter);
649 EXPECT_EQ(jsonValue->GetString("motionBlur"), "");
650 testFilter.AddFilterAttr("focusable");
651 foregroundProperty.ToJsonValue(jsonValue, testFilter);
652 EXPECT_EQ(jsonValue->GetString("motionBlur"), "");
653 }
654
655 /**
656 * @tc.name: RenderPropertyTest006
657 * @tc.desc: Test cast to RenderPropertyTestNg
658 * @tc.type: FUNC
659 */
660 HWTEST_F(RenderPropertyTestNg, RenderPropertyTest006, TestSize.Level1)
661 {
662 /**
663 * @tc.steps: step1. Build a object clipProperty.
664 */
665 NG::ClipProperty clipProperty;
666 NG::InspectorFilter testFilter;
667 auto jsonValue = JsonUtil::Create(true);
668 RefPtr<BasicShape> basicShape = AceType::MakeRefPtr<BasicShape>();
669 basicShape->SetBasicShapeType(static_cast<BasicShapeType>(7)); // 7 is not a valid BasicShapeType.
670 clipProperty.propClipShape = basicShape;
671 clipProperty.propClipMask = basicShape;
672
673 /**
674 * @tc.steps: step2. call ToJsonValue.
675 */
676 clipProperty.ToJsonValue(jsonValue, testFilter);
677 EXPECT_EQ(jsonValue->GetString("clip"), "{}");
678 testFilter.AddFilterAttr("focusable");
679 clipProperty.ToJsonValue(jsonValue, testFilter);
680 EXPECT_EQ(jsonValue->GetString("clip"), "{}");
681 }
682
683 /**
684 * @tc.name: RenderPropertyTest007
685 * @tc.desc: Test cast to RenderPropertyTestNg
686 * @tc.type: FUNC
687 */
688 HWTEST_F(RenderPropertyTestNg, RenderPropertyTest007, TestSize.Level1)
689 {
690 /**
691 * @tc.steps: step1. Build a object gradientProperty.
692 */
693 NG::GradientProperty gradientProperty;
694 NG::InspectorFilter testFilter;
695 auto jsonValue = JsonUtil::Create(true);
696 NG::Gradient gradient;
697 gradientProperty.propLinearGradient = gradient;
698
699 /**
700 * @tc.steps: step2. call ToJsonValue.
701 */
702 gradientProperty.ToJsonValue(jsonValue, testFilter);
703 EXPECT_TRUE(gradientProperty.propLinearGradient.has_value());
704 testFilter.AddFilterAttr("focusable");
705 gradientProperty.ToJsonValue(jsonValue, testFilter);
706 EXPECT_TRUE(gradientProperty.propLinearGradient.has_value());
707 }
708
709 /**
710 * @tc.name: RenderPropertyTest008
711 * @tc.desc: Test cast to RenderPropertyTestNg
712 * @tc.type: FUNC
713 */
714 HWTEST_F(RenderPropertyTestNg, RenderPropertyTest008, TestSize.Level1)
715 {
716 /**
717 * @tc.steps: step1. Build a object transformProperty.
718 */
719 NG::TransformProperty transformProperty;
720 NG::BorderProperty borderProperty;
721 NG::OuterBorderProperty outerBorderProperty;
722 NG::InspectorFilter testFilter;
723 auto jsonValue = JsonUtil::Create(true);
724 transformProperty.propTransformRotate = VECTOR_5F_TEST;
725 auto offset = DimensionOffset(Offset(1.0, 1.0));
726 offset.SetZ(1.0_px);
727 transformProperty.propTransformCenter = offset;
728
729 /**
730 * @tc.steps: step2. call ToJsonValue.
731 */
732 transformProperty.ToJsonValue(jsonValue, testFilter);
733 EXPECT_EQ(jsonValue->GetValue("rotate")->GetString("x"), "20.000000");
734 EXPECT_EQ(jsonValue->GetValue("rotate")->GetString("y"), "40.000000");
735 EXPECT_EQ(jsonValue->GetValue("rotate")->GetString("z"), "60.000000");
736 EXPECT_EQ(jsonValue->GetValue("rotate")->GetString("angle"), "80.000000");
737 testFilter.AddFilterAttr("focusable");
738 transformProperty.ToJsonValue(jsonValue, testFilter);
739 borderProperty.ToJsonValue(jsonValue, testFilter);
740 outerBorderProperty.ToJsonValue(jsonValue, testFilter);
741 EXPECT_EQ(jsonValue->GetValue("rotate")->GetString("x"), "20.000000");
742 EXPECT_EQ(jsonValue->GetValue("rotate")->GetString("y"), "40.000000");
743 EXPECT_EQ(jsonValue->GetValue("rotate")->GetString("z"), "60.000000");
744 EXPECT_EQ(jsonValue->GetValue("rotate")->GetString("angle"), "80.000000");
745 }
746
747 /**
748 * @tc.name: RenderPropertyTest009
749 * @tc.desc: Test cast to RenderPropertyTestNg
750 * @tc.type: FUNC
751 */
752 HWTEST_F(RenderPropertyTestNg, RenderPropertyTest009, TestSize.Level1)
753 {
754 /**
755 * @tc.steps: step1. Build a object pointLightProperty.
756 */
757 NG::PointLightProperty pointLightProperty;
758 NG::InspectorFilter testFilter;
759 auto jsonValue = JsonUtil::Create(true);
760 NG::TranslateOptions options { 0.0f, 0.0f, 0.0f };
761 pointLightProperty.propLightPosition = options;
762 pointLightProperty.propLightIntensity = 1.0;
763
764 /**
765 * @tc.steps: step2. call ToJsonValue.
766 */
767 pointLightProperty.ToJsonValue(jsonValue, testFilter);
768 EXPECT_EQ(jsonValue->GetValue("pointLight")->GetString("lightIntensity"), "");
769 testFilter.AddFilterAttr("focusable");
770 pointLightProperty.ToJsonValue(jsonValue, testFilter);
771 EXPECT_EQ(jsonValue->GetValue("pointLight")->GetString("lightIntensity"), "");
772 }
773 } // namespace OHOS::Ace
774