Index: tests/natools-smaz_tests.adb ================================================================== --- tests/natools-smaz_tests.adb +++ tests/natools-smaz_tests.adb @@ -15,21 +15,24 @@ ------------------------------------------------------------------------------ with Ada.Streams; with Ada.Strings.Unbounded; with Natools.Smaz_256; +with Natools.Smaz_Generic; with Natools.Smaz_Original; package body Natools.Smaz_Tests is - function Image (S : Ada.Streams.Stream_Element_Array) return String; - - procedure Roundtrip_Test + generic + with package Smaz is new Natools.Smaz_Generic (<>); + procedure Generic_Roundtrip_Test (Test : in out NT.Test; - Dict : in Smaz_256.Dictionary; + Dict : in Smaz.Dictionary; Decompressed : in String; Compressed : in Ada.Streams.Stream_Element_Array); + + function Image (S : Ada.Streams.Stream_Element_Array) return String; ------------------------------ -- Local Helper Subprograms -- ------------------------------ @@ -44,13 +47,13 @@ return To_String (Result); end Image; - procedure Roundtrip_Test + procedure Generic_Roundtrip_Test (Test : in out NT.Test; - Dict : in Smaz_256.Dictionary; + Dict : in Smaz.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; @@ -58,11 +61,11 @@ declare First_OK : Boolean := False; begin declare Buffer : constant Ada.Streams.Stream_Element_Array - := Smaz_256.Compress (Dict, Decompressed); + := Smaz.Compress (Dict, Decompressed); begin First_OK := True; if Buffer /= Compressed then Test.Fail ("Bad compression of """ & Decompressed & '"'); @@ -69,11 +72,11 @@ Test.Info ("Found: " & Image (Buffer)); Test.Info ("Expected:" & Image (Compressed)); declare Round : constant String - := Smaz_256.Decompress (Dict, Buffer); + := Smaz.Decompress (Dict, Buffer); begin if Round /= Decompressed then Test.Info ("Roundtrip failed, got: """ & Round & '"'); else Test.Info ("Roundtrip OK"); @@ -93,11 +96,11 @@ declare First_OK : Boolean := False; begin declare Buffer : constant String - := Smaz_256.Decompress (Dict, Compressed); + := Smaz.Decompress (Dict, Compressed); begin First_OK := True; if Buffer /= Decompressed then Test.Fail ("Bad decompression of " & Image (Compressed)); @@ -104,11 +107,11 @@ Test.Info ("Found: """ & Buffer & '"'); Test.Info ("Expected:""" & Decompressed & '"'); declare Round : constant Ada.Streams.Stream_Element_Array - := Smaz_256.Compress (Dict, Buffer); + := Smaz.Compress (Dict, Buffer); begin if Round /= Compressed then Test.Info ("Roundtrip failed, got: " & Image (Round)); else Test.Info ("Roundtrip OK"); @@ -122,30 +125,46 @@ Test.Info ("During compression of " & Image (Compressed)); end if; Test.Report_Exception (Error, NT.Fail); end; - end Roundtrip_Test; + end Generic_Roundtrip_Test; + + + procedure Roundtrip_Test is new Generic_Roundtrip_Test (Natools.Smaz_256); ------------------------- -- Complete Test Suite -- ------------------------- procedure All_Tests (Report : in out NT.Reporter'Class) is begin - Sample_Strings (Report); + Report.Section ("Base 256"); + All_Tests_256 (Report); + Report.End_Section; end All_Tests; - ---------------------- - -- Individual Tests -- - ---------------------- + ------------------------------ + -- Test Suite for Each Base -- + ------------------------------ + + procedure All_Tests_256 (Report : in out NT.Reporter'Class) is + begin + Sample_Strings_256 (Report); + end All_Tests_256; + + + + ------------------------------- + -- Individual Base-256 Tests -- + ------------------------------- - procedure Sample_Strings (Report : in out NT.Reporter'Class) is + procedure Sample_Strings_256 (Report : in out NT.Reporter'Class) is Test : NT.Test := Report.Item ("Roundtrip on sample strings"); begin Roundtrip_Test (Test, Smaz_Original.Dictionary, "This is a small string", (254, 84, 76, 56, 172, 62, 173, 152, 62, 195, 70)); @@ -181,8 +200,8 @@ Roundtrip_Test (Test, Smaz_Original.Dictionary, ": : : :", (255, 6, 58, 32, 58, 32, 58, 32, 58)); exception when Error : others => Test.Report_Exception (Error); - end Sample_Strings; + end Sample_Strings_256; end Natools.Smaz_Tests; Index: tests/natools-smaz_tests.ads ================================================================== --- tests/natools-smaz_tests.ads +++ tests/natools-smaz_tests.ads @@ -20,8 +20,10 @@ package NT renames Natools.Tests; procedure All_Tests (Report : in out NT.Reporter'Class); - procedure Sample_Strings (Report : in out NT.Reporter'Class); + procedure All_Tests_256 (Report : in out NT.Reporter'Class); + + procedure Sample_Strings_256 (Report : in out NT.Reporter'Class); end Natools.Smaz_Tests;