File: testx3dloadinternalcocos2d.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 (86 lines) | stat: -rw-r--r-- 2,157 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
{
  Copyright 2024-2024 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 X3DLoadInternalCocos2d unit. }
unit TestX3DLoadInternalCocos2d;

interface

uses CastleTester;

type
  TTestX3DLoadInternalCocos2d = class(TCastleTestCase)
  published
    procedure TestCocos2dParsingBool;
    procedure TestCocos2dParsingVectors;
  end;

implementation

uses SysUtils, DOM,
  CastleXmlUtils, X3DLoadInternalCocos2d;

procedure TTestX3DLoadInternalCocos2d.TestCocos2dParsingBool;
var
  D: TXMLDocument;
  RootE, E: TDOMElement;
begin
  D := TXMLDocument.Create;
  try
    RootE := D.CreateElement('root');
    { D.AppendChild not needed with FPC 3.2.2 or Delphi 10.2, but needed with Delphi 11.3 }
    D.AppendChild(RootE);

    E := RootE.CreateChild('true');
    AssertEquals(true, Cocos2dReadBool(E));

    E := RootE.CreateChild('false');
    AssertEquals(false, Cocos2dReadBool(E));

    E := RootE.CreateChild('something');
    AssertEquals(false, Cocos2dReadBool(E));
  finally FreeAndNil(D) end;
end;

procedure TTestX3DLoadInternalCocos2d.TestCocos2dParsingVectors;
var
  A, B, C, D: Integer;
  Valid: Boolean;
begin
  Valid := Cocos2dReadDual('{60,88}', A, B);
  AssertTrue(Valid);
  AssertEquals(A, 60);
  AssertEquals(B, 88);

  Valid := Cocos2dReadQuad('{{1,2},{60,88}}', A, B, C, D);
  AssertTrue(Valid);
  AssertEquals(A, 1);
  AssertEquals(B, 2);
  AssertEquals(C, 60);
  AssertEquals(D, 88);

  // Michalis got a testcase in private with:
  // <string>{0,0},{60,88}</string>
  Valid := Cocos2dReadQuad('{1,2},{60,88}', A, B, C, D);
  AssertTrue(Valid);
  AssertEquals(A, 1);
  AssertEquals(B, 2);
  AssertEquals(C, 60);
  AssertEquals(D, 88);
end;

initialization
  RegisterTest(TTestX3DLoadInternalCocos2d);
end.