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