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 ----------------------------------------------------------------
8 -- Continuous test for ZLib multithreading. If the test would fail
9 -- we should provide thread safe allocation routines for the Z_Stream.
11 -- Id: mtest.adb,v 1.4 2004/07/23 07:49:54 vagul Exp
15 with Ada
.Numerics
.Discrete_Random
;
18 with Ada
.Task_Identification
;
24 Stop
: Boolean := False;
28 subtype Visible_Symbols
is Stream_Element
range 16#
20#
.. 16#
7E#
;
30 package Random_Elements
is
31 new Ada
.Numerics
.Discrete_Random
(Visible_Symbols
);
35 task body Test_Task
is
36 Buffer
: Stream_Element_Array
(1 .. 100_000
);
37 Gen
: Random_Elements
.Generator
;
39 Buffer_First
: Stream_Element_Offset
;
40 Compare_First
: Stream_Element_Offset
;
42 Deflate
: Filter_Type
;
43 Inflate
: Filter_Type
;
45 procedure Further
(Item
: in Stream_Element_Array
);
48 (Item
: out Ada
.Streams
.Stream_Element_Array
;
49 Last
: out Ada
.Streams
.Stream_Element_Offset
);
55 procedure Further
(Item
: in Stream_Element_Array
) is
57 procedure Compare
(Item
: in Stream_Element_Array
);
63 procedure Compare
(Item
: in Stream_Element_Array
) is
64 Next_First
: Stream_Element_Offset
:= Compare_First
+ Item
'Length;
66 if Buffer
(Compare_First
.. Next_First
- 1) /= Item
then
70 Compare_First
:= Next_First
;
73 procedure Compare_Write
is new ZLib
.Write
(Write
=> Compare
);
75 Compare_Write
(Inflate
, Item
, No_Flush
);
83 (Item
: out Ada
.Streams
.Stream_Element_Array
;
84 Last
: out Ada
.Streams
.Stream_Element_Offset
)
86 Buff_Diff
: Stream_Element_Offset
:= Buffer
'Last - Buffer_First
;
87 Next_First
: Stream_Element_Offset
;
89 if Item
'Length <= Buff_Diff
then
92 Next_First
:= Buffer_First
+ Item
'Length;
94 Item
:= Buffer
(Buffer_First
.. Next_First
- 1);
96 Buffer_First
:= Next_First
;
98 Last
:= Item
'First + Buff_Diff
;
99 Item
(Item
'First .. Last
) := Buffer
(Buffer_First
.. Buffer
'Last);
100 Buffer_First
:= Buffer
'Last + 1;
104 procedure Translate
is new Generic_Translate
105 (Data_In
=> Read_Buffer
,
106 Data_Out
=> Further
);
109 Random_Elements
.Reset
(Gen
);
111 Buffer
:= (others => 20);
114 for J
in Buffer
'Range loop
115 Buffer
(J
) := Random_Elements
.Random
(Gen
);
117 Deflate_Init
(Deflate
);
118 Inflate_Init
(Inflate
);
120 Buffer_First
:= Buffer
'First;
121 Compare_First
:= Buffer
'First;
125 if Compare_First
/= Buffer
'Last + 1 then
130 (Ada
.Task_Identification
.Image
131 (Ada
.Task_Identification
.Current_Task
)
132 & Stream_Element_Offset
'Image (J
)
133 & ZLib
.Count
'Image (Total_Out
(Deflate
)));
143 Ada
.Text_IO
.Put_Line
(Ada
.Exceptions
.Exception_Information
(E
));
147 Test
: array (1 .. 4) of Test_Task
;
149 pragma Unreferenced
(Test
);
154 Ada
.Text_IO
.Get_Immediate
(Dummy
);