diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4c283396..07e750ae 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -107,6 +107,10 @@ build_and_test: $VSS_URL/packages/generic/$PACKAGE/$VERSION/$PACKAGE |\ tar xjf - -C ./data + # Make directory for XUnit test reports + export XUNIT_XML_PATH=.xunit-logs/ + mkdir -p $XUNIT_XML_PATH + # Build VSS and run tests ( eval $(anod printenv --sandbox-dir /it/wave gnatall) ;\ make COVERAGE_MODE=gcov build-libs-static check ;\ @@ -118,12 +122,14 @@ build_and_test: coverage: /^\s*lines:\s*\d+.\d+\%/ artifacts: + when: always reports: coverage_report: coverage_format: cobertura path: gcov.xml codequality: - spellcheck.json + junit: .xunit-logs/*.xml build_gnatdoc: services: diff --git a/gnat/tests/vss_text_tests.gpr b/gnat/tests/vss_text_tests.gpr index e8830980..2ed44014 100644 --- a/gnat/tests/vss_text_tests.gpr +++ b/gnat/tests/vss_text_tests.gpr @@ -49,7 +49,7 @@ project VSS_Text_Tests is end Compiler; package Binder is - for Switches ("Ada") use ("-Wb"); + for Switches ("Ada") use ("-Wb", "-Es"); end Binder; end VSS_Text_Tests; diff --git a/testsuite/common/test_support.adb b/testsuite/common/test_support.adb index 4c44ed5c..d28aa4c6 100644 --- a/testsuite/common/test_support.adb +++ b/testsuite/common/test_support.adb @@ -1,11 +1,79 @@ -- --- Copyright (C) 2021-2022, AdaCore +-- Copyright (C) 2021-2023, AdaCore -- -- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -- +with Ada.Characters.Latin_1; +with Ada.Containers.Vectors; +with Ada.Command_Line; +with Ada.Directories; +with Ada.Environment_Variables; +with Ada.Exceptions; +with Ada.Finalization; +with Ada.Strings.Fixed; +with Ada.Strings.Unbounded; +with Ada.Text_IO; + +with GNAT.Exception_Actions; + package body Test_Support is + use type Ada.Strings.Unbounded.Unbounded_String; + + Default_Testsuite : constant String := "DEFAULT_TESTSUITE"; + Default_Testcase : constant String := "DEFAULT_TESTCASE"; + + type Testcase_Status is (Unknown, Succeed, Failed, Errored, Skipped); + + type Testcase_Information is record + Name : Ada.Strings.Unbounded.Unbounded_String; + Status : Testcase_Status := Unknown; + Message : Ada.Strings.Unbounded.Unbounded_String; + Traceback : Ada.Strings.Unbounded.Unbounded_String; + Assertions : Natural := 0; + end record; + + package Testcase_Vectors is + new Ada.Containers.Vectors (Positive, Testcase_Information); + + type Testsuite_Information is record + Name : Ada.Strings.Unbounded.Unbounded_String; + Testcases : Testcase_Vectors.Vector; + end record; + + package Testsuite_Vectors is + new Ada.Containers.Vectors (Positive, Testsuite_Information); + + type Testsuite_Set_Information is record + Name : Ada.Strings.Unbounded.Unbounded_String; + Testsuites : Testsuite_Vectors.Vector; + end record; + + type Test_Information is + limited new Ada.Finalization.Limited_Controlled with record + Testsuite_Set : Testsuite_Set_Information; + Active_Testsuite : Testsuite_Information; + Active_Testcase : Testcase_Information; + end record; + + overriding procedure Finalize (Self : in out Test_Information); + + procedure Global_Unhandled_Exception + (Occurrence : Ada.Exceptions.Exception_Occurrence); + + Controller : Test_Information; + + procedure Start_Testsuite (Name : String); + + procedure End_Testsuite; + + procedure Start_Testcase (Name : String); + + procedure End_Testcase; + + procedure Write_JUnit_XML (File : String); + ------------ -- Assert -- ------------ @@ -15,11 +83,436 @@ package body Test_Support is Message : String := ""; Location : String := GNAT.Source_Info.Source_Location) is begin + if Controller.Active_Testcase.Name = "" then + -- Start default testcase. + + Start_Testcase (Default_Testcase); + end if; + + -- Increment assertions count + + Controller.Active_Testcase.Assertions := @ + 1; + if not Condition then - raise Test_Failed with "at " - & Location - & (if Message /= "" then " " & Message else ""); + Fail (Message, Location); end if; end Assert; + ------------------ + -- End_Testcase -- + ------------------ + + procedure End_Testcase is + begin + Controller.Active_Testsuite.Testcases.Append + (Controller.Active_Testcase); + + Controller.Active_Testcase := + (Name => <>, + Status => Unknown, + Message => <>, + Traceback => <>, + Assertions => 0); + end End_Testcase; + + ------------------- + -- End_Testsuite -- + ------------------- + + procedure End_Testsuite is + begin + Controller.Testsuite_Set.Testsuites.Append (Controller.Active_Testsuite); + Controller.Active_Testsuite := (Name => <>, Testcases => <>); + end End_Testsuite; + + ---------- + -- Fail -- + ---------- + + procedure Fail + (Message : String := ""; + Location : String := GNAT.Source_Info.Source_Location) is + begin + if Controller.Active_Testcase.Name = "" then + -- Start default testcase. + + Start_Testcase (Default_Testcase); + end if; + + Controller.Active_Testcase.Message := + Ada.Strings.Unbounded.To_Unbounded_String (Message); + + Controller.Active_Testcase.Traceback := + Ada.Strings.Unbounded.To_Unbounded_String (Location); + + Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); + + raise Test_Failed with "at " + & Location + & (if Message /= "" then " " & Message else ""); + end Fail; + + -------------- + -- Finalize -- + -------------- + + overriding procedure Finalize (Self : in out Test_Information) is + JUnit_XML_Variable : constant String := "XUNIT_XML_PATH"; + + Verbose : constant Boolean := + (for some J in 1 .. Ada.Command_Line.Argument_Count => + Ada.Command_Line.Argument (J) = "--verbose") + or else + Ada.Environment_Variables.Exists ("VERBOSE_TEST_REPORT"); + + begin + if Controller.Active_Testcase.Name = Default_Testcase then + -- End default testcase. + + End_Testcase; + end if; + + if Controller.Active_Testsuite.Name = Default_Testsuite then + -- End default testsuite. + + End_Testsuite; + end if; + + if Ada.Environment_Variables.Exists (JUnit_XML_Variable) then + declare + Path : constant String := + Ada.Environment_Variables.Value (JUnit_XML_Variable); + + Main : constant String := Ada.Directories.Base_Name + (Ada.Command_Line.Command_Name); + + File : constant String := Ada.Directories.Compose + (Path, Main, "xml"); + begin + Write_JUnit_XML (File); + end; + end if; + + Ada.Text_IO.Put_Line + (Ada.Strings.Unbounded.To_String (Controller.Testsuite_Set.Name) + & ':'); + + for Testsuite of Controller.Testsuite_Set.Testsuites loop + Ada.Text_IO.Put_Line + (" " & Ada.Strings.Unbounded.To_String (Testsuite.Name) & ':'); + + for Testcase of Testsuite.Testcases loop + Ada.Text_IO.Put_Line + (" " & Ada.Strings.Unbounded.To_String (Testcase.Name) + & ": " & Testcase_Status'Image (Testcase.Status) + & (if Verbose and then Testcase.Message /= "" + then Ada.Characters.Latin_1.HT & + Ada.Strings.Unbounded.To_String (Testcase.Message) + else "")); + + if Verbose and Testcase.Traceback /= "" then + Ada.Text_IO.Put_Line + (Ada.Strings.Unbounded.To_String (Testcase.Traceback)); + + Ada.Text_IO.New_Line; + end if; + end loop; + end loop; + + if (for some Testsuite of Controller.Testsuite_Set.Testsuites => + (for some Testcase of Testsuite.Testcases => + Testcase.Status /= Succeed)) + then + Ada.Text_IO.New_Line; + Ada.Text_IO.Put_Line ("SOME TESTCASE HAS NOT SUCCEED!"); + + if not Verbose then + Ada.Text_IO.New_Line; + Ada.Text_IO.Put ("Run with `--verbose` option or "); + Ada.Text_IO.Put ("VERBOSE_TEST_REPORT environment set "); + Ada.Text_IO.Put_Line ("to see more info."); + end if; + end if; + exception + when E : others => + -- Handle all exceptions in the finalization. + -- GDB can't catch them, because they raised in the runtime + -- finalization and this makes hard to debug. + Ada.Text_IO.Put_Line (Ada.Exceptions.Exception_Information (E)); + Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); + end Finalize; + + -------------------------------- + -- Global_Unhandled_Exception -- + -------------------------------- + + procedure Global_Unhandled_Exception + (Occurrence : Ada.Exceptions.Exception_Occurrence) + is + use type Ada.Exceptions.Exception_Id; + + begin + if Controller.Active_Testcase.Name = "" then + Start_Testcase (Default_Testcase); + end if; + + -- Set status of the active testcase depending of the unhandled + -- exception. It is case when default testsuite and default testcase + -- are used. + + if Ada.Exceptions.Exception_Identity (Occurrence) + = Test_Failed'Identity + then + Controller.Active_Testcase.Status := Failed; + + elsif Ada.Exceptions.Exception_Identity (Occurrence) + = Test_Skipped'Identity + then + Controller.Active_Testcase.Status := Skipped; + + else + Controller.Active_Testcase.Status := Errored; + end if; + end Global_Unhandled_Exception; + + ------------------ + -- Run_Testcase -- + ------------------ + + procedure Run_Testcase + (Testcase : not null access procedure; + Name : String; + Message : String := ""; + Location : String := GNAT.Source_Info.Source_Location) + is + pragma Unreferenced (Message, Location); + + begin + Start_Testcase (Name); + + Testcase.all; + + End_Testcase; + + exception + when Test_Failed => + Controller.Active_Testcase.Status := Failed; + End_Testcase; + + when Test_Skipped => + Controller.Active_Testcase.Status := Skipped; + End_Testcase; + + when E : others => + Controller.Active_Testcase.Status := Errored; + + Controller.Active_Testcase.Message := + Ada.Strings.Unbounded.To_Unbounded_String + (Ada.Exceptions.Exception_Message (E)); + + Controller.Active_Testcase.Traceback := + Ada.Strings.Unbounded.To_Unbounded_String + (Ada.Exceptions.Exception_Information (E)); + + End_Testcase; + end Run_Testcase; + + ------------------- + -- Run_Testsuite -- + ------------------- + + procedure Run_Testsuite + (Testsuite : not null access procedure; + Name : String; + Message : String := ""; + Location : String := GNAT.Source_Info.Source_Location) + is + pragma Unreferenced (Message, Location); + + begin + Start_Testsuite (Name); + + Testsuite.all; + + End_Testsuite; + + exception + when others => + End_Testsuite; + end Run_Testsuite; + + ---------- + -- Skip -- + ---------- + + procedure Skip + (Message : String := ""; + Location : String := GNAT.Source_Info.Source_Location) + is + pragma Unreferenced (Location); + + begin + if Controller.Active_Testcase.Name = "" then + -- Start default testcase. + + Start_Testcase (Default_Testcase); + end if; + + Controller.Active_Testcase.Message := + Ada.Strings.Unbounded.To_Unbounded_String (Message); + + Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure); + + raise Test_Skipped; + end Skip; + + -------------------- + -- Start_Testcase -- + -------------------- + + procedure Start_Testcase (Name : String) is + begin + if Controller.Active_Testcase.Name /= "" then + raise Program_Error; + -- XXX Nested testcases is not supported. + end if; + + if Controller.Active_Testsuite.Name = "" then + -- Start default testsuite. + + Start_Testsuite (Default_Testsuite); + end if; + + Controller.Active_Testcase := + (Name => Ada.Strings.Unbounded.To_Unbounded_String (Name), + Status => Succeed, + Message => <>, + Traceback => <>, + Assertions => 0); + end Start_Testcase; + + --------------------- + -- Start_Testsuite -- + --------------------- + + procedure Start_Testsuite (Name : String) is + begin + if Controller.Active_Testsuite.Name /= "" then + raise Program_Error; + -- XXX Nested testsuites not implemented. + end if; + + Controller.Active_Testsuite := + (Name => Ada.Strings.Unbounded.To_Unbounded_String (Name), + Testcases => <>); + end Start_Testsuite; + + --------------------- + -- Write_JUnit_XML -- + --------------------- + + procedure Write_JUnit_XML (File : String) is + Output : Ada.Text_IO.File_Type; + begin + Ada.Text_IO.Create (Output, Name => File, Form => "WCEM=8"); + + Ada.Text_IO.Put_Line + (Output, ""); + + Ada.Text_IO.Put (Output, ""); + + for Testsuite of Controller.Testsuite_Set.Testsuites loop + + Ada.Text_IO.Put (Output, " "); + + for Testcase of Testsuite.Testcases loop + + Ada.Text_IO.Put (Output, " + Ada.Text_IO.Put_Line + (Output, + ">BAD TESTSUITE: Unknown testcase status"); + + when Succeed => + Ada.Text_IO.Put_Line (Output, "/>"); + + when Failed => + Ada.Text_IO.Put (Output, ">"); + + Ada.Text_IO.Put_Line + (Output, + Ada.Strings.Unbounded.To_String (Testcase.Traceback)); + + Ada.Text_IO.Put_Line (Output, ""); + + when Errored => + Ada.Text_IO.Put_Line (Output, ">"); + + Ada.Text_IO.Put + (Output, + Ada.Strings.Unbounded.To_String (Testcase.Message)); + + Ada.Text_IO.Put_Line + (Output, + Ada.Strings.Unbounded.To_String (Testcase.Traceback)); + + Ada.Text_IO.Put_Line (Output, ""); + + when Skipped => + -- There is no clear definition of use of the 'message' + -- attribute of the 'skipped' tag. It is generated for + -- compatibility with e3's XUnit XML convertor'. + + Ada.Text_IO.Put + (Output, ">"); + end case; + end loop; + + Ada.Text_IO.Put_Line (Output, " "); + + end loop; + + Ada.Text_IO.Put_Line (Output, ""); + Ada.Text_IO.Close (Output); + end Write_JUnit_XML; + +begin + Controller.Testsuite_Set.Name := + Ada.Strings.Unbounded.To_Unbounded_String (Ada.Command_Line.Command_Name); + GNAT.Exception_Actions.Register_Global_Unhandled_Action + (Global_Unhandled_Exception'Access); end Test_Support; diff --git a/testsuite/common/test_support.ads b/testsuite/common/test_support.ads index 8b8bd10a..339aec64 100644 --- a/testsuite/common/test_support.ads +++ b/testsuite/common/test_support.ads @@ -1,18 +1,90 @@ -- --- Copyright (C) 2021-2022, AdaCore +-- Copyright (C) 2021-2023, AdaCore -- -- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -- +-- Package to support test control and report generation. +-- +-- Typical use of the package is present in code snippet below. +-- +-- procedure Test_Driver is +-- +-- procedure Testcase is +-- begin +-- Test_Support.Assert (True /= False, "True is not False"); +-- Test_Support.Assert (True = True, "True is True"); +-- Test_Support.Assert (False = False, "False is False"); +-- end Testcase; +-- +-- procedure Testsuite is +-- begin +-- Test_Support.Run_Testcase (Testcase'Access, "equal-operator"); +-- -- more calls of Run_Testcase +-- end Testsuite; +-- +-- begin +-- Test_Support.Run_Testsuite (Testsuite'Access, "test of Boolean"); +-- end Test_Driver; +-- +-- Call of Assert with False contition terminates execution of the testcase. +-- Testcase execution can be terminated by the call of Fail subprogram, it +-- means that testcase fails, or by the call of Skip subprogram, it means +-- that testcase is not executed. +-- +-- Testcase subprogram not need to catch exceptions, in case of unhandled +-- exception testcase's status is set to error. +-- +-- If some testcase failed/errored/skipped, execution of other testcases and +-- testsuites continues. +-- +-- It is possible to avoid call of Run_Testsuite when there is only single +-- testsuite present, testsuite name DEFAULT_TESTSUITE will be created in +-- such case. However, it is not recommended. +-- +-- Likewise, it is possible to avoit call of Run_Testcase and use only Assert, +-- Fail, Skip subprograms. Both default testsuite and testcase will be created +-- in this case. It is not recommended too. + with GNAT.Source_Info; package Test_Support is - Test_Failed : exception; + pragma Elaborate_Body; + + procedure Run_Testsuite + (Testsuite : not null access procedure; + Name : String; + Message : String := ""; + Location : String := GNAT.Source_Info.Source_Location); + -- Run given subprogram as testsuite. + + procedure Run_Testcase + (Testcase : not null access procedure; + Name : String; + Message : String := ""; + Location : String := GNAT.Source_Info.Source_Location); + -- Run given subprogram as testcase. procedure Assert (Condition : Boolean; Message : String := ""; Location : String := GNAT.Source_Info.Source_Location); + -- Check condition and terminates testcase execution when it is False. + + procedure Fail + (Message : String := ""; + Location : String := GNAT.Source_Info.Source_Location) with No_Return; + -- Terminates testcase execution and mark testcase as failed. + + procedure Skip + (Message : String := ""; + Location : String := GNAT.Source_Info.Source_Location) with No_Return; + -- Terminates testcase execution and mark testcase as skipped. + +private + + Test_Failed : exception; + Test_Skipped : exception; end Test_Support; diff --git a/testsuite/json/test_json_content_handler.adb b/testsuite/json/test_json_content_handler.adb index 994ae261..aa7c6064 100644 --- a/testsuite/json/test_json_content_handler.adb +++ b/testsuite/json/test_json_content_handler.adb @@ -1,5 +1,5 @@ -- --- Copyright (C) 2020-2021, AdaCore +-- Copyright (C) 2020-2023, AdaCore -- -- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -- @@ -12,8 +12,12 @@ with Ada.Assertions; with VSS.JSON.Content_Handlers; with VSS.Strings; +with Test_Support; + procedure Test_JSON_Content_Handler is + procedure Test_JSON_Content_Handler; + type Test_Content_Handler is limited new VSS.JSON.Content_Handlers.JSON_Content_Handler with record @@ -192,214 +196,342 @@ procedure Test_JSON_Content_Handler is Success := Self.Status; end String_Value; - Handler : aliased Test_Content_Handler; + ------------------------------- + -- Test_JSON_Content_Handler -- + ------------------------------- -begin - -- Start_Document + procedure Test_JSON_Content_Handler is + Handler : aliased Test_Content_Handler; - Handler.Status := True; - Handler.Start_Document; + procedure Test_Start_Document; + -- Start_Document - begin - Handler.Status := False; - Handler.Start_Document; + procedure Test_End_Document; + -- End_Document - raise Program_Error; + procedure Test_Start_Array; + -- Start_Array - exception - when Ada.Assertions.Assertion_Error => - null; - end; + procedure Test_End_Array; + -- End_Array - -- End_Document + procedure Test_Start_Object; + -- Start_Object - Handler.Status := True; - Handler.End_Document; + procedure Test_End_Object; + -- End_Object - begin - Handler.Status := False; - Handler.End_Document; + procedure Test_Key_Name; + -- Key_Name - raise Program_Error; + procedure Test_String_Value; + -- String_Value - exception - when Ada.Assertions.Assertion_Error => - null; - end; + procedure Test_Number_Value; + -- Number_Value - -- Start_Array + procedure Test_Boolean_Value; + -- Boolean_Value - Handler.Status := True; - Handler.Start_Array; + procedure Test_Null_Value; + -- Null_Value - begin - Handler.Status := False; - Handler.Start_Array; + procedure Test_Integer_Value; + -- Integer_Value - raise Program_Error; + procedure Test_Float_Value; + -- Float_Value - exception - when Ada.Assertions.Assertion_Error => - null; - end; + ------------------------ + -- Test_Boolean_Value -- + ------------------------ - -- End_Array + procedure Test_Boolean_Value is + begin + Handler.Status := True; + Handler.Boolean_Value (False); - Handler.Status := True; - Handler.End_Array; + begin + Handler.Status := False; + Handler.Boolean_Value (False); - begin - Handler.Status := False; - Handler.End_Array; + Test_Support.Fail; - raise Program_Error; + exception + when Ada.Assertions.Assertion_Error => + null; + end; + end Test_Boolean_Value; - exception - when Ada.Assertions.Assertion_Error => - null; - end; + -------------------- + -- Test_End_Array -- + -------------------- - -- Start_Object + procedure Test_End_Array is + begin + Handler.Status := True; + Handler.End_Array; - Handler.Status := True; - Handler.Start_Object; + begin + Handler.Status := False; + Handler.End_Array; - begin - Handler.Status := False; - Handler.Start_Object; + Test_Support.Fail; - raise Program_Error; + exception + when Ada.Assertions.Assertion_Error => + null; + end; + end Test_End_Array; - exception - when Ada.Assertions.Assertion_Error => - null; - end; + ----------------------- + -- Test_End_Document -- + ----------------------- - -- End_Object + procedure Test_End_Document is + begin + Handler.Status := True; + Handler.End_Document; - Handler.Status := True; - Handler.End_Object; + begin + Handler.Status := False; + Handler.End_Document; - begin - Handler.Status := False; - Handler.End_Object; + Test_Support.Fail; - raise Program_Error; + exception + when Ada.Assertions.Assertion_Error => + null; + end; + end Test_End_Document; - exception - when Ada.Assertions.Assertion_Error => - null; - end; + --------------------- + -- Test_End_Object -- + --------------------- - -- Key_Name + procedure Test_End_Object is + begin + Handler.Status := True; + Handler.End_Object; - Handler.Status := True; - Handler.Key_Name (VSS.Strings.Empty_Virtual_String); - - begin - Handler.Status := False; - Handler.Key_Name (VSS.Strings.Empty_Virtual_String); + begin + Handler.Status := False; + Handler.End_Object; - raise Program_Error; + Test_Support.Fail; - exception - when Ada.Assertions.Assertion_Error => - null; - end; - - -- String_Value - - Handler.Status := True; - Handler.String_Value (VSS.Strings.Empty_Virtual_String); - - begin - Handler.Status := False; - Handler.String_Value (VSS.Strings.Empty_Virtual_String); - - raise Program_Error; - - exception - when Ada.Assertions.Assertion_Error => - null; - end; - - -- Number_Value - - Handler.Status := True; - Handler.Number_Value ((others => <>)); - - begin - Handler.Status := False; - Handler.Number_Value ((others => <>)); + exception + when Ada.Assertions.Assertion_Error => + null; + end; + end Test_End_Object; - raise Program_Error; + ---------------------- + -- Test_Float_Value -- + ---------------------- + + procedure Test_Float_Value is + begin + Handler.Status := True; + Handler.Float_Value (0.0); + + begin + Handler.Status := False; + Handler.Float_Value (0.0); + + Test_Support.Fail; + + exception + when Ada.Assertions.Assertion_Error => + null; + end; + end Test_Float_Value; + + ------------------------ + -- Test_Integer_Value -- + ------------------------ + + procedure Test_Integer_Value is + begin + Handler.Status := True; + Handler.Integer_Value (0); + + begin + Handler.Status := False; + Handler.Integer_Value (0); + + Test_Support.Fail; + + exception + when Ada.Assertions.Assertion_Error => + null; + end; + end Test_Integer_Value; + + ------------------- + -- Test_Key_Name -- + ------------------- + + procedure Test_Key_Name is + begin + Handler.Status := True; + Handler.Key_Name (VSS.Strings.Empty_Virtual_String); + + begin + Handler.Status := False; + Handler.Key_Name (VSS.Strings.Empty_Virtual_String); + + Test_Support.Fail; + + exception + when Ada.Assertions.Assertion_Error => + null; + end; + end Test_Key_Name; + + --------------------- + -- Test_Null_Value -- + --------------------- + + procedure Test_Null_Value is + begin + Handler.Status := True; + Handler.Null_Value; + + begin + Handler.Status := False; + Handler.Null_Value; + + Test_Support.Fail; + + exception + when Ada.Assertions.Assertion_Error => + null; + end; + end Test_Null_Value; + + ----------------------- + -- Test_Number_Value -- + ----------------------- + + procedure Test_Number_Value is + begin + Handler.Status := True; + Handler.Number_Value ((others => <>)); + + begin + Handler.Status := False; + Handler.Number_Value ((others => <>)); + + Test_Support.Fail; + + exception + when Ada.Assertions.Assertion_Error => + null; + end; + end Test_Number_Value; + + ---------------------- + -- Test_Start_Array -- + ---------------------- + + procedure Test_Start_Array is + begin + Handler.Status := True; + Handler.Start_Array; + + begin + Handler.Status := False; + Handler.Start_Array; + + Test_Support.Fail; + + exception + when Ada.Assertions.Assertion_Error => + null; + end; + end Test_Start_Array; + + ------------------------- + -- Test_Start_Document -- + ------------------------- + + procedure Test_Start_Document is + begin + Handler.Status := True; + Handler.Start_Document; + + begin + Handler.Status := False; + Handler.Start_Document; + + Test_Support.Fail; + + exception + when Ada.Assertions.Assertion_Error => + null; + end; + end Test_Start_Document; + + ----------------------- + -- Test_Start_Object -- + ----------------------- - exception - when Ada.Assertions.Assertion_Error => - null; - end; + procedure Test_Start_Object is + begin + Handler.Status := True; + Handler.Start_Object; + + begin + Handler.Status := False; + Handler.Start_Object; + + Test_Support.Fail; + + exception + when Ada.Assertions.Assertion_Error => + null; + end; + end Test_Start_Object; + + ----------------------- + -- Test_String_Value -- + ----------------------- - -- Boolean_Value + procedure Test_String_Value is + begin + Handler.Status := True; + Handler.String_Value (VSS.Strings.Empty_Virtual_String); + + begin + Handler.Status := False; + Handler.String_Value (VSS.Strings.Empty_Virtual_String); + + Test_Support.Fail; - Handler.Status := True; - Handler.Boolean_Value (False); + exception + when Ada.Assertions.Assertion_Error => + null; + end; + end Test_String_Value; begin - Handler.Status := False; - Handler.Boolean_Value (False); + Test_Support.Run_Testcase (Test_Start_Document'Access, "Start_Document"); + Test_Support.Run_Testcase (Test_End_Document'Access, "End_Document"); + Test_Support.Run_Testcase (Test_Start_Array'Access, "Start_Array"); + Test_Support.Run_Testcase (Test_End_Array'Access, "End_Array"); + Test_Support.Run_Testcase (Test_Start_Object'Access, "Start_Object"); + Test_Support.Run_Testcase (Test_End_Object'Access, "End_Object"); + Test_Support.Run_Testcase (Test_Key_Name'Access, "Key_Name"); + Test_Support.Run_Testcase (Test_String_Value'Access, "String_Value"); + Test_Support.Run_Testcase (Test_Number_Value'Access, "Number_Value"); + Test_Support.Run_Testcase (Test_Boolean_Value'Access, "Boolean_Value"); + Test_Support.Run_Testcase (Test_Null_Value'Access, "Null_Value"); + Test_Support.Run_Testcase (Test_Integer_Value'Access, "Integer_Value"); + Test_Support.Run_Testcase (Test_Float_Value'Access, "Float_Value"); + end Test_JSON_Content_Handler; - raise Program_Error; - - exception - when Ada.Assertions.Assertion_Error => - null; - end; - - -- Null_Value - - Handler.Status := True; - Handler.Null_Value; - - begin - Handler.Status := False; - Handler.Null_Value; - - raise Program_Error; - - exception - when Ada.Assertions.Assertion_Error => - null; - end; - - -- Integer_Value - - Handler.Status := True; - Handler.Integer_Value (0); - - begin - Handler.Status := False; - Handler.Integer_Value (0); - - raise Program_Error; - - exception - when Ada.Assertions.Assertion_Error => - null; - end; - - -- Float_Value - - Handler.Status := True; - Handler.Float_Value (0.0); - - begin - Handler.Status := False; - Handler.Float_Value (0.0); - - raise Program_Error; - - exception - when Ada.Assertions.Assertion_Error => - null; - end; +begin + Test_Support.Run_Testsuite + (Test_JSON_Content_Handler'Access, "JSON_Content_Handler"); end Test_JSON_Content_Handler; diff --git a/testsuite/text/test_characters.adb b/testsuite/text/test_characters.adb index 8562516b..5f1449cc 100644 --- a/testsuite/text/test_characters.adb +++ b/testsuite/text/test_characters.adb @@ -28,11 +28,13 @@ procedure Test_Characters is procedure Test_Properties; -- Test properties of all characters. - procedure Test_Well_Know; + procedure Test_Well_Known; -- Test properties of few well known character to be sure that properties -- for them have expected values. Full coverage of all characters is done -- in other tests for some groups of properties. + UCD_Loaded : Boolean := False; + -------------------- -- Initialize_UCD -- -------------------- @@ -40,7 +42,7 @@ procedure Test_Characters is procedure Initialize_UCD is begin if Ada.Command_Line.Argument_Count /= 1 then - raise Program_Error; + return; end if; declare @@ -56,6 +58,8 @@ procedure Test_Characters is UCD.Derived_General_Category_Loader.Load (UCD_Root); UCD.Derived_Core_Properties_Loader.Load (UCD_Root); + + UCD_Loaded := True; end; end Initialize_UCD; @@ -64,168 +68,178 @@ procedure Test_Characters is --------------------- procedure Test_Properties is - use type UCD.Properties.Property_Value_Access; - - GC_Property : constant UCD.Properties.Property_Access := - UCD.Properties.Resolve ("gc"); - GC_Mapping : constant - array (VSS.Characters.General_Category) - of UCD.Properties.Property_Value_Access := - [VSS.Characters.Uppercase_Letter => - UCD.Properties.Resolve (GC_Property, "Lu"), - VSS.Characters.Lowercase_Letter => - UCD.Properties.Resolve (GC_Property, "Ll"), - VSS.Characters.Titlecase_Letter => - UCD.Properties.Resolve (GC_Property, "Lt"), - VSS.Characters.Modifier_Letter => - UCD.Properties.Resolve (GC_Property, "Lm"), - VSS.Characters.Other_Letter => - UCD.Properties.Resolve (GC_Property, "Lo"), - - VSS.Characters.Nonspacing_Mark => - UCD.Properties.Resolve (GC_Property, "Mn"), - VSS.Characters.Spacing_Mark => - UCD.Properties.Resolve (GC_Property, "Mc"), - VSS.Characters.Enclosing_Mark => - UCD.Properties.Resolve (GC_Property, "Me"), - - VSS.Characters.Decimal_Number => - UCD.Properties.Resolve (GC_Property, "Nd"), - VSS.Characters.Letter_Number => - UCD.Properties.Resolve (GC_Property, "Nl"), - VSS.Characters.Other_Number => - UCD.Properties.Resolve (GC_Property, "No"), - - VSS.Characters.Connector_Punctuation => - UCD.Properties.Resolve (GC_Property, "Pc"), - VSS.Characters.Dash_Punctuation => - UCD.Properties.Resolve (GC_Property, "Pd"), - VSS.Characters.Open_Punctuation => - UCD.Properties.Resolve (GC_Property, "Ps"), - VSS.Characters.Close_Punctuation => - UCD.Properties.Resolve (GC_Property, "Pe"), - VSS.Characters.Initial_Punctuation => - UCD.Properties.Resolve (GC_Property, "Pi"), - VSS.Characters.Final_Punctuation => - UCD.Properties.Resolve (GC_Property, "Pf"), - VSS.Characters.Other_Punctuation => - UCD.Properties.Resolve (GC_Property, "Po"), - - VSS.Characters.Math_Symbol => - UCD.Properties.Resolve (GC_Property, "Sm"), - VSS.Characters.Currency_Symbol => - UCD.Properties.Resolve (GC_Property, "Sc"), - VSS.Characters.Modifier_Symbol => - UCD.Properties.Resolve (GC_Property, "Sk"), - VSS.Characters.Other_Symbol => - UCD.Properties.Resolve (GC_Property, "So"), - - VSS.Characters.Space_Separator => - UCD.Properties.Resolve (GC_Property, "Zs"), - VSS.Characters.Line_Separator => - UCD.Properties.Resolve (GC_Property, "Zl"), - VSS.Characters.Paragraph_Separator => - UCD.Properties.Resolve (GC_Property, "Zp"), - - VSS.Characters.Control => - UCD.Properties.Resolve (GC_Property, "Cc"), - VSS.Characters.Format => - UCD.Properties.Resolve (GC_Property, "Cf"), - VSS.Characters.Surrogate => - UCD.Properties.Resolve (GC_Property, "Cs"), - VSS.Characters.Private_Use => - UCD.Properties.Resolve (GC_Property, "Co"), - VSS.Characters.Unassigned => - UCD.Properties.Resolve (GC_Property, "Cn")]; - - Lowercase_Property : constant UCD.Properties.Property_Access := - UCD.Properties.Resolve ("Lowercase"); - Lowercase_Y : constant UCD.Properties.Property_Value_Access := - UCD.Properties.Resolve (Lowercase_Property, "Y"); - Lowercase_N : constant UCD.Properties.Property_Value_Access := - UCD.Properties.Resolve (Lowercase_Property, "N"); - Uppercase_Property : constant UCD.Properties.Property_Access := - UCD.Properties.Resolve ("Uppercase"); - Uppercase_Y : constant UCD.Properties.Property_Value_Access := - UCD.Properties.Resolve (Uppercase_Property, "Y"); - Uppercase_N : constant UCD.Properties.Property_Value_Access := - UCD.Properties.Resolve (Uppercase_Property, "N"); - Cased_Property : constant UCD.Properties.Property_Access := - UCD.Properties.Resolve ("Cased"); - Cased_Y : constant UCD.Properties.Property_Value_Access := - UCD.Properties.Resolve (Cased_Property, "Y"); - Cased_N : constant UCD.Properties.Property_Value_Access := - UCD.Properties.Resolve (Cased_Property, "N"); - begin - for Character in VSS.Characters.Virtual_Character'First_Valid - .. VSS.Characters.Virtual_Character'Last_Valid - loop - -- General Category - - Test_Support.Assert - (UCD.Characters.Get - (VSS.Characters.Virtual_Character'Pos (Character), GC_Property) - = GC_Mapping (VSS.Characters.Get_General_Category (Character))); - - -- Lowercase - - if VSS.Characters.Is_Valid_Virtual_Character (Character) - and then VSS.Characters.Get_Lowercase (Character) - then - Test_Support.Assert - (UCD.Characters.Get - (VSS.Characters.Virtual_Character'Pos (Character), - Lowercase_Property) = Lowercase_Y); - - else - Test_Support.Assert - (UCD.Characters.Get - (VSS.Characters.Virtual_Character'Pos (Character), - Lowercase_Property) = Lowercase_N); - end if; - - -- Uppercase - - if VSS.Characters.Is_Valid_Virtual_Character (Character) - and then VSS.Characters.Get_Uppercase (Character) - then - Test_Support.Assert - (UCD.Characters.Get - (VSS.Characters.Virtual_Character'Pos (Character), - Uppercase_Property) = Uppercase_Y); + Initialize_UCD; - else - Test_Support.Assert - (UCD.Characters.Get - (VSS.Characters.Virtual_Character'Pos (Character), - Uppercase_Property) = Uppercase_N); - end if; + if not UCD_Loaded then + Test_Support.Fail ("UCD is not available"); + end if; - -- Cased + declare + use type UCD.Properties.Property_Value_Access; + + GC_Property : constant UCD.Properties.Property_Access := + UCD.Properties.Resolve ("gc"); + GC_Mapping : constant + array (VSS.Characters.General_Category) + of UCD.Properties.Property_Value_Access := + [VSS.Characters.Uppercase_Letter => + UCD.Properties.Resolve (GC_Property, "Lu"), + VSS.Characters.Lowercase_Letter => + UCD.Properties.Resolve (GC_Property, "Ll"), + VSS.Characters.Titlecase_Letter => + UCD.Properties.Resolve (GC_Property, "Lt"), + VSS.Characters.Modifier_Letter => + UCD.Properties.Resolve (GC_Property, "Lm"), + VSS.Characters.Other_Letter => + UCD.Properties.Resolve (GC_Property, "Lo"), + + VSS.Characters.Nonspacing_Mark => + UCD.Properties.Resolve (GC_Property, "Mn"), + VSS.Characters.Spacing_Mark => + UCD.Properties.Resolve (GC_Property, "Mc"), + VSS.Characters.Enclosing_Mark => + UCD.Properties.Resolve (GC_Property, "Me"), + + VSS.Characters.Decimal_Number => + UCD.Properties.Resolve (GC_Property, "Nd"), + VSS.Characters.Letter_Number => + UCD.Properties.Resolve (GC_Property, "Nl"), + VSS.Characters.Other_Number => + UCD.Properties.Resolve (GC_Property, "No"), + + VSS.Characters.Connector_Punctuation => + UCD.Properties.Resolve (GC_Property, "Pc"), + VSS.Characters.Dash_Punctuation => + UCD.Properties.Resolve (GC_Property, "Pd"), + VSS.Characters.Open_Punctuation => + UCD.Properties.Resolve (GC_Property, "Ps"), + VSS.Characters.Close_Punctuation => + UCD.Properties.Resolve (GC_Property, "Pe"), + VSS.Characters.Initial_Punctuation => + UCD.Properties.Resolve (GC_Property, "Pi"), + VSS.Characters.Final_Punctuation => + UCD.Properties.Resolve (GC_Property, "Pf"), + VSS.Characters.Other_Punctuation => + UCD.Properties.Resolve (GC_Property, "Po"), + + VSS.Characters.Math_Symbol => + UCD.Properties.Resolve (GC_Property, "Sm"), + VSS.Characters.Currency_Symbol => + UCD.Properties.Resolve (GC_Property, "Sc"), + VSS.Characters.Modifier_Symbol => + UCD.Properties.Resolve (GC_Property, "Sk"), + VSS.Characters.Other_Symbol => + UCD.Properties.Resolve (GC_Property, "So"), + + VSS.Characters.Space_Separator => + UCD.Properties.Resolve (GC_Property, "Zs"), + VSS.Characters.Line_Separator => + UCD.Properties.Resolve (GC_Property, "Zl"), + VSS.Characters.Paragraph_Separator => + UCD.Properties.Resolve (GC_Property, "Zp"), + + VSS.Characters.Control => + UCD.Properties.Resolve (GC_Property, "Cc"), + VSS.Characters.Format => + UCD.Properties.Resolve (GC_Property, "Cf"), + VSS.Characters.Surrogate => + UCD.Properties.Resolve (GC_Property, "Cs"), + VSS.Characters.Private_Use => + UCD.Properties.Resolve (GC_Property, "Co"), + VSS.Characters.Unassigned => + UCD.Properties.Resolve (GC_Property, "Cn")]; + + Lowercase_Property : constant UCD.Properties.Property_Access := + UCD.Properties.Resolve ("Lowercase"); + Lowercase_Y : constant UCD.Properties.Property_Value_Access := + UCD.Properties.Resolve (Lowercase_Property, "Y"); + Lowercase_N : constant UCD.Properties.Property_Value_Access := + UCD.Properties.Resolve (Lowercase_Property, "N"); + Uppercase_Property : constant UCD.Properties.Property_Access := + UCD.Properties.Resolve ("Uppercase"); + Uppercase_Y : constant UCD.Properties.Property_Value_Access := + UCD.Properties.Resolve (Uppercase_Property, "Y"); + Uppercase_N : constant UCD.Properties.Property_Value_Access := + UCD.Properties.Resolve (Uppercase_Property, "N"); + Cased_Property : constant UCD.Properties.Property_Access := + UCD.Properties.Resolve ("Cased"); + Cased_Y : constant UCD.Properties.Property_Value_Access := + UCD.Properties.Resolve (Cased_Property, "Y"); + Cased_N : constant UCD.Properties.Property_Value_Access := + UCD.Properties.Resolve (Cased_Property, "N"); - if VSS.Characters.Is_Valid_Virtual_Character (Character) - and then VSS.Characters.Get_Cased (Character) - then - Test_Support.Assert - (UCD.Characters.Get - (VSS.Characters.Virtual_Character'Pos (Character), - Cased_Property) = Cased_Y); + begin + for Character in VSS.Characters.Virtual_Character'First_Valid + .. VSS.Characters.Virtual_Character'Last_Valid + loop + -- General Category - else Test_Support.Assert (UCD.Characters.Get (VSS.Characters.Virtual_Character'Pos (Character), - Cased_Property) = Cased_N); - end if; - end loop; + GC_Property) + = GC_Mapping (VSS.Characters.Get_General_Category (Character))); + + -- Lowercase + + if VSS.Characters.Is_Valid_Virtual_Character (Character) + and then VSS.Characters.Get_Lowercase (Character) + then + Test_Support.Assert + (UCD.Characters.Get + (VSS.Characters.Virtual_Character'Pos (Character), + Lowercase_Property) = Lowercase_Y); + + else + Test_Support.Assert + (UCD.Characters.Get + (VSS.Characters.Virtual_Character'Pos (Character), + Lowercase_Property) = Lowercase_N); + end if; + + -- Uppercase + + if VSS.Characters.Is_Valid_Virtual_Character (Character) + and then VSS.Characters.Get_Uppercase (Character) + then + Test_Support.Assert + (UCD.Characters.Get + (VSS.Characters.Virtual_Character'Pos (Character), + Uppercase_Property) = Uppercase_Y); + + else + Test_Support.Assert + (UCD.Characters.Get + (VSS.Characters.Virtual_Character'Pos (Character), + Uppercase_Property) = Uppercase_N); + end if; + + -- Cased + + if VSS.Characters.Is_Valid_Virtual_Character (Character) + and then VSS.Characters.Get_Cased (Character) + then + Test_Support.Assert + (UCD.Characters.Get + (VSS.Characters.Virtual_Character'Pos (Character), + Cased_Property) = Cased_Y); + + else + Test_Support.Assert + (UCD.Characters.Get + (VSS.Characters.Virtual_Character'Pos (Character), + Cased_Property) = Cased_N); + end if; + end loop; + end; end Test_Properties; - -------------------- - -- Test_Well_Know -- - -------------------- + --------------------- + -- Test_Well_Known -- + --------------------- - procedure Test_Well_Know is + procedure Test_Well_Known is use type VSS.Characters.Virtual_Character; use type VSS.Strings.Virtual_String; @@ -285,11 +299,14 @@ procedure Test_Characters is (VSS.Characters.Get_Titlecase_Mapping ('1') = "1"); Test_Support.Assert (VSS.Characters.Get_Uppercase_Mapping ('1') = "1"); - end Test_Well_Know; + end Test_Well_Known; begin - Test_Well_Know; + Test_Support.Run_Testcase + (Test_Well_Known'Access, "well-known-character-properties"); - Initialize_UCD; - Test_Properties; + Test_Support.Run_Testcase + (Test_Properties'Access, + "all-character-properties", + "Test character's properties of all characters"); end Test_Characters;