Skip to content

Commit

Permalink
Remove testsuite dependency to libiconv
Browse files Browse the repository at this point in the history
Migrate gnatcoll-iconv specific code into the dedicated test.
  • Loading branch information
yakobowski committed Jul 10, 2024
1 parent 8ace854 commit fde2b3e
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 133 deletions.
1 change: 0 additions & 1 deletion testsuite/support/test.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
-- The scenario variable TEST_SOURCES is automatically set by the
-- driver to point to the test sources.
with "gnatcoll_core";
with "gnatcoll_iconv";

project Test is
Test_Sources := External("TEST_SOURCES");
Expand Down
98 changes: 0 additions & 98 deletions testsuite/support/test_assert.adb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@
-- --
------------------------------------------------------------------------------

with Ada.Exceptions;
with Ada.Strings.Unbounded;
with Ada.Text_IO;
with GNATCOLL.Iconv;

package body Test_Assert is
package IO renames Ada.Text_IO;
package Iconv renames GNATCOLL.Iconv;

------------
-- Assert --
Expand Down Expand Up @@ -81,100 +77,6 @@ package body Test_Assert is
end if;
end Assert;

------------
-- Assert --
------------

function Bytes_Image (Input : String) return String;
function Bytes_Image (Input : String) return String
is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
for C in Input'Range loop
Ada.Strings.Unbounded.Append (Result, Character'Pos (Input (C))'Img);
end loop;
return Ada.Strings.Unbounded.To_String (Result);
end Bytes_Image;

procedure Assert_Iconv
(Input : String;
Expected : String;
From_Code : String;
To_Code : String;
Transliteration : Boolean := False;
Ignore : Boolean := False;
Msg : String := "";
Location : String := SI.Source_Location)
is
begin
declare
Result : constant String := Iconv.Iconv
(Input => Input,
To_Code => To_Code,
From_Code => From_Code,
Transliteration => Transliteration,
Ignore => Ignore);
Success : constant Boolean := Result = Expected;
begin
Assert (Success, Msg, Location);
if not Success then
IO.Put_Line ("iconv(" & Bytes_Image (Input) &
", to_code => " & To_Code &
", from_code => " & From_code &
", transliteration => " & Transliteration'Img &
", ignore => " & Ignore'Img);
IO.Put_Line ("- expect: " & Bytes_Image (Expected));

IO.Put_Line ("- got: " & Bytes_Image (Result));
end if;
end;
exception
when E : others =>
Assert (False, Msg, Location);
IO.Put_Line ("got exception: " & ASCII.LF &
Ada.Exceptions.Exception_Information (E));
end Assert_Iconv;

procedure Assert_Invalid_Sequence
(Input : String;
From_Code : String;
To_Code : String;
Transliteration : Boolean := False;
Ignore : Boolean := False;
Msg : String := "";
Location : String := SI.Source_Location)
is
begin
declare
Result : constant String := Iconv.Iconv
(Input => Input,
To_Code => To_Code,
From_Code => From_Code,
Transliteration => Transliteration,
Ignore => Ignore);
begin
Assert (False, Msg, Location);
IO.Put_Line ("iconv(" & Input &
", to_code => " & To_Code &
", from_code => " & From_code &
", transliteration => " & Transliteration'Img &
", ignore => " & Ignore'Img);
IO.Put_Line ("- expect: Invalid_Sequence_Error ");
IO.Put ("- got: ");
for C in Result'Range loop
IO.Put (Character'Pos (Result (C))'Img);
end loop;
IO.New_Line;
end;
exception
when Iconv.Invalid_Sequence_Error =>
Assert (True, Msg, Location);
when E : others =>
Assert (False, Msg, Location);
IO.Put_Line ("got exception: " & ASCII.LF &
Ada.Exceptions.Exception_Information (E));
end Assert_Invalid_Sequence;

------------
-- Report --
------------
Expand Down
23 changes: 0 additions & 23 deletions testsuite/support/test_assert.ads
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,6 @@ package Test_Assert is
-- If Left = Right then test case is considered PASSED, otherwise
-- the test status is FAILED and Final_Status set to 1.

procedure Assert_Iconv
(Input : String;
Expected : String;
From_Code : String;
To_Code : String;
Transliteration : Boolean := False;
Ignore : Boolean := False;
Msg : String := "";
Location : String := SI.Source_Location);
-- Transform Input using Iconv and expect Expected as a result
-- The other parameters are for GNATCOLL.Iconv.Iconv

procedure Assert_Invalid_Sequence
(Input : String;
From_Code : String;
To_Code : String;
Transliteration : Boolean := False;
Ignore : Boolean := False;
Msg : String := "";
Location : String := SI.Source_Location);
-- Assert that input sequence will be considered by Iconv as an invalid
-- sequence.

function Report return Natural;
-- Report should be called the following way at the end of a test
-- program main function:
Expand Down
1 change: 0 additions & 1 deletion testsuite/tests/coders/test.gpr
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
with "gnatcoll_core";
with "gnatcoll_iconv";
with "gnatcoll_lzma";
with "gnatcoll_zlib";

Expand Down
121 changes: 112 additions & 9 deletions testsuite/tests/iconv/iconv1/test.adb
Original file line number Diff line number Diff line change
@@ -1,10 +1,113 @@
with Ada.Exceptions;
with Ada.Strings.Unbounded;
with Ada.Text_IO;
with GNAT.Source_Info;
with GNATCOLL.Iconv;
with Test_Assert;

function Test return Integer is

package A renames Test_Assert;
package Iconv renames GNATCOLL.Iconv;
package IO renames Ada.Text_IO;
package SI renames GNAT.Source_Info;


function Bytes_Image (Input : String) return String;
function Bytes_Image (Input : String) return String
is
Result : Ada.Strings.Unbounded.Unbounded_String;
begin
for C in Input'Range loop
Ada.Strings.Unbounded.Append (Result, Character'Pos (Input (C))'Img);
end loop;
return Ada.Strings.Unbounded.To_String (Result);
end Bytes_Image;

procedure Assert_Iconv
(Input : String;
Expected : String;
From_Code : String;
To_Code : String;
Transliteration : Boolean := False;
Ignore : Boolean := False;
Msg : String := "";
Location : String := SI.Source_Location)
is
-- Transform Input using Iconv and expect Expected as a result
-- The other parameters are for GNATCOLL.Iconv.Iconv
begin
declare
Result : constant String := Iconv.Iconv
(Input => Input,
To_Code => To_Code,
From_Code => From_Code,
Transliteration => Transliteration,
Ignore => Ignore);
Success : constant Boolean := Result = Expected;
begin
A.Assert (Success, Msg, Location);
if not Success then
IO.Put_Line ("iconv(" & Bytes_Image (Input) &
", to_code => " & To_Code &
", from_code => " & From_code &
", transliteration => " & Transliteration'Img &
", ignore => " & Ignore'Img);
IO.Put_Line ("- expect: " & Bytes_Image (Expected));

IO.Put_Line ("- got: " & Bytes_Image (Result));
end if;
end;
exception
when E : others =>
A.Assert (False, Msg, Location);
IO.Put_Line ("got exception: " & ASCII.LF &
Ada.Exceptions.Exception_Information (E));
end Assert_Iconv;


procedure Assert_Invalid_Sequence
(Input : String;
From_Code : String;
To_Code : String;
Transliteration : Boolean := False;
Ignore : Boolean := False;
Msg : String := "";
Location : String := SI.Source_Location)
is
-- Assert that input sequence will be considered by Iconv as an invalid
-- sequence.
begin
declare
Result : constant String := Iconv.Iconv
(Input => Input,
To_Code => To_Code,
From_Code => From_Code,
Transliteration => Transliteration,
Ignore => Ignore);
begin
A.Assert (False, Msg, Location);
IO.Put_Line ("iconv(" & Input &
", to_code => " & To_Code &
", from_code => " & From_code &
", transliteration => " & Transliteration'Img &
", ignore => " & Ignore'Img);
IO.Put_Line ("- expect: Invalid_Sequence_Error ");
IO.Put ("- got: ");
for C in Result'Range loop
IO.Put (Character'Pos (Result (C))'Img);
end loop;
IO.New_Line;
end;
exception
when Iconv.Invalid_Sequence_Error =>
A.Assert (True, Msg, Location);
when E : others =>
A.Assert (False, Msg, Location);
IO.Put_Line ("got exception: " & ASCII.LF &
Ada.Exceptions.Exception_Information (E));
end Assert_Invalid_Sequence;


Eacute : constant Character := Character'Val (16#E9#);
-- in Iso_8859-1
Expand All @@ -26,30 +129,30 @@ function Test return Integer is
Character'Val (16#C7#) & Character'Val (16#82#);

begin
A.Assert_Iconv ("Simple test", "Simple test", "", "", Msg => "simple test");
A.Assert_Iconv ("Simple " & Eacute, "Simple " & Eacute_UTF8, Iconv.Iso_8859_1, Iconv.UTF8);
A.Assert_Iconv ("Simple " & R_Koi8, "Simple " & R_UTF8, Iconv.KOI8_R, Iconv.UTF8);
Assert_Iconv ("Simple test", "Simple test", "", "", Msg => "simple test");
Assert_Iconv ("Simple " & Eacute, "Simple " & Eacute_UTF8, Iconv.Iso_8859_1, Iconv.UTF8);
Assert_Iconv ("Simple " & R_Koi8, "Simple " & R_UTF8, Iconv.KOI8_R, Iconv.UTF8);

A.Assert_Invalid_Sequence
Assert_Invalid_Sequence
("Simple " & Eacute, Iconv.Iso_8859_1, Iconv.KOI8_R);

-- Test with invalid character both in the middle and at the end
A.Assert_Iconv
Assert_Iconv
("Simple " & Eacute, "Simple ", Iconv.Iso_8859_1, Iconv.KOI8_R,
Ignore => True);
A.Assert_Iconv
Assert_Iconv
("T" & Eacute & "Simple", "TSimple", Iconv.Iso_8859_1, Iconv.KOI8_R,
Ignore => True);

A.Assert_Iconv
Assert_Iconv
(Input => Ellipsis_UTF8,
Expected => "...",
From_Code => Iconv.UTF8,
To_Code => Iconv.ASCII,
Transliteration => True,
Msg => "Test transliteration on ellipsis");

A.Assert_Iconv
Assert_Iconv
(Input => Ellipsis_UTF8,
Expected => "",
From_Code => Iconv.UTF8,
Expand All @@ -58,7 +161,7 @@ begin
Ignore => True,
Msg => "Test UTF-8 to ASCII of ellipsis without transliteration");

A.Assert_Iconv
Assert_Iconv
(Input => Alveolar_Click & "A",
Expected => "?" & "A",
From_Code => Iconv.UTF8,
Expand Down
1 change: 0 additions & 1 deletion testsuite/tests/omp/sort/test.gpr
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
with "gnatcoll_iconv";
with "gnatcoll_omp";

project Test is
Expand Down

0 comments on commit fde2b3e

Please sign in to comment.