zipada_56.0.2_b3043499/test/test_chunk.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
--  Testing End_Error
--  TT's version has a forgiving behaviour for
--  reading arrays beyond the file's end

with Ada.Streams.Stream_IO;             use Ada.Streams.Stream_IO;
with Ada.IO_Exceptions;
with Ada.Text_IO;
with UnZip.Streams;                     use UnZip.Streams;

procedure Test_Chunk is

  procedure Consume_Chunks (s : UnZip.Streams.Stream_Access) is
    chunk : String (1 .. 950); -- Length(f2) = 961 = 31**2
  begin
    for i in 1 .. 1000 loop
      String'Read (s, chunk);
      Ada.Text_IO.Put ('[' & chunk & ']');
    end loop;
  exception
    when Ada.IO_Exceptions.End_Error =>
      Ada.Text_IO.Put ("[=== End_Error (RM 13.13.2(37) T'Read) ===]");
    when Constraint_Error =>
      Ada.Text_IO.Put ("[=== Constraint_Error (OA 7.2.2 on T'Read) ===]");
  end Consume_Chunks;

  f1 : Zipped_File_Type;
  f2 : Ada.Streams.Stream_IO.File_Type;
  a : constant String := "Test_UnZ_Streams.zip";
  n : constant String := "Test_UnZ_Streams.adb";

begin
  --  Test zipped file:
  Open (
        File         => f1,
        Archive_Name => a,
        Name         => n
  );
  Consume_Chunks (Stream (f1));
  Close (f1);
  --  Test unzipped file:
  Open (
        File => f2,
        Mode => In_File,
        Name => n
  );
  Consume_Chunks (UnZip.Streams.Stream_Access (Stream (f2)));
  Close (f2);
end Test_Chunk;