Index: tests/natools-s_expressions-encodings-tests.adb ================================================================== --- tests/natools-s_expressions-encodings-tests.adb +++ tests/natools-s_expressions-encodings-tests.adb @@ -22,10 +22,11 @@ procedure All_Tests (Report : in out NT.Reporter'Class) is begin Hexadecimal_Test (Report); Base64_Test (Report); + User_Base64_Test (Report); end All_Tests; procedure Hexadecimal_Test (Report : in out NT.Reporter'Class) is All_Octets : Atom (1 .. 256); @@ -252,6 +253,60 @@ & Ada.Exceptions.Exception_Name (Error) & " has been raised"); end; end Base64_Test; + + procedure User_Base64_Test (Report : in out NT.Reporter'Class) is + Test : NT.Test := Report.Item ("Base-64 with user-defined charset"); + begin + declare + Digit_62 : constant Octet := Character'Pos ('-'); + Digit_63 : constant Octet := Character'Pos ('_'); + -- Charset for Base-64 URI (RFC 4648) + + Padding : constant Octet := Character'Pos ('|'); + + Source : constant Atom + := (4#0000#, 4#0100#, 4#2003#, 4#0100#, 4#1101#, 4#2013#, + 4#0200#, 4#2102#, 4#2023#, 4#0300#, 4#3103#, 4#2033#, + 4#1001#, 4#0110#, 4#2103#, 4#1101#, 4#1111#, 4#2113#, + 4#1201#, 4#2112#, 4#2123#, 4#1301#, 4#3113#, 4#2133#, + 4#2002#, 4#0120#, 4#2203#, 4#2102#, 4#1121#, 4#2213#, + 4#2202#, 4#2122#, 4#2223#, 4#2302#, 4#3123#, 4#2233#, + 4#3003#, 4#0130#, 4#2303#, 4#3103#, 4#1131#, 4#2313#, + 4#3203#, 4#2132#, 4#2323#, 4#3303#, 4#3133#, 4#2333#, + 16#42#); + Expected : constant Atom + := (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, + 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, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, Digit_62, Digit_63, + 81, 103, Padding, Padding); + Encoded_Short : constant Atom + := Encode_Base64 (Source, Digit_62, Digit_63); + Encoded_Long : constant Atom + := Encode_Base64 (Source, Digit_62, Digit_63, Padding); + begin + Test_Tools.Test_Atom (Test, Expected, Encoded_Long); + + Test_Tools.Test_Atom + (Test, + Expected (Expected'First .. Expected'Last - 2), + Encoded_Short); + + Test_Tools.Test_Atom + (Test, + Source, + Decode_Base64 (Encoded_Long, Digit_62, Digit_63)); + + Test_Tools.Test_Atom + (Test, + Source, + Decode_Base64 (Encoded_Short, Digit_62, Digit_63)); + end; + exception + when Error : others => Test.Report_Exception (Error); + end User_Base64_Test; + end Natools.S_Expressions.Encodings.Tests; Index: tests/natools-s_expressions-encodings-tests.ads ================================================================== --- tests/natools-s_expressions-encodings-tests.ads +++ tests/natools-s_expressions-encodings-tests.ads @@ -29,8 +29,9 @@ procedure All_Tests (Report : in out NT.Reporter'Class); -- Run all available tests procedure Hexadecimal_Test (Report : in out NT.Reporter'Class); procedure Base64_Test (Report : in out NT.Reporter'Class); + procedure User_Base64_Test (Report : in out NT.Reporter'Class); -- Run test suite for each encoding type end Natools.S_Expressions.Encodings.Tests;