File: testcastleshapes.pas

package info (click to toggle)
castle-game-engine 7.0~alpha.3%2Bdfsg2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 969,476 kB
  • sloc: pascal: 911,523; javascript: 28,186; cpp: 14,157; xml: 9,939; ansic: 9,229; java: 3,653; objc: 2,737; sh: 1,214; makefile: 657; php: 65; lisp: 21; ruby: 8
file content (96 lines) | stat: -rw-r--r-- 3,048 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// -*- compile-command: "./test_single_testcase.sh TTestCastleShapes" -*-
{
  Copyright 2022-2022 Michalis Kamburelis.

  This file is part of "Castle Game Engine".

  "Castle Game Engine" is free software; see the file COPYING.txt,
  included in this distribution, for details about the copyright.

  "Castle Game Engine" is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

  ----------------------------------------------------------------------------
}

{ Test CastleShapes unit. }
unit TestCastleShapes;

interface

uses
  Classes, SysUtils, CastleTester;

type
  TTestCastleShapes = class(TCastleTestCase)
    procedure TestShapeParentNodes;
  end;

implementation

uses CastleSceneCore, X3DNodes, CastleShapes;

procedure TTestCastleShapes.TestShapeParentNodes;
var
  Box: TBoxNode;
  Shape: TShapeNode;
  T1: TTransformNode;
  T2: TTransformNode;
  Shapes: TShapeList;
  RootNode: TX3DRootNode;
  Scene: TCastleSceneCore;
begin
  Box := TBoxNode.CreateWithShape(Shape);
  Shape.X3DName := 'CommonShape';

  T1 := TTransformNode.Create('T1');
  T1.AddChildren(Shape);

  T2 := TTransformNode.Create('T2');
  T2.AddChildren(Shape);

  RootNode := TX3DRootNode.Create('Root');
  RootNode.AddChildren(T1);
  RootNode.AddChildren(T2);
  RootNode.AddChildren(Shape);

  Scene := TCastleSceneCore.Create(nil);
  try
    Scene.Load(RootNode, true);

    Shapes := Scene.Shapes.TraverseList(true);
    AssertEquals(3, Shapes.Count);

    AssertTrue(Shapes[0].OriginalGeometry = Box);
    AssertTrue(Shapes[0].Node = Shape);
    AssertTrue(Shapes[0].GeometryParentNode = Shape);
    AssertTrue(Shapes[0].GeometryGrandParentNode = T1);
    AssertTrue(Shapes[0].GeometryGrandGrandParentNode = RootNode);
    AssertEquals('CommonShape', Shapes[0].GeometryParentNodeName);
    AssertEquals('T1', Shapes[0].GeometryGrandParentNodeName);
    AssertEquals('Root', Shapes[0].GeometryGrandGrandParentNodeName);

    AssertTrue(Shapes[1].OriginalGeometry = Box);
    AssertTrue(Shapes[1].Node = Shape);
    AssertTrue(Shapes[1].GeometryParentNode = Shape);
    AssertTrue(Shapes[1].GeometryGrandParentNode = T2);
    AssertTrue(Shapes[1].GeometryGrandGrandParentNode = RootNode);
    AssertEquals('CommonShape', Shapes[1].GeometryParentNodeName);
    AssertEquals('T2', Shapes[1].GeometryGrandParentNodeName);
    AssertEquals('Root', Shapes[1].GeometryGrandGrandParentNodeName);

    AssertTrue(Shapes[2].OriginalGeometry = Box);
    AssertTrue(Shapes[2].Node = Shape);
    AssertTrue(Shapes[2].GeometryParentNode = Shape);
    AssertTrue(Shapes[2].GeometryGrandParentNode = RootNode);
    AssertTrue(Shapes[2].GeometryGrandGrandParentNode = nil);
    AssertEquals('CommonShape', Shapes[2].GeometryParentNodeName);
    AssertEquals('Root', Shapes[2].GeometryGrandParentNodeName);
    AssertEquals('', Shapes[2].GeometryGrandGrandParentNodeName);
  finally FreeAndNil(Scene) end;
end;

initialization
  RegisterTest(TTestCastleShapes);
end.