Debian Codegraph @

gcc/testsuite/ada/acats/tests/cxa/cxa4019.a

raw
1 -- CXA4019.A
2 --
3 -- Grant of Unlimited Rights
4 --
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
14 -- to do so.
15 --
16 -- DISCLAIMER
17 --
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.
24 --*
25 --
26 -- OBJECTIVE:
27 -- Check that the subprograms defined in package Ada.Strings.Wide_Bounded
28 -- are available, and that they produce correct results, especially
29 -- under conditions where truncation of the result is required.
30 -- Specifically, check the subprograms Append, Count with non-Identity
31 -- maps, Index with non-Identity maps, Index with Set parameters,
32 -- Insert (function and procedure), Replace_Slice (function and
33 -- procedure), To_Bounded_Wide_String, and Translate (function and
34 -- procedure).
35 --
36 -- TEST DESCRIPTION:
37 -- This test, in conjunction with tests CXA4017, CXA4018, and CXA4020,
38 -- will provide coverage of the most common usages of the functionality
39 -- found in the Ada.Strings.Wide_Bounded package. It deals in large part
40 -- with truncation effects and options. This test contains many small,
41 -- specific test cases, situations that are often difficult to generate
42 -- in large numbers in an application-based test. These cases represent
43 -- specific usage paradigms in-the-small.
44 --
45 --
46 -- CHANGE HISTORY:
47 -- 06 Dec 94 SAIC ACVC 2.0
48 -- 06 Nov 95 SAIC Corrected expected result string in subtest for
49 -- ACVC 2.0.1.
50 -- Moved function Dog_to_Cat_Mapping to library
51 -- level to correct accessibility problem in test.
52 -- 22 Aug 96 SAIC Corrected three subtests identified in reviewer
53 -- comments.
54 -- 17 Feb 97 PWB.CTA Corrected result strings for Translate and Insert
55 --
56 --!
57
58 package CXA40190 is
59
60 -- Wide Character mapping function defined for use with specific
61 -- versions of functions Index and Count.
62
63 function Dog_to_Cat_Mapping (From : Wide_Character)
64 return Wide_Character;
65
66 end CXA40190;
67
68 package body CXA40190 is
69
70 -- Translates "dog" to "cat".
71 function Dog_to_Cat_Mapping (From : Wide_Character)
72 return Wide_Character is
73 begin
74 if From = 'd' then
75 return 'c';
76 elsif From = 'o' then
77 return 'a';
78 elsif From = 'g' then
79 return 't';
80 else
81 return From;
82 end if;
83 end Dog_to_Cat_Mapping;
84
85 end CXA40190;
86
87
88 with CXA40190;
89 with Report;
90 with Ada.Characters.Handling;
91 with Ada.Strings.Wide_Bounded;
92 with Ada.Strings.Wide_Maps;
93 with Ada.Strings.Wide_Maps.Wide_Constants;
94
95 procedure CXA4019 is
96
97 -- The following two functions are used to translate character and string
98 -- values to "Wide" values. They will be applied to all the Wide_Bounded
99 -- subprogram parameters to simulate the use of Wide_Characters and
100 -- Wide_Strings in actual practice.
101
102 function Equiv (Ch : Character) return Wide_Character is
103 C : Character := Ch;
104 begin
105 if Ch = ' ' then
106 return Ada.Characters.Handling.To_Wide_Character(C);
107 else
108 return Wide_Character'Val(Character'Pos(Ch) +
109 Character'Pos(Character'Last) + 1);
110 end if;
111 end Equiv;
112
113
114 function Equiv (Str : String) return Wide_String is
115 WS : Wide_String(Str'First..Str'Last);
116 begin
117 for i in Str'First..Str'Last loop
118 WS(i) := Equiv(Str(i));
119 end loop;
120 return WS;
121 end Equiv;
122
123 begin
124
125 Report.Test("CXA4019", "Check that the subprograms defined in " &
126 "package Ada.Strings.Wide_Bounded are " &
127 "available, and that they produce correct " &
128 "results, especially under conditions where " &
129 "truncation of the result is required");
130
131 Test_Block:
132 declare
133
134 use CXA40190;
135
136 package AS renames Ada.Strings;
137 package ASB renames Ada.Strings.Wide_Bounded;
138 package ASWC renames Ada.Strings.Wide_Maps.Wide_Constants;
139 package Maps renames Ada.Strings.Wide_Maps;
140
141 package B10 is new ASB.Generic_Bounded_Length(Max => 10);
142 use type B10.Bounded_Wide_String;
143
144 Result_String : B10.Bounded_Wide_String;
145 Test_String : B10.Bounded_Wide_String;
146 AtoE_Bnd_Str : B10.Bounded_Wide_String :=
147 B10.To_Bounded_Wide_String(Equiv("abcde"));
148 FtoJ_Bnd_Str : B10.Bounded_Wide_String :=
149 B10.To_Bounded_Wide_String(Equiv("fghij"));
150 AtoJ_Bnd_Str : B10.Bounded_Wide_String :=
151 B10.To_Bounded_Wide_String(Equiv("abcdefghij"));
152
153 Location : Natural := 0;
154 Total_Count : Natural := 0;
155
156 CD_Set : Maps.Wide_Character_Set := Maps.To_Set("cd");
157 Wide_CD_Set : Maps.Wide_Character_Set := Maps.To_Set(Equiv("cd"));
158
159 AB_to_YZ_Map : Maps.Wide_Character_Mapping :=
160 Maps.To_Mapping(From => "ab", To => "yz");
161
162 Wide_AB_to_YZ_Map : Maps.Wide_Character_Mapping :=
163 Maps.To_Mapping(From => Equiv("ab"),
164 To => Equiv("yz"));
165
166 CD_to_XY_Map : Maps.Wide_Character_Mapping :=
167 Maps.To_Mapping(From => "cd", To => "xy");
168
169 Wide_CD_to_XY_Map : Maps.Wide_Character_Mapping :=
170 Maps.To_Mapping(From => Equiv("cd"),
171 To => Equiv("xy"));
172
173
174 -- Access-to-Subprogram object defined for use with specific versions of
175 -- functions Index, Count Translate, and procedure Translate.
176
177 Map_Ptr : Maps.Wide_Character_Mapping_Function :=
178 Dog_to_Cat_Mapping'Access;
179
180
181
182 begin
183
184 -- Function To_Bounded_Wide_String with Truncation
185 -- Evaluate the function Append with parameters that will
186 -- cause the truncation of the result.
187
188 -- Drop = Error (default case, Length_Error will be raised)
189
190 begin
191 Test_String :=
192 B10.To_Bounded_Wide_String
193 (Equiv("Much too long for this bounded wide string"));
194 Report.Failed("Length Error not raised by To_Bounded_Wide_String");
195 exception
196 when AS.Length_Error => null; -- Expected exception raised.
197 when others =>
198 Report.Failed
199 ("Incorrect exception raised by To_Bounded_Wide_String");
200 end;
201
202 -- Drop = Left
203
204 Test_String :=
205 B10.To_Bounded_Wide_String(Source => Equiv("abcdefghijklmn"),
206 Drop => Ada.Strings.Left);
207
208 if Test_String /= B10.To_Bounded_Wide_String(Equiv("efghijklmn")) then
209 Report.Failed
210 ("Incorrect result from To_Bounded_Wide_String, Drop = Left");
211 end if;
212
213 -- Drop = Right
214
215 Test_String :=
216 B10.To_Bounded_Wide_String(Source => Equiv("abcdefghijklmn"),
217 Drop => Ada.Strings.Right);
218
219 if not(Test_String = AtoJ_Bnd_Str) then
220 Report.Failed
221 ("Incorrect result from To_Bounded_Wide_String, Drop = Right");
222 end if;
223
224
225
226
227 -- Function Append with Truncation
228 -- Evaluate the function Append with parameters that will
229 -- cause the truncation of the result.
230
231 -- Drop = Error (default case, Length_Error will be raised)
232
233 begin
234 -- Append (Bnd Str, Bnd Str);
235 Result_String :=
236 B10.Append(B10.To_Bounded_Wide_String(Equiv("abcde")),
237 B10.To_Bounded_Wide_String(Equiv("fghijk"))); -- 11 char
238 Report.Failed("Length_Error not raised by Append - 1");
239 exception
240 when AS.Length_Error => null; -- OK, correct exception raised.
241 when others =>
242 Report.Failed("Incorrect exception raised by Append - 1");
243 end;
244
245 begin
246 -- Append (Str, Bnd Str);
247 Result_String :=
248 B10.Append(B10.To_Wide_String(AtoE_Bnd_Str),
249 B10.To_Bounded_Wide_String(Equiv("fghijk")),
250 AS.Error);
251 Report.Failed("Length_Error not raised by Append - 2");
252 exception
253 when AS.Length_Error => null; -- OK, correct exception raised.
254 when others =>
255 Report.Failed("Incorrect exception raised by Append - 2");
256 end;
257
258 begin
259 -- Append (Bnd Str, Char);
260 Result_String :=
261 B10.Append(B10.To_Bounded_Wide_String("abcdefghij"), 'k');
262 Report.Failed("Length_Error not raised by Append - 3");
263 exception
264 when AS.Length_Error => null; -- OK, correct exception raised.
265 when others =>
266 Report.Failed("Incorrect exception raised by Append - 3");
267 end;
268
269 -- Drop = Left
270
271 -- Append (Bnd Str, Bnd Str)
272 Result_String :=
273 B10.Append(B10.To_Bounded_Wide_String(Equiv("abcdefgh")), -- 8 chs
274 B10.To_Bounded_Wide_String(Equiv("ijklmn")), -- 6 chs
275 Ada.Strings.Left);
276
277 if Result_String /=
278 B10.To_Bounded_Wide_String(Equiv("efghijklmn")) -- 10 chars
279 then
280 Report.Failed("Incorrect truncation performed by Append - 4");
281 end if;
282
283 -- Append (Bnd Str, Str)
284 Result_String :=
285 B10.Append(B10.To_Bounded_Wide_String("abcdefghij"),
286 "xyz",
287 Ada.Strings.Left);
288
289 if Result_String /= B10.To_Bounded_Wide_String("defghijxyz") then
290 Report.Failed("Incorrect truncation performed by Append - 5");
291 end if;
292
293 -- Append (Char, Bnd Str)
294
295 Result_String :=
296 B10.Append(Equiv('A'),
297 B10.To_Bounded_Wide_String(Equiv("abcdefghij")),
298 Ada.Strings.Left);
299
300 if Result_String /= B10.To_Bounded_Wide_String(Equiv("abcdefghij"))
301 then
302 Report.Failed("Incorrect truncation performed by Append - 6");
303 end if;
304
305 -- Drop = Right
306
307 -- Append (Bnd Str, Bnd Str)
308 Result_String := B10.Append(FtoJ_Bnd_Str,
309 AtoJ_Bnd_Str,
310 Ada.Strings.Right);
311
312 if Result_String /=
313 B10.To_Bounded_Wide_String(Equiv("fghijabcde"))
314 then
315 Report.Failed("Incorrect truncation performed by Append - 7");
316 end if;
317
318 -- Append (Str, Bnd Str)
319 Result_String := B10.Append(B10.To_Wide_String(AtoE_Bnd_Str),
320 AtoJ_Bnd_Str,
321 Ada.Strings.Right);
322
323 if Result_String /=
324 B10.To_Bounded_Wide_String(Equiv("abcdeabcde"))
325 then
326 Report.Failed("Incorrect truncation performed by Append - 8");
327 end if;
328
329 -- Append (Char, Bnd Str)
330 Result_String := B10.Append(Equiv('A'), AtoJ_Bnd_Str, Ada.Strings.Right);
331
332 if Result_String /= B10.To_Bounded_Wide_String(Equiv("Aabcdefghi")) then
333 Report.Failed("Incorrect truncation performed by Append - 9");
334 end if;
335
336
337
338 -- Function Index with non-Identity map.
339 -- Evaluate the function Index with a non-identity map
340 -- parameter which will cause mapping of the source parameter
341 -- prior to the evaluation of the index position search.
342
343 Location :=
344 B10.Index(Source => B10.To_Bounded_Wide_String("foxy fox 2"),
345 Pattern => "FOX",
346 Going => Ada.Strings.Backward,
347 Mapping => ASWC.Upper_Case_Map);
348
349 if Location /= 6 then
350 Report.Failed("Incorrect result from Index, non-Identity map - 1");
351 end if;
352
353 Location :=
354 B10.Index(B10.To_Bounded_Wide_String("THE QUICK "),
355 "quick",
356 Ada.Strings.Forward,
357 Ada.Strings.Wide_Maps.Wide_Constants.Lower_Case_Map);
358
359 if Location /= 5 then
360 Report.Failed("Incorrect result from Index, non-Identity map - 2");
361 end if;
362
363 Location := B10.Index(Source => B10.To_Bounded_Wide_String("The the"),
364 Pattern => "the",
365 Going => Ada.Strings.Forward,
366 Mapping => ASWC.Lower_Case_Map);
367
368 if Location /= 1 then
369 Report.Failed("Incorrect result from Index, non-Identity map - 3");
370 end if;
371
372
373
374 if B10.Index(B10.To_Bounded_Wide_String("abcd"), -- Pattern = Source
375 "abcd") /= 1 or
376 B10.Index(B10.To_Bounded_Wide_String("abc"), -- Pattern < Source
377 "abcd") /= 0 or
378 B10.Index(B10.Null_Bounded_Wide_String, -- Source = Null
379 "abc") /= 0
380 then
381 Report.Failed("Incorrect result from Index with string patterns");
382 end if;
383
384
385
386 -- Function Index with access-to-subprogram mapping value.
387 -- Evaluate the function Index with a wide character mapping function
388 -- object that performs the mapping operation.
389
390 Location := B10.Index(Source => B10.To_Bounded_Wide_String("My dog"),
391 Pattern => "cat",
392 Going => Ada.Strings.Forward,
393 Mapping => Map_Ptr); -- change "dog" to "cat"
394
395 if Location /= 4 then
396 Report.Failed("Incorrect result from Index, w/map ptr - 1");
397 end if;
398
399 Location := B10.Index(B10.To_Bounded_Wide_String("cat or dog"),
400 "cat",
401 Ada.Strings.Backward,
402 Map_Ptr);
403
404 if Location /= 8 then
405 Report.Failed("Incorrect result from Index, w/map ptr - 2");
406 end if;
407
408 if B10.Index(B10.To_Bounded_Wide_String("dog"), -- Pattern = Source
409 "cat",
410 Ada.Strings.Forward,
411 Map_Ptr) /= 1 or
412 B10.Index(B10.To_Bounded_Wide_String("dog"), -- Pattern < Source
413 "cats",
414 Ada.Strings.Backward,
415 Map_Ptr) /= 0 or
416 B10.Index(B10.Null_Bounded_Wide_String, -- Source = Null
417 "cat",
418 Ada.Strings.Forward,
419 Map_Ptr) /= 0 or
420 B10.Index(B10.To_Bounded_Wide_String("hot dog"),
421 "dog",
422 Ada.Strings.Backward,
423 Map_Ptr) /= 0 or
424 B10.Index(B10.To_Bounded_Wide_String(" cat dog "),
425 " cat",
426 Ada.Strings.Backward,
427 Map_Ptr) /= 5 or
428 B10.Index(B10.To_Bounded_Wide_String("dog CatDog"),
429 "cat",
430 Ada.Strings.Backward,
431 Map_Ptr) /= 1 or
432 B10.Index(B10.To_Bounded_Wide_String("CatandDog"),
433 "cat",
434 Ada.Strings.Forward,
435 Map_Ptr) /= 0 or
436 B10.Index(B10.To_Bounded_Wide_String("dddd"),
437 "ccccc",
438 Ada.Strings.Backward,
439 Map_Ptr) /= 0
440 then
441 Report.Failed("Incorrect result from Index w/map ptr - 3");
442 end if;
443
444
445
446 -- Function Index (for Sets).
447 -- This version of Index uses Sets as the basis of the search.
448
449 -- Test = Inside, Going = Forward (Default case).
450 Location :=
451 B10.Index(Source => B10.To_Bounded_Wide_String(Equiv("abcdeabcde")),
452 Set => Wide_CD_Set,
453 Test => Ada.Strings.Inside,
454 Going => Ada.Strings.Forward);
455
456 if not (Location = 3) then -- position of first 'c' equivalent in source.
457 Report.Failed("Incorrect result from Index using Sets - 1");
458 end if;
459
460 -- Test = Inside, Going = Backward.
461 Location :=
462 B10.Index(Source => B10."&"(AtoE_Bnd_Str, AtoE_Bnd_Str),
463 Set => Wide_CD_Set,
464 Test => Ada.Strings.Inside,
465 Going => Ada.Strings.Backward);
466
467 if not (Location = 9) then -- position of last 'd' in source.
468 Report.Failed("Incorrect result from Index using Sets - 2");
469 end if;
470
471 -- Test = Outside, Going = Forward.
472 Location := B10.Index(B10.To_Bounded_Wide_String("deddacd"),
473 CD_Set,
474 Test => Ada.Strings.Outside,
475 Going => Ada.Strings.Forward);
476
477 if Location /= 2 then -- position of 'e' in source.
478 Report.Failed("Incorrect result from Index using Sets - 3");
479 end if;
480
481 -- Test = Outside, Going = Backward.
482 Location := B10.Index(B10.To_Bounded_Wide_String(Equiv("deddacd")),
483 Wide_CD_Set,
484 Ada.Strings.Outside,
485 Ada.Strings.Backward);
486
487 if Location /= 5 then -- position of 'a', correct.
488 Report.Failed("Incorrect result from Index using Sets - 4");
489 end if;
490
491 if B10.Index(B10.To_Bounded_Wide_String("cd"), -- Source = Set
492 CD_Set) /= 1 or
493 B10.Index(B10.To_Bounded_Wide_String("c"), -- Source < Set
494 CD_Set) /= 1 or
495 B10.Index(B10.Null_Bounded_Wide_String, -- Source = Null
496 Wide_CD_Set) /= 0 or
497 B10.Index(AtoE_Bnd_Str,
498 Maps.To_Set('x')) /= 0 -- No match.
499 then
500 Report.Failed("Incorrect result from Index using Sets - 5");
501 end if;
502
503
504
505 -- Function Count with non-Identity mapping.
506 -- Evaluate the function Count with a non-identity map
507 -- parameter which will cause mapping of the source parameter
508 -- prior to the evaluation of the number of matching patterns.
509
510 Total_Count :=
511 B10.Count(Source => B10.To_Bounded_Wide_String("THE THE TH"),
512 Pattern => "th",
513 Mapping => ASWC.Lower_Case_Map);
514
515 if Total_Count /= 3 then
516 Report.Failed
517 ("Incorrect result from function Count, non-Identity map - 1");
518 end if;
519
520 -- And a few with identity maps as well.
521
522 if B10.Count(B10.To_Bounded_Wide_String(Equiv("ABABABABAB")),
523 Equiv("ABA"),
524 Maps.Identity) /= 2 or
525 B10.Count(B10.To_Bounded_Wide_String("ADCBADABCD"),
526 "AB",
527 Maps.To_Mapping("CD", "AB")) /= 5 or
528 B10.Count(B10.To_Bounded_Wide_String(Equiv("aaaaaaaaaa")),
529 Equiv("aaa")) /= 3 or
530 B10.Count(B10.To_Bounded_Wide_String(Equiv("XX")),
531 Equiv("XXX"),
532 Maps.Identity) /= 0 or
533 B10.Count(AtoE_Bnd_Str, -- Source = Pattern
534 Equiv("abcde")) /= 1 or
535 B10.Count(B10.Null_Bounded_Wide_String, -- Source = Null
536 " ") /= 0
537 then
538 Report.Failed
539 ("Incorrect result from function Count, w,w/o mapping");
540 end if;
541
542
543
544
545
546 -- Function Count with access-to-subprogram mapping.
547 -- Evaluate the version function Count that uses an access-to-subprogram
548 -- map parameter.
549
550 Total_Count :=
551 B10.Count(Source => B10.To_Bounded_Wide_String("dogdogdo"),
552 Pattern => "ca",
553 Mapping => Map_Ptr);
554
555 if Total_Count /= 3 then
556 Report.Failed
557 ("Incorrect result from function Count, w/map ptr - 1");
558 end if;
559
560
561 if B10.Count(B10.To_Bounded_Wide_String("DdOoGgod"),
562 "c",
563 Map_Ptr) /= 2 or
564 B10.Count(B10.To_Bounded_Wide_String("dododododo"),
565 "do",
566 Map_Ptr) /= 0 or
567 B10.Count(B10.To_Bounded_Wide_String("Dog or dog"),
568 "cat",
569 Map_Ptr) /= 1 or
570 B10.Count(B10.To_Bounded_Wide_String("dddddddddd"),
571 "ccccc",
572 Map_Ptr) /= 2 or
573 B10.Count(B10.To_Bounded_Wide_String("do"), -- Source < Pattern
574 "cat",
575 Map_Ptr) /= 0 or
576 B10.Count(B10.To_Bounded_Wide_String(" dog "), -- Source = Pattern
577 " cat ",
578 Map_Ptr) /= 1 or
579 B10.Count(B10.Null_Bounded_Wide_String, -- Source = Null
580 " ",
581 Map_Ptr) /= 0
582 then
583 Report.Failed
584 ("Incorrect result from function Count, w/map ptr - 2");
585 end if;
586
587
588
589
590 -- Procedure Translate
591
592 -- Partial mapping of source.
593
594 Test_String := B10.To_Bounded_Wide_String("abcdeabcab");
595
596 B10.Translate(Source => Test_String, Mapping => AB_to_YZ_Map);
597
598 if Test_String /= B10.To_Bounded_Wide_String("yzcdeyzcyz") then
599 Report.Failed("Incorrect result from procedure Translate - 1");
600 end if;
601
602 -- Total mapping of source.
603
604 Test_String := B10.To_Bounded_Wide_String("abbaaababb");
605
606 B10.Translate(Source => Test_String, Mapping => ASWC.Upper_Case_Map);
607
608 if Test_String /= B10.To_Bounded_Wide_String("ABBAAABABB") then
609 Report.Failed("Incorrect result from procedure Translate - 2");
610 end if;
611
612 -- No mapping of source.
613
614 Test_String := B10.To_Bounded_Wide_String(Equiv("xyzsypcc"));
615
616 B10.Translate(Source => Test_String, Mapping => Wide_AB_to_YZ_Map);
617
618 if Test_String /= B10.To_Bounded_Wide_String(Equiv("xyzsypcc")) then
619 Report.Failed("Incorrect result from procedure Translate - 3");
620 end if;
621
622 -- Map > 2 characters, partial mapping.
623
624 Test_String := B10.To_Bounded_Wide_String("opabcdelmn");
625
626 B10.Translate(Test_String,
627 Maps.To_Mapping("abcde", "lmnop"));
628
629 if Test_String /= B10.To_Bounded_Wide_String("oplmnoplmn") then
630 Report.Failed("Incorrect result from procedure Translate - 4");
631 end if;
632
633
634
635
636 -- Procedure Translate with access-to-subprogram mapping.
637 -- Use the version of Procedure Translate that takes an
638 -- access-to-subprogram parameter to perform the Source mapping.
639
640 -- Partial mapping of source.
641
642 Test_String := B10.To_Bounded_Wide_String("dogeatdog");
643
644 B10.Translate(Source => Test_String, Mapping => Map_Ptr);
645
646 if Test_String /= B10.To_Bounded_Wide_String("cateatcat") then
647 Report.Failed
648 ("Incorrect result from procedure Translate w/map ptr - 1");
649 end if;
650
651 Test_String := B10.To_Bounded_Wide_String("odogcatlmn");
652
653 B10.Translate(Test_String, Map_Ptr);
654
655 if Test_String /= B10.To_Bounded_Wide_String("acatcatlmn") then
656 Report.Failed
657 ("Incorrect result from procedure Translate w/map ptr - 2");
658 end if;
659
660
661 -- Total mapping of source.
662
663 Test_String := B10.To_Bounded_Wide_String("gggooooddd");
664
665 B10.Translate(Source => Test_String, Mapping => Map_Ptr);
666
667 if Test_String /= B10.To_Bounded_Wide_String("tttaaaaccc") then
668 Report.Failed
669 ("Incorrect result from procedure Translate w/map ptr- 3");
670 end if;
671
672 -- No mapping of source.
673
674 Test_String := B10.To_Bounded_Wide_String(" DOG cat ");
675
676 B10.Translate(Source => Test_String, Mapping => Map_Ptr);
677
678 if Test_String /= B10.To_Bounded_Wide_String(" DOG cat ") then
679 Report.Failed
680 ("Incorrect result from procedure Translate w/map ptr - 4");
681 end if;
682
683 Test_String := B10.Null_Bounded_Wide_String;
684
685 B10.Translate(Source => Test_String, Mapping => Map_Ptr);
686
687 if Test_String /= B10.To_Bounded_Wide_String("") then
688 Report.Failed
689 ("Incorrect result from procedure Translate w/map ptr - 5");
690 end if;
691
692
693
694
695 -- Function Translate with access-to-subprogram mapping.
696 -- Use the version of Function Translate that takes an
697 -- access-to-subprogram parameter to perform the Source mapping.
698
699 -- Partial mapping of source.
700
701 if B10.Translate(Source => B10.To_Bounded_Wide_String("cateatdog"),
702 Mapping => Map_Ptr) /=
703 B10.To_Bounded_Wide_String("cateatcat")
704 then
705 Report.Failed
706 ("Incorrect result from function Translate w/map ptr - 1");
707 end if;
708
709 if B10.Translate(B10.To_Bounded_Wide_String("cadogtac"),
710 Map_Ptr) /=
711 B10.To_Bounded_Wide_String("cacattac")
712 then
713 Report.Failed
714 ("Incorrect result from function Translate w/map ptr - 2");
715 end if;
716
717 -- Total mapping of source.
718
719 if B10.Translate(Source => B10.To_Bounded_Wide_String("dogodggdo"),
720 Mapping => Map_Ptr) /=
721 B10.To_Bounded_Wide_String("catacttca")
722 then
723 Report.Failed
724 ("Incorrect result from function Translate w/map ptr- 3");
725 end if;
726
727 -- No mapping of source.
728
729 if B10.Translate(Source => B10.To_Bounded_Wide_String(" DOG cat "),
730 Mapping => Map_Ptr) /=
731 B10.To_Bounded_Wide_String(" DOG cat ")
732 then
733 Report.Failed
734 ("Incorrect result from function Translate w/map ptr - 4");
735 end if;
736
737 if B10.Translate(B10.To_Bounded_Wide_String("d "), Map_Ptr) /=
738 B10.To_Bounded_Wide_String("c ") or
739 B10.Translate(B10.To_Bounded_Wide_String(" god"), Map_Ptr) /=
740 B10.To_Bounded_Wide_String(" tac") or
741 B10.Translate(B10.To_Bounded_Wide_String("d o g D og"), Map_Ptr) /=
742 B10.To_Bounded_Wide_String("c a t D at") or
743 B10.Translate(B10.To_Bounded_Wide_String(" "), Map_Ptr) /=
744 B10.To_Bounded_Wide_String(" ") or
745 B10.Translate(B10.To_Bounded_Wide_String("dddddddddd"), Map_Ptr) /=
746 B10.To_Bounded_Wide_String("cccccccccc")
747 then
748 Report.Failed
749 ("Incorrect result from function Translate w/map ptr - 5");
750 end if;
751
752 if B10.Translate(Source => B10.Null_Bounded_Wide_String,
753 Mapping => Map_Ptr) /=
754 B10.To_Bounded_Wide_String("")
755 then
756 Report.Failed
757 ("Incorrect result from function Translate w/map ptr - 6");
758 end if;
759
760
761
762
763 -- Function Replace_Slice
764 -- Evaluate function Replace_Slice with
765 -- a variety of Truncation options.
766
767 -- Drop = Error (Default)
768
769 begin
770 Test_String := AtoJ_Bnd_Str;
771 Result_String :=
772 B10.Replace_Slice(Source => Test_String,
773 Low => 3,
774 High => 5, -- 3-5, 3 chars.
775 By => Equiv("xxxxxx")); -- more than 3.
776 Report.Failed("Length_Error not raised by Function Replace_Slice");
777 exception
778 when AS.Length_Error => null; -- Correct exception raised.
779 when others =>
780 Report.Failed
781 ("Incorrect exception raised by Function Replace_Slice");
782 end;
783
784 -- Drop = Left
785
786 Result_String :=
787 B10.Replace_Slice(Source => Test_String,
788 Low => 7,
789 High => 10, -- 7-10, 4 chars.
790 By => Equiv("xxxxxx"), -- 6 chars.
791 Drop => Ada.Strings.Left);
792
793 if Result_String /=
794 B10.To_Bounded_Wide_String(Equiv("cdefxxxxxx")) -- drop a,b
795 then
796 Report.Failed
797 ("Incorrect result from Function Replace Slice, Drop = Left");
798 end if;
799
800 -- Drop = Right
801
802 Result_String :=
803 B10.Replace_Slice(Source => Test_String,
804 Low => 2,
805 High => 5, -- 2-5, 4 chars.
806 By => Equiv("xxxxxx"), -- 6 chars.
807 Drop => Ada.Strings.Right);
808
809 if Result_String /=
810 B10.To_Bounded_Wide_String(Equiv("axxxxxxfgh")) -- drop i,j
811 then
812 Report.Failed
813 ("Incorrect result from Function Replace Slice, Drop = Right");
814 end if;
815
816 -- Low = High = Source'Last, "By" length = 1.
817
818 if B10.Replace_Slice(AtoE_Bnd_Str,
819 B10.To_Wide_String(AtoE_Bnd_Str)'Last,
820 B10.To_Wide_String(AtoE_Bnd_Str)'Last,
821 Equiv("X"),
822 Ada.Strings.Error) /=
823 B10.To_Bounded_Wide_String(Equiv("abcdX"))
824 then
825 Report.Failed("Incorrect result from Function Replace_Slice");
826 end if;
827
828 -- Index_Error raised when High < Source'First - 1.
829 begin
830 Test_String :=
831 B10.Replace_Slice(AtoE_Bnd_Str,
832 B10.To_Wide_String(AtoE_Bnd_Str)'First,
833 B10.To_Wide_String(AtoE_Bnd_Str)'First - 2,
834 Equiv("hijklm"));
835 Report.Failed("Index_Error not raised by Function Replace_Slice");
836 exception
837 when AS.Index_Error => null; -- OK, expected exception
838 when Constraint_Error => null; -- Also OK, since RM is not clear
839 when others =>
840 Report.Failed
841 ("Incorrect exception raised by Function Replace_Slice");
842 end;
843
844
845
846 -- Procedure Replace_Slice
847 -- Evaluate procedure Replace_Slice with
848 -- a variety of Truncation options.
849
850 -- Drop = Error (Default)
851
852 begin
853 Test_String := AtoJ_Bnd_Str;
854 B10.Replace_Slice(Source => Test_String,
855 Low => 3,
856 High => 5, -- 3-5, 3 chars.
857 By => Equiv("xxxxxx")); -- more than 3.
858 Report.Failed("Length_Error not raised by Procedure Replace_Slice");
859 exception
860 when AS.Length_Error => null; -- Correct exception raised.
861 when others =>
862 Report.Failed
863 ("Incorrect exception raised by Procedure Replace_Slice");
864 end;
865
866 -- Drop = Left
867
868 Test_String := AtoJ_Bnd_Str;
869 B10.Replace_Slice(Source => Test_String,
870 Low => 7,
871 High => 9, -- 7-9, 3 chars.
872 By => Equiv("xxxxx"), -- 5 chars.
873 Drop => Ada.Strings.Left);
874
875 if Test_String /=
876 B10.To_Bounded_Wide_String(Equiv("cdefxxxxxj")) -- drop a,b
877 then
878 Report.Failed
879 ("Incorrect result from Procedure Replace Slice, Drop = Left");
880 end if;
881
882 -- Drop = Right
883
884 Test_String := AtoJ_Bnd_Str;
885 B10.Replace_Slice(Source => Test_String,
886 Low => 1,
887 High => 3, -- 1-3, 3chars.
888 By => Equiv("xxxx"), -- 4 chars.
889 Drop => Ada.Strings.Right);
890
891 if Test_String /=
892 B10.To_Bounded_Wide_String(Equiv("xxxxdefghi")) -- drop j
893 then
894 Report.Failed
895 ("Incorrect result from Procedure Replace Slice, Drop = Right");
896 end if;
897
898 -- High = Source'First, Low > High (Insert before Low).
899
900 Test_String := AtoE_Bnd_Str;
901 B10.Replace_Slice(Source => Test_String,
902 Low => B10.To_Wide_String(Test_String)'Last,
903 High => B10.To_Wide_String(Test_String)'First,
904 By => Equiv("XXXX"), -- 4 chars.
905 Drop => Ada.Strings.Right);
906
907 if Test_String /= B10.To_Bounded_Wide_String(Equiv("abcdXXXXe")) then
908 Report.Failed
909 ("Incorrect result from Procedure Replace Slice");
910 end if;
911
912
913
914
915 -- Function Insert with Truncation
916 -- Drop = Error (Default).
917
918 begin
919 Result_String :=
920 B10.Insert(Source => AtoJ_Bnd_Str, -- "abcdefghij"
921 Before => 2,
922 New_Item => Equiv("xyz"));
923 Report.Failed("Length_Error not raised by Function Insert");
924 exception
925 when AS.Length_Error => null; -- Correct exception raised.
926 when others =>
927 Report.Failed("Incorrect exception raised by Function Insert");
928 end;
929
930 -- Drop = Left
931
932 Result_String :=
933 B10.Insert(Source => AtoJ_Bnd_Str, -- "abcdefghij"
934 Before => 5,
935 New_Item => Equiv("xyz"), -- 3 additional chars.
936 Drop => Ada.Strings.Left);
937
938 if B10.To_Wide_String(Result_String) /= Equiv("dxyzefghij") then
939 Report.Failed("Incorrect result from Function Insert, Drop = Left");
940 end if;
941
942 -- Drop = Right
943
944 Result_String :=
945 B10.Insert(Source => B10.To_Bounded_Wide_String("abcdef"),
946 Before => 2,
947 New_Item => "vwxyz", -- 5 additional chars.
948 Drop => Ada.Strings.Right);
949
950 if B10.To_Wide_String(Result_String) /= "avwxyzbcde" then -- drop f.
951 Report.Failed("Incorrect result from Function Insert, Drop = Right");
952 end if;
953
954 -- Additional cases.
955
956 if B10.Insert(B10.To_Bounded_Wide_String("a"), 1, " B") /=
957 B10.To_Bounded_Wide_String(" Ba") or
958 B10.Insert(B10.Null_Bounded_Wide_String, 1, Equiv("abcde")) /=
959 AtoE_Bnd_Str or
960 B10.Insert(B10.To_Bounded_Wide_String("ab"), 2, "") /=
961 B10.To_Bounded_Wide_String("ab")
962 then
963 Report.Failed("Incorrect result from Function Insert");
964 end if;
965
966
967
968 -- Procedure Insert
969
970 -- Drop = Error (Default).
971 begin
972 Test_String := AtoJ_Bnd_Str;
973 B10.Insert(Source => Test_String,
974 Before => 9,
975 New_Item => Equiv("wxyz"),
976 Drop => Ada.Strings.Error);
977 Report.Failed("Length_Error not raised by Procedure Insert");
978 exception
979 when AS.Length_Error => null; -- Correct exception raised.
980 when others =>
981 Report.Failed("Incorrect exception raised by Procedure Insert");
982 end;
983
984 -- Drop = Left
985
986 Test_String := AtoJ_Bnd_Str;
987 B10.Insert(Source => Test_String,
988 Before => B10.Length(Test_String), -- before last char
989 New_Item => Equiv("xyz"), -- 3 additional chars.
990 Drop => Ada.Strings.Left);
991
992 if B10.To_Wide_String(Test_String) /= Equiv("defghixyzj") then
993 Report.Failed("Incorrect result from Procedure Insert, Drop = Left");
994 end if;
995
996 -- Drop = Right
997
998 Test_String := AtoJ_Bnd_Str;
999 B10.Insert(Source => Test_String,
1000 Before => 4,
1001 New_Item => Equiv("yz"), -- 2 additional chars.
1002 Drop => Ada.Strings.Right);
1003
1004 if B10.To_Wide_String(Test_String) /= Equiv("abcyzdefgh") then
1005 Report.Failed
1006 ("Incorrect result from Procedure Insert, Drop = Right");
1007 end if;
1008
1009 -- Before = Source'First, New_Item length = 1.
1010
1011 Test_String := B10.To_Bounded_Wide_String(" abc ");
1012 B10.Insert(Test_String,
1013 B10.To_Wide_String(Test_String)'First,
1014 "Z");
1015
1016 if Test_String /= B10.To_Bounded_Wide_String("Z abc ") then
1017 Report.Failed("Incorrect result from Procedure Insert");
1018 end if;
1019
1020
1021 exception
1022 when others => Report.Failed("Exception raised in Test_Block");
1023 end Test_Block;
1024
1025 Report.Result;
1026
1027 end CXA4019;