1 ----------------------------------------------------------------
2 -- ZLib for Ada thick binding. --
4 -- Copyright (C) 2002-2003 Dmitriy Anisimkov --
6 -- Open source license information is in the zlib.ads file. --
7 ----------------------------------------------------------------
9 -- Id: read.adb,v 1.8 2004/05/31 10:53:40 vagul Exp
11 -- Test/demo program for the generic read interface.
13 with Ada
.Numerics
.Discrete_Random
;
23 ------------------------------------
24 -- Test configuration parameters --
25 ------------------------------------
27 File_Size
: Stream_Element_Offset
:= 100_000
;
29 Continuous
: constant Boolean := False;
30 -- If this constant is True, the test would be repeated again and again,
31 -- with increment File_Size for every iteration.
33 Header
: constant ZLib
.Header_Type
:= ZLib
.Default
;
34 -- Do not use Header other than Default in ZLib versions 1.1.4 and older.
36 Init_Random
: constant := 8;
37 -- We are using the same random sequence, in case of we catch bug,
38 -- so we would be able to reproduce it.
42 Pack_Size
: Stream_Element_Offset
;
43 Offset
: Stream_Element_Offset
;
45 Filter
: ZLib
.Filter_Type
;
47 subtype Visible_Symbols
48 is Stream_Element
range 16#
20#
.. 16#
7E#
;
50 package Random_Elements
is new
51 Ada
.Numerics
.Discrete_Random
(Visible_Symbols
);
53 Gen
: Random_Elements
.Generator
;
54 Period
: constant Stream_Element_Offset
:= 200;
55 -- Period constant variable for random generator not to be very random.
56 -- Bigger period, harder random.
58 Read_Buffer
: Stream_Element_Array
(1 .. 2048);
59 Read_First
: Stream_Element_Offset
;
60 Read_Last
: Stream_Element_Offset
;
65 (Item
: out Stream_Element_Array
;
66 Last
: out Stream_Element_Offset
);
67 -- this procedure is for generic instantiation of
69 -- reading data from the File_In.
71 procedure Read
is new ZLib
.Read
74 Rest_First
=> Read_First
,
75 Rest_Last
=> Read_Last
);
82 (Item
: out Stream_Element_Array
;
83 Last
: out Stream_Element_Offset
) is
85 Last
:= Stream_Element_Offset
'Min
87 Item
'First + File_Size
- Offset
);
89 for J
in Item
'First .. Last
loop
90 if J
< Item
'First + Period
then
91 Item
(J
) := Random_Elements
.Random
(Gen
);
93 Item
(J
) := Item
(J
- Period
);
106 Random_Elements
.Reset
(Gen
, Init_Random
);
109 Read_First
:= Read_Buffer
'Last + 1;
110 Read_Last
:= Read_Buffer
'Last;
114 Ada
.Text_IO
.Put_Line
("ZLib " & ZLib
.Version
);
117 for Level
in ZLib
.Compression_Level
'Range loop
119 Ada
.Text_IO
.Put
("Level ="
120 & ZLib
.Compression_Level
'Image (Level
));
122 -- Deflate using generic instantiation.
132 (Stream_Element_Offset
'Image (File_Size
) & " ->");
136 Buffer
: Stream_Element_Array
(1 .. 1024);
137 Last
: Stream_Element_Offset
;
139 Read
(Filter
, Buffer
, Last
);
141 Pack_Size
:= Pack_Size
+ Last
- Buffer
'First + 1;
143 exit when Last
< Buffer
'Last;
147 Ada
.Text_IO
.Put_Line
(Stream_Element_Offset
'Image (Pack_Size
));
152 exit when not Continuous
;
154 File_Size
:= File_Size
+ 1;