| 1 |
// -*- compile-command: "./test_single_testcase.sh TTestCastleShapes" -*- |
| 2 |
{ |
| 3 |
Copyright 2022-2022 Michalis Kamburelis. |
| 4 |
|
| 5 |
This file is part of "Castle Game Engine". |
| 6 |
|
| 7 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 8 |
included in this distribution, for details about the copyright. |
| 9 |
|
| 10 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
|
| 14 |
---------------------------------------------------------------------------- |
| 15 |
} |
| 16 |
|
| 17 |
{ Test CastleShapes unit. } |
| 18 |
unit TestCastleShapes; |
| 19 |
|
| 20 |
interface |
| 21 |
|
| 22 |
uses |
| 23 |
Classes, SysUtils, CastleTester; |
| 24 |
|
| 25 |
type |
| 26 |
TTestCastleShapes = class(TCastleTestCase) |
| 27 |
procedure TestShapeParentNodes; |
| 28 |
end; |
| 29 |
|
| 30 |
implementation |
| 31 |
|
| 32 |
uses CastleSceneCore, X3DNodes, CastleShapes; |
| 33 |
|
| 34 |
procedure TTestCastleShapes.TestShapeParentNodes; |
| 35 |
var |
| 36 |
Box: TBoxNode; |
| 37 |
Shape: TShapeNode; |
| 38 |
T1: TTransformNode; |
| 39 |
T2: TTransformNode; |
| 40 |
Shapes: TShapeList; |
| 41 |
RootNode: TX3DRootNode; |
| 42 |
Scene: TCastleSceneCore; |
| 43 |
begin |
| 44 |
Box := TBoxNode.CreateWithShape(Shape); |
| 45 |
Shape.X3DName := 'CommonShape'; |
| 46 |
|
| 47 |
T1 := TTransformNode.Create('T1'); |
| 48 |
T1.AddChildren(Shape); |
| 49 |
|
| 50 |
T2 := TTransformNode.Create('T2'); |
| 51 |
T2.AddChildren(Shape); |
| 52 |
|
| 53 |
RootNode := TX3DRootNode.Create('Root'); |
| 54 |
RootNode.AddChildren(T1); |
| 55 |
RootNode.AddChildren(T2); |
| 56 |
RootNode.AddChildren(Shape); |
| 57 |
|
| 58 |
Scene := TCastleSceneCore.Create(nil); |
| 59 |
try |
| 60 |
Scene.Load(RootNode, true); |
| 61 |
|
| 62 |
Shapes := Scene.Shapes.TraverseList(true); |
| 63 |
AssertEquals(3, Shapes.Count); |
| 64 |
|
| 65 |
AssertTrue(Shapes[0].OriginalGeometry = Box); |
| 66 |
AssertTrue(Shapes[0].Node = Shape); |
| 67 |
AssertTrue(Shapes[0].GeometryParentNode = Shape); |
| 68 |
AssertTrue(Shapes[0].GeometryGrandParentNode = T1); |
| 69 |
AssertTrue(Shapes[0].GeometryGrandGrandParentNode = RootNode); |
| 70 |
AssertEquals('CommonShape', Shapes[0].GeometryParentNodeName); |
| 71 |
AssertEquals('T1', Shapes[0].GeometryGrandParentNodeName); |
| 72 |
AssertEquals('Root', Shapes[0].GeometryGrandGrandParentNodeName); |
| 73 |
|
| 74 |
AssertTrue(Shapes[1].OriginalGeometry = Box); |
| 75 |
AssertTrue(Shapes[1].Node = Shape); |
| 76 |
AssertTrue(Shapes[1].GeometryParentNode = Shape); |
| 77 |
AssertTrue(Shapes[1].GeometryGrandParentNode = T2); |
| 78 |
AssertTrue(Shapes[1].GeometryGrandGrandParentNode = RootNode); |
| 79 |
AssertEquals('CommonShape', Shapes[1].GeometryParentNodeName); |
| 80 |
AssertEquals('T2', Shapes[1].GeometryGrandParentNodeName); |
| 81 |
AssertEquals('Root', Shapes[1].GeometryGrandGrandParentNodeName); |
| 82 |
|
| 83 |
AssertTrue(Shapes[2].OriginalGeometry = Box); |
| 84 |
AssertTrue(Shapes[2].Node = Shape); |
| 85 |
AssertTrue(Shapes[2].GeometryParentNode = Shape); |
| 86 |
AssertTrue(Shapes[2].GeometryGrandParentNode = RootNode); |
| 87 |
AssertTrue(Shapes[2].GeometryGrandGrandParentNode = nil); |
| 88 |
AssertEquals('CommonShape', Shapes[2].GeometryParentNodeName); |
| 89 |
AssertEquals('Root', Shapes[2].GeometryGrandParentNodeName); |
| 90 |
AssertEquals('', Shapes[2].GeometryGrandGrandParentNodeName); |
| 91 |
finally FreeAndNil(Scene) end; |
| 92 |
end; |
| 93 |
|
| 94 |
initialization |
| 95 |
RegisterTest(TTestCastleShapes); |
| 96 |
end. |