1 /* 2 * Copyright (c) 2022 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 <vector> 17 18 #include "gtest/gtest.h" 19 20 #define private public 21 #define protected public 22 23 #include "base_shape_pattern_test_ng.h" 24 #include "test/mock/core/rosen/mock_canvas.h" 25 26 #include "base/geometry/axis.h" 27 #include "base/geometry/dimension.h" 28 #include "base/geometry/ng/size_t.h" 29 #include "core/components/common/properties/color.h" 30 #include "core/components_ng/base/ui_node.h" 31 #include "core/components_ng/base/view_stack_processor.h" 32 #include "core/components_ng/pattern/shape/circle_model_ng.h" 33 #include "core/components_ng/pattern/shape/circle_pattern.h" 34 #include "core/components_ng/pattern/shape/ellipse_model_ng.h" 35 #include "core/components_ng/pattern/shape/shape_abstract_model_ng.h" 36 #include "core/components_ng/pattern/shape/shape_container_layout_algorithm.h" 37 #include "core/components_ng/pattern/shape/shape_container_paint_property.h" 38 #include "core/components_ng/pattern/shape/shape_container_pattern.h" 39 #include "core/components_ng/pattern/shape/shape_model_ng.h" 40 #include "core/components_ng/pattern/shape/shape_pattern.h" 41 42 using namespace testing; 43 using namespace testing::ext; 44 45 namespace OHOS::Ace::NG { 46 47 namespace { 48 const float ZERO = 0.0; 49 const float LEFT = -20.0f; 50 const float TOP = -30.0f; 51 const int32_t COLUMN = 2; 52 const int32_t ROW = 3; 53 std::vector<double> MESH = { 1, 2, 4, 6, 4, 2, 1, 3, 5, 1, 3, 5, 6, 3, 2, 2, 4, 5, 5, 3, 2, 2, 2, 4 }; 54 const float CONTAINER_WIDTH = 300.0f; 55 const float CONTAINER_HEIGHT = 300.0f; 56 const float FIRST_ITEM_WIDTH = 150.0f; 57 const float FIRST_ITEM_HEIGHT = 75.0f; 58 const float MAIN_SIZE = 600.0f; 59 const SizeF FIRST_ITEM_SIZE(FIRST_ITEM_WIDTH, FIRST_ITEM_HEIGHT); 60 } // namespace 61 62 class ShapePatternTestNg : public BaseShapePatternTestNg { 63 public: CreadFrameNode()64 RefPtr<FrameNode> CreadFrameNode() override 65 { 66 return nullptr; 67 } 68 Draw(RefPtr<FrameNode> frameNode)69 void Draw(RefPtr<FrameNode> frameNode) override {} 70 }; 71 72 /** 73 * @tc.name: LayoutAlgorithm001 74 * @tc.desc: create shape with width And height 75 * @tc.type: FUNC 76 */ 77 78 HWTEST_F(ShapePatternTestNg, LayoutAlgorithm001, TestSize.Level1) 79 { 80 ShapeModelNG().Create(); 81 auto width = Dimension(WIDTH); 82 auto height = Dimension(HEIGHT); 83 auto shapeAbstactModel = ShapeAbstractModelNG(); 84 shapeAbstactModel.SetWidth(width); 85 shapeAbstactModel.SetHeight(height); 86 RefPtr<UINode> uiNode = ViewStackProcessor::GetInstance()->Finish(); 87 RefPtr<FrameNode> frameNode = AceType::DynamicCast<FrameNode>(uiNode); 88 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 89 EXPECT_NE(geometryNode, nullptr); 90 RefPtr<LayoutWrapperNode> layoutWrapper = 91 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty()); 92 EXPECT_EQ(frameNode == nullptr, false); 93 auto pattern = frameNode->GetPattern<ShapeContainerPattern>(); 94 EXPECT_EQ(pattern == nullptr, false); 95 auto layoutProperty = frameNode->GetLayoutProperty(); 96 EXPECT_EQ(layoutProperty == nullptr, false); 97 auto layoutAlgorithm = AceType::DynamicCast<BoxLayoutAlgorithm>(pattern->CreateLayoutAlgorithm()); 98 EXPECT_EQ(layoutAlgorithm == nullptr, false); 99 LayoutConstraintF layoutConstraint; 100 layoutConstraint.percentReference.SetWidth(WIDTH); 101 layoutConstraint.percentReference.SetHeight(HEIGHT); 102 layoutConstraint.selfIdealSize.SetWidth(WIDTH); 103 layoutConstraint.selfIdealSize.SetHeight(HEIGHT); 104 layoutProperty->UpdateLayoutConstraint(layoutConstraint); 105 layoutProperty->UpdateContentConstraint(); 106 auto size = layoutAlgorithm->MeasureContent( 107 layoutProperty->CreateContentConstraint(), AccessibilityManager::RawPtr(layoutWrapper)); 108 EXPECT_EQ(size.has_value(), true); 109 EXPECT_FLOAT_EQ(size.value().Width(), WIDTH); 110 EXPECT_FLOAT_EQ(size.value().Height(), HEIGHT); 111 } 112 113 /** 114 * @tc.name: ContainerPaintProperty001 115 * @tc.desc: create shape with viewport 116 * @tc.type: FUNC 117 */ 118 119 HWTEST_F(ShapePatternTestNg, ContainerPaintProperty001, TestSize.Level1) 120 { 121 auto shapeModel = ShapeModelNG(); 122 shapeModel.Create(); 123 shapeModel.SetViewPort(Dimension(LEFT), Dimension(TOP), Dimension(WIDTH), Dimension(HEIGHT)); 124 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->GetMainElementNode()); 125 EXPECT_EQ(frameNode == nullptr, false); 126 ViewStackProcessor::GetInstance()->Pop(); 127 auto paintProperty = frameNode->GetPaintProperty<ShapeContainerPaintProperty>(); 128 EXPECT_EQ(paintProperty == nullptr, false); 129 EXPECT_EQ(paintProperty->HasShapeViewBox(), true); 130 EXPECT_EQ(paintProperty->GetShapeViewBoxValue().Left().ConvertToPx(), LEFT); 131 EXPECT_EQ(paintProperty->GetShapeViewBoxValue().Top().ConvertToPx(), TOP); 132 EXPECT_EQ(paintProperty->GetShapeViewBoxValue().Width().ConvertToPx(), WIDTH); 133 EXPECT_EQ(paintProperty->GetShapeViewBoxValue().Height().ConvertToPx(), HEIGHT); 134 auto pattern = frameNode->GetPattern<ShapeContainerPattern>(); 135 EXPECT_EQ(paintProperty == nullptr, false); 136 RefPtr<LayoutWrapperNode> layoutWrapper = frameNode->CreateLayoutWrapper(true, true); 137 EXPECT_EQ(layoutWrapper == nullptr, false); 138 frameNode->SetActive(true); 139 frameNode->SwapDirtyLayoutWrapperOnMainThread(layoutWrapper); 140 } 141 142 /** 143 * @tc.name: ContainerPaintProperty002 144 * @tc.desc: create shape with mesh 145 * @tc.type: FUNC 146 */ 147 148 HWTEST_F(ShapePatternTestNg, ContainerPaintProperty002, TestSize.Level1) 149 { 150 auto shapeModel = ShapeModelNG(); 151 shapeModel.Create(); 152 shapeModel.SetBitmapMesh(MESH, COLUMN, ROW); 153 RefPtr<UINode> uiNode = ViewStackProcessor::GetInstance()->Finish(); 154 RefPtr<FrameNode> frameNode = AceType::DynamicCast<FrameNode>(uiNode); 155 EXPECT_EQ(frameNode == nullptr, false); 156 auto paintProperty = frameNode->GetPaintProperty<ShapeContainerPaintProperty>(); 157 EXPECT_EQ(paintProperty == nullptr, false); 158 EXPECT_EQ(paintProperty->HasImageMesh(), true); 159 EXPECT_EQ(paintProperty->GetImageMeshValue().GetColumn(), COLUMN); 160 EXPECT_EQ(paintProperty->GetImageMeshValue().GetRow(), ROW); 161 auto mesh = paintProperty->GetImageMeshValue().GetMesh(); 162 auto size = static_cast<int32_t>(mesh.size()); 163 EXPECT_EQ(size, (COLUMN + 1) * (ROW + 1) * 2); 164 EXPECT_EQ(size, MESH.size()); 165 for (int32_t i = 0; i < size; i++) { 166 EXPECT_EQ(mesh.at(i), MESH.at(i)); 167 } 168 } 169 170 /** 171 * @tc.name: InheritedProperty001 172 * @tc.desc: check property inherit 173 * @tc.type: FUNC 174 */ 175 176 HWTEST_F(ShapePatternTestNg, InheritedProperty001, TestSize.Level1) 177 { 178 auto shapeModel1 = ShapeModelNG(); 179 shapeModel1.Create(); 180 shapeModel1.SetFill(Color::RED); 181 shapeModel1.SetFillOpacity(OPACITY); 182 auto shapeModel2 = ShapeModelNG(); 183 shapeModel2.Create(); 184 shapeModel2.SetStroke(Color::BLUE); 185 shapeModel2.SetStrokeWidth(Dimension(STROKE_WIDTH)); 186 auto len = static_cast<int32_t>(STROKE_DASH_ARRAY.size()); 187 std::vector<Dimension> strokeDashArray(len); 188 for (int32_t i = 0; i < len; i++) { 189 strokeDashArray[i] = Dimension(STROKE_DASH_ARRAY.at(i)); 190 } 191 shapeModel2.SetStrokeDashArray(strokeDashArray); 192 shapeModel2.SetStrokeDashOffset(Dimension(DASHOFFSET)); 193 shapeModel2.SetStrokeLineCap(LINE_CAP); 194 shapeModel2.SetStrokeLineJoin(LINE_JOIN); 195 shapeModel2.SetStrokeMiterLimit(STROKE_LIMIT); 196 shapeModel2.SetAntiAlias(ANTIALIAS); 197 shapeModel2.SetStrokeOpacity(OPACITY); 198 auto circleModel = CircleModelNG(); 199 circleModel.Create(); 200 auto shapeAbstactModel = ShapeAbstractModelNG(); 201 SetSize(shapeAbstactModel); 202 auto circleFrameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->GetMainElementNode()); 203 ViewStackProcessor::GetInstance()->Pop(); 204 ViewStackProcessor::GetInstance()->Pop(); 205 ViewStackProcessor::GetInstance()->Pop(); 206 auto pattern = circleFrameNode->GetPattern<CirclePattern>(); 207 EXPECT_EQ(pattern == nullptr, false); 208 auto layoutProperty = circleFrameNode->GetLayoutProperty(); 209 EXPECT_EQ(layoutProperty == nullptr, false); 210 auto layoutAlgorithm = AceType::DynamicCast<ShapeLayoutAlgorithm>(pattern->CreateLayoutAlgorithm()); 211 EXPECT_EQ(layoutAlgorithm == nullptr, false); 212 LayoutConstraintF layoutConstraint; 213 layoutConstraint.percentReference.SetWidth(WIDTH); 214 layoutConstraint.percentReference.SetHeight(HEIGHT); 215 layoutConstraint.selfIdealSize.SetWidth(WIDTH); 216 layoutConstraint.selfIdealSize.SetHeight(HEIGHT); 217 layoutProperty->UpdateLayoutConstraint(layoutConstraint); 218 layoutProperty->UpdateContentConstraint(); 219 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 220 ASSERT_NE(geometryNode, nullptr); 221 LayoutWrapperNode layoutWrapper = 222 LayoutWrapperNode(circleFrameNode, geometryNode, circleFrameNode->GetLayoutProperty()); 223 auto size = layoutAlgorithm->MeasureContent(layoutProperty->CreateContentConstraint(), &layoutWrapper); 224 EXPECT_EQ(size.has_value(), true); 225 auto paintMethod = pattern->CreateNodePaintMethod(); 226 EXPECT_EQ(paintMethod == nullptr, false); 227 circleFrameNode->GetGeometryNode()->SetContentSize(size.value()); 228 auto paintWrapper = AceType::MakeRefPtr<PaintWrapper>(circleFrameNode->GetRenderContext(), 229 circleFrameNode->GetGeometryNode()->Clone(), circleFrameNode->GetPaintProperty<ShapePaintProperty>()); 230 EXPECT_EQ(paintWrapper == nullptr, false); 231 auto contentDraw = paintMethod->GetContentDrawFunction(AceType::RawPtr(paintWrapper)); 232 EXPECT_EQ(contentDraw == nullptr, false); 233 std::shared_ptr<SkCanvas> canvas = std::make_shared<SkCanvas>(); 234 Testing::MockCanvas rsCavas(&canvas); 235 auto shapePaintProperty = AceType::DynamicCast<ShapePaintProperty>(paintWrapper->GetPaintProperty()->Clone()); 236 if (!shapePaintProperty->HasStrokeWidth() || !NearZero(shapePaintProperty->GetStrokeWidth()->Value())) { 237 EXPECT_CALL(rsCavas, AttachPen(_)).WillOnce(ReturnRef(rsCavas)); 238 } 239 EXPECT_CALL(rsCavas, AttachBrush(_)).WillOnce(ReturnRef(rsCavas)); 240 EXPECT_CALL(rsCavas, DrawCircle(_, _)).WillOnce(Return()); 241 EXPECT_CALL(rsCavas, DetachPen()).WillOnce(ReturnRef(rsCavas)); 242 EXPECT_CALL(rsCavas, DetachBrush()).WillOnce(ReturnRef(rsCavas)); 243 contentDraw(rsCavas); 244 } 245 246 /** 247 * @tc.name: MeasureContent001 248 * @tc.desc: check ShapeContainerLayoutAlgorithm MeasureContent when ShapeViewBox is invaild 249 * @tc.type: FUNC 250 */ 251 252 HWTEST_F(ShapePatternTestNg, MeasureContent001, TestSize.Level1) 253 { 254 auto shapeModel = ShapeModelNG(); 255 shapeModel.Create(); 256 shapeModel.SetBitmapMesh(MESH, COLUMN, ROW); 257 RefPtr<UINode> uiNode = ViewStackProcessor::GetInstance()->Finish(); 258 RefPtr<FrameNode> frameNode = AceType::DynamicCast<FrameNode>(uiNode); 259 EXPECT_TRUE(frameNode); 260 auto paintProperty = frameNode->GetPaintProperty<ShapeContainerPaintProperty>(); 261 EXPECT_TRUE(paintProperty); 262 auto pattern = frameNode->GetPattern<ShapeContainerPattern>(); 263 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 264 EXPECT_TRUE(geometryNode); 265 RefPtr<LayoutWrapperNode> layoutWrapper = 266 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty()); 267 LayoutConstraintF constrain; 268 auto layoutAlgorithm = pattern->CreateLayoutAlgorithm(); 269 auto newSize = layoutAlgorithm->MeasureContent(constrain, AccessibilityManager::RawPtr(layoutWrapper)); 270 LayoutConstraintF constrain2; 271 constrain2.selfIdealSize = OptionalSize<float>(std::nullopt, std::nullopt); 272 newSize = layoutAlgorithm->MeasureContent(constrain2, AccessibilityManager::RawPtr(layoutWrapper)); 273 EXPECT_TRUE(newSize); 274 } 275 276 /** 277 * @tc.name: MeasureContent002 278 * @tc.desc: check ShapeContainerLayoutAlgorithm MeasureContent when ShapeViewBox is vaild 279 * @tc.type: FUNC 280 */ 281 282 HWTEST_F(ShapePatternTestNg, MeasureContent002, TestSize.Level1) 283 { 284 auto shapeModel = ShapeModelNG(); 285 shapeModel.Create(); 286 shapeModel.SetBitmapMesh(MESH, COLUMN, ROW); 287 /** 288 * @tc.desc: set HasShapeViewBox() == TRUE && GetShapeViewBoxValue().IsValid() == FALSE; 289 */ 290 shapeModel.SetViewPort(Dimension(ZERO), Dimension(ZERO), Dimension(ZERO), Dimension(ZERO)); 291 RefPtr<UINode> uiNode = ViewStackProcessor::GetInstance()->Finish(); 292 RefPtr<FrameNode> frameNode = AceType::DynamicCast<FrameNode>(uiNode); 293 EXPECT_TRUE(frameNode); 294 auto paintProperty = frameNode->GetPaintProperty<ShapeContainerPaintProperty>(); 295 EXPECT_TRUE(paintProperty); 296 EXPECT_TRUE(paintProperty->HasShapeViewBox()); 297 EXPECT_EQ(paintProperty->GetShapeViewBoxValue().IsValid(), false); 298 auto pattern = frameNode->GetPattern<ShapeContainerPattern>(); 299 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 300 EXPECT_TRUE(geometryNode); 301 RefPtr<LayoutWrapperNode> layoutWrapper = 302 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty()); 303 LayoutConstraintF constrain; 304 auto layoutAlgorithm = pattern->CreateLayoutAlgorithm(); 305 /** 306 * @tc.desc: Call MeasureContent(selfIdealSize != Null && selfIdealSize.IsValid == TRUE) 307 */ 308 auto newSize = layoutAlgorithm->MeasureContent(constrain, AccessibilityManager::RawPtr(layoutWrapper)); 309 EXPECT_TRUE(newSize); 310 } 311 312 /** 313 * @tc.name: MeasureContent003 314 * @tc.desc: check ShapeContainerLayoutAlgorithm MeasureContent when selfIdealSize is vaild/invaild 315 * @tc.type: FUNC 316 */ 317 318 HWTEST_F(ShapePatternTestNg, MeasureContent003, TestSize.Level1) 319 { 320 auto shapeModel = ShapeModelNG(); 321 shapeModel.Create(); 322 shapeModel.SetBitmapMesh(MESH, COLUMN, ROW); 323 /** 324 * @tc.desc: set HasShapeViewBox() == TRUE && GetShapeViewBoxValue().IsValid() == TRUE; 325 */ 326 shapeModel.SetViewPort(Dimension(LEFT), Dimension(TOP), Dimension(WIDTH), Dimension(HEIGHT)); 327 RefPtr<UINode> uiNode = ViewStackProcessor::GetInstance()->Finish(); 328 RefPtr<FrameNode> frameNode = AceType::DynamicCast<FrameNode>(uiNode); 329 EXPECT_TRUE(frameNode); 330 auto paintProperty = frameNode->GetPaintProperty<ShapeContainerPaintProperty>(); 331 EXPECT_TRUE(paintProperty); 332 EXPECT_TRUE(paintProperty->HasShapeViewBox()); 333 EXPECT_TRUE(paintProperty->GetShapeViewBoxValue().IsValid()); 334 auto pattern = frameNode->GetPattern<ShapeContainerPattern>(); 335 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 336 EXPECT_TRUE(geometryNode); 337 RefPtr<LayoutWrapperNode> layoutWrapper = 338 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty()); 339 /** 340 * @tc.desc: Call MeasureContent(selfIdealSize == Null && GreatNotEqual == TRUE) 341 */ 342 LayoutConstraintF constrain; 343 constrain.selfIdealSize = OptionalSize<float>(std::nullopt, std::nullopt); 344 auto layoutAlgorithm = pattern->CreateLayoutAlgorithm(); 345 auto newSize = layoutAlgorithm->MeasureContent(constrain, AccessibilityManager::RawPtr(layoutWrapper)); 346 /** 347 * @tc.desc: Call MeasureContent(selfIdealSize != Null && selfIdealSize.IsValid != TRUE) 348 */ 349 LayoutConstraintF constrain2; 350 constrain2.selfIdealSize = OptionalSize<float>(0, 0); 351 newSize = layoutAlgorithm->MeasureContent(constrain2, AccessibilityManager::RawPtr(layoutWrapper)); 352 /** 353 * @tc.desc: Call MeasureContent(selfIdealSize != Null && selfIdealSize.IsValid == TRUE && 354 * (hasDefineWidth && !hasDefineHeight && GreatNotEqual(portWidth, 0.0))) 355 */ 356 LayoutConstraintF constrain3; 357 constrain3.selfIdealSize = OptionalSize<float>(-1, std::nullopt); 358 newSize = layoutAlgorithm->MeasureContent(constrain3, AccessibilityManager::RawPtr(layoutWrapper)); 359 /** 360 * @tc.desc: Call MeasureContent(selfIdealSize != Null && selfIdealSize.IsValid != TRUE && 361 * (!hasDefineWidth && hasDefineHeight && GreatNotEqual(portHeight, 0.0))) 362 */ 363 LayoutConstraintF constrain4; 364 constrain4.selfIdealSize = OptionalSize<float>(std::nullopt, -1); 365 newSize = layoutAlgorithm->MeasureContent(constrain4, AccessibilityManager::RawPtr(layoutWrapper)); 366 } 367 368 /** 369 * @tc.name: GetChildrenSize 370 * @tc.desc: check ShapeContainerLayoutAlgorithm GetChildrenSize 371 * @tc.type: FUNC 372 */ 373 374 HWTEST_F(ShapePatternTestNg, GetChildrenSize001, TestSize.Level1) 375 { 376 auto shapeModel = ShapeModelNG(); 377 shapeModel.Create(); 378 shapeModel.SetBitmapMesh(MESH, COLUMN, ROW); 379 RefPtr<UINode> uiNode = ViewStackProcessor::GetInstance()->Finish(); 380 RefPtr<FrameNode> frameNode = AceType::DynamicCast<FrameNode>(uiNode); 381 EXPECT_TRUE(frameNode); 382 auto paintProperty = frameNode->GetPaintProperty<ShapeContainerPaintProperty>(); 383 EXPECT_TRUE(paintProperty); 384 auto pattern = frameNode->GetPattern<ShapeContainerPattern>(); 385 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 386 EXPECT_TRUE(geometryNode); 387 RefPtr<LayoutWrapperNode> layoutWrapper = 388 AceType::MakeRefPtr<LayoutWrapperNode>(frameNode, geometryNode, frameNode->GetLayoutProperty()); 389 auto layoutAlgorithm = pattern->CreateLayoutAlgorithm(); 390 auto shapeContainerLayoutAlgorithm = AceType::DynamicCast<ShapeContainerLayoutAlgorithm>(layoutAlgorithm); 391 auto childFrame = 392 shapeContainerLayoutAlgorithm->GetChildrenSize(AccessibilityManager::RawPtr(layoutWrapper), SizeF(0, 0)); 393 EXPECT_TRUE(childFrame.IsNonNegative()); 394 } 395 396 /** 397 * @tc.name: GetChildrenSize 398 * @tc.desc: check ShapeContainerLayoutAlgorithm GetChildrenSize 399 * @tc.type: FUNC 400 */ 401 HWTEST_F(ShapePatternTestNg, GetChildrenSize002, TestSize.Level1) 402 { 403 ShapeModelNG().Create(); 404 auto frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->GetMainElementNode()); 405 EXPECT_FALSE(frameNode == nullptr); 406 CircleModelNG().Create(); 407 auto firstItem = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->GetMainElementNode()); 408 EXPECT_FALSE(firstItem == nullptr); 409 /** 410 * @tc.desc: create parent and child framenode 411 */ 412 frameNode->AddChild(firstItem); 413 414 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>(); 415 ASSERT_NE(geometryNode, nullptr); 416 geometryNode->SetFrameSize(SizeF(CONTAINER_WIDTH, CONTAINER_HEIGHT)); 417 LayoutWrapperNode layoutWrapper = LayoutWrapperNode(frameNode, geometryNode, frameNode->GetLayoutProperty()); 418 419 auto framePattern = frameNode->GetPattern<ShapeContainerPattern>(); 420 EXPECT_FALSE(framePattern == nullptr); 421 auto layoutAlgorithm = framePattern->CreateLayoutAlgorithm(); 422 auto shapeContainerLayoutAlgorithm = AceType::DynamicCast<ShapeContainerLayoutAlgorithm>(layoutAlgorithm); 423 layoutWrapper.SetLayoutAlgorithm( 424 AccessibilityManager::MakeRefPtr<LayoutAlgorithmWrapper>(shapeContainerLayoutAlgorithm)); 425 /** 426 * @tc.desc: Set Parent LayoutConstraint 427 */ 428 LayoutConstraintF parentLayoutConstrain; 429 parentLayoutConstrain.selfIdealSize = OptionalSize<float>(CONTAINER_WIDTH, CONTAINER_HEIGHT); 430 parentLayoutConstrain.percentReference = SizeF(CONTAINER_WIDTH, CONTAINER_HEIGHT); 431 firstItem->GetGeometryNode()->SetParentLayoutConstraint(parentLayoutConstrain); 432 EXPECT_TRUE(firstItem->GetGeometryNode()->GetParentLayoutConstraint()); 433 434 auto childLayoutConstraint = layoutWrapper.GetLayoutProperty()->CreateChildConstraint(); 435 childLayoutConstraint.selfIdealSize = OptionalSizeF(FIRST_ITEM_SIZE); 436 437 /** 438 * @tc.desc: set child GeometryNode MarginFrameSize 439 * Call GetChildrenSize(childSize.Width() > 0 && childSize.Height() > 0) 440 */ 441 RefPtr<GeometryNode> firstGeometryNode = AceType::MakeRefPtr<GeometryNode>(); 442 firstGeometryNode->SetFrameSize(SizeF(CONTAINER_WIDTH, CONTAINER_HEIGHT)); 443 firstGeometryNode->GetMarginFrameSize().SetMainSize(MAIN_SIZE, Axis::HORIZONTAL); 444 445 RefPtr<LayoutWrapperNode> firstLayoutWrapper = 446 AceType::MakeRefPtr<LayoutWrapperNode>(firstItem, firstGeometryNode, firstItem->GetLayoutProperty()); 447 EXPECT_FALSE(firstLayoutWrapper == nullptr); 448 auto firstItemPattern = firstItem->GetPattern<CirclePattern>(); 449 EXPECT_FALSE(firstItemPattern == nullptr); 450 firstLayoutWrapper->GetLayoutProperty()->UpdateLayoutConstraint(childLayoutConstraint); 451 firstLayoutWrapper->GetLayoutProperty()->UpdateUserDefinedIdealSize( 452 CalcSize(CalcLength(FIRST_ITEM_WIDTH), CalcLength(FIRST_ITEM_HEIGHT))); 453 layoutWrapper.AppendChild(firstLayoutWrapper); 454 455 /** 456 * @tc.desc: set child2 GeometryNode MarginFrameSize == NULL 457 * Call GetChildrenSize(childSize.Width() == 0 && childSize.Height() == 0) 458 */ 459 RefPtr<GeometryNode> secondGeometryNode = AceType::MakeRefPtr<GeometryNode>(); 460 secondGeometryNode->Reset(); 461 RefPtr<LayoutWrapperNode> secondLayoutWrapper = 462 AceType::MakeRefPtr<LayoutWrapperNode>(firstItem, secondGeometryNode, firstItem->GetLayoutProperty()); 463 EXPECT_FALSE(secondLayoutWrapper == nullptr); 464 secondLayoutWrapper->GetLayoutProperty()->UpdateLayoutConstraint(childLayoutConstraint); 465 secondLayoutWrapper->GetLayoutProperty()->UpdateUserDefinedIdealSize( 466 CalcSize(CalcLength(FIRST_ITEM_WIDTH), CalcLength(FIRST_ITEM_HEIGHT))); 467 layoutWrapper.AppendChild(secondLayoutWrapper); 468 auto childFrame = shapeContainerLayoutAlgorithm->GetChildrenSize(&layoutWrapper, SizeF(0, 0)); 469 EXPECT_TRUE(childFrame.IsNonNegative()); 470 } 471 } // namespace OHOS::Ace::NG