| 1 |
// -*- compile-command: "./test_single_testcase.sh TTestCastleFileFilters" -*- |
| 2 |
{ |
| 3 |
Copyright 2011-2023 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 CastleFileFilters unit. } |
| 18 |
unit TestCastleFileFilters; |
| 19 |
|
| 20 |
interface |
| 21 |
|
| 22 |
uses CastleTester; |
| 23 |
|
| 24 |
type |
| 25 |
TTestCastleFileFilters = class(TCastleTestCase) |
| 26 |
published |
| 27 |
procedure TestFileFilterFromString; |
| 28 |
end; |
| 29 |
|
| 30 |
implementation |
| 31 |
|
| 32 |
uses SysUtils, Classes, CastleFileFilters; |
| 33 |
|
| 34 |
{ Account for hack done in TFileFilterList.LclFmxFiltersFromString |
| 35 |
to account for FMX Linux bug: filter index is 0-based then. } |
| 36 |
{$ifndef FPC} |
| 37 |
{$ifdef LINUX} |
| 38 |
{$define CASTLE_ASSERT_FILTER_BUMPED_1} |
| 39 |
{$endif} |
| 40 |
{$endif} |
| 41 |
|
| 42 |
procedure TTestCastleFileFilters.TestFileFilterFromString; |
| 43 |
var |
| 44 |
LCLFilter: string; |
| 45 |
LCLFilterIndex: Integer; |
| 46 |
begin |
| 47 |
TFileFilterList.LclFmxFiltersFromString('All files (*)|*|*All images (*.png;*.jpg)|*.png;*.jpg|PNG images (*.png)|*.png|JPEG images (*.jpg)|*.jpg', |
| 48 |
LCLFilter, LCLFilterIndex); |
| 49 |
AssertTrue(LCLFilter = 'All files (*)|*|All images (*.png;*.jpg)|*.png;*.jpg|PNG images (*.png)|*.png|JPEG images (*.jpg)|*.jpg|'); |
| 50 |
AssertEquals(2 {$ifdef CASTLE_ASSERT_FILTER_BUMPED_1} -1 {$endif}, LCLFilterIndex); |
| 51 |
|
| 52 |
TFileFilterList.LclFmxFiltersFromString('All files (*)|*|*All images (*.png;*.jpg)|*.png;*.jpg|PNG images (*.png)|*.png|JPEG images (*.jpg)|*.jpg', |
| 53 |
LCLFilter, LCLFilterIndex, false); |
| 54 |
AssertTrue(LCLFilter = 'PNG images (*.png)|*.png|JPEG images (*.jpg)|*.jpg|'); |
| 55 |
AssertEquals(1 {$ifdef CASTLE_ASSERT_FILTER_BUMPED_1} -1 {$endif}, LCLFilterIndex); |
| 56 |
|
| 57 |
TFileFilterList.LclFmxFiltersFromString('All files (*)|*|All images (*.png;*.jpg)|*.png;*.jpg|PNG images (*.png)|*.png|*JPEG images (*.jpg)|*.jpg', |
| 58 |
LCLFilter, LCLFilterIndex, false); |
| 59 |
AssertTrue(LCLFilter = 'PNG images (*.png)|*.png|JPEG images (*.jpg)|*.jpg|'); |
| 60 |
AssertEquals(2 {$ifdef CASTLE_ASSERT_FILTER_BUMPED_1} -1 {$endif}, LCLFilterIndex); |
| 61 |
end; |
| 62 |
|
| 63 |
initialization |
| 64 |
RegisterTest(TTestCastleFileFilters); |
| 65 |
end. |