48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
-
-
+
-
-
+
+
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
+
-
|
(Test : in out NT.Test;
Dict : in Dictionary;
Decompressed : in String;
Compressed : in Ada.Streams.Stream_Element_Array)
is
use type Ada.Streams.Stream_Element_Array;
use type Ada.Streams.Stream_Element_Offset;
Buffer : Ada.Streams.Stream_Element_Array
(1 .. Compressed_Upper_Bound (Dict, Decompressed) + 10);
begin
declare
First_OK : Boolean := False;
begin
declare
Buffer : constant Ada.Streams.Stream_Element_Array
:= Compress (Dict, Decompressed);
Last : Ada.Streams.Stream_Element_Offset;
Done : Boolean := False;
begin
begin
Compress (Dict, Decompressed, Buffer, Last);
Done := True;
begin
First_OK := True;
if Buffer /= Compressed then
Test.Fail ("Bad compression of """ & Decompressed & '"');
Test.Info ("Found: " & Image (Buffer));
Test.Info ("Expected:" & Image (Compressed));
declare
Round : constant String := Decompress (Dict, Buffer);
begin
if Round /= Decompressed then
Test.Info ("Roundtrip failed, got: """ & Round & '"');
else
Test.Info ("Roundtrip OK");
end if;
end;
end if;
end;
exception
when Error : others =>
if not First_OK then
Test.Info ("During compression of """ & Decompressed & '"');
Test.Info ("During compression of """ & Decompressed & '"');
end if;
Test.Report_Exception (Error, NT.Fail);
end;
declare
First_OK : Boolean := False;
begin
declare
Buffer : constant String := Decompress (Dict, Compressed);
begin
First_OK := True;
if Done and then Buffer (1 .. Last) /= Compressed then
Test.Fail ("Compression of """ & Decompressed & """ failed");
Test.Info ("Found: " & Image (Buffer (1 .. Last)));
Test.Info ("Expected:" & Image (Compressed));
if Buffer /= Decompressed then
Test.Fail ("Bad decompression of " & Image (Compressed));
Test.Info ("Found: """ & Buffer & '"');
Test.Info ("Expected:""" & Decompressed & '"');
end if;
declare
declare
Buffer_2 : String
(1 .. Decompressed_Length (Dict, Buffer (1 .. Last)));
Round : constant Ada.Streams.Stream_Element_Array
:= Compress (Dict, Buffer);
Last_2 : Natural;
Done : Boolean := False;
begin
begin
begin
if Round /= Compressed then
Test.Info ("Roundtrip failed, got: " & Image (Round));
else
Decompress (Dict, Buffer (1 .. Last), Buffer_2, Last_2);
Done := True;
exception
when Error : others =>
Test.Info ("During compression of """ & Decompressed & '"');
Test.Info ("Roundtrip OK");
end if;
end;
end if;
end;
exception
when Error : others =>
if not First_OK then
Test.Info ("During compression of " & Image (Compressed));
Test.Report_Exception (Error, NT.Fail);
end;
end if;
if Done and then Buffer_2 (1 .. Last_2) /= Decompressed then
Test.Fail ("Roundtrip for """ & Decompressed & """ failed");
Test.Info ("Found """ & Buffer_2 (1 .. Last_2) & '"');
Test.Report_Exception (Error, NT.Fail);
end if;
end;
end Roundtrip_Test;
-------------------------
-- Complete Test Suite --
|