3 -- Grant of Unlimited Rights
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
7 -- unlimited rights in the software and documentation contained herein.
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
9 -- this public release, the Government intends to confer upon all
10 -- recipients unlimited rights equal to those held by the Government.
11 -- These rights include rights to use, duplicate, release or disclose the
12 -- released technical data and computer software in whole or in part, in
13 -- any manner and for any purpose whatsoever, and to have or permit others
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
27 -- Check that the subprograms defined in package Ada.Strings.Wide_Fixed
28 -- are available, and that they produce correct results. Specifically,
29 -- check the subprograms Delete, Head, Insert, Overwrite, Replace_Slice,
30 -- Tail, Trim, and "*".
33 -- This test, when combined with tests CXA4013-15 will provide
34 -- coverage of the functionality found in package Ada.Strings.Wide_Fixed.
35 -- This test contains many small, specific test cases, situations that
36 -- although common in user environments, are often difficult to generate
37 -- in large numbers in a application-based test. They represent
38 -- individual usage paradigms in-the-small.
42 -- 06 Dec 94 SAIC ACVC 2.0
43 -- 10 Apr 94 SAIC Modified comments in a subtest failure message.
44 -- 06 Nov 95 SAIC Corrected subtest results for ACVC 2.0.1
45 -- 14 Mar 01 RLB Added checks that the lower bound is 1, similar
46 -- to CXA4005. These changes were made to test
47 -- Defect Report 8652/0049, as reflected in
48 -- Technical Corrigendum 1.
54 with Ada
.Strings
.Wide_Fixed
;
55 with Ada
.Strings
.Wide_Maps
;
59 type TC_Name_Holder
is access String;
60 Name
: TC_Name_Holder
;
62 function TC_Check
(S
: Wide_String) return Wide_String is
65 Report
.Failed
("Lower bound of result of function " & Name
.all &
66 " is" & Integer'Image (S
'First));
71 procedure TC_Set_Name
(N
: String) is
73 Name
:= new String'(N);
78 Report.Test("CXA4016", "Check that the subprograms defined in " &
79 "package Ada.Strings.Wide_Fixed are available, " &
80 "and that they produce correct results");
85 package ASW renames Ada.Strings.Wide_Fixed;
86 package Wide_Maps renames Ada.Strings.Wide_Maps;
92 Overwrite_String : Wide_String(1..10) :=
93 (others => Ada.Strings.Wide_Space);
94 Replace_String : Wide_String(10..30) :=
95 (others => Ada.Strings.Wide_Space);
97 Source_String1 : Wide_String(1..5) := "abcde"; -- odd len wd str
98 Source_String2 : Wide_String(1..6) := "abcdef"; -- even len wd str
99 Source_String3 : Wide_String(1..12) := "abcdefghijkl";
100 Source_String4 : Wide_String(1..12) := "abcdefghij "; -- last two ch pad
101 Source_String5 : Wide_String(1..12) := " cdefghijkl"; -- first two ch pad
102 Source_String6 : Wide_String(1..12) := "abcdefabcdef";
104 Location : Natural := 0;
105 Slice_Start : Positive;
107 Slice_Count : Natural := 0;
109 CD_Set : Wide_Maps.Wide_Character_Set :=
110 Wide_Maps.To_Set("cd");
111 X_Set : Wide_Maps.Wide_Character_Set :=
112 Wide_Maps.To_Set('x
');
113 ABCD_Set : Wide_Maps.Wide_Character_Set :=
114 Wide_Maps.To_Set("abcd");
115 A_to_F_Set : Wide_Maps.Wide_Character_Set :=
116 Wide_Maps.To_Set("abcdef");
118 CD_to_XY_Map : Wide_Maps.Wide_Character_Mapping :=
119 Wide_Maps.To_Mapping(From => "cd", To => "xy");
123 -- Procedure Replace_Slice
124 -- The functionality of this procedure is similar to procedure Move,
125 -- and is tested here in the same manner, evaluated with various
126 -- combinations of parameters.
128 -- Index_Error propagation when Low > Source'Last + 1
131 ASW.Replace_Slice(Result_String,
132 Result_String'Last + 2, -- should raise exception
135 Report.Failed("Index_Error not raised by Replace_Slice - 1");
137 when Ada.Strings.Index_Error => null; -- OK, expected exception.
139 Report.Failed("Incorrect exception from Replace_Slice - 1");
142 -- Index_Error propagation when High < Source'First - 1
145 ASW.Replace_Slice(Replace_String(20..30),
146 Replace_String'First,
147 Replace_String'First - 2, -- should raise exception
149 Report.Failed("Index_Error not raised by Replace_Slice - 2");
151 when Ada.Strings.Index_Error => null; -- OK, expected exception.
153 Report.Failed("Incorrect exception from Replace_Slice - 2");
156 -- Justify = Left (default case)
158 Result_String := "XXXXXXXXXX";
160 ASW.Replace_Slice(Source => Result_String,
163 By => Source_String1); -- "abcde"
165 if Result_String /= "abcde " then
166 Report.Failed("Incorrect result from Replace_Slice - Justify = Left");
171 ASW.Replace_Slice(Source => Result_String,
173 High => Result_String'Last,
174 By => Source_String2, -- "abcdef"
175 Drop => Ada.Strings.Error,
176 Justify => Ada.Strings.Right);
178 if Result_String /= " abcdef" then
179 Report.Failed("Incorrect result from Replace_Slice - Justify=Right");
182 -- Justify = Center (two cases, odd and even pad lengths)
184 ASW.Replace_Slice(Result_String,
187 Source_String1, -- "abcde"
190 'x
'); -- non-default padding.
192 if Result_String /= "xxabcdexxx" then -- Unequal padding added right
193 Report.Failed("Incorrect result, Replace_Slice - Justify=Center - 1");
196 ASW.Replace_Slice(Result_String,
199 Source_String2, -- "abcdef"
203 if Result_String /= " abcdef " then -- Equal padding added on L/R.
204 Report.Failed("Incorrect result from Replace_Slice with " &
205 "Justify = Center - 2");
208 -- When the source string is longer than the target string, several
209 -- cases can be examined, with the results depending on the value of
210 -- the Drop parameter.
214 ASW.Replace_Slice(Result_String,
217 Source_String3, -- "abcdefghijkl"
218 Drop => Ada.Strings.Left);
220 if Result_String /= "cdefghijkl" then
221 Report.Failed("Incorrect result from Replace_Slice - Drop=Left");
226 ASW.Replace_Slice(Result_String,
229 Source_String3, -- "abcdefghijkl"
232 if Result_String /= "abcdefghij" then
233 Report.Failed("Incorrect result, Replace_Slice with Drop=Right");
238 -- The effect in this case depends on the value of the justify
239 -- parameter, and on whether any characters in Source other than
240 -- Pad would fail to be copied.
242 -- Drop = Error, Justify = Left, right overflow characters are pad.
244 ASW.Replace_Slice(Result_String,
247 Source_String4, -- "abcdefghij "
248 Drop => Ada.Strings.Error,
249 Justify => Ada.Strings.Left);
251 if not(Result_String = "abcdefghij") then -- leftmost 10 characters
252 Report.Failed("Incorrect result, Replace_Slice - Drop = Error - 1");
255 -- Drop = Error, Justify = Right, left overflow characters are pad.
257 ASW.Replace_Slice(Source => Result_String,
259 High => Result_String'Last,
260 By => Source_String5, -- " cdefghijkl"
261 Drop => Ada.Strings.Error,
262 Justify => Ada.Strings.Right);
264 if Result_String /= "cdefghijkl" then -- rightmost 10 characters
265 Report.Failed("Incorrect result, Replace_Slice - Drop = Error - 2");
268 -- In other cases of Drop=Error, Length_Error is propagated, such as:
272 ASW.Replace_Slice(Source => Result_String,
274 High => Result_String'Last,
275 By => Source_String3, -- "abcdefghijkl"
276 Drop => Ada.Strings.Error);
278 Report.Failed("Length_Error not raised by Replace_Slice - 1");
281 when Ada.Strings.Length_Error => null; -- OK
283 Report.Failed("Incorrect exception from Replace_Slice - 3");
287 -- Function Replace_Slice
289 TC_Set_Name ("Replace_Slice");
291 if TC_Check (ASW.Replace_Slice("abcde", 3, 3, "x"))
292 /= "abxde" or -- High = Low
293 TC_Check (ASW.Replace_Slice("abc", 2, 3, "xyz")) /= "axyz" or
294 TC_Check (ASW.Replace_Slice("abcd", 4, 1, "xy"))
295 /= "abcxyd" or -- High < Low
296 TC_Check (ASW.Replace_Slice("abc", 2, 3, "x")) /= "ax" or
297 TC_Check (ASW.Replace_Slice("a", 1, 1, "z")) /= "z"
299 Report.Failed("Incorrect result from Function Replace_Slice - 1");
302 if TC_Check (ASW.Replace_Slice("abcde", 5, 5, "z"))
303 /= "abcdz" or -- By length 1
304 TC_Check (ASW.Replace_Slice("abc", 1, 3, "xyz"))
305 /= "xyz" or -- High > Low
306 TC_Check (ASW.Replace_Slice("abc", 3, 2, "xy"))
307 /= "abxyc" or -- insert
308 TC_Check (ASW.Replace_Slice("a", 1, 1, "xyz")) /= "xyz"
310 Report.Failed("Incorrect result from Function Replace_Slice - 2");
317 TC_Set_Name ("Insert");
320 New_String : constant Wide_String :=
322 ASW.Insert(Source => Source_String1(2..5), -- "bcde"
324 New_Item => Source_String2)); -- "abcdef"
326 if New_String /= "abcdefbcde" then
327 Report.Failed("Incorrect result from Function Insert - 1");
331 if TC_Check (ASW.Insert("a", 1, "z")) /= "za" or
332 TC_Check (ASW.Insert("abc", 3, "")) /= "abc" or
333 TC_Check (ASW.Insert("abc", 4, "z")) /= "abcz"
335 Report.Failed("Incorrect result from Function Insert - 2");
339 if TC_Check (ASW.Insert(Source => Source_String1(2..5), -- "bcde"
340 Before => Report.Ident_Int(7),
341 New_Item => Source_String2)) -- "abcdef"
343 Report.Failed("Index_Error not raised by Insert - 3A");
345 Report.Failed("Index_Error not raised by Insert - 3B");
348 when Ada.Strings.Index_Error => null; -- OK, expected exception.
350 Report.Failed("Incorrect exception from Insert - 3");
358 ASW.Insert(Source => Insert_String,
360 New_Item => Source_String2, -- "abcdef"
361 Drop => Ada.Strings.Right);
363 if Insert_String /= " abcde" then -- last char of New_Item dropped.
364 Report.Failed("Incorrect result from Insert with Drop = Right");
369 ASW.Insert(Source => Insert_String, -- 10 char string
370 Before => 2, -- 9 chars, 2..10 available
371 New_Item => Source_String3, -- 12 characters long.
372 Drop => Ada.Strings.Left); -- truncate from Left.
374 if Insert_String /= "l abcde" then -- 10 chars, leading blank.
375 Report.Failed("Incorrect result from Insert with Drop=Left");
381 ASW.Insert(Source => Result_String, -- 10 chars
382 Before => Result_String'Last,
383 New_Item => "abcdefghijk",
384 Drop => Ada.Strings.Error);
385 Report.Failed("Exception not raised by Procedure Insert");
387 when Ada.Strings.Length_Error => null; -- OK, expected exception
389 Report.Failed("Incorrect exception raised by Procedure Insert");
394 -- Function Overwrite
396 TC_Set_Name ("Overwrite");
398 Overwrite_String := TC_Check (
399 ASW.Overwrite(Result_String, -- 10 chars
400 1, -- starting at pos=1
401 Source_String3(1..10)));
403 if Overwrite_String /= Source_String3(1..10) then
404 Report.Failed("Incorrect result from Function Overwrite - 1");
408 if TC_Check (ASW.Overwrite("abcdef", 4, "xyz")) /= "abcxyz" or
409 TC_Check (ASW.Overwrite("a", 1, "xyz"))
410 /= "xyz" or -- chars appended
411 TC_Check (ASW.Overwrite("abc", 3, " "))
412 /= "ab " or -- blanks appended
413 TC_Check (ASW.Overwrite("abcde", 1, "z" )) /= "zbcde"
415 Report.Failed("Incorrect result from Function Overwrite - 2");
420 -- Procedure Overwrite, with truncation.
422 ASW.Overwrite(Source => Overwrite_String, -- 10 characters.
424 New_Item => Source_String3, -- 12 characters.
425 Drop => Ada.Strings.Left);
427 if Overwrite_String /= "cdefghijkl" then
428 Report.Failed("Incorrect result from Overwrite with Drop=Left");
431 -- The default drop value is Right, used here.
433 ASW.Overwrite(Source => Overwrite_String, -- 10 characters.
435 New_Item => Source_String3); -- 12 characters.
437 if Overwrite_String /= "abcdefghij" then
438 Report.Failed("Incorrect result from Overwrite with Drop=Right");
444 ASW.Overwrite(Source => Overwrite_String, -- 10 characters.
446 New_Item => Source_String3, -- 12 characters.
447 Drop => Ada.Strings.Error);
448 Report.Failed("Exception not raised by Procedure Overwrite");
450 when Ada.Strings.Length_Error => null; -- OK, expected exception.
453 ("Incorrect exception raised by Procedure Overwrite");
456 Overwrite_String := "ababababab";
457 ASW.Overwrite(Overwrite_String, Overwrite_String'Last, "z");
458 ASW.Overwrite(Overwrite_String, Overwrite_String'First,"z");
459 ASW.Overwrite(Overwrite_String, 5, "zz");
461 if Overwrite_String /= "zbabzzabaz" then
462 Report.Failed("Incorrect result from Procedure Overwrite");
469 TC_Set_Name ("Delete");
472 New_String1 : constant Wide_String := -- Returns a 4 char wide str.
473 TC_Check (ASW.Delete(Source => Source_String3,
476 New_String2 : constant Wide_String := -- This returns Source.
477 TC_Check (ASW.Delete(Source_String3, 10, 3));
479 if New_String1 /= "abkl" or
480 New_String2 /= Source_String3
482 Report.Failed("Incorrect result from Function Delete - 1");
486 if TC_Check (ASW.Delete("a", 1, 1))
487 /= "" or -- Source length = 1
488 TC_Check (ASW.Delete("abc", 1, 2))
489 /= "c" or -- From = Source'First
490 TC_Check (ASW.Delete("abc", 3, 3))
491 /= "ab" or -- From = Source'Last
492 TC_Check (ASW.Delete("abc", 3, 1))
493 /= "abc" -- From > Through
495 Report.Failed("Incorrect result from Function Delete - 2");
504 Delete_String := Source_String3(1..10); -- Initialize to "abcdefghij"
506 ASW.Delete(Source => Delete_String,
508 Through => Delete_String'Last,
509 Justify => Ada.Strings.Left,
510 Pad => 'x
'); -- pad with char 'x
'
512 if Delete_String /= "abcdexxxxx" then
513 Report.Failed("Incorrect result from Delete - Justify = Left");
518 ASW.Delete(Source => Delete_String, -- Remove x"s from end and
519 From => 6, -- shift right.
520 Through => Delete_String'Last,
521 Justify => Ada.Strings.Right,
522 Pad => 'x
'); -- pad with char 'x
' on left.
524 if Delete_String /= "xxxxxabcde" then
525 Report.Failed("Incorrect result from Delete - Justify = Right");
530 ASW.Delete(Source => Delete_String,
533 Justify => Ada.Strings.Center,
536 if Delete_String /= "zzabcdezzz" then -- extra pad char on right side.
537 Report.Failed("Incorrect result from Delete - Justify = Center");
543 -- Use non-identity character sets to perform the trim operation.
545 TC_Set_Name ("Trim");
547 Trim_String := "cdabcdefcd";
549 -- Remove the "cd" from each end of the string. This will not effect
550 -- the "cd" slice at 5..6.
553 New_String : constant Wide_String :=
554 TC_Check (ASW.Trim(Source => Trim_String,
555 Left => CD_Set, Right => CD_Set));
557 if New_String /= Source_String2 then -- string "abcdef"
559 ("Incorrect result from Trim with wide character sets");
563 if TC_Check (ASW.Trim("abcdef", Wide_Maps.Null_Set, Wide_Maps.Null_Set))
565 Report.Failed("Incorrect result from Trim with Null sets");
568 if TC_Check (ASW.Trim("cdxx", CD_Set, X_Set)) /= "" then
569 Report.Failed("Incorrect result from Trim, wide string removal");
577 ASW.Trim(Source => Trim_String,
580 Justify => Ada.Strings.Right,
583 if Trim_String /= "xxxxabcdef" then
584 Report.Failed("Incorrect result from Trim with Justify = Right");
589 ASW.Trim(Source => Trim_String,
591 Right => Wide_Maps.Null_Set,
592 Justify => Ada.Strings.Left,
595 if Trim_String /= "abcdef " then -- Padded with 4 blanks on right.
596 Report.Failed("Incorrect result from Trim with Justify = Left");
601 ASW.Trim(Source => Trim_String,
604 Justify => Ada.Strings.Center,
607 if Trim_String /= "xxef xx" then -- Padded with 4 pad chars on L/R
608 Report.Failed("Incorrect result from Trim with Justify = Center");
613 -- Function Head, testing use of padding.
615 TC_Set_Name ("Head");
617 -- Use the wide characters of Source_String1 ("abcde") and pad the
618 -- last five wide characters of Result_String with 'x
' wide characters.
620 Result_String := TC_CHeck (ASW.Head(Source_String1, 10, 'x
'));
622 if Result_String /= "abcdexxxxx" then
623 Report.Failed("Incorrect result from Function Head with padding");
626 if TC_Check (ASW.Head(" ab ", 2)) /= " " or
627 TC_Check (ASW.Head("a", 6, 'A
')) /= "aAAAAA" or
628 TC_Check (ASW.Head(ASW.Head("abc ", 7, 'x
'), 10, 'X
'))
631 Report.Failed("Incorrect result from Function Head");
636 -- Function Tail, testing use of padding.
638 TC_Set_Name ("Tail");
640 -- Use the wide characters of Source_String1 ("abcde") and pad the
641 -- first five wide characters of Result_String with 'x
' wide characters.
643 Result_String := TC_Check (ASW.Tail(Source_String1, 10, 'x
'));
645 if Result_String /= "xxxxxabcde" then
646 Report.Failed("Incorrect result from Function Tail with padding");
649 if TC_Check (ASW.Tail("abcde ", 5))
650 /= "cde " or -- blanks, back
651 TC_Check (ASW.Tail(" abc ", 8, ' '))
652 /= " abc " or -- blanks, front/back
653 TC_Check (ASW.Tail("", 5, 'Z
'))
654 /= "ZZZZZ" or -- pad characters only
655 TC_Check (ASW.Tail("abc", 0))
656 /= "" or -- null result
657 TC_Check (ASW.Tail(ASW.Tail(" abc ", 6, 'x
'),
659 'X
')) /= "XXXXx abc "
661 Report.Failed("Incorrect result from Function Tail");
666 -- Function "*" - with (Natural, Wide_String) parameters
668 TC_Set_Name ("""*""");
670 if TC_Check (ASW."*"(3, Source_String1)) /= "abcdeabcdeabcde" or
671 TC_Check (ASW."*"(2, Source_String2)) /= Source_String6 or
672 TC_Check (ASW."*"(4, Source_String1(1..2))) /= "abababab" or
673 TC_Check (ASW."*"(0, Source_String1)) /= ""
676 ("Incorrect result from Function ""*"" with wide strings");
680 when others => Report.Failed("Exception raised in Test_Block");