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 Count, Find_Token, Index, Index_Non_Blank, and
33 -- This test, when combined with tests CXA4013,14,16 will provide
34 -- coverage of the functionality found in 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.
41 -- 06 Dec 94 SAIC ACVC 2.0
42 -- 02 Nov 95 SAIC Corrected various accesssibility problems and
43 -- expected result strings for ACVC 2.0.1.
49 -- Wide Character mapping function defined for use with specific
50 -- versions of functions Index and Count.
52 function AK_to_ZQ_Mapping
(From
: Wide_Character) return Wide_Character;
56 package body CXA40150
is
58 function AK_to_ZQ_Mapping
(From
: Wide_Character)
59 return Wide_Character is
76 with Ada
.Strings
.Wide_Fixed
;
77 with Ada
.Strings
.Wide_Maps
;
82 Report
.Test
("CXA4015", "Check that the subprograms defined in " &
83 "package Ada.Strings.Wide_Fixed are available, " &
84 "and that they produce correct results");
92 package ASF
renames Ada
.Strings
.Wide_Fixed
;
93 package Maps
renames Ada
.Strings
.Wide_Maps
;
95 Result_String
: Wide_String(1..10) :=
96 (others => Ada
.Strings
.Wide_Space
);
98 Source_String1
: Wide_String(1..5) := "abcde"; -- odd len Wide_String
99 Source_String2
: Wide_String(1..6) := "abcdef"; -- even len Wide_String
100 Source_String3
: Wide_String(1..12) := "abcdefghijkl";
101 Source_String4
: Wide_String(1..12) := "abcdefghij "; -- last 2 ch pad
102 Source_String5
: Wide_String(1..12) := " cdefghijkl"; -- first 2 ch pad
103 Source_String6
: Wide_String(1..12) := "abcdefabcdef";
105 Location
: Natural := 0;
106 Slice_Start
: Positive;
108 Slice_Count
: Natural := 0;
110 CD_Set
: Maps
.Wide_Character_Set
:= Maps
.To_Set
("cd");
111 ABCD_Set
: Maps
.Wide_Character_Set
:= Maps
.To_Set
("abcd");
112 A_to_F_Set
: Maps
.Wide_Character_Set
:= Maps
.To_Set
("abcdef");
114 CD_to_XY_Map
: Maps
.Wide_Character_Mapping
:=
115 Maps
.To_Mapping
(From
=> "cd", To
=> "xy");
118 -- Access-to-Subprogram object defined for use with specific versions of
119 -- functions Index and Count.
121 Map_Ptr
: Maps
.Wide_Character_Mapping_Function
:=
122 AK_to_ZQ_Mapping
'Access;
129 -- Evaluate the Procedure Move with various combinations of
132 -- Justify = Left (default case)
134 ASF
.Move
(Source
=> Source_String1
, -- "abcde"
135 Target
=> Result_String
);
137 if Result_String
/= "abcde " then
138 Report
.Failed
("Incorrect result from Move with Justify = Left");
143 ASF
.Move
(Source
=> Source_String2
, -- "abcdef"
144 Target
=> Result_String
,
145 Drop
=> Ada
.Strings
.Error
,
146 Justify
=> Ada
.Strings
.Right
);
148 if Result_String
/= " abcdef" then
149 Report
.Failed
("Incorrect result from Move with Justify = Right");
152 -- Justify = Center (two cases, odd and even pad lengths)
154 ASF
.Move
(Source_String1
, -- "abcde"
158 'x'); -- non-default padding.
160 if Result_String
/= "xxabcdexxx" then -- Unequal padding added right
161 Report
.Failed
("Incorrect result from Move with Justify = Center-1");
164 ASF
.Move
(Source_String2
, -- "abcdef"
169 if Result_String
/= " abcdef " then -- Equal padding added on L/R.
170 Report
.Failed
("Incorrect result from Move with Justify = Center-2");
173 -- When the source Wide_String is longer than the target Wide_String,
174 -- several cases can be examined, with the results depending on the
175 -- value of the Drop parameter.
179 ASF
.Move
(Source
=> Source_String3
, -- "abcdefghijkl"
180 Target
=> Result_String
,
181 Drop
=> Ada
.Strings
.Left
);
183 if Result_String
/= "cdefghijkl" then
184 Report
.Failed
("Incorrect result from Move with Drop = Left");
189 ASF
.Move
(Source_String3
, Result_String
, Ada
.Strings
.Right
);
191 if Result_String
/= "abcdefghij" then
192 Report
.Failed
("Incorrect result from Move with Drop = Right");
196 -- The effect in this case depends on the value of the justify
197 -- parameter, and on whether any characters in Source other than
198 -- Pad would fail to be copied.
200 -- Drop = Error, Justify = Left, right overflow characters are pad.
202 ASF
.Move
(Source
=> Source_String4
, -- "abcdefghij "
203 Target
=> Result_String
,
204 Drop
=> Ada
.Strings
.Error
,
205 Justify
=> Ada
.Strings
.Left
);
207 if not(Result_String
= "abcdefghij") then -- leftmost 10 characters
208 Report
.Failed
("Incorrect result from Move with Drop = Error - 1");
211 -- Drop = Error, Justify = Right, left overflow characters are pad.
213 ASF
.Move
(Source_String5
, -- " cdefghijkl"
218 if Result_String
/= "cdefghijkl" then -- rightmost 10 characters
219 Report
.Failed
("Incorrect result from Move with Drop = Error - 2");
222 -- In other cases of Drop=Error, Length_Error is propagated, such as:
226 ASF
.Move
(Source_String3
, -- 12 characters, no Pad.
227 Result_String
, -- 10 characters
231 Report
.Failed
("Length_Error not raised by Move - 1");
234 when Ada
.Strings
.Length_Error
=> null; -- OK
236 Report
.Failed
("Incorrect exception raised by Move - 1");
242 -- (Other usage examples of this function found in CXA4013-14.)
243 -- Check when the pattern is not found in the source.
245 if ASF
.Index
("abcdef", "gh") /= 0 or
246 ASF
.Index
("abcde", "abcdef") /= 0 or -- pattern > source
249 Ada
.Strings
.Backward
) /= 0 or
250 ASF
.Index
("", "ab") /= 0 or -- null source Wide_String.
251 ASF
.Index
("abcde", " ") /= 0 -- blank pattern.
253 Report
.Failed
("Incorrect result from Index, no pattern match");
256 -- Check that Pattern_Error is raised when the pattern is the
259 Location
:= ASF
.Index
(Source_String6
, -- "abcdefabcdef"
260 "", -- null pattern Wide_String.
261 Ada
.Strings
.Forward
);
262 Report
.Failed
("Pattern_Error not raised by Index");
264 when Ada
.Strings
.Pattern_Error
=> null; -- OK, expected exception.
266 Report
.Failed
("Incorrect exception raised by Index, null pattern");
269 -- Use the search direction "backward" to locate the particular
270 -- pattern within the source Wide_String.
272 Location
:= ASF
.Index
(Source_String6
, -- "abcdefabcdef"
273 "de", -- slice 4..5, 10..11
274 Ada
.Strings
.Backward
); -- search from right end.
276 if Location
/= 10 then
277 Report
.Failed
("Incorrect result from Index going Backward");
283 -- Use the version of Index that takes a Wide_Character_Mapping_Function
285 -- Use the search directions Forward and Backward to locate the
286 -- particular pattern wide string within the source wide string.
288 Location
:= ASF
.Index
("akzqefakzqef",
289 "qzq", -- slice 8..10
290 Ada
.Strings
.Backward
,
291 Map_Ptr
); -- perform 'a' to 'z', 'k' to 'q'
293 if Location
/= 8 then
295 ("Incorrect result from Index w/map ptr going Backward");
298 Location
:= ASF
.Index
("ddkkddakcdakdefcadckdfzaaqd",
301 Map_Ptr
); -- perform 'a' to 'z', 'k' to 'q'
303 if Location
/= 7 then
305 ("Incorrect result from Index w/map ptr going Forward");
309 if ASF
.Index
("aakkzq", "zq", Ada
.Strings
.Forward
, Map_Ptr
) /= 2 or
310 ASF
.Index
("qzedka", "qz", Ada
.Strings
.Backward
, Map_Ptr
) /= 5 or
311 ASF
.Index
("zazaza", "zzzz", Ada
.Strings
.Backward
, Map_Ptr
) /= 3 or
312 ASF
.Index
("kka", "qqz", Ada
.Strings
.Forward
, Map_Ptr
) /= 1
314 Report
.Failed
("Incorrect result from Index w/map ptr");
318 -- Check when the pattern wide string is not found in the source.
320 if ASF
.Index
("akzqef", "kzq", Ada
.Strings
.Forward
, Map_Ptr
) /= 0 or
321 ASF
.Index
("abcde", "abcdef", Ada
.Strings
.Backward
, Map_Ptr
) /= 0 or
322 ASF
.Index
("xyz", "akzde", Ada
.Strings
.Backward
, Map_Ptr
) /= 0 or
323 ASF
.Index
("", "zq", Ada
.Strings
.Forward
, Map_Ptr
) /= 0 or
324 ASF
.Index
("akcde", " ", Ada
.Strings
.Backward
, Map_Ptr
) /= 0
327 ("Incorrect result from Index w/map ptr, no pattern match");
330 -- Check that Pattern_Error is raised when the pattern is a
333 Location
:= ASF
.Index
("akzqefakqzef",
334 "", -- null pattern Wide_String.
337 Report
.Failed
("Pattern_Error not raised by Index w/map ptr");
339 when Ada
.Strings
.Pattern_Error
=> null; -- OK, expected exception.
342 ("Incorrect exception raised by Index w/map ptr, null pattern");
348 -- Using the version of Index testing wide character set membership,
349 -- check combinations of forward/backward, inside/outside parameter
352 if ASF
.Index
(Source
=> Source_String1
, -- "abcde"
354 Test
=> Ada
.Strings
.Inside
,
355 Going
=> Ada
.Strings
.Forward
) /= 3 or -- 'c' at pos 3.
356 ASF
.Index
(Source_String6
, -- "abcdefabcdef"
359 Ada
.Strings
.Backward
) /= 12 or -- 'f' at position 12
360 ASF
.Index
(Source_String6
, -- "abcdefabcdef"
363 Ada
.Strings
.Backward
) /= 10 or -- 'd' at position 10
364 ASF
.Index
("cdcdcdcdacdcdcdcd",
367 Ada
.Strings
.Forward
) /= 9 -- 'a' at position 9
369 Report
.Failed
("Incorrect result from function Index for sets - 1");
372 -- Additional interesting uses/combinations using Index for sets.
374 if ASF
.Index
("cd", -- same size, str-set
377 Ada
.Strings
.Forward
) /= 1 or -- 'c' at position 1
378 ASF
.Index
("abcd", -- same size, str-set,
379 Maps
.To_Set
("efgh"), -- different contents.
381 Ada
.Strings
.Forward
) /= 1 or
382 ASF
.Index
("abccd", -- set > Wide_String
383 Maps
.To_Set
("acegik"),
385 Ada
.Strings
.Backward
) /= 4 or -- 'c' at position 4
387 Maps
.Null_Set
) /= 0 or
388 ASF
.Index
("", -- Null string.
390 ASF
.Index
("abc ab", -- blank included
391 Maps
.To_Set
("e "), -- in Wide_String and
392 Ada
.Strings
.Inside
, -- set.
393 Ada
.Strings
.Backward
) /= 4 -- blank in Wide_Str.
395 Report
.Failed
("Incorrect result from function Index for sets - 2");
400 -- Function Index_Non_Blank.
401 -- (Other usage examples of this function found in CXA4013-14.)
404 if ASF
.Index_Non_Blank
(Source
=> Source_String4
, -- "abcdefghij "
405 Going
=> Ada
.Strings
.Backward
) /= 10 or
406 ASF
.Index_Non_Blank
("abc def ghi jkl ",
407 Ada
.Strings
.Backward
) /= 15 or
408 ASF
.Index_Non_Blank
(" abcdef") /= 3 or
409 ASF
.Index_Non_Blank
(" ") /= 0
411 Report
.Failed
("Incorrect result from Index_Non_Blank");
417 -- (Other usage examples of this function found in CXA4013-14.)
419 if ASF
.Count
("abababa", "aba") /= 2 or
420 ASF
.Count
("abababa", "ab" ) /= 3 or
421 ASF
.Count
("babababa", "ab") /= 3 or
422 ASF
.Count
("abaabaaba", "aba") /= 3 or
423 ASF
.Count
("xxxxxxxxxxxxxxxxxxxy", "xy") /= 1 or
424 ASF
.Count
("xxxxxxxxxxxxxxxxxxxx", "x") /= 20
426 Report
.Failed
("Incorrect result from Function Count");
429 -- Determine the number of slices of Source that when mapped to a
430 -- non-identity map, match the pattern Wide_String.
432 Slice_Count
:= ASF
.Count
(Source_String6
, -- "abcdefabcdef"
434 CD_to_XY_Map
); -- maps 'c' to 'x', 'd' to 'y'
436 if Slice_Count
/= 2 then -- two slices "xy" in "mapped" Source_String6
437 Report
.Failed
("Incorrect result from Count with non-identity map");
440 -- If the pattern supplied to Function Count is the null Wide_String,
441 -- then Pattern_Error is propagated.
443 The_Null_Wide_String
: constant Wide_String := "";
445 Slice_Count
:= ASF
.Count
(Source_String6
, The_Null_Wide_String
);
446 Report
.Failed
("Pattern_Error not raised by Function Count");
448 when Ada
.Strings
.Pattern_Error
=> null; -- OK
450 Report
.Failed
("Incorrect exception from Count with null pattern");
457 -- Use the version of Count that takes a Wide_Character_Mapping_Function
458 -- value as the basis of its source mapping.
460 if ASF
.Count
("akakaka", "zqz", Map_Ptr
) /= 2 or
461 ASF
.Count
("akakaka", "qz", Map_Ptr
) /= 3 or
462 ASF
.Count
("kakakaka", "q", Map_Ptr
) /= 4 or
463 ASF
.Count
("zzqaakzaqzzk", "zzq", Map_Ptr
) /= 4 or
464 ASF
.Count
(" ", "z", Map_Ptr
) /= 0 or
465 ASF
.Count
("", "qz", Map_Ptr
) /= 0 or
466 ASF
.Count
("abbababab", "zq", Map_Ptr
) /= 0 or
467 ASF
.Count
("aaaaaaaaaaaaaaaaaakk", "zqq", Map_Ptr
) /= 1 or
468 ASF
.Count
("azaazaazzzaaaaazzzza", "z", Map_Ptr
) /= 20
470 Report
.Failed
("Incorrect result from Function Count w/map ptr");
473 -- If the pattern supplied to Function Count is a null Wide_String,
474 -- then Pattern_Error is propagated.
476 The_Null_Wide_String
: constant Wide_String := "";
478 Slice_Count
:= ASF
.Count
(Source_String6
,
479 The_Null_Wide_String
,
482 ("Pattern_Error not raised by Function Count w/map ptr");
484 when Ada
.Strings
.Pattern_Error
=> null; -- OK
487 ("Incorrect exception from Count w/map ptr, null pattern");
493 -- Function Count returning the number of characters in a particular
494 -- set that are found in source Wide_String.
496 if ASF
.Count
(Source_String6
, CD_Set
) /= 4 or -- 2 'c' and 'd' chars.
497 ASF
.Count
("cddaccdaccdd", CD_Set
) /= 10
499 Report
.Failed
("Incorrect result from Count with set");
504 -- Function Find_Token.
505 -- (Other usage examples of this function found in CXA4013-14.)
507 ASF
.Find_Token
(Source
=> Source_String6
, -- First slice with no
508 Set
=> ABCD_Set
, -- 'a', 'b', 'c', or 'd'
509 Test
=> Ada
.Strings
.Outside
, -- is "ef" at 5..6.
510 First
=> Slice_Start
,
513 if Slice_Start
/= 5 or Slice_End
/= 6 then
514 Report
.Failed
("Incorrect result from Find_Token - 1");
517 -- If no appropriate slice is contained by the source Wide_String,
518 -- then the value returned in Last is zero, and the value in First is
521 ASF
.Find_Token
(Source_String6
, -- "abcdefabcdef"
522 A_to_F_Set
, -- Set of characters 'a' thru 'f'.
523 Ada
.Strings
.Outside
, -- No characters outside this set.
527 if Slice_Start
/= Source_String6
'First or Slice_End
/= 0 then
528 Report
.Failed
("Incorrect result from Find_Token - 2");
531 -- Additional testing of Find_Token.
533 ASF
.Find_Token
("eabcdabcddcab",
539 if Slice_Start
/= 2 or Slice_End
/= 13 then
540 Report
.Failed
("Incorrect result from Find_Token - 3");
543 ASF
.Find_Token
("efghijklabcdabcd",
549 if Slice_Start
/= 1 or Slice_End
/= 8 then
550 Report
.Failed
("Incorrect result from Find_Token - 4");
553 ASF
.Find_Token
("abcdefgabcdabcd",
559 if Slice_Start
/= 5 or Slice_End
/= 7 then
560 Report
.Failed
("Incorrect result from Find_Token - 5");
563 ASF
.Find_Token
("abcdcbabcdcba",
569 if Slice_Start
/= 1 or Slice_End
/= 13 then
570 Report
.Failed
("Incorrect result from Find_Token - 6");
575 when others => Report
.Failed
("Exception raised in Test_Block");