Natools

Check-in [21fd02233a]
Login
Overview
Comment:smaz-tests: rewrite Roundtrip_Test to make both roundtrip directions
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 21fd02233a1e68449fcd24b2cdc298ee85a799fd
User & Date: nat on 2016-09-18 21:06:16
Other Links: manifest | tags
Context
2016-09-19
17:47
smaz-tests: update the expected compressed to match improved encoder check-in: 4a97e983b0 user: nat tags: trunk
2016-09-18
21:06
smaz-tests: rewrite Roundtrip_Test to make both roundtrip directions check-in: 21fd02233a user: nat tags: trunk
2016-09-17
19:15
smaz: add functions that return directly the filtered array check-in: f85deca432 user: nat tags: trunk
Changes

Modified tests/natools-smaz-tests.adb from [f615a75ea1] to [89531cdf45].

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 --