OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [ada/] [acats/] [tests/] [cxa/] [cxa4008.a] - Blame information for rev 720

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 720 jeremybenn
-- CXA4008.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.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,
33
--      and Translate.
34
--
35
-- TEST DESCRIPTION:
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.
43
--
44
--
45
-- CHANGE HISTORY:
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.
50
--
51
--!
52
 
53
with Report;
54
with Ada.Strings.Maps.Constants;
55
with Ada.Strings.Bounded;
56
with Ada.Strings.Maps;
57
 
58
procedure CXA4008 is
59
 
60
begin
61
 
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");
67
 
68
   Test_Block:
69
   declare
70
 
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;
75
 
76
      package B10 is new ASB.Generic_Bounded_Length(Max => 10);
77
      use type B10.Bounded_String;
78
 
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");
85
 
86
      Location     : Natural := 0;
87
      Total_Count  : Natural := 0;
88
 
89
      CD_Set       : Maps.Character_Set := Maps.To_Set("cd");
90
 
91
      AB_to_YZ_Map : Maps.Character_Mapping :=
92
                       Maps.To_Mapping(From =>  "ab",  To => "yz");
93
 
94
      CD_to_XY_Map : Maps.Character_Mapping :=
95
                       Maps.To_Mapping(From =>  "cd",  To => "xy");
96
 
97
 
98
   begin
99
      -- Function To_Bounded_String with Truncation
100
      -- Evaluate the function Append with parameters that will
101
      -- cause the truncation of the result.
102
 
103
      -- Drop = Error (default case, Length_Error will be raised)
104
 
105
      begin
106
         Test_String :=
107
           B10.To_Bounded_String("Much too long for this bounded string");
108
         Report.Failed("Length Error not raised by To_Bounded_String");
109
      exception
110
         when AS.Length_Error => null;  -- Expected exception raised.
111
         when others          =>
112
           Report.Failed("Incorrect exception raised by To_Bounded_String");
113
      end;
114
 
115
      -- Drop = Left
116
 
117
      Test_String := B10.To_Bounded_String(Source => "abcdefghijklmn",
118
                                           Drop   => Ada.Strings.Left);
119
 
120
      if Test_String /= B10.To_Bounded_String("efghijklmn") then
121
         Report.Failed
122
           ("Incorrect result from To_Bounded_String, Drop = Left");
123
      end if;
124
 
125
      -- Drop = Right
126
 
127
      Test_String := B10.To_Bounded_String(Source => "abcdefghijklmn",
128
                                           Drop   => Ada.Strings.Right);
129
 
130
      if not(Test_String = AtoJ_Bnd_Str) then
131
         Report.Failed
132
           ("Incorrect result from To_Bounded_String, Drop = Right");
133
      end if;
134
 
135
 
136
 
137
 
138
      -- Function Append with Truncation
139
      -- Evaluate the function Append with parameters that will
140
      -- cause the truncation of the result.
141
 
142
      -- Drop = Error (default case, Length_Error will be raised)
143
 
144
      begin
145
         -- Append (Bnd Str, Bnd Str);
146
         Result_String :=
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");
150
      exception
151
         when AS.Length_Error => null;   -- OK, correct exception raised.
152
         when others          =>
153
            Report.Failed("Incorrect exception raised by Append - 1");
154
      end;
155
 
156
      begin
157
         -- Append (Str, Bnd Str);
158
         Result_String := B10.Append(B10.To_String(AtoE_Bnd_Str),
159
                                     B10.To_Bounded_String("fghijk"),
160
                                     AS.Error);
161
         Report.Failed("Length_Error not raised by Append - 2");
162
      exception
163
         when AS.Length_Error => null;   -- OK, correct exception raised.
164
         when others          =>
165
            Report.Failed("Incorrect exception raised by Append - 2");
166
      end;
167
 
168
      begin
169
         -- Append (Bnd Str, Char);
170
         Result_String :=
171
           B10.Append(B10.To_Bounded_String("abcdefghij"), 'k');
172
         Report.Failed("Length_Error not raised by Append - 3");
173
      exception
174
         when AS.Length_Error => null;   -- OK, correct exception raised.
175
         when others          =>
176
            Report.Failed("Incorrect exception raised by Append - 3");
177
      end;
178
 
179
      -- Drop = Left
180
 
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
184
                                  Ada.Strings.Left);
185
 
186
      if Result_String /= B10.To_Bounded_String("efghijklmn") then -- 10 chars
187
         Report.Failed("Incorrect truncation performed by Append - 4");
188
      end if;
189
 
190
      -- Append (Bnd Str, Str)
191
      Result_String :=
192
        B10.Append(B10.To_Bounded_String("abcdefghij"),
193
                   "xyz",
194
                   Ada.Strings.Left);
195
 
196
      if Result_String /= B10.To_Bounded_String("defghijxyz") then
197
         Report.Failed("Incorrect truncation performed by Append - 5");
198
      end if;
199
 
200
      -- Append (Char, Bnd Str)
201
 
202
      Result_String := B10.Append('A',
203
                                  B10.To_Bounded_String("abcdefghij"),
204
                                  Ada.Strings.Left);
205
 
206
      if Result_String /= B10.To_Bounded_String("abcdefghij") then
207
         Report.Failed("Incorrect truncation performed by Append - 6");
208
      end if;
209
 
210
      -- Drop = Right
211
 
212
      -- Append (Bnd Str, Bnd Str)
213
      Result_String := B10.Append(FtoJ_Bnd_Str,
214
                                  AtoJ_Bnd_Str,
215
                                  Ada.Strings.Right);
216
 
217
      if Result_String /= B10.To_Bounded_String("fghijabcde") then
218
         Report.Failed("Incorrect truncation performed by Append - 7");
219
      end if;
220
 
221
      -- Append (Str, Bnd Str)
222
      Result_String := B10.Append(B10.To_String(AtoE_Bnd_Str),
223
                                  AtoJ_Bnd_Str,
224
                                  Ada.Strings.Right);
225
 
226
      if Result_String /= B10.To_Bounded_String("abcdeabcde") then
227
         Report.Failed("Incorrect truncation performed by Append - 8");
228
      end if;
229
 
230
      -- Append (Char, Bnd Str)
231
      Result_String := B10.Append('A', AtoJ_Bnd_Str, Ada.Strings.Right);
232
 
233
      if Result_String /= B10.To_Bounded_String("Aabcdefghi") then
234
         Report.Failed("Incorrect truncation performed by Append - 9");
235
      end if;
236
 
237
 
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.
242
 
243
      Location := B10.Index(Source  => AtoJ_Bnd_Str,   -- "abcdefghij"
244
                            Pattern => "xy",
245
                            Going   => Ada.Strings.Forward,
246
                            Mapping => CD_to_XY_Map);  -- change "cd" to "xy"
247
 
248
      if Location /= 3 then
249
         Report.Failed("Incorrect result from Index, non-Identity map - 1");
250
      end if;
251
 
252
      Location := B10.Index(B10.To_Bounded_String("AND IF MAN"),
253
                            "an",
254
                            Ada.Strings.Backward,
255
                            ASC.Lower_Case_Map);
256
 
257
      if Location /= 9 then
258
         Report.Failed("Incorrect result from Index, non-Identity map - 2");
259
      end if;
260
 
261
      Location := B10.Index(Source  => B10.To_Bounded_String("The the"),
262
                            Pattern => "the",
263
                            Going   => Ada.Strings.Forward,
264
                            Mapping => ASC.Lower_Case_Map);
265
 
266
      if Location /= 1 then
267
         Report.Failed("Incorrect result from Index, non-Identity map - 3");
268
      end if;
269
 
270
 
271
      if B10.Index(B10.To_Bounded_String("abcd"),        -- Pattern = Source
272
                   "abcd")                       /= 1 or
273
         B10.Index(B10.To_Bounded_String("abc"),         -- Pattern < Source
274
                   "abcd")                       /= 0 or
275
         B10.Index(B10.Null_Bounded_String,              -- Source = Null
276
                   "abc")                        /= 0
277
      then
278
         Report.Failed("Incorrect result from Index with string patterns");
279
      end if;
280
 
281
 
282
      -- Function Index (for Sets).
283
      -- This version of Index uses Sets as the basis of the search.
284
 
285
      -- Test = Inside, Going = Forward  (Default case).
286
      Location :=
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);
291
 
292
      if not (Location = 3) then     -- position of first 'c' in source.
293
         Report.Failed("Incorrect result from Index using Sets - 1");
294
      end if;
295
 
296
      -- Test = Inside, Going = Backward.
297
      Location :=
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);
302
 
303
      if not (Location = 9) then   -- position of last 'd' in source.
304
         Report.Failed("Incorrect result from Index using Sets - 2");
305
      end if;
306
 
307
      -- Test = Outside, Going = Forward.
308
      Location := B10.Index(B10.To_Bounded_String("deddacd"),
309
                            CD_Set,
310
                            Test  => Ada.Strings.Outside,
311
                            Going => Ada.Strings.Forward);
312
 
313
      if Location /= 2  then  -- position of 'e' in source.
314
         Report.Failed("Incorrect result from Index using Sets - 3");
315
      end if;
316
 
317
      -- Test = Outside, Going = Backward.
318
      Location := B10.Index(B10.To_Bounded_String("deddacd"),
319
                            CD_Set,
320
                            Ada.Strings.Outside,
321
                            Ada.Strings.Backward);
322
 
323
      if Location /= 5 then                      -- correct position of 'a'.
324
         Report.Failed("Incorrect result from Index using Sets - 4");
325
      end if;
326
 
327
      if B10.Index(B10.To_Bounded_String("cd"),        -- Source = Set
328
                   CD_Set)                     /= 1 or
329
         B10.Index(B10.To_Bounded_String("c"),         -- Source < Set
330
                   CD_Set)                     /= 1 or
331
         B10.Index(B10.Null_Bounded_String,            -- Source = Null
332
                   CD_Set)                     /= 0 or
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.
337
      then
338
         Report.Failed("Incorrect result from Index using Sets - 5");
339
      end if;
340
 
341
 
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.
346
 
347
      Total_Count :=
348
        B10.Count(Source  => B10.To_Bounded_String("abbabaabab"),
349
                  Pattern => "yz",
350
                  Mapping => AB_to_YZ_Map);
351
 
352
      if Total_Count /= 4 then
353
         Report.Failed
354
           ("Incorrect result from function Count, non-Identity map - 1");
355
      end if;
356
 
357
      -- And a few with identity maps as well.
358
 
359
      if B10.Count(B10.To_Bounded_String("ABABABABAB"),
360
                   "ABA",
361
                   Maps.Identity)                       /= 2 or
362
         B10.Count(B10.To_Bounded_String("ADCBADABCD"),
363
                   "AB",
364
                   Maps.To_Mapping("CD", "AB"))         /= 5 or
365
         B10.Count(B10.To_Bounded_String("aaaaaaaaaa"),
366
                   "aaa")                               /= 3 or
367
         B10.Count(B10.To_Bounded_String("XX"),         -- Source < Pattern
368
                   "XXX",
369
                   Maps.Identity)                       /= 0 or
370
         B10.Count(AtoE_Bnd_Str,                        -- Source = Pattern
371
                   "abcde")                             /= 1 or
372
         B10.Count(B10.Null_Bounded_String,             -- Source = Null
373
                   " ")                                 /= 0
374
      then
375
         Report.Failed
376
           ("Incorrect result from function Count, w,w/o mapping");
377
      end if;
378
 
379
 
380
      -- Procedure Translate
381
 
382
      -- Partial mapping of source.
383
 
384
      Test_String := B10.To_Bounded_String("abcdeabcab");
385
 
386
      B10.Translate(Source => Test_String, Mapping => AB_to_YZ_Map);
387
 
388
      if Test_String /= B10.To_Bounded_String("yzcdeyzcyz") then
389
         Report.Failed("Incorrect result from procedure Translate - 1");
390
      end if;
391
 
392
      -- Total mapping of source.
393
 
394
      Test_String := B10.To_Bounded_String("abbaaababb");
395
 
396
      B10.Translate(Source => Test_String, Mapping => ASC.Upper_Case_Map);
397
 
398
      if Test_String /= B10.To_Bounded_String("ABBAAABABB") then
399
         Report.Failed("Incorrect result from procedure Translate - 2");
400
      end if;
401
 
402
      -- No mapping of source.
403
 
404
      Test_String := B10.To_Bounded_String("xyzsypcc");
405
 
406
      B10.Translate(Source => Test_String, Mapping => AB_to_YZ_Map);
407
 
408
      if Test_String /= B10.To_Bounded_String("xyzsypcc") then
409
         Report.Failed("Incorrect result from procedure Translate - 3");
410
      end if;
411
 
412
      -- Map > 2 characters, partial mapping.
413
 
414
      Test_String := B10.To_Bounded_String("have faith");
415
 
416
      B10.Translate(Test_String,
417
                    Maps.To_Mapping("aeiou", "AEIOU"));
418
 
419
      if Test_String /= B10.To_Bounded_String("hAvE fAIth") then
420
         Report.Failed("Incorrect result from procedure Translate - 4");
421
      end if;
422
 
423
 
424
      -- Function Replace_Slice
425
      -- Evaluate function Replace_Slice with
426
      -- a variety of Truncation options.
427
 
428
      -- Drop = Error (Default)
429
 
430
      begin
431
         Test_String   := AtoJ_Bnd_Str;
432
         Result_String :=
433
           B10.Replace_Slice(Source => Test_String,  -- "abcdefghij"
434
                             Low    => 3,
435
                             High   => 5,            -- 3-5, 3 chars.
436
                             By     => "xxxxxx");    -- more than 3.
437
         Report.Failed("Length_Error not raised by Function Replace_Slice");
438
      exception
439
         when AS.Length_Error => null;   -- Correct exception raised.
440
         when others          =>
441
            Report.Failed
442
              ("Incorrect exception raised by Function Replace_Slice");
443
      end;
444
 
445
      -- Drop = Left
446
 
447
      Result_String :=
448
        B10.Replace_Slice(Source => Test_String,  -- "abcdefghij"
449
                          Low    =>  7,
450
                          High   => 10,           -- 7-10, 4 chars.
451
                          By     => "xxxxxx",     --  6 chars.
452
                          Drop   => Ada.Strings.Left);
453
 
454
      if Result_String /= B10.To_Bounded_String("cdefxxxxxx") then -- drop a,b
455
         Report.Failed
456
           ("Incorrect result from Function Replace Slice, Drop = Left");
457
      end if;
458
 
459
      -- Drop = Right
460
 
461
      Result_String :=
462
        B10.Replace_Slice(Source => Test_String, -- "abcdefghij"
463
                          Low    =>  2,
464
                          High   =>  5,          -- 2-5, 4 chars.
465
                          By     => "xxxxxx",    --  6 chars.
466
                          Drop   => Ada.Strings.Right);
467
 
468
      if Result_String /= B10.To_Bounded_String("axxxxxxfgh") then -- drop i,j
469
         Report.Failed
470
           ("Incorrect result from Function Replace Slice, Drop = Right");
471
      end if;
472
 
473
      -- Low = High = Source'Last, "By" length = 1.
474
 
475
      if B10.Replace_Slice(AtoE_Bnd_Str,
476
                           B10.To_String(AtoE_Bnd_Str)'Last,
477
                           B10.To_String(AtoE_Bnd_Str)'Last,
478
                           "X",
479
                           Ada.Strings.Error)  /=
480
         B10.To_Bounded_String("abcdX")
481
      then
482
         Report.Failed("Incorrect result from Function Replace_Slice");
483
      end if;
484
 
485
 
486
 
487
      -- Procedure Replace_Slice
488
      -- Evaluate procedure Replace_Slice with
489
      -- a variety of Truncation options.
490
 
491
      -- Drop = Error (Default)
492
 
493
      begin
494
         Test_String := AtoJ_Bnd_Str;
495
         B10.Replace_Slice(Source => Test_String,  -- "abcdefghij"
496
                           Low    => 3,
497
                           High   => 5,            -- 3-5, 3 chars.
498
                           By     => "xxxxxx");    -- more than 3.
499
         Report.Failed("Length_Error not raised by Procedure Replace_Slice");
500
      exception
501
         when AS.Length_Error => null;   -- Correct exception raised.
502
         when others          =>
503
            Report.Failed
504
              ("Incorrect exception raised by Procedure Replace_Slice");
505
      end;
506
 
507
      -- Drop = Left
508
 
509
      Test_String := AtoJ_Bnd_Str;
510
      B10.Replace_Slice(Source => Test_String,  -- "abcdefghij"
511
                        Low    =>  7,
512
                        High   =>  9,           -- 7-9, 3 chars.
513
                        By     => "xxxxx",      --  5 chars.
514
                        Drop   => Ada.Strings.Left);
515
 
516
      if Test_String /= B10.To_Bounded_String("cdefxxxxxj") then -- drop a,b
517
         Report.Failed
518
           ("Incorrect result from Procedure Replace Slice, Drop = Left");
519
      end if;
520
 
521
      -- Drop = Right
522
 
523
      Test_String := AtoJ_Bnd_Str;
524
      B10.Replace_Slice(Source => Test_String,  -- "abcdefghij"
525
                        Low    =>  1,
526
                        High   =>  3,           -- 1-3, 3chars.
527
                        By     => "xxxx",       --  4 chars.
528
                        Drop   => Ada.Strings.Right);
529
 
530
      if Test_String /= B10.To_Bounded_String("xxxxdefghi") then  -- drop j
531
         Report.Failed
532
           ("Incorrect result from Procedure Replace Slice, Drop = Right");
533
      end if;
534
 
535
      -- High = Source'First, Low > High (Insert before Low).
536
 
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);
543
 
544
      if Test_String /= B10.To_Bounded_String("abcdXXXXe") then
545
         Report.Failed
546
           ("Incorrect result from Procedure Replace Slice");
547
      end if;
548
 
549
 
550
 
551
      -- Function Insert with Truncation
552
      -- Drop = Error (Default).
553
 
554
      begin
555
         Result_String :=
556
           B10.Insert(Source   => AtoJ_Bnd_Str,    -- "abcdefghij"
557
                      Before   => 2,
558
                      New_Item => "xyz");
559
         Report.Failed("Length_Error not raised by Function Insert");
560
      exception
561
         when AS.Length_Error => null;  -- Correct exception raised.
562
         when others          =>
563
            Report.Failed("Incorrect exception raised by Function Insert");
564
      end;
565
 
566
      -- Drop = Left
567
 
568
      Result_String :=
569
        B10.Insert(Source   => AtoJ_Bnd_Str,      -- "abcdefghij"
570
                   Before   => 5,
571
                   New_Item => "xyz",             -- 3 additional chars.
572
                   Drop     => Ada.Strings.Left);
573
 
574
      if B10.To_String(Result_String) /= "dxyzefghij" then   -- drop a, b, c
575
         Report.Failed("Incorrect result from Function Insert, Drop = Left");
576
      end if;
577
 
578
      -- Drop = Right
579
 
580
      Result_String :=
581
        B10.Insert(Source   => B10.To_Bounded_String("abcdef"),
582
                   Before   => 2,
583
                   New_Item => "vwxyz",             -- 5 additional chars.
584
                   Drop     => Ada.Strings.Right);
585
 
586
      if B10.To_String(Result_String) /= "avwxyzbcde" then     -- drop f.
587
         Report.Failed("Incorrect result from Function Insert, Drop = Right");
588
      end if;
589
 
590
      -- Additional cases.
591
 
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") /=
595
         AtoE_Bnd_Str                                       or
596
         B10.Insert(B10.To_Bounded_String("ab"), 2, "")  /=
597
         B10.To_Bounded_String("ab")
598
      then
599
         Report.Failed("Incorrect result from Function Insert");
600
      end if;
601
 
602
 
603
      -- Procedure Insert
604
 
605
      -- Drop = Error (Default).
606
      begin
607
         Test_String := AtoJ_Bnd_Str;
608
         B10.Insert(Source   => Test_String,    -- "abcdefghij"
609
                    Before   => 9,
610
                    New_Item => "wxyz",
611
                    Drop     => Ada.Strings.Error);
612
         Report.Failed("Length_Error not raised by Procedure Insert");
613
      exception
614
         when AS.Length_Error => null;  -- Correct exception raised.
615
         when others          =>
616
            Report.Failed("Incorrect exception raised by Procedure Insert");
617
      end;
618
 
619
      -- Drop = Left
620
 
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);
626
 
627
      if B10.To_String(Test_String) /= "defghixyzj" then     -- drop a, b, c
628
         Report.Failed("Incorrect result from Procedure Insert, Drop = Left");
629
      end if;
630
 
631
      -- Drop = Right
632
 
633
      Test_String := AtoJ_Bnd_Str;
634
      B10.Insert(Source   => Test_String,
635
                 Before   => 4,
636
                 New_Item => "yz",             -- 2 additional chars.
637
                 Drop     => Ada.Strings.Right);
638
 
639
      if B10.To_String(Test_String) /= "abcyzdefgh" then     -- drop i,j
640
         Report.Failed
641
           ("Incorrect result from Procedure Insert, Drop = Right");
642
      end if;
643
 
644
      -- Before = Source'First, New_Item length = 1.
645
 
646
      Test_String := B10.To_Bounded_String(" abc ");
647
      B10.Insert(Test_String,
648
                 B10.To_String(Test_String)'First,
649
                 "Z");
650
 
651
      if Test_String /= B10.To_Bounded_String("Z abc ") then
652
         Report.Failed("Incorrect result from Procedure Insert");
653
      end if;
654
 
655
 
656
   exception
657
      when others => Report.Failed("Exception raised in  Test_Block");
658
   end Test_Block;
659
 
660
   Report.Result;
661
 
662
end CXA4008;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.