Debian Codegraph @

tests/code/testcases/testcastleinternaldatauri.pas

raw
1 {
2 Copyright 2023-2023 Michalis Kamburelis.
3
4 This file is part of "Castle Game Engine".
5
6 "Castle Game Engine" is free software; see the file COPYING.txt,
7 included in this distribution, for details about the copyright.
8
9 "Castle Game Engine" is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 ----------------------------------------------------------------------------
14 }
15
16 { Test CastleInternalDataUri unit. }
17 unit TestCastleInternalDataUri;
18
19 interface
20
21 uses
22 Classes, SysUtils, CastleTester;
23
24 type
25 TTestCastleInternalDataUri = class(TCastleTestCase)
26 { Test reading data URI encoded with base64. }
27 procedure TestDataUri;
28 end;
29
30 implementation
31
32 uses CastleDownload, CastleInternalSoundFile, CastleImages, CastleUriUtils,
33 CastleSoundBase, CastleUtils;
34
35 procedure TTestCastleInternalDataUri.TestDataUri;
36 const
37 ImageDataUri = {$I data_uri_embedded/bricks_base64.inc};
38 WavDataUri = {$I data_uri_embedded/werewolf_howling_wav_base64.inc};
39 var
40 S: TStream;
41 Img: TCastleImage;
42 SoundFile: TSoundFile;
43 begin
44 S := Download(ImageDataUri);
45 try
46 finally FreeAndNil(S) end;
47
48 Img := LoadImage(ImageDataUri);
49 try
50 AssertEquals(1024, Img.Width);
51 AssertEquals(1024, Img.Height);
52 finally FreeAndNil(Img) end;
53
54 SoundFile := TSoundFile.Create(WavDataUri);
55 try
56 // Writeln('Loaded: ', UriCaption(SoundFile.URL));
57 // Writeln(' Format: ', DataFormatToStr(SoundFile.DataFormat));
58 // Writeln(' Frequency: ', SoundFile.Frequency);
59 // Writeln(' Duration: ', SoundFile.Duration:1:2);
60
61 AssertTrue(SoundFile.DataFormat = sfMono16);
62 AssertSameValue(3.75, SoundFile.Duration, 0.01);
63 AssertEquals(22050, SoundFile.Frequency);
64 AssertEquals('data:audio/x-wav;base64,...', UriCaption(SoundFile.URL));
65 finally FreeAndNil(SoundFile) end;
66 end;
67
68 initialization
69 RegisterTest(TTestCastleInternalDataUri);
70 end.