Index: tests/natools-s_expressions-encodings-tests.adb ================================================================== --- tests/natools-s_expressions-encodings-tests.adb +++ tests/natools-s_expressions-encodings-tests.adb @@ -1,7 +1,7 @@ ------------------------------------------------------------------------------ --- Copyright (c) 2013, Natacha Porté -- +-- Copyright (c) 2013-2014, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- @@ -11,21 +11,21 @@ -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- ------------------------------------------------------------------------------ + +with Ada.Exceptions; with Natools.S_Expressions.Test_Tools; package body Natools.S_Expressions.Encodings.Tests is procedure All_Tests (Report : in out NT.Reporter'Class) is begin - Report.Section ("Encodings in S-expressions"); Hexadecimal_Test (Report); Base64_Test (Report); - Report.End_Section; end All_Tests; procedure Hexadecimal_Test (Report : in out NT.Reporter'Class) is All_Octets : Atom (1 .. 256); @@ -65,10 +65,55 @@ 16#AB#, 16#CD#, 16#EF#, 16#AB#, 16#CD#, 16#EF#), Decode_Hex (All_Octets)); exception when Error : others => Report.Report_Exception (Name, Error); end; + + declare + Name : constant String := "Decoding an odd number of nibbles"; + begin + Test_Tools.Test_Atom + (Report, Name, + (16#45#, 16#56#, 16#70#), + Decode_Hex (To_Atom ("45 56 7"))); + exception + when Error : others => Report.Report_Exception (Name, Error); + end; + + declare + Name : constant String := "Decode_Hex with non-hex-digit"; + Result : Octet; + begin + Result := Decode_Hex (180); + Report.Item (Name, NT.Fail); + Report.Info ("No exception raised. Result: " & Octet'Image (Result)); + exception + when Constraint_Error => + Report.Item (Name, NT.Success); + when Error : others => + Report.Item (Name, NT.Fail); + Report.Info ("Unexpected exception " + & Ada.Exceptions.Exception_Name (Error) + & " has been raised"); + end; + + declare + Name : constant String := "Overflow in Encode_Hex"; + Result : Octet; + begin + Result := Encode_Hex (16, Lower); + Report.Item (Name, NT.Fail); + Report.Info ("No exception raised. Result: " & Octet'Image (Result)); + exception + when Constraint_Error => + Report.Item (Name, NT.Success); + when Error : others => + Report.Item (Name, NT.Fail); + Report.Info ("Unexpected exception " + & Ada.Exceptions.Exception_Name (Error) + & " has been raised"); + end; end Hexadecimal_Test; procedure Base64_Test (Report : in out NT.Reporter'Class) is begin @@ -171,8 +216,42 @@ Report.Item (Name, NT.Success); end if; exception when Error : others => Report.Report_Exception (Name, Error); end; + + declare + Name : constant String := "Decode_Base64 with non-base64-digit"; + Result : Octet; + begin + Result := Decode_Base64 (127); + Report.Item (Name, NT.Fail); + Report.Info ("No exception raised. Result: " & Octet'Image (Result)); + exception + when Constraint_Error => + Report.Item (Name, NT.Success); + when Error : others => + Report.Item (Name, NT.Fail); + Report.Info ("Unexpected exception " + & Ada.Exceptions.Exception_Name (Error) + & " has been raised"); + end; + + declare + Name : constant String := "Overflow in Encode_Base64"; + Result : Octet; + begin + Result := Encode_Base64 (64); + Report.Item (Name, NT.Fail); + Report.Info ("No exception raised. Result: " & Octet'Image (Result)); + exception + when Constraint_Error => + Report.Item (Name, NT.Success); + when Error : others => + Report.Item (Name, NT.Fail); + Report.Info ("Unexpected exception " + & Ada.Exceptions.Exception_Name (Error) + & " has been raised"); + end; end Base64_Test; end Natools.S_Expressions.Encodings.Tests;