| 1 |
// -*- compile-command: "./test_single_testcase.sh TTestCastleWindowOpen" -*- |
| 2 |
{ |
| 3 |
Copyright 2014-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 doing various stuff from TCastleWindow.OnOpen. } |
| 18 |
unit TestCastleWindowOpen; |
| 19 |
|
| 20 |
interface |
| 21 |
|
| 22 |
uses Classes, SysUtils, |
| 23 |
CastleTester, CastleWindow; |
| 24 |
|
| 25 |
type |
| 26 |
TTestCastleWindowOpen = class(TCastleTestCase) |
| 27 |
published |
| 28 |
procedure TestSaveScreenFromOpen; |
| 29 |
procedure TestLoadLevelFromOpen; |
| 30 |
end; |
| 31 |
|
| 32 |
implementation |
| 33 |
|
| 34 |
uses CastleControls, CastleImages, |
| 35 |
CastleUIControls, CastleViewport, CastleLevels; |
| 36 |
|
| 37 |
type |
| 38 |
TControl2 = class(TCastleUserInterface) |
| 39 |
procedure GLContextOpen; override; |
| 40 |
end; |
| 41 |
|
| 42 |
procedure TControl2.GLContextOpen; |
| 43 |
var |
| 44 |
Image: TCastleImage; |
| 45 |
begin |
| 46 |
Image := Application.MainWindow.SaveScreen; |
| 47 |
FreeAndNil(Image); |
| 48 |
end; |
| 49 |
|
| 50 |
procedure WindowOpen2(Container: TCastleContainer); |
| 51 |
var |
| 52 |
Image: TCastleImage; |
| 53 |
begin |
| 54 |
Image := Application.MainWindow.SaveScreen; |
| 55 |
FreeAndNil(Image); |
| 56 |
end; |
| 57 |
|
| 58 |
procedure TTestCastleWindowOpen.TestSaveScreenFromOpen; |
| 59 |
var |
| 60 |
Window: TCastleWindow; |
| 61 |
begin |
| 62 |
if not CanCreateWindowForTest then |
| 63 |
Exit; |
| 64 |
|
| 65 |
Window := CreateWindowForTest; |
| 66 |
try |
| 67 |
Window.Controls.InsertFront(TControl2.Create(Window)); |
| 68 |
Window.Controls.InsertFront(TCastleButton.Create(Window)); |
| 69 |
Window.Controls.InsertFront(TControl2.Create(Window)); |
| 70 |
Window.OnOpen := @WindowOpen2; |
| 71 |
Application.MainWindow := Window; |
| 72 |
|
| 73 |
Window.Open; |
| 74 |
Window.Close; |
| 75 |
finally |
| 76 |
DestroyWindowForTest(Window); |
| 77 |
end; |
| 78 |
end; |
| 79 |
|
| 80 |
var |
| 81 |
// Avalable during TTestCastleWindowOpen.TestLoadLevelFromOpen |
| 82 |
SceneManagerForLoadLevel: TGameSceneManager; |
| 83 |
|
| 84 |
type |
| 85 |
TControl3 = class(TCastleUserInterface) |
| 86 |
procedure GLContextOpen; override; |
| 87 |
end; |
| 88 |
|
| 89 |
procedure TControl3.GLContextOpen; |
| 90 |
begin |
| 91 |
SceneManagerForLoadLevel.LoadLevel('level_without_loading_image'); |
| 92 |
end; |
| 93 |
|
| 94 |
procedure WindowOpen3(Container: TCastleContainer); |
| 95 |
begin |
| 96 |
SceneManagerForLoadLevel.LoadLevel('level_without_loading_image'); |
| 97 |
end; |
| 98 |
|
| 99 |
procedure TTestCastleWindowOpen.TestLoadLevelFromOpen; |
| 100 |
|
| 101 |
procedure DoTest(const WithButton: boolean); |
| 102 |
var |
| 103 |
Window: TCastleWindow; |
| 104 |
begin |
| 105 |
Window := CreateWindowForTest; |
| 106 |
try |
| 107 |
SceneManagerForLoadLevel := TGameSceneManager.Create(Window); |
| 108 |
SceneManagerForLoadLevel.FullSize := true; |
| 109 |
Window.Controls.InsertFront(SceneManagerForLoadLevel); |
| 110 |
|
| 111 |
Window.Controls.InsertFront(TControl3.Create(Window)); |
| 112 |
if WithButton then |
| 113 |
Window.Controls.InsertFront(TCastleButton.Create(Window)); |
| 114 |
Window.Controls.InsertFront(TControl3.Create(Window)); |
| 115 |
Window.OnOpen := @WindowOpen3; |
| 116 |
|
| 117 |
Window.Open; |
| 118 |
Window.Close; |
| 119 |
finally |
| 120 |
DestroyWindowForTest(Window); |
| 121 |
end; |
| 122 |
end; |
| 123 |
|
| 124 |
begin |
| 125 |
if not CanCreateWindowForTest then |
| 126 |
Exit; |
| 127 |
|
| 128 |
Levels.LoadFromFiles('castle-data:/game/level_without_loading_image'); |
| 129 |
DoTest(false); |
| 130 |
DoTest(true); |
| 131 |
end; |
| 132 |
|
| 133 |
initialization |
| 134 |
RegisterTest(TTestCastleWindowOpen); |
| 135 |
end. |