Debian Codegraph @

tests/code/testcases/testcastleinternalrttiutils.pas

raw
1 // -*- compile-command: "./test_single_testcase.sh TTestCastleInternalRttiUtils" -*-
2 {
3 Copyright 2009-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 CastleInternalRttiUtils unit. }
18 unit TestCastleInternalRttiUtils;
19
20 interface
21
22 uses CastleTester;
23
24 type
25 TTestCastleInternalRttiUtils = class(TCastleTestCase)
26 published
27 procedure TestPropertyHasDefaultValue;
28 procedure TestPropertyGetValue;
29 end;
30
31 implementation
32
33 uses SysUtils, Math, Classes, TypInfo,
34 CastleVectors, CastleTransform, CastleInternalRttiUtils;
35
36 procedure TTestCastleInternalRttiUtils.TestPropertyHasDefaultValue;
37 var
38 Cam: TCastleCamera;
39 begin
40 Cam := TCastleCamera.Create(nil);
41 try
42 Cam.ProjectionNear := 10;
43 AssertTrue(PropertyHasDefaultValue(Cam, GetPropInfo(Cam, 'ProjectionType')));
44 AssertFalse(PropertyHasDefaultValue(Cam, GetPropInfo(Cam, 'ProjectionNear')));
45 AssertTrue(PropertyHasDefaultValue(Cam, GetPropInfo(Cam, 'ProjectionFar')));
46
47 AssertFalse(Cam.TranslationPersistent.ValueIsStreamed);
48 Cam.Translation := Vector3(10, 0, 0);
49 AssertTrue(Cam.TranslationPersistent.ValueIsStreamed);
50
51 { vector components have no defaults (not even 0 is considered default),
52 they are decided using IsStoredProp. }
53 AssertFalse(PropertyHasDefaultValue(Cam.TranslationPersistent, GetPropInfo(Cam.TranslationPersistent, 'X')));
54 AssertFalse(PropertyHasDefaultValue(Cam.TranslationPersistent, GetPropInfo(Cam.TranslationPersistent, 'Y')));
55 AssertFalse(PropertyHasDefaultValue(Cam.TranslationPersistent, GetPropInfo(Cam.TranslationPersistent, 'Z')));
56
57 AssertTrue(IsStoredProp(Cam.TranslationPersistent, GetPropInfo(Cam.TranslationPersistent, 'X')));
58 AssertFalse(IsStoredProp(Cam.TranslationPersistent, GetPropInfo(Cam.TranslationPersistent, 'Y')));
59 AssertFalse(IsStoredProp(Cam.TranslationPersistent, GetPropInfo(Cam.TranslationPersistent, 'Z')));
60 finally FreeAndNil(Cam) end;
61 end;
62
63 procedure TTestCastleInternalRttiUtils.TestPropertyGetValue;
64 var
65 Cam: TCastleCamera;
66 PropName, PropValue: String;
67 begin
68 Cam := TCastleCamera.Create(nil);
69 try
70 Cam.ProjectionNear := 10;
71
72 PropertyGet(Cam, GetPropInfo(Cam, 'ProjectionType'), PropName, PropValue);
73 AssertEquals('ProjectionType', PropName);
74 AssertEquals('ptPerspective', PropValue);
75
76 PropertyGet(Cam, GetPropInfo(Cam, 'ProjectionNear'), PropName, PropValue);
77 AssertEquals('ProjectionNear', PropName);
78 AssertEquals('10', PropValue);
79
80 PropertyGet(Cam, GetPropInfo(Cam, 'ProjectionFar'), PropName, PropValue);
81 AssertEquals('ProjectionFar', PropName);
82 AssertEquals('0', PropValue);
83
84 Cam.Translation := Vector3(10, 0, 0);
85
86 PropertyGet(Cam.TranslationPersistent, GetPropInfo(Cam.TranslationPersistent, 'X'), PropName, PropValue);
87 AssertEquals('X', PropName);
88 AssertEquals('10', PropValue);
89
90 PropertyGet(Cam.TranslationPersistent, GetPropInfo(Cam.TranslationPersistent, 'Y'), PropName, PropValue);
91 AssertEquals('Y', PropName);
92 AssertEquals('0', PropValue);
93
94 PropertyGet(Cam.TranslationPersistent, GetPropInfo(Cam.TranslationPersistent, 'Z'), PropName, PropValue);
95 AssertEquals('Z', PropName);
96 AssertEquals('0', PropValue);
97 finally FreeAndNil(Cam) end;
98 end;
99
100 initialization
101 RegisterTest(TTestCastleInternalRttiUtils);
102 end.