| 1 |
{ |
| 2 |
Copyright 2024-2024 Michalis Kamburelis. |
| 3 |
|
| 4 |
This file is part of "Castle Game Engine". |
| 5 |
|
| 6 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 7 |
included in this distribution, for details about the copyright. |
| 8 |
|
| 9 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
|
| 13 |
---------------------------------------------------------------------------- |
| 14 |
} |
| 15 |
|
| 16 |
{ Test X3DLoadInternalCocos2d unit. } |
| 17 |
unit TestX3DLoadInternalCocos2d; |
| 18 |
|
| 19 |
interface |
| 20 |
|
| 21 |
uses CastleTester; |
| 22 |
|
| 23 |
type |
| 24 |
TTestX3DLoadInternalCocos2d = class(TCastleTestCase) |
| 25 |
published |
| 26 |
procedure TestCocos2dParsingBool; |
| 27 |
procedure TestCocos2dParsingVectors; |
| 28 |
end; |
| 29 |
|
| 30 |
implementation |
| 31 |
|
| 32 |
uses SysUtils, DOM, |
| 33 |
CastleXmlUtils, X3DLoadInternalCocos2d; |
| 34 |
|
| 35 |
procedure TTestX3DLoadInternalCocos2d.TestCocos2dParsingBool; |
| 36 |
var |
| 37 |
D: TXMLDocument; |
| 38 |
RootE, E: TDOMElement; |
| 39 |
begin |
| 40 |
D := TXMLDocument.Create; |
| 41 |
try |
| 42 |
RootE := D.CreateElement('root'); |
| 43 |
{ D.AppendChild not needed with FPC 3.2.2 or Delphi 10.2, but needed with Delphi 11.3 } |
| 44 |
D.AppendChild(RootE); |
| 45 |
|
| 46 |
E := RootE.CreateChild('true'); |
| 47 |
AssertEquals(true, Cocos2dReadBool(E)); |
| 48 |
|
| 49 |
E := RootE.CreateChild('false'); |
| 50 |
AssertEquals(false, Cocos2dReadBool(E)); |
| 51 |
|
| 52 |
E := RootE.CreateChild('something'); |
| 53 |
AssertEquals(false, Cocos2dReadBool(E)); |
| 54 |
finally FreeAndNil(D) end; |
| 55 |
end; |
| 56 |
|
| 57 |
procedure TTestX3DLoadInternalCocos2d.TestCocos2dParsingVectors; |
| 58 |
var |
| 59 |
A, B, C, D: Integer; |
| 60 |
Valid: Boolean; |
| 61 |
begin |
| 62 |
Valid := Cocos2dReadDual('{60,88}', A, B); |
| 63 |
AssertTrue(Valid); |
| 64 |
AssertEquals(A, 60); |
| 65 |
AssertEquals(B, 88); |
| 66 |
|
| 67 |
Valid := Cocos2dReadQuad('{{1,2},{60,88}}', A, B, C, D); |
| 68 |
AssertTrue(Valid); |
| 69 |
AssertEquals(A, 1); |
| 70 |
AssertEquals(B, 2); |
| 71 |
AssertEquals(C, 60); |
| 72 |
AssertEquals(D, 88); |
| 73 |
|
| 74 |
// Michalis got a testcase in private with: |
| 75 |
// <string>{0,0},{60,88}</string> |
| 76 |
Valid := Cocos2dReadQuad('{1,2},{60,88}', A, B, C, D); |
| 77 |
AssertTrue(Valid); |
| 78 |
AssertEquals(A, 1); |
| 79 |
AssertEquals(B, 2); |
| 80 |
AssertEquals(C, 60); |
| 81 |
AssertEquals(D, 88); |
| 82 |
end; |
| 83 |
|
| 84 |
initialization |
| 85 |
RegisterTest(TTestX3DLoadInternalCocos2d); |
| 86 |
end. |