1-- Testing End_Error
2-- TT's version has a forgiving behaviour for
3-- reading arrays beyond the file's end
4
5with Ada.Streams.Stream_IO;             use Ada.Streams.Stream_IO;
6with Ada.IO_Exceptions;
7with Ada.Text_IO;
8with UnZip.Streams;                     use UnZip.Streams;
9
10procedure Test_Chunk is
11
12  procedure Consume_Chunks(s: UnZip.Streams.Stream_Access) is
13    chunk: String(1..950); -- Length(f2) = 961 = 31**2
14  begin
15    for i in 1..1000 loop
16      String'Read(s, chunk);
17      Ada.Text_IO.Put('[' & chunk & ']');
18    end loop;
19  exception
20    when Ada.IO_Exceptions.End_Error =>
21      Ada.Text_IO.Put("[=== End_Error (RM 13.13.2(37) T'Read) ===]");
22    when Constraint_Error =>
23      Ada.Text_IO.Put("[=== Constraint_Error (OA 7.2.2 on T'Read) ===]");
24  end Consume_Chunks;
25
26  f1: Zipped_File_Type;
27  f2: Ada.Streams.Stream_IO.File_Type;
28  a: constant String:= "Test_UnZ_Streams.zip";
29  n: constant String:= "Test_UnZ_Streams.adb";
30
31begin
32  -- Test zipped file:
33  Open(
34        File         => f1,
35        Archive_Name => a,
36        Name         => n
37  );
38  Consume_Chunks(Stream(f1));
39  Close(f1);
40  -- Test unzipped file:
41  Open(
42        File => f2,
43        Mode => In_File,
44        Name => n
45  );
46  Consume_Chunks(UnZip.Streams.Stream_Access(Stream(f2)));
47  Close(f2);
48end Test_Chunk;
49