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.Bounded are
28 -- available, and that they produce correct results, especially under
29 -- conditions where truncation of the result is required. Specifically,
30 -- check the subprograms Append, Count with non-Identity maps, Index with
31 -- non-Identity maps, Index with Set parameters, Insert (function and
32 -- procedure), Replace_Slice (function and procedure), To_Bounded_String,
36 -- This test, in conjunction with tests CXA4006, CXA4007, and CXA4009,
37 -- will provide coverage of the most common usages of the functionality
38 -- found in the Ada.Strings.Bounded package. It deals in large part
39 -- with truncation effects and options. This test contains many small,
40 -- specific test cases, situations that are often difficult to generate
41 -- in large numbers in an application-based test. These cases represent
42 -- specific usage paradigms in-the-small.
46 -- 06 Dec 94 SAIC ACVC 2.0
47 -- 10 Apr 95 SAIC Corrected acceptance condition of subtest for
48 -- Function Append with Truncation = Left.
49 -- 31 Oct 95 SAIC Update and repair for ACVC 2.0.1.
54 with Ada
.Strings
.Maps
.Constants
;
55 with Ada
.Strings
.Bounded
;
56 with Ada
.Strings
.Maps
;
62 Report
.Test
("CXA4008", "Check that the subprograms defined in " &
63 "package Ada.Strings.Bounded are available, " &
64 "and that they produce correct results, " &
65 "especially under conditions where " &
66 "truncation of the result is required");
71 package AS
renames Ada
.Strings
;
72 package ASB
renames Ada
.Strings
.Bounded
;
73 package ASC
renames Ada
.Strings
.Maps
.Constants
;
74 package Maps
renames Ada
.Strings
.Maps
;
76 package B10
is new ASB
.Generic_Bounded_Length
(Max
=> 10);
77 use type B10
.Bounded_String
;
79 Result_String
: B10
.Bounded_String
;
80 Test_String
: B10
.Bounded_String
;
81 AtoE_Bnd_Str
: B10
.Bounded_String
:= B10
.To_Bounded_String
("abcde");
82 FtoJ_Bnd_Str
: B10
.Bounded_String
:= B10
.To_Bounded_String
("fghij");
83 AtoJ_Bnd_Str
: B10
.Bounded_String
:=
84 B10
.To_Bounded_String
("abcdefghij");
86 Location
: Natural := 0;
87 Total_Count
: Natural := 0;
89 CD_Set
: Maps
.Character_Set
:= Maps
.To_Set
("cd");
91 AB_to_YZ_Map
: Maps
.Character_Mapping
:=
92 Maps
.To_Mapping
(From
=> "ab", To
=> "yz");
94 CD_to_XY_Map
: Maps
.Character_Mapping
:=
95 Maps
.To_Mapping
(From
=> "cd", To
=> "xy");
99 -- Function To_Bounded_String with Truncation
100 -- Evaluate the function Append with parameters that will
101 -- cause the truncation of the result.
103 -- Drop = Error (default case, Length_Error will be raised)
107 B10
.To_Bounded_String
("Much too long for this bounded string");
108 Report
.Failed
("Length Error not raised by To_Bounded_String");
110 when AS
.Length_Error
=> null; -- Expected exception raised.
112 Report
.Failed
("Incorrect exception raised by To_Bounded_String");
117 Test_String
:= B10
.To_Bounded_String
(Source
=> "abcdefghijklmn",
118 Drop
=> Ada
.Strings
.Left
);
120 if Test_String
/= B10
.To_Bounded_String
("efghijklmn") then
122 ("Incorrect result from To_Bounded_String, Drop = Left");
127 Test_String
:= B10
.To_Bounded_String
(Source
=> "abcdefghijklmn",
128 Drop
=> Ada
.Strings
.Right
);
130 if not(Test_String
= AtoJ_Bnd_Str
) then
132 ("Incorrect result from To_Bounded_String, Drop = Right");
138 -- Function Append with Truncation
139 -- Evaluate the function Append with parameters that will
140 -- cause the truncation of the result.
142 -- Drop = Error (default case, Length_Error will be raised)
145 -- Append (Bnd Str, Bnd Str);
147 B10
.Append
(B10
.To_Bounded_String
("abcde"),
148 B10
.To_Bounded_String
("fghijk")); -- 11 char
149 Report
.Failed
("Length_Error not raised by Append - 1");
151 when AS
.Length_Error
=> null; -- OK, correct exception raised.
153 Report
.Failed
("Incorrect exception raised by Append - 1");
157 -- Append (Str, Bnd Str);
158 Result_String
:= B10
.Append
(B10
.To_String
(AtoE_Bnd_Str
),
159 B10
.To_Bounded_String
("fghijk"),
161 Report
.Failed
("Length_Error not raised by Append - 2");
163 when AS
.Length_Error
=> null; -- OK, correct exception raised.
165 Report
.Failed
("Incorrect exception raised by Append - 2");
169 -- Append (Bnd Str, Char);
171 B10
.Append
(B10
.To_Bounded_String
("abcdefghij"), 'k');
172 Report
.Failed
("Length_Error not raised by Append - 3");
174 when AS
.Length_Error
=> null; -- OK, correct exception raised.
176 Report
.Failed
("Incorrect exception raised by Append - 3");
181 -- Append (Bnd Str, Bnd Str)
182 Result_String
:= B10
.Append
(B10
.To_Bounded_String
("abcdefgh"), -- 8 chs
183 B10
.To_Bounded_String
("ijklmn"), -- 6 chs
186 if Result_String
/= B10
.To_Bounded_String
("efghijklmn") then -- 10 chars
187 Report
.Failed
("Incorrect truncation performed by Append - 4");
190 -- Append (Bnd Str, Str)
192 B10
.Append
(B10
.To_Bounded_String
("abcdefghij"),
196 if Result_String
/= B10
.To_Bounded_String
("defghijxyz") then
197 Report
.Failed
("Incorrect truncation performed by Append - 5");
200 -- Append (Char, Bnd Str)
202 Result_String
:= B10
.Append
('A',
203 B10
.To_Bounded_String
("abcdefghij"),
206 if Result_String
/= B10
.To_Bounded_String
("abcdefghij") then
207 Report
.Failed
("Incorrect truncation performed by Append - 6");
212 -- Append (Bnd Str, Bnd Str)
213 Result_String
:= B10
.Append
(FtoJ_Bnd_Str
,
217 if Result_String
/= B10
.To_Bounded_String
("fghijabcde") then
218 Report
.Failed
("Incorrect truncation performed by Append - 7");
221 -- Append (Str, Bnd Str)
222 Result_String
:= B10
.Append
(B10
.To_String
(AtoE_Bnd_Str
),
226 if Result_String
/= B10
.To_Bounded_String
("abcdeabcde") then
227 Report
.Failed
("Incorrect truncation performed by Append - 8");
230 -- Append (Char, Bnd Str)
231 Result_String
:= B10
.Append
('A', AtoJ_Bnd_Str
, Ada
.Strings
.Right
);
233 if Result_String
/= B10
.To_Bounded_String
("Aabcdefghi") then
234 Report
.Failed
("Incorrect truncation performed by Append - 9");
238 -- Function Index with non-Identity map.
239 -- Evaluate the function Index with a non-identity map
240 -- parameter which will cause mapping of the source parameter
241 -- prior to the evaluation of the index position search.
243 Location
:= B10
.Index
(Source
=> AtoJ_Bnd_Str
, -- "abcdefghij"
245 Going
=> Ada
.Strings
.Forward
,
246 Mapping
=> CD_to_XY_Map
); -- change "cd" to "xy"
248 if Location
/= 3 then
249 Report
.Failed
("Incorrect result from Index, non-Identity map - 1");
252 Location
:= B10
.Index
(B10
.To_Bounded_String
("AND IF MAN"),
254 Ada
.Strings
.Backward
,
257 if Location
/= 9 then
258 Report
.Failed
("Incorrect result from Index, non-Identity map - 2");
261 Location
:= B10
.Index
(Source
=> B10
.To_Bounded_String
("The the"),
263 Going
=> Ada
.Strings
.Forward
,
264 Mapping
=> ASC
.Lower_Case_Map
);
266 if Location
/= 1 then
267 Report
.Failed
("Incorrect result from Index, non-Identity map - 3");
271 if B10
.Index
(B10
.To_Bounded_String
("abcd"), -- Pattern = Source
273 B10
.Index
(B10
.To_Bounded_String
("abc"), -- Pattern < Source
275 B10
.Index
(B10
.Null_Bounded_String
, -- Source = Null
278 Report
.Failed
("Incorrect result from Index with string patterns");
282 -- Function Index (for Sets).
283 -- This version of Index uses Sets as the basis of the search.
285 -- Test = Inside, Going = Forward (Default case).
287 B10
.Index
(Source
=> B10
.To_Bounded_String
("abcdeabcde"),
288 Set
=> CD_Set
, -- set containing 'c' and 'd'
289 Test
=> Ada
.Strings
.Inside
,
290 Going
=> Ada
.Strings
.Forward
);
292 if not (Location
= 3) then -- position of first 'c' in source.
293 Report
.Failed
("Incorrect result from Index using Sets - 1");
296 -- Test = Inside, Going = Backward.
298 B10
.Index
(Source
=> B10
."&"(AtoE_Bnd_Str
, AtoE_Bnd_Str
),
299 Set
=> CD_Set
, -- set containing 'c' and 'd'
300 Test
=> Ada
.Strings
.Inside
,
301 Going
=> Ada
.Strings
.Backward
);
303 if not (Location
= 9) then -- position of last 'd' in source.
304 Report
.Failed
("Incorrect result from Index using Sets - 2");
307 -- Test = Outside, Going = Forward.
308 Location
:= B10
.Index
(B10
.To_Bounded_String
("deddacd"),
310 Test
=> Ada
.Strings
.Outside
,
311 Going
=> Ada
.Strings
.Forward
);
313 if Location
/= 2 then -- position of 'e' in source.
314 Report
.Failed
("Incorrect result from Index using Sets - 3");
317 -- Test = Outside, Going = Backward.
318 Location
:= B10
.Index
(B10
.To_Bounded_String
("deddacd"),
321 Ada
.Strings
.Backward
);
323 if Location
/= 5 then -- correct position of 'a'.
324 Report
.Failed
("Incorrect result from Index using Sets - 4");
327 if B10
.Index
(B10
.To_Bounded_String
("cd"), -- Source = Set
329 B10
.Index
(B10
.To_Bounded_String
("c"), -- Source < Set
331 B10
.Index
(B10
.Null_Bounded_String
, -- Source = Null
333 B10
.Index
(AtoE_Bnd_Str
, -- "abcde"
334 Maps
.Null_Set
) /= 0 or -- Null set
335 B10
.Index
(AtoE_Bnd_Str
,
336 Maps
.To_Set
('x')) /= 0 -- No match.
338 Report
.Failed
("Incorrect result from Index using Sets - 5");
342 -- Function Count with non-Identity mapping.
343 -- Evaluate the function Count with a non-identity map
344 -- parameter which will cause mapping of the source parameter
345 -- prior to the evaluation of the number of matching patterns.
348 B10
.Count
(Source
=> B10
.To_Bounded_String
("abbabaabab"),
350 Mapping
=> AB_to_YZ_Map
);
352 if Total_Count
/= 4 then
354 ("Incorrect result from function Count, non-Identity map - 1");
357 -- And a few with identity maps as well.
359 if B10
.Count
(B10
.To_Bounded_String
("ABABABABAB"),
361 Maps
.Identity
) /= 2 or
362 B10
.Count
(B10
.To_Bounded_String
("ADCBADABCD"),
364 Maps
.To_Mapping
("CD", "AB")) /= 5 or
365 B10
.Count
(B10
.To_Bounded_String
("aaaaaaaaaa"),
367 B10
.Count
(B10
.To_Bounded_String
("XX"), -- Source < Pattern
369 Maps
.Identity
) /= 0 or
370 B10
.Count
(AtoE_Bnd_Str
, -- Source = Pattern
372 B10
.Count
(B10
.Null_Bounded_String
, -- Source = Null
376 ("Incorrect result from function Count, w,w/o mapping");
380 -- Procedure Translate
382 -- Partial mapping of source.
384 Test_String
:= B10
.To_Bounded_String
("abcdeabcab");
386 B10
.Translate
(Source
=> Test_String
, Mapping
=> AB_to_YZ_Map
);
388 if Test_String
/= B10
.To_Bounded_String
("yzcdeyzcyz") then
389 Report
.Failed
("Incorrect result from procedure Translate - 1");
392 -- Total mapping of source.
394 Test_String
:= B10
.To_Bounded_String
("abbaaababb");
396 B10
.Translate
(Source
=> Test_String
, Mapping
=> ASC
.Upper_Case_Map
);
398 if Test_String
/= B10
.To_Bounded_String
("ABBAAABABB") then
399 Report
.Failed
("Incorrect result from procedure Translate - 2");
402 -- No mapping of source.
404 Test_String
:= B10
.To_Bounded_String
("xyzsypcc");
406 B10
.Translate
(Source
=> Test_String
, Mapping
=> AB_to_YZ_Map
);
408 if Test_String
/= B10
.To_Bounded_String
("xyzsypcc") then
409 Report
.Failed
("Incorrect result from procedure Translate - 3");
412 -- Map > 2 characters, partial mapping.
414 Test_String
:= B10
.To_Bounded_String
("have faith");
416 B10
.Translate
(Test_String
,
417 Maps
.To_Mapping
("aeiou", "AEIOU"));
419 if Test_String
/= B10
.To_Bounded_String
("hAvE fAIth") then
420 Report
.Failed
("Incorrect result from procedure Translate - 4");
424 -- Function Replace_Slice
425 -- Evaluate function Replace_Slice with
426 -- a variety of Truncation options.
428 -- Drop = Error (Default)
431 Test_String
:= AtoJ_Bnd_Str
;
433 B10
.Replace_Slice
(Source
=> Test_String
, -- "abcdefghij"
435 High
=> 5, -- 3-5, 3 chars.
436 By
=> "xxxxxx"); -- more than 3.
437 Report
.Failed
("Length_Error not raised by Function Replace_Slice");
439 when AS
.Length_Error
=> null; -- Correct exception raised.
442 ("Incorrect exception raised by Function Replace_Slice");
448 B10
.Replace_Slice
(Source
=> Test_String
, -- "abcdefghij"
450 High
=> 10, -- 7-10, 4 chars.
451 By
=> "xxxxxx", -- 6 chars.
452 Drop
=> Ada
.Strings
.Left
);
454 if Result_String
/= B10
.To_Bounded_String
("cdefxxxxxx") then -- drop a,b
456 ("Incorrect result from Function Replace Slice, Drop = Left");
462 B10
.Replace_Slice
(Source
=> Test_String
, -- "abcdefghij"
464 High
=> 5, -- 2-5, 4 chars.
465 By
=> "xxxxxx", -- 6 chars.
466 Drop
=> Ada
.Strings
.Right
);
468 if Result_String
/= B10
.To_Bounded_String
("axxxxxxfgh") then -- drop i,j
470 ("Incorrect result from Function Replace Slice, Drop = Right");
473 -- Low = High = Source'Last, "By" length = 1.
475 if B10
.Replace_Slice
(AtoE_Bnd_Str
,
476 B10
.To_String
(AtoE_Bnd_Str
)'Last,
477 B10
.To_String
(AtoE_Bnd_Str
)'Last,
479 Ada
.Strings
.Error
) /=
480 B10
.To_Bounded_String
("abcdX")
482 Report
.Failed
("Incorrect result from Function Replace_Slice");
487 -- Procedure Replace_Slice
488 -- Evaluate procedure Replace_Slice with
489 -- a variety of Truncation options.
491 -- Drop = Error (Default)
494 Test_String
:= AtoJ_Bnd_Str
;
495 B10
.Replace_Slice
(Source
=> Test_String
, -- "abcdefghij"
497 High
=> 5, -- 3-5, 3 chars.
498 By
=> "xxxxxx"); -- more than 3.
499 Report
.Failed
("Length_Error not raised by Procedure Replace_Slice");
501 when AS
.Length_Error
=> null; -- Correct exception raised.
504 ("Incorrect exception raised by Procedure Replace_Slice");
509 Test_String
:= AtoJ_Bnd_Str
;
510 B10
.Replace_Slice
(Source
=> Test_String
, -- "abcdefghij"
512 High
=> 9, -- 7-9, 3 chars.
513 By
=> "xxxxx", -- 5 chars.
514 Drop
=> Ada
.Strings
.Left
);
516 if Test_String
/= B10
.To_Bounded_String
("cdefxxxxxj") then -- drop a,b
518 ("Incorrect result from Procedure Replace Slice, Drop = Left");
523 Test_String
:= AtoJ_Bnd_Str
;
524 B10
.Replace_Slice
(Source
=> Test_String
, -- "abcdefghij"
526 High
=> 3, -- 1-3, 3chars.
527 By
=> "xxxx", -- 4 chars.
528 Drop
=> Ada
.Strings
.Right
);
530 if Test_String
/= B10
.To_Bounded_String
("xxxxdefghi") then -- drop j
532 ("Incorrect result from Procedure Replace Slice, Drop = Right");
535 -- High = Source'First, Low > High (Insert before Low).
537 Test_String
:= AtoE_Bnd_Str
;
538 B10
.Replace_Slice
(Source
=> Test_String
, -- "abcde"
539 Low
=> B10
.To_String
(Test_String
)'Last,
540 High
=> B10
.To_String
(Test_String
)'First,
541 By
=> "XXXX", -- 4 chars.
542 Drop
=> Ada
.Strings
.Right
);
544 if Test_String
/= B10
.To_Bounded_String
("abcdXXXXe") then
546 ("Incorrect result from Procedure Replace Slice");
551 -- Function Insert with Truncation
552 -- Drop = Error (Default).
556 B10
.Insert
(Source
=> AtoJ_Bnd_Str
, -- "abcdefghij"
559 Report
.Failed
("Length_Error not raised by Function Insert");
561 when AS
.Length_Error
=> null; -- Correct exception raised.
563 Report
.Failed
("Incorrect exception raised by Function Insert");
569 B10
.Insert
(Source
=> AtoJ_Bnd_Str
, -- "abcdefghij"
571 New_Item
=> "xyz", -- 3 additional chars.
572 Drop
=> Ada
.Strings
.Left
);
574 if B10
.To_String
(Result_String
) /= "dxyzefghij" then -- drop a, b, c
575 Report
.Failed
("Incorrect result from Function Insert, Drop = Left");
581 B10
.Insert
(Source
=> B10
.To_Bounded_String
("abcdef"),
583 New_Item
=> "vwxyz", -- 5 additional chars.
584 Drop
=> Ada
.Strings
.Right
);
586 if B10
.To_String
(Result_String
) /= "avwxyzbcde" then -- drop f.
587 Report
.Failed
("Incorrect result from Function Insert, Drop = Right");
592 if B10
.Insert
(B10
.To_Bounded_String
("a"), 1, " B") /=
593 B10
.To_Bounded_String
(" Ba") or
594 B10
.Insert
(B10
.Null_Bounded_String
, 1, "abcde") /=
596 B10
.Insert
(B10
.To_Bounded_String
("ab"), 2, "") /=
597 B10
.To_Bounded_String
("ab")
599 Report
.Failed
("Incorrect result from Function Insert");
605 -- Drop = Error (Default).
607 Test_String
:= AtoJ_Bnd_Str
;
608 B10
.Insert
(Source
=> Test_String
, -- "abcdefghij"
611 Drop
=> Ada
.Strings
.Error
);
612 Report
.Failed
("Length_Error not raised by Procedure Insert");
614 when AS
.Length_Error
=> null; -- Correct exception raised.
616 Report
.Failed
("Incorrect exception raised by Procedure Insert");
621 Test_String
:= AtoJ_Bnd_Str
;
622 B10
.Insert
(Source
=> Test_String
, -- "abcdefghij"
623 Before
=> B10
.Length
(Test_String
), -- before last char
624 New_Item
=> "xyz", -- 3 additional chars.
625 Drop
=> Ada
.Strings
.Left
);
627 if B10
.To_String
(Test_String
) /= "defghixyzj" then -- drop a, b, c
628 Report
.Failed
("Incorrect result from Procedure Insert, Drop = Left");
633 Test_String
:= AtoJ_Bnd_Str
;
634 B10
.Insert
(Source
=> Test_String
,
636 New_Item
=> "yz", -- 2 additional chars.
637 Drop
=> Ada
.Strings
.Right
);
639 if B10
.To_String
(Test_String
) /= "abcyzdefgh" then -- drop i,j
641 ("Incorrect result from Procedure Insert, Drop = Right");
644 -- Before = Source'First, New_Item length = 1.
646 Test_String
:= B10
.To_Bounded_String
(" abc ");
647 B10
.Insert
(Test_String
,
648 B10
.To_String
(Test_String
)'First,
651 if Test_String
/= B10
.To_Bounded_String
("Z abc ") then
652 Report
.Failed
("Incorrect result from Procedure Insert");
657 when others => Report
.Failed
("Exception raised in Test_Block");