| 1 |
// -*- compile-command: "./test_single_testcase.sh TTestCastleComponentSerialize" -*- |
| 2 |
{ |
| 3 |
Copyright 2017-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 CastleComponentSerialize unit. } |
| 18 |
unit TestCastleComponentSerialize; |
| 19 |
|
| 20 |
interface |
| 21 |
|
| 22 |
uses |
| 23 |
Classes, SysUtils, CastleTester; |
| 24 |
|
| 25 |
type |
| 26 |
TTestCastleComponentSerialize = class(TCastleTestCase) |
| 27 |
procedure TestDefaultValues; |
| 28 |
procedure TestEmptyCaption; |
| 29 |
procedure TestSaveLoad1; |
| 30 |
procedure TestSaveLoad2; |
| 31 |
procedure TestDeserializeObjectReferences; |
| 32 |
procedure TestDepth; |
| 33 |
procedure TestVectorDeserializedOnce; |
| 34 |
procedure TestCustomSerialization; |
| 35 |
procedure TestInternalAssignUsingSerialization; |
| 36 |
procedure TestViewportCameraReferencesReading; |
| 37 |
procedure TestToleratingInvalidReferences; |
| 38 |
procedure TestPastePreserveReferences; |
| 39 |
procedure TestPastePreserveReferencesOutsideCopied; |
| 40 |
procedure TestAssociateReferences; |
| 41 |
procedure TestAssociateReferencesReuseDesign; |
| 42 |
end; |
| 43 |
|
| 44 |
implementation |
| 45 |
|
| 46 |
uses CastleFilesUtils, CastleComponentSerialize, CastleVectors, |
| 47 |
CastleUIControls, CastleControls, CastleUtils, CastleSceneManager, |
| 48 |
CastleScene, CastleClassUtils, CastleColors, CastleStringUtils, CastleTransform, |
| 49 |
CastleFonts, |
| 50 |
{ needed to deserialize castle-data:/designs/test_object_references.castle-user-interface } |
| 51 |
Castle2DSceneManager; |
| 52 |
|
| 53 |
{ TMyComponent -------------------------------------------------------------- } |
| 54 |
|
| 55 |
type |
| 56 |
TMyComponent = class(TComponent) |
| 57 |
private |
| 58 |
FPosition, FScale: TVector3; |
| 59 |
FPositionPersistent: TCastleVector3Persistent; |
| 60 |
FScalePersistent: TCastleVector3Persistent; |
| 61 |
function GetPosition: TVector3; |
| 62 |
procedure SetPosition(const AValue: TVector3); |
| 63 |
function GetScale: TVector3; |
| 64 |
procedure SetScale(const AValue: TVector3); |
| 65 |
public |
| 66 |
SetScalePersistentCalls, SetPositionPersistentCalls: Cardinal; |
| 67 |
constructor Create(AOwner: TComponent); override; |
| 68 |
destructor Destroy; override; |
| 69 |
property Position: TVector3 read FPosition write FPosition; |
| 70 |
property Scale: TVector3 read FScale write FScale; |
| 71 |
published |
| 72 |
{ @link(Position) that can be visually edited in |
| 73 |
Lazarus, Delphi and Castle Game Engine visual designer. |
| 74 |
Normal user code does not need to deal with this, |
| 75 |
instead read or write @link(Position) directly. |
| 76 |
|
| 77 |
@seealso Position } |
| 78 |
property PositionPersistent: TCastleVector3Persistent read FPositionPersistent; |
| 79 |
|
| 80 |
{ @link(Scale) that can be visually edited in |
| 81 |
Lazarus, Delphi and Castle Game Engine visual designer. |
| 82 |
Normal user code does not need to deal with this, |
| 83 |
instead read or write @link(Scale) directly. |
| 84 |
|
| 85 |
@seealso Scale } |
| 86 |
property ScalePersistent: TCastleVector3Persistent read FScalePersistent; |
| 87 |
end; |
| 88 |
|
| 89 |
constructor TMyComponent.Create(AOwner: TComponent); |
| 90 |
begin |
| 91 |
inherited Create(AOwner); |
| 92 |
FScale := Vector3(1, 1, 1); |
| 93 |
|
| 94 |
// FPositionComponent := TCastleVector3Component.Create(nil); |
| 95 |
// FPositionComponent.Name := 'Position'; |
| 96 |
// FPositionComponent.SetSubComponent(true); |
| 97 |
// FPositionComponent.InternalGetValue := @GetPosition; |
| 98 |
// FPositionComponent.InternalSetValue := @SetPosition; |
| 99 |
// FPositionComponent.InternalDefaultValue := FPosition; // current value is default |
| 100 |
|
| 101 |
// FScaleComponent := TCastleVector3Component.Create(nil); |
| 102 |
// FScaleComponent.Name := 'Scale'; |
| 103 |
// FScaleComponent.SetSubComponent(true); |
| 104 |
// FScaleComponent.InternalGetValue := @GetScale; |
| 105 |
// FScaleComponent.InternalSetValue := @SetScale; |
| 106 |
// FScaleComponent.InternalDefaultValue := FScale; // current value is default |
| 107 |
|
| 108 |
FPositionPersistent := TCastleVector3Persistent.Create; |
| 109 |
FPositionPersistent.SetSubComponent(true); |
| 110 |
FPositionPersistent.InternalGetValue := {$ifdef FPC}@{$endif}GetPosition; |
| 111 |
FPositionPersistent.InternalSetValue := {$ifdef FPC}@{$endif}SetPosition; |
| 112 |
FPositionPersistent.InternalDefaultValue := FPosition; // current value is default |
| 113 |
|
| 114 |
FScalePersistent := TCastleVector3Persistent.Create; |
| 115 |
FScalePersistent.SetSubComponent(true); |
| 116 |
FScalePersistent.InternalGetValue := {$ifdef FPC}@{$endif}GetScale; |
| 117 |
FScalePersistent.InternalSetValue := {$ifdef FPC}@{$endif}SetScale; |
| 118 |
FScalePersistent.InternalDefaultValue := FScale; // current value is default |
| 119 |
end; |
| 120 |
|
| 121 |
destructor TMyComponent.Destroy; |
| 122 |
begin |
| 123 |
FreeAndNil(FPositionPersistent); |
| 124 |
FreeAndNil(FScalePersistent); |
| 125 |
inherited; |
| 126 |
end; |
| 127 |
|
| 128 |
function TMyComponent.GetPosition: TVector3; |
| 129 |
begin |
| 130 |
Result := Position; |
| 131 |
end; |
| 132 |
|
| 133 |
procedure TMyComponent.SetPosition(const AValue: TVector3); |
| 134 |
begin |
| 135 |
Inc(SetPositionPersistentCalls); |
| 136 |
Position := AValue; |
| 137 |
end; |
| 138 |
|
| 139 |
function TMyComponent.GetScale: TVector3; |
| 140 |
begin |
| 141 |
Result := Scale; |
| 142 |
end; |
| 143 |
|
| 144 |
procedure TMyComponent.SetScale(const AValue: TVector3); |
| 145 |
begin |
| 146 |
Inc(SetScalePersistentCalls); |
| 147 |
Scale := AValue; |
| 148 |
end; |
| 149 |
|
| 150 |
{ TTestCastleComponentSerialize ---------------------------------------------- } |
| 151 |
|
| 152 |
procedure TTestCastleComponentSerialize.TestDefaultValues; |
| 153 |
var |
| 154 |
TempFileName: String; |
| 155 |
TestOutputOwner: TComponent; |
| 156 |
TestInput, TestOutput: TMyComponent; |
| 157 |
begin |
| 158 |
TempFileName := GetTempFileNameCheck; |
| 159 |
|
| 160 |
TestInput := TMyComponent.Create(nil); |
| 161 |
try |
| 162 |
AssertVectorEquals(Vector3(0, 0, 0), TestInput.PositionPersistent.Value); |
| 163 |
AssertVectorEquals(Vector3(0, 0, 0), TestInput.Position); |
| 164 |
AssertVectorEquals(Vector3(1, 1, 1), TestInput.ScalePersistent.Value); |
| 165 |
AssertVectorEquals(Vector3(1, 1, 1), TestInput.Scale); |
| 166 |
|
| 167 |
TestInput.PositionPersistent.Value := Vector3(0, 20, 30); |
| 168 |
TestInput.ScalePersistent.Value := Vector3(0, 1, 2); |
| 169 |
|
| 170 |
AssertVectorEquals(Vector3(0, 20, 30), TestInput.PositionPersistent.Value); |
| 171 |
AssertVectorEquals(Vector3(0, 20, 30), TestInput.Position); |
| 172 |
AssertVectorEquals(Vector3(0, 1, 2), TestInput.ScalePersistent.Value); |
| 173 |
AssertVectorEquals(Vector3(0, 1, 2), TestInput.Scale); |
| 174 |
|
| 175 |
ComponentSave(TestInput, TempFileName); |
| 176 |
finally |
| 177 |
FreeAndNil(TestInput); |
| 178 |
end; |
| 179 |
|
| 180 |
TestOutputOwner := TComponent.Create(nil); |
| 181 |
try |
| 182 |
TestOutput := ComponentLoad(TempFileName, TestOutputOwner) as TMyComponent; |
| 183 |
AssertVectorEquals(Vector3(0, 20, 30), TestOutput.PositionPersistent.Value); |
| 184 |
AssertVectorEquals(Vector3(0, 20, 30), TestOutput.Position); |
| 185 |
AssertVectorEquals(Vector3(0, 1, 2), TestOutput.ScalePersistent.Value); |
| 186 |
AssertVectorEquals(Vector3(0, 1, 2), TestOutput.Scale); |
| 187 |
finally |
| 188 |
FreeAndNil(TestOutputOwner); |
| 189 |
end; |
| 190 |
|
| 191 |
CheckDeleteFile(TempFileName, true); |
| 192 |
end; |
| 193 |
|
| 194 |
procedure TTestCastleComponentSerialize.TestEmptyCaption; |
| 195 |
var |
| 196 |
UiOwner: TComponent; |
| 197 |
//C: TCastleUserInterface; |
| 198 |
begin |
| 199 |
UiOwner := TComponent.Create(nil); |
| 200 |
try |
| 201 |
UserInterfaceLoad('castle-data:/designs/test_caption_empty.castle-user-interface', UiOwner); |
| 202 |
AssertEquals('Button1', (UiOwner.FindRequiredComponent('Button1') as TCastleButton).Caption); |
| 203 |
AssertEquals('', (UiOwner.FindRequiredComponent('Button2') as TCastleButton).Caption); |
| 204 |
AssertEquals('Button3', (UiOwner.FindRequiredComponent('Button3') as TCastleButton).Caption); |
| 205 |
finally FreeAndNil(UiOwner) end; |
| 206 |
end; |
| 207 |
|
| 208 |
procedure TTestCastleComponentSerialize.TestSaveLoad1; |
| 209 |
var |
| 210 |
UiOwner: TComponent; |
| 211 |
Ui: TCastleButton; |
| 212 |
Lab: TCastleLabel; |
| 213 |
LoadedUi: TCastleUserInterface; |
| 214 |
TempFileName: String; |
| 215 |
begin |
| 216 |
UiOwner := TComponent.Create(nil); |
| 217 |
try |
| 218 |
Ui := TCastleButton.Create(UiOwner); |
| 219 |
|
| 220 |
Lab := TCastleLabel.Create(UiOwner); |
| 221 |
Lab.Color := Vector4(0, 1, 0, 1); |
| 222 |
Lab.FrameColor := Vector4(0, 1, 0, 1); |
| 223 |
Lab.Caption := 'test caption' + NL + 'another caption'; |
| 224 |
Lab.LineSpacing := 4; |
| 225 |
Ui.InsertFront(Lab); |
| 226 |
|
| 227 |
TempFileName := GetTempFileNameCheck; |
| 228 |
UserInterfaceSave(Ui, TempFileName); |
| 229 |
finally FreeAndNil(UiOwner) end; |
| 230 |
|
| 231 |
Ui := nil; // make sure state is cleared |
| 232 |
Lab := nil; |
| 233 |
|
| 234 |
UiOwner := TComponent.Create(nil); |
| 235 |
try |
| 236 |
LoadedUi := UserInterfaceLoad(TempFileName, UiOwner); |
| 237 |
AssertTrue(LoadedUi is TCastleButton); |
| 238 |
Ui := LoadedUi as TCastleButton; |
| 239 |
|
| 240 |
AssertEquals(Ui.ControlsCount, 1); |
| 241 |
AssertTrue(Ui.Controls[0] is TCastleLabel); |
| 242 |
Lab := Ui.Controls[0] as TCastleLabel; |
| 243 |
|
| 244 |
AssertVectorEquals(Vector4(0, 1, 0, 1), Lab.Color); |
| 245 |
AssertVectorEquals(Vector4(0, 1, 0, 1), Lab.FrameColor); |
| 246 |
AssertEquals(4, Lab.LineSpacing); |
| 247 |
AssertEquals('test caption' + NL + 'another caption', Lab.Caption); |
| 248 |
finally FreeAndNil(UiOwner) end; |
| 249 |
end; |
| 250 |
|
| 251 |
procedure TTestCastleComponentSerialize.TestSaveLoad2; |
| 252 |
var |
| 253 |
UiOwner: TComponent; |
| 254 |
Ui: TCastleButton; |
| 255 |
Lab: TCastleLabel; |
| 256 |
LoadedUi: TCastleUserInterface; |
| 257 |
TempFileName: String; |
| 258 |
begin |
| 259 |
UiOwner := TComponent.Create(nil); |
| 260 |
try |
| 261 |
Ui := TCastleButton.Create(UiOwner); |
| 262 |
|
| 263 |
Lab := TCastleLabel.Create(UiOwner); |
| 264 |
// leave defaults |
| 265 |
Ui.InsertFront(Lab); |
| 266 |
|
| 267 |
TempFileName := GetTempFileNameCheck; |
| 268 |
UserInterfaceSave(Ui, TempFileName); |
| 269 |
finally FreeAndNil(UiOwner) end; |
| 270 |
|
| 271 |
Ui := nil; // make sure state is cleared |
| 272 |
Lab := nil; |
| 273 |
|
| 274 |
UiOwner := TComponent.Create(nil); |
| 275 |
try |
| 276 |
LoadedUi := UserInterfaceLoad(TempFileName, UiOwner); |
| 277 |
AssertTrue(LoadedUi is TCastleButton); |
| 278 |
Ui := LoadedUi as TCastleButton; |
| 279 |
|
| 280 |
AssertEquals(Ui.ControlsCount, 1); |
| 281 |
AssertTrue(Ui.Controls[0] is TCastleLabel); |
| 282 |
Lab := Ui.Controls[0] as TCastleLabel; |
| 283 |
|
| 284 |
AssertVectorEquals(Vector4(0, 0, 0, 1), Lab.Color); |
| 285 |
AssertVectorEquals(Vector4(1, 1, 1, 1), Lab.FrameColor); |
| 286 |
AssertEquals(TCastleLabel.DefaultLineSpacing, Lab.LineSpacing); |
| 287 |
AssertEquals('', Lab.Caption); |
| 288 |
finally FreeAndNil(UiOwner) end; |
| 289 |
end; |
| 290 |
|
| 291 |
procedure TTestCastleComponentSerialize.TestDeserializeObjectReferences; |
| 292 |
var |
| 293 |
UiOwner: TComponent; |
| 294 |
//Ui: TCastleUserInterface; |
| 295 |
Sm1, Sm2, Sm3: TCastleSceneManager; |
| 296 |
{Scene1, Scene2, }Scene3, Scene4{, Scene5, Scene6}: TCastleScene; |
| 297 |
begin |
| 298 |
UiOwner := TComponent.Create(nil); |
| 299 |
try |
| 300 |
{Ui := }UserInterfaceLoad('castle-data:/designs/test_object_references.castle-user-interface', UiOwner); |
| 301 |
Sm1 := UiOwner.FindRequiredComponent('SceneManager1') as TCastleSceneManager; |
| 302 |
Sm2 := UiOwner.FindRequiredComponent('SceneManager2') as TCastleSceneManager; |
| 303 |
Sm3 := UiOwner.FindRequiredComponent('SceneManager3') as TCastleSceneManager; |
| 304 |
// Scene1 := UiOwner.FindRequiredComponent('Scene1') as TCastleScene; |
| 305 |
// Scene2 := UiOwner.FindRequiredComponent('Scene2') as TCastleScene; |
| 306 |
Scene3 := UiOwner.FindRequiredComponent('Scene3') as TCastleScene; |
| 307 |
Scene4 := UiOwner.FindRequiredComponent('Scene4') as TCastleScene; |
| 308 |
// Scene5 := UiOwner.FindRequiredComponent('Scene5') as TCastleScene; |
| 309 |
// Scene6 := UiOwner.FindRequiredComponent('Scene6') as TCastleScene; |
| 310 |
AssertTrue(Sm1.MainScene = Scene3); |
| 311 |
AssertTrue(Sm2.MainScene = Scene4); |
| 312 |
AssertTrue(Sm3.MainScene = nil); |
| 313 |
finally FreeAndNil(UiOwner) end; |
| 314 |
end; |
| 315 |
|
| 316 |
procedure TTestCastleComponentSerialize.TestDepth; |
| 317 |
{ Internally, CastleComponentSerialize must increase SerializationProcessPool |
| 318 |
for larger depths. Make sure it works OK. } |
| 319 |
var |
| 320 |
I: Integer; |
| 321 |
UiOwner, C: TComponent; |
| 322 |
RootLabel, ParentLabel: TCastleLabel; |
| 323 |
ChildLabel: TCastleLabel; |
| 324 |
TempFileName: String; |
| 325 |
begin |
| 326 |
UiOwner := TComponent.Create(nil); |
| 327 |
try |
| 328 |
RootLabel := TCastleLabel.Create(UiOwner); |
| 329 |
RootLabel.Tag := 1000; |
| 330 |
|
| 331 |
C := TComponent.Create(UiOwner); |
| 332 |
C.Tag := 2000; |
| 333 |
RootLabel.AddNonVisualComponent(C); |
| 334 |
|
| 335 |
ParentLabel := RootLabel; |
| 336 |
for I := 1 to 100 do |
| 337 |
begin |
| 338 |
ChildLabel := TCastleLabel.Create(UiOwner); |
| 339 |
ChildLabel.Tag := 1000 + I; |
| 340 |
ParentLabel.InsertFront(ChildLabel); |
| 341 |
|
| 342 |
C := TComponent.Create(UiOwner); |
| 343 |
C.Tag := 2000 + I; |
| 344 |
ChildLabel.AddNonVisualComponent(C); |
| 345 |
|
| 346 |
ParentLabel := ChildLabel; |
| 347 |
end; |
| 348 |
|
| 349 |
TempFileName := GetTempFileNameCheck; |
| 350 |
ComponentSave(RootLabel, TempFileName); |
| 351 |
TestLog( |
| 352 |
'TTestCastleComponentSerialize.TestDepth: Saved to ' + TempFileName); |
| 353 |
|
| 354 |
finally FreeAndNil(UiOwner) end; |
| 355 |
|
| 356 |
{ Now load, and see if we have the same structure } |
| 357 |
UiOwner := TComponent.Create(nil); |
| 358 |
try |
| 359 |
RootLabel := ComponentLoad(TempFileName, UiOwner) as TCastleLabel; |
| 360 |
|
| 361 |
AssertEquals(1000, RootLabel.Tag); |
| 362 |
AssertEquals(1, RootLabel.NonVisualComponentsCount); |
| 363 |
C := RootLabel.NonVisualComponents[0]; |
| 364 |
AssertEquals(2000, C.Tag); |
| 365 |
|
| 366 |
ParentLabel := RootLabel; |
| 367 |
for I := 1 to 100 do |
| 368 |
begin |
| 369 |
AssertEquals(1, ParentLabel.ControlsCount); |
| 370 |
ChildLabel := ParentLabel.Controls[0] as TCastleLabel; |
| 371 |
AssertEquals(1000 + I, ChildLabel.Tag); |
| 372 |
|
| 373 |
AssertEquals(1, ChildLabel.NonVisualComponentsCount); |
| 374 |
C := ChildLabel.NonVisualComponents[0]; |
| 375 |
AssertEquals(2000 + I, C.Tag); |
| 376 |
|
| 377 |
ParentLabel := ChildLabel; |
| 378 |
end; |
| 379 |
finally FreeAndNil(UiOwner) end; |
| 380 |
end; |
| 381 |
|
| 382 |
procedure TTestCastleComponentSerialize.TestVectorDeserializedOnce; |
| 383 |
var |
| 384 |
TestOutputOwner: TComponent; |
| 385 |
TestInput, TestOutput: TMyComponent; |
| 386 |
TempFileName: String; |
| 387 |
begin |
| 388 |
TestInput := TMyComponent.Create(nil); |
| 389 |
try |
| 390 |
TestInput.Position := Vector3(1, 2, 3); |
| 391 |
TestInput.Scale := Vector3(4, 5, 6); |
| 392 |
AssertEquals(0, TestInput.SetScalePersistentCalls); |
| 393 |
AssertEquals(0, TestInput.SetPositionPersistentCalls); |
| 394 |
|
| 395 |
TempFileName := GetTempFileNameCheck; |
| 396 |
ComponentSave(TestInput, TempFileName); |
| 397 |
finally |
| 398 |
FreeAndNil(TestInput); |
| 399 |
end; |
| 400 |
|
| 401 |
TestOutputOwner := TComponent.Create(nil); |
| 402 |
try |
| 403 |
TestOutput := ComponentLoad(TempFileName, TestOutputOwner) as TMyComponent; |
| 404 |
AssertVectorEquals(Vector3(1, 2, 3), TestOutput.Position); |
| 405 |
AssertVectorEquals(Vector3(4, 5, 6), TestOutput.Scale); |
| 406 |
AssertEquals(1, TestOutput.SetScalePersistentCalls); |
| 407 |
AssertEquals(1, TestOutput.SetPositionPersistentCalls); |
| 408 |
finally |
| 409 |
FreeAndNil(TestOutputOwner); |
| 410 |
end; |
| 411 |
end; |
| 412 |
|
| 413 |
type |
| 414 |
TTestComponent2 = class; |
| 415 |
|
| 416 |
TTestComponent1 = class(TCastleComponent) |
| 417 |
strict private |
| 418 |
FSomeSingle: Single; |
| 419 |
private |
| 420 |
InternalSingle: Single; |
| 421 |
InternalString: String; |
| 422 |
InternalBoolean: Boolean; |
| 423 |
InternalInteger: Integer; |
| 424 |
InternalSubComponent: TTestComponent2; |
| 425 |
InternalColor: TCastleColor; |
| 426 |
InternalColorRGB: TCastleColorRGB; |
| 427 |
InternalVec2: TVector2; |
| 428 |
InternalVec3: TVector3; |
| 429 |
InternalVec4: TVector4; |
| 430 |
InternalVecNotPresent: TVector4; |
| 431 |
InternalVecOnly2ComponentsPresent: TVector4; |
| 432 |
public |
| 433 |
constructor Create(AOwner: TComponent); override; |
| 434 |
procedure CustomSerialization(const SerializationProcess: TSerializationProcess); override; |
| 435 |
published |
| 436 |
property SomeSingle: Single read FSomeSingle write FSomeSingle {$ifdef FPC}default 0{$endif}; |
| 437 |
end; |
| 438 |
|
| 439 |
TTestComponent2 = class(TCastleComponent) |
| 440 |
strict private |
| 441 |
FSomeSingle: Single; |
| 442 |
private |
| 443 |
InternalSingle: Single; |
| 444 |
InternalString: String; |
| 445 |
InternalBoolean: Boolean; |
| 446 |
InternalInteger: Integer; |
| 447 |
InternalColor: TCastleColor; |
| 448 |
InternalColorRGB: TCastleColorRGB; |
| 449 |
InternalVec2: TVector2; |
| 450 |
InternalVec3: TVector3; |
| 451 |
InternalVec4: TVector4; |
| 452 |
InternalVecNotPresent: TVector4; |
| 453 |
InternalVecOnly2ComponentsPresent: TVector4; |
| 454 |
public |
| 455 |
constructor Create(AOwner: TComponent); override; |
| 456 |
procedure CustomSerialization(const SerializationProcess: TSerializationProcess); override; |
| 457 |
published |
| 458 |
property SomeSingle: Single read FSomeSingle write FSomeSingle {$ifdef FPC}default 0{$endif}; |
| 459 |
end; |
| 460 |
|
| 461 |
constructor TTestComponent1.Create(AOwner: TComponent); |
| 462 |
begin |
| 463 |
inherited; |
| 464 |
InternalSubComponent := TTestComponent2.Create(Self); |
| 465 |
InternalSubComponent.Name := 'SomeSubComponentName'; |
| 466 |
InternalSubComponent.SetSubComponent(true); // this only decides if SomeSubComponentName is recorded |
| 467 |
|
| 468 |
InternalVecNotPresent := Vector4(901, 902, 903, 904); |
| 469 |
InternalVecOnly2ComponentsPresent := Vector4(801, 802, 803, 804); |
| 470 |
end; |
| 471 |
|
| 472 |
procedure TTestComponent1.CustomSerialization(const SerializationProcess: TSerializationProcess); |
| 473 |
begin |
| 474 |
inherited; |
| 475 |
SerializationProcess.ReadWriteInteger('InternalInteger', InternalInteger, true); |
| 476 |
SerializationProcess.ReadWriteBoolean('InternalBoolean', InternalBoolean, true); |
| 477 |
SerializationProcess.ReadWriteString('InternalString', InternalString, true); |
| 478 |
SerializationProcess.ReadWriteSingle('InternalSingle', InternalSingle, true); |
| 479 |
|
| 480 |
SerializationProcess.ReadWriteSubComponent('InternalSubComponent', InternalSubComponent, true); |
| 481 |
|
| 482 |
SerializationProcess.ReadWriteColor('InternalColor', InternalColor, White, true); |
| 483 |
SerializationProcess.ReadWriteColor('InternalColorRGB', InternalColorRGB, WhiteRGB, true); |
| 484 |
SerializationProcess.ReadWriteVector('InternalVec2', InternalVec2, Vector2(-1, -1), true); |
| 485 |
SerializationProcess.ReadWriteVector('InternalVec3', InternalVec3, Vector3(-1, -1, -1), true); |
| 486 |
SerializationProcess.ReadWriteVector('InternalVec4', InternalVec4, Vector4(-1, -1, -1, -1), true); |
| 487 |
SerializationProcess.ReadWriteVector('InternalVecNotPresent', InternalVecNotPresent, Vector4(-1, -1, -1, -1), true); |
| 488 |
SerializationProcess.ReadWriteVector('InternalVecOnly2ComponentsPresent', InternalVecOnly2ComponentsPresent, Vector4(-1, -1, -1, -1), true); |
| 489 |
end; |
| 490 |
|
| 491 |
constructor TTestComponent2.Create(AOwner: TComponent); |
| 492 |
begin |
| 493 |
inherited; |
| 494 |
InternalVecNotPresent := Vector4(11901, 11902, 11903, 11904); |
| 495 |
InternalVecOnly2ComponentsPresent := Vector4(11801, 11802, 11803, 11804); |
| 496 |
end; |
| 497 |
|
| 498 |
procedure TTestComponent2.CustomSerialization(const SerializationProcess: TSerializationProcess); |
| 499 |
begin |
| 500 |
inherited; |
| 501 |
SerializationProcess.ReadWriteInteger('InternalInteger', InternalInteger, true); |
| 502 |
SerializationProcess.ReadWriteBoolean('InternalBoolean', InternalBoolean, true); |
| 503 |
SerializationProcess.ReadWriteString('InternalString', InternalString, true); |
| 504 |
SerializationProcess.ReadWriteSingle('InternalSingle', InternalSingle, true); |
| 505 |
|
| 506 |
SerializationProcess.ReadWriteColor('InternalColor', InternalColor, White, true); |
| 507 |
SerializationProcess.ReadWriteColor('InternalColorRGB', InternalColorRGB, WhiteRGB, true); |
| 508 |
SerializationProcess.ReadWriteVector('InternalVec2', InternalVec2, Vector2(-1, -1), true); |
| 509 |
SerializationProcess.ReadWriteVector('InternalVec3', InternalVec3, Vector3(-1, -1, -1), true); |
| 510 |
SerializationProcess.ReadWriteVector('InternalVec4', InternalVec4, Vector4(-1, -1, -1, -1), true); |
| 511 |
SerializationProcess.ReadWriteVector('InternalVecNotPresent', InternalVecNotPresent, Vector4(-1, -1, -1, -1), true); |
| 512 |
SerializationProcess.ReadWriteVector('InternalVecOnly2ComponentsPresent', InternalVecOnly2ComponentsPresent, Vector4(-1, -1, -1, -1), true); |
| 513 |
end; |
| 514 |
|
| 515 |
procedure TTestCastleComponentSerialize.TestCustomSerialization; |
| 516 |
const |
| 517 |
ValidOutputNumbersCount = 51; |
| 518 |
ValidOutputNumbers: array [0..ValidOutputNumbersCount - 1] of Float = ( |
| 519 |
3333, |
| 520 |
123.456, |
| 521 |
4444, |
| 522 |
789.123, |
| 523 |
|
| 524 |
4004, |
| 525 |
4003, |
| 526 |
4002, |
| 527 |
4001, |
| 528 |
|
| 529 |
4007, |
| 530 |
4006, |
| 531 |
4005, |
| 532 |
|
| 533 |
40010, |
| 534 |
40011, |
| 535 |
|
| 536 |
40020, |
| 537 |
40021, |
| 538 |
40022, |
| 539 |
|
| 540 |
40033, |
| 541 |
40030, |
| 542 |
40031, |
| 543 |
40032, |
| 544 |
|
| 545 |
11904, |
| 546 |
11901, |
| 547 |
11902, |
| 548 |
11903, |
| 549 |
|
| 550 |
11804, |
| 551 |
11801, |
| 552 |
4060031, |
| 553 |
4060032, |
| 554 |
|
| 555 |
4, |
| 556 |
3, |
| 557 |
2, |
| 558 |
|
| 559 |
7, |
| 560 |
6, |
| 561 |
5, |
| 562 |
|
| 563 |
10, |
| 564 |
11, |
| 565 |
|
| 566 |
20, |
| 567 |
21, |
| 568 |
22, |
| 569 |
|
| 570 |
33, |
| 571 |
30, |
| 572 |
31, |
| 573 |
32, |
| 574 |
|
| 575 |
904, |
| 576 |
901, |
| 577 |
902, |
| 578 |
903, |
| 579 |
|
| 580 |
804, |
| 581 |
801, |
| 582 |
60031, |
| 583 |
60032 |
| 584 |
); |
| 585 |
var |
| 586 |
COwner: TComponent; |
| 587 |
T1: TTestComponent1; |
| 588 |
ValidOutput: String; |
| 589 |
I: Integer; |
| 590 |
NumbersReadBack: array [0..ValidOutputNumbersCount - 1] of Float; |
| 591 |
NumbersReadBackPtrs: array [0..ValidOutputNumbersCount - 1] of Pointer; |
| 592 |
begin |
| 593 |
COwner := TComponent.Create(nil); |
| 594 |
try |
| 595 |
T1 := ComponentLoad('castle-data:/designs/test_custom_serialization.castle-component', COwner) as TTestComponent1; |
| 596 |
|
| 597 |
{ Test reading with CustomSerialization } |
| 598 |
|
| 599 |
AssertEquals('TestComponent1', T1.Name); |
| 600 |
AssertSameValue(3333, T1.SomeSingle); |
| 601 |
AssertSameValue(123.456, T1.InternalSingle, 0.0001); |
| 602 |
AssertEquals('something something', T1.InternalString); |
| 603 |
AssertTrue(T1.InternalBoolean); |
| 604 |
AssertEquals(123, T1.InternalInteger); |
| 605 |
AssertVectorEquals(Vector4(1, 2, 3, 4), T1.InternalColor); |
| 606 |
AssertVectorEquals(Vector3(5, 6, 7), T1.InternalColorRGB); |
| 607 |
AssertVectorEquals(Vector2(10, 11), T1.InternalVec2); |
| 608 |
AssertVectorEquals(Vector3(20, 21, 22), T1.InternalVec3); |
| 609 |
AssertVectorEquals(Vector4(30, 31, 32, 33), T1.InternalVec4); |
| 610 |
AssertVectorEquals(Vector4(901, 902, 903, 904), T1.InternalVecNotPresent); |
| 611 |
AssertVectorEquals(Vector4(801, 60031, 60032, 804), T1.InternalVecOnly2ComponentsPresent); |
| 612 |
|
| 613 |
AssertEquals('TestComponent2', T1.InternalSubComponent.Name); |
| 614 |
AssertSameValue(4444, T1.InternalSubComponent.SomeSingle); |
| 615 |
AssertSameValue(789.123, T1.InternalSubComponent.InternalSingle, 0.0001); |
| 616 |
AssertEquals('something else something', T1.InternalSubComponent.InternalString); |
| 617 |
AssertTrue(T1.InternalSubComponent.InternalBoolean); |
| 618 |
AssertEquals(789, T1.InternalSubComponent.InternalInteger); |
| 619 |
AssertVectorEquals(Vector4(4001, 4002, 4003, 4004), T1.InternalSubComponent.InternalColor); |
| 620 |
AssertVectorEquals(Vector3(4005, 4006, 4007), T1.InternalSubComponent.InternalColorRGB); |
| 621 |
AssertVectorEquals(Vector2(40010, 40011), T1.InternalSubComponent.InternalVec2); |
| 622 |
AssertVectorEquals(Vector3(40020, 40021, 40022), T1.InternalSubComponent.InternalVec3); |
| 623 |
AssertVectorEquals(Vector4(40030, 40031, 40032, 40033), T1.InternalSubComponent.InternalVec4); |
| 624 |
AssertVectorEquals(Vector4(11901, 11902, 11903, 11904), T1.InternalSubComponent.InternalVecNotPresent); |
| 625 |
AssertVectorEquals(Vector4(11801, 4060031, 4060032, 11804), T1.InternalSubComponent.InternalVecOnly2ComponentsPresent); |
| 626 |
|
| 627 |
{ Test writing with CustomSerialization. |
| 628 |
Save the result to string, see whether it matches what we expect. |
| 629 |
Note that we don't enforce how floats are encoded in JSON, |
| 630 |
this may be different between compilers and platforms due to floating-point accuracy, |
| 631 |
and the way default conversion float->string is done. } |
| 632 |
|
| 633 |
for I := 0 to ValidOutputNumbersCount - 1 do |
| 634 |
NumbersReadBackPtrs[I] := @(NumbersReadBack[I]); |
| 635 |
|
| 636 |
ValidOutput := FileToString('castle-data:/designs/test_custom_serialization_valid_output.castle-component'); |
| 637 |
DeFormat(ComponentToString(T1), ValidOutput, NumbersReadBackPtrs, false); |
| 638 |
|
| 639 |
for I := 0 to ValidOutputNumbersCount - 1 do |
| 640 |
AssertEquals(ValidOutputNumbers[I], NumbersReadBack[I]); |
| 641 |
finally FreeAndNil(COwner) end; |
| 642 |
end; |
| 643 |
|
| 644 |
procedure TTestCastleComponentSerialize.TestInternalAssignUsingSerialization; |
| 645 |
var |
| 646 |
C1, C2: TCastleCamera; |
| 647 |
Pos, Dir, Up: TVector3; |
| 648 |
begin |
| 649 |
C1 := nil; |
| 650 |
C2 := nil; |
| 651 |
try |
| 652 |
C1 := TCastleCamera.Create(nil); |
| 653 |
C2 := TCastleCamera.Create(nil); |
| 654 |
C1.SetView( |
| 655 |
Vector3(1, 2, 3), |
| 656 |
Vector3(0, 0, 1), |
| 657 |
Vector3(-1, 0, 0) |
| 658 |
); |
| 659 |
InternalAssignUsingSerialization(C2, C1); |
| 660 |
C2.GetView( |
| 661 |
Pos, |
| 662 |
Dir, |
| 663 |
Up); |
| 664 |
AssertVectorEquals(Vector3(1, 2, 3), Pos); |
| 665 |
AssertVectorEquals(Vector3(0, 0, 1), Dir); |
| 666 |
AssertVectorEquals(Vector3(-1, 0, 0), Up); |
| 667 |
finally |
| 668 |
FreeAndNil(C1); |
| 669 |
FreeAndNil(C2); |
| 670 |
end; |
| 671 |
end; |
| 672 |
|
| 673 |
procedure TTestCastleComponentSerialize.TestViewportCameraReferencesReading; |
| 674 |
var |
| 675 |
// Ui: TCastleUserInterface; |
| 676 |
UiOwner: TComponent; |
| 677 |
Viewport1, Viewport2: TCastleViewport; |
| 678 |
begin |
| 679 |
UiOwner := TComponent.Create(nil); |
| 680 |
try |
| 681 |
{Ui := }UserInterfaceLoad('castle-data:/designs/test_viewport_using_another_camera.castle-user-interface', UiOwner); |
| 682 |
Viewport1 := UiOwner.FindRequiredComponent('Viewport1') as TCastleViewport; |
| 683 |
Viewport2 := UiOwner.FindRequiredComponent('Viewport2') as TCastleViewport; |
| 684 |
AssertEquals('Camera2', Viewport1.Camera.Name); |
| 685 |
AssertEquals('Camera2', Viewport2.Camera.Name); |
| 686 |
finally FreeAndNil(UiOwner) end; |
| 687 |
end; |
| 688 |
|
| 689 |
procedure TTestCastleComponentSerialize.TestToleratingInvalidReferences; |
| 690 |
var |
| 691 |
// Ui: TCastleUserInterface; |
| 692 |
UiOwner: TComponent; |
| 693 |
Viewport1: TCastleViewport; |
| 694 |
begin |
| 695 |
UiOwner := TComponent.Create(nil); |
| 696 |
try |
| 697 |
{Ui := }UserInterfaceLoad('castle-data:/designs/test_viewport_invalid_camera_reference.castle-user-interface', UiOwner); |
| 698 |
Viewport1 := UiOwner.FindRequiredComponent('Viewport1') as TCastleViewport; |
| 699 |
AssertTrue(Viewport1.Camera = nil); |
| 700 |
finally FreeAndNil(UiOwner) end; |
| 701 |
end; |
| 702 |
|
| 703 |
procedure TTestCastleComponentSerialize.TestPastePreserveReferences; |
| 704 |
var |
| 705 |
Viewport1, Viewport2: TCastleViewport; |
| 706 |
Camera1, Camera2: TCastleCamera; |
| 707 |
Background1, Background2: TCastleBackground; |
| 708 |
DesignOwner: TComponent; |
| 709 |
begin |
| 710 |
DesignOwner := TComponent.Create(nil); |
| 711 |
try |
| 712 |
Viewport1 := TCastleViewport.Create(DesignOwner); |
| 713 |
Viewport1.Name := 'Viewport1'; |
| 714 |
Viewport1.Camera.Free; // remove camera auto-created by TCastleViewport.Create |
| 715 |
|
| 716 |
Camera1 := TCastleCamera.Create(DesignOwner); |
| 717 |
Camera1.Name := 'Camera1'; |
| 718 |
Viewport1.Items.Add(Camera1); |
| 719 |
|
| 720 |
Background1 := TCastleBackground.Create(DesignOwner); |
| 721 |
Background1.Name := 'Background1'; |
| 722 |
Viewport1.AddNonVisualComponent(Background1); |
| 723 |
|
| 724 |
Viewport1.Camera := Camera1; |
| 725 |
Viewport1.Background := Background1; |
| 726 |
|
| 727 |
AssertTrue(Viewport1.Items.Count = 1); |
| 728 |
AssertTrue(Viewport1.Items[0] = Camera1); |
| 729 |
AssertTrue(Viewport1.NonVisualComponentsCount = 1); |
| 730 |
AssertTrue(Viewport1.NonVisualComponents[0] = Background1); |
| 731 |
|
| 732 |
AssertTrue(Viewport1.Camera = Camera1); |
| 733 |
AssertTrue(Viewport1.Background = Background1); |
| 734 |
|
| 735 |
// copy Viewport1 into *same* owner, |
| 736 |
// we should make new references good. |
| 737 |
Viewport2 := StringToComponent(ComponentToString(Viewport1), DesignOwner) |
| 738 |
as TCastleViewport; |
| 739 |
|
| 740 |
AssertTrue(Viewport2.Items.Count = 1); |
| 741 |
Camera2 := Viewport2.Items[0] as TCastleCamera; |
| 742 |
AssertTrue(Viewport2.NonVisualComponentsCount = 1); |
| 743 |
Background2 := Viewport2.NonVisualComponents[0] as TCastleBackground; |
| 744 |
|
| 745 |
// new names should be OK |
| 746 |
AssertEquals('Viewport2', Viewport2.Name); |
| 747 |
AssertEquals('Camera2', Camera2.Name); |
| 748 |
AssertEquals('Background2', Background2.Name); |
| 749 |
|
| 750 |
// new references should be inter-connected OK |
| 751 |
AssertTrue(Viewport2.Camera = Camera2); |
| 752 |
AssertTrue(Viewport2.Background = Background2); |
| 753 |
finally FreeAndNil(DesignOwner) end; |
| 754 |
end; |
| 755 |
|
| 756 |
procedure TTestCastleComponentSerialize.TestPastePreserveReferencesOutsideCopied; |
| 757 |
|
| 758 |
{ Differently than in TTestCastleComponentSerialize.TestPastePreserveReferences, |
| 759 |
we test copying of hierarchy that has a reference to an object outside of |
| 760 |
this hierarchy. In particular, you copy TCastleLabel that has some CustomFont |
| 761 |
assigned, abd this CustomFont is not copied, but it is reachable in the owner. |
| 762 |
} |
| 763 |
|
| 764 |
var |
| 765 |
Label1, Label2: TCastleLabel; |
| 766 |
MyFont: TCastleFont; |
| 767 |
DesignOwner: TComponent; |
| 768 |
begin |
| 769 |
DesignOwner := TComponent.Create(nil); |
| 770 |
try |
| 771 |
MyFont := TCastleFont.Create(DesignOwner); |
| 772 |
MyFont.Name := 'MyFont'; |
| 773 |
|
| 774 |
Label1 := TCastleLabel.Create(DesignOwner); |
| 775 |
Label1.Name := 'Label1'; |
| 776 |
Label1.CustomFont := MyFont; |
| 777 |
Label1.Caption := 'blablabla'; |
| 778 |
|
| 779 |
Label2 := StringToComponent(ComponentToString(Label1), DesignOwner) |
| 780 |
as TCastleLabel; |
| 781 |
|
| 782 |
AssertEquals('Label2', Label2.Name); |
| 783 |
AssertEquals('blablabla', Label2.Caption); |
| 784 |
AssertTrue(Label2.CustomFont = MyFont); |
| 785 |
finally FreeAndNil(DesignOwner) end; |
| 786 |
end; |
| 787 |
|
| 788 |
type |
| 789 |
TRocketDesign = class(TPersistent) |
| 790 |
published |
| 791 |
RocketRigidBody: TCastleRigidBody; |
| 792 |
Sphere1: TCastleTransform; |
| 793 |
end; |
| 794 |
|
| 795 |
procedure TTestCastleComponentSerialize.TestAssociateReferences; |
| 796 |
var |
| 797 |
RocketsOwner: TComponent; |
| 798 |
RocketsFactory: TCastleComponentFactory; |
| 799 |
Rocket1: TCastleTransform; |
| 800 |
RocketDesign1: TRocketDesign; |
| 801 |
Rocket2: TCastleTransform; |
| 802 |
RocketDesign2: TRocketDesign; |
| 803 |
begin |
| 804 |
RocketsOwner := nil; |
| 805 |
RocketDesign1 := nil; |
| 806 |
RocketDesign2 := nil; |
| 807 |
RocketsFactory := nil; |
| 808 |
try |
| 809 |
RocketsOwner := TComponent.Create(nil); |
| 810 |
|
| 811 |
RocketsFactory := TCastleComponentFactory.Create(nil); |
| 812 |
RocketsFactory.Url := 'castle-data:/designs/test_associate_references.castle-transform'; |
| 813 |
|
| 814 |
RocketDesign1 := TRocketDesign.Create; |
| 815 |
Rocket1 := RocketsFactory.ComponentLoad(RocketsOwner, RocketDesign1) as TCastleTransform; |
| 816 |
AssertTrue(RocketDesign1.RocketRigidBody <> nil); |
| 817 |
AssertEquals('RocketRigidBody', RocketDesign1.RocketRigidBody.Name); |
| 818 |
AssertTrue(RocketDesign1.Sphere1 <> nil); |
| 819 |
AssertEquals('Sphere1', RocketDesign1.Sphere1.Name); |
| 820 |
|
| 821 |
RocketDesign2 := TRocketDesign.Create; |
| 822 |
Rocket2 := RocketsFactory.ComponentLoad(RocketsOwner, RocketDesign2) as TCastleTransform; |
| 823 |
AssertTrue(RocketDesign2.RocketRigidBody <> nil); |
| 824 |
AssertEquals('RocketRigidBody1', RocketDesign2.RocketRigidBody.Name); |
| 825 |
AssertTrue(RocketDesign2.Sphere1 <> nil); |
| 826 |
AssertEquals('Sphere2', RocketDesign2.Sphere1.Name); |
| 827 |
|
| 828 |
{ Both RocketDesign1 and RocketDesign2 should have different references, |
| 829 |
despite Rocket1 and Rocket2 having the same owner. } |
| 830 |
AssertTrue(RocketDesign1.RocketRigidBody <> RocketDesign2.RocketRigidBody); |
| 831 |
AssertTrue(RocketDesign1.Sphere1 <> RocketDesign2.Sphere1); |
| 832 |
finally |
| 833 |
// can be freed early, and Rocket1 and Rocket2 remain valid |
| 834 |
FreeAndNil(RocketDesign1); |
| 835 |
FreeAndNil(RocketDesign2); |
| 836 |
AssertTrue(Rocket1.Name <> ''); |
| 837 |
AssertTrue(Rocket2.Name <> ''); |
| 838 |
|
| 839 |
// factory can also be freed, and Rocket1 and Rocket2 remain valid |
| 840 |
FreeAndNil(RocketsFactory); |
| 841 |
AssertTrue(Rocket1.Name <> ''); |
| 842 |
AssertTrue(Rocket2.Name <> ''); |
| 843 |
|
| 844 |
FreeAndNil(RocketsOwner); |
| 845 |
end; |
| 846 |
end; |
| 847 |
|
| 848 |
procedure TTestCastleComponentSerialize.TestAssociateReferencesReuseDesign; |
| 849 |
var |
| 850 |
RocketsOwner: TComponent; |
| 851 |
RocketsFactory: TCastleComponentFactory; |
| 852 |
RocketDesign: TRocketDesign; |
| 853 |
Rocket1: TCastleTransform; |
| 854 |
Rocket2: TCastleTransform; |
| 855 |
begin |
| 856 |
RocketsOwner := nil; |
| 857 |
RocketDesign := nil; |
| 858 |
RocketsFactory := nil; |
| 859 |
try |
| 860 |
RocketsOwner := TComponent.Create(nil); |
| 861 |
|
| 862 |
RocketsFactory := TCastleComponentFactory.Create(nil); |
| 863 |
RocketsFactory.Url := 'castle-data:/designs/test_associate_references.castle-transform'; |
| 864 |
|
| 865 |
RocketDesign := TRocketDesign.Create; |
| 866 |
|
| 867 |
Rocket1 := RocketsFactory.ComponentLoad(RocketsOwner, RocketDesign) as TCastleTransform; |
| 868 |
AssertTrue(RocketDesign.RocketRigidBody <> nil); |
| 869 |
AssertEquals('RocketRigidBody', RocketDesign.RocketRigidBody.Name); |
| 870 |
AssertTrue(RocketDesign.Sphere1 <> nil); |
| 871 |
AssertEquals('Sphere1', RocketDesign.Sphere1.Name); |
| 872 |
|
| 873 |
Rocket2 := RocketsFactory.ComponentLoad(RocketsOwner, RocketDesign) as TCastleTransform; |
| 874 |
AssertTrue(RocketDesign.RocketRigidBody <> nil); |
| 875 |
AssertEquals('RocketRigidBody1', RocketDesign.RocketRigidBody.Name); |
| 876 |
AssertTrue(RocketDesign.Sphere1 <> nil); |
| 877 |
AssertEquals('Sphere2', RocketDesign.Sphere1.Name); |
| 878 |
finally |
| 879 |
// can be freed early, and Rocket1 and Rocket2 remain valid |
| 880 |
FreeAndNil(RocketDesign); |
| 881 |
AssertTrue(Rocket1.Name <> ''); |
| 882 |
AssertTrue(Rocket2.Name <> ''); |
| 883 |
|
| 884 |
// factory can also be freed, and Rocket1 and Rocket2 remain valid |
| 885 |
FreeAndNil(RocketsFactory); |
| 886 |
AssertTrue(Rocket1.Name <> ''); |
| 887 |
AssertTrue(Rocket2.Name <> ''); |
| 888 |
|
| 889 |
FreeAndNil(RocketsOwner); |
| 890 |
end; |
| 891 |
end; |
| 892 |
|
| 893 |
initialization |
| 894 |
RegisterTest(TTestCastleComponentSerialize); |
| 895 |
|
| 896 |
RegisterSerializableComponent(TMyComponent, 'My Test Component'); |
| 897 |
RegisterSerializableComponent(TComponent, 'Component (Basic)'); |
| 898 |
|
| 899 |
RegisterSerializableComponent(TTestComponent1, 'T1'); |
| 900 |
RegisterSerializableComponent(TTestComponent2, 'T2'); |
| 901 |
end. |