| 1 |
// -*- compile-command: "./test_single_testcase.sh TTestLocalizationGetText" -*- |
| 2 |
{ |
| 3 |
Copyright 2022-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 CastleLocalizationGetText unit. } |
| 18 |
unit TestCastleLocalizationGetText; |
| 19 |
|
| 20 |
interface |
| 21 |
|
| 22 |
uses |
| 23 |
Classes, SysUtils, CastleTester; |
| 24 |
|
| 25 |
type |
| 26 |
TTestLocalizationGetText = class(TCastleTestCase) |
| 27 |
published |
| 28 |
{$ifdef FPC} // CastleLocalizationGetText not available for Delphi yet |
| 29 |
procedure TestTranslateUi; |
| 30 |
{$endif} |
| 31 |
end; |
| 32 |
|
| 33 |
implementation |
| 34 |
|
| 35 |
{$ifdef FPC} // CastleLocalizationGetText not available for Delphi yet |
| 36 |
|
| 37 |
uses CastleLocalizationGetText, CastleClassUtils, CastleUIControls, |
| 38 |
CastleComponentSerialize, CastleControls; |
| 39 |
|
| 40 |
procedure TTestLocalizationGetText.TestTranslateUi; |
| 41 |
|
| 42 |
procedure CheckEnglish; |
| 43 |
var |
| 44 |
UiOwner: TComponent; |
| 45 |
//Ui: TCastleUserInterface; |
| 46 |
L: TCastleLabel; |
| 47 |
E: TCastleEdit; |
| 48 |
begin |
| 49 |
UiOwner := TComponent.Create(nil); |
| 50 |
try |
| 51 |
{Ui := }UserInterfaceLoad('castle-data:/localization_gettext/gameviewmain.castle-user-interface', UiOwner); |
| 52 |
L := UiOwner.FindRequiredComponent('Label1') as TCastleLabel; |
| 53 |
AssertEquals('My Label', L.Caption); |
| 54 |
E := UiOwner.FindRequiredComponent('Edit') as TCastleEdit; |
| 55 |
AssertEquals('Initial Edit Contents', E.Text); |
| 56 |
finally FreeAndNil(UiOwner) end; |
| 57 |
end; |
| 58 |
|
| 59 |
procedure CheckPolish; |
| 60 |
var |
| 61 |
UiOwner: TComponent; |
| 62 |
//Ui: TCastleUserInterface; |
| 63 |
L: TCastleLabel; |
| 64 |
E: TCastleEdit; |
| 65 |
begin |
| 66 |
UiOwner := TComponent.Create(nil); |
| 67 |
try |
| 68 |
{Ui := }UserInterfaceLoad('castle-data:/localization_gettext/gameviewmain.castle-user-interface', UiOwner); |
| 69 |
L := UiOwner.FindRequiredComponent('Label1') as TCastleLabel; |
| 70 |
AssertEquals('Moja Etykieta', L.Caption); |
| 71 |
E := UiOwner.FindRequiredComponent('Edit') as TCastleEdit; |
| 72 |
AssertEquals('Początkowa zawartość', E.Text); |
| 73 |
finally FreeAndNil(UiOwner) end; |
| 74 |
end; |
| 75 |
|
| 76 |
begin |
| 77 |
CheckEnglish; |
| 78 |
TranslateAllDesigns('castle-data:/localization_gettext/user_interface.pl.mo'); |
| 79 |
CheckPolish; |
| 80 |
TranslateAllDesigns(''); |
| 81 |
CheckEnglish; |
| 82 |
end; |
| 83 |
{$endif} |
| 84 |
|
| 85 |
initialization |
| 86 |
RegisterTest(TTestLocalizationGetText); |
| 87 |
end. |