Debian Codegraph @

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

raw
1 -- CXA4032.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 procedures defined in package Ada.Strings.Unbounded
28 -- are available, and that they produce correct results. Specifically,
29 -- check the procedures Replace_Slice, Insert, Overwrite, Delete,
30 -- Trim (2 versions), Head, and Tail.
31 --
32 -- TEST DESCRIPTION:
33 -- This test demonstrates the uses of many of the procedures defined
34 -- in package Ada.Strings.Unbounded for use with unbounded strings.
35 -- The test simulates how unbounded strings could be processed in a
36 -- user environment, using the procedures provided in this package.
37 --
38 -- This test, when taken in conjunction with tests CXA4010, CXA4011,
39 -- CXA4030, and CXA4031 will constitute a test of all the functionality
40 -- contained in package Ada.Strings.Unbounded. This test uses a variety
41 -- of the procedures defined in the unbounded string package in ways
42 -- typical of common usage.
43 --
44 --
45 -- CHANGE HISTORY:
46 -- 02 Mar 95 SAIC Initial prerelease version.
47 --
48 --!
49
50 with Report;
51 with Ada.Strings;
52 with Ada.Strings.Maps;
53 with Ada.Strings.Maps.Constants;
54 with Ada.Strings.Unbounded;
55
56 procedure CXA4032 is
57 begin
58
59 Report.Test ("CXA4032", "Check that the subprograms defined in " &
60 "package Ada.Strings.Unbounded are available, " &
61 "and that they produce correct results");
62
63 Test_Block:
64 declare
65
66 package Unb renames Ada.Strings.Unbounded;
67 use Unb;
68 use Ada.Strings;
69
70 TC_Null_String : constant String := "";
71 TC_String_5 : String(1..5) := "ABCDE";
72
73 TC_Unb_String : Unb.Unbounded_String :=
74 Unb.To_Unbounded_String("Test String");
75
76 begin
77
78 -- Procedure Replace_Slice
79
80 begin -- Low > Source'Last+1
81 Unb.Replace_Slice(Source => TC_Unb_String,
82 Low => Unb.Length(TC_Unb_String) + 2,
83 High => Unb.Length(TC_Unb_String),
84 By => TC_String_5);
85 Report.Failed("Index_Error not raised by Replace_Slice when Low " &
86 "> Source'Last+1");
87 exception
88 when Index_Error => null; -- OK, expected exception.
89 when others =>
90 Report.Failed("Unexpected exception raised by Replace_Slice" &
91 "when Low > Source'Last+1");
92 end;
93
94 -- High >= Low
95
96 TC_Unb_String := Unb.To_Unbounded_String("Test String");
97
98 Unb.Replace_Slice(TC_Unb_String, 5, 5, TC_String_5);
99
100 if TC_Unb_String /= Unb.To_Unbounded_String("TestABCDEString") then
101 Report.Failed("Incorrect results from Replace_Slice - 1");
102 end if;
103
104 Unb.Replace_Slice(TC_Unb_String, 1, 4, TC_String_5);
105
106 if TC_Unb_String /= Unb.To_Unbounded_String("ABCDEABCDEString") then
107 Report.Failed("Incorrect results from Replace_Slice - 2");
108 end if;
109
110 Unb.Replace_Slice(TC_Unb_String,
111 11,
112 Unb.Length(TC_Unb_String),
113 TC_Null_String);
114
115 if TC_Unb_String /= Unb.To_Unbounded_String("ABCDEABCDE") then
116 Report.Failed("Incorrect results from Replace_Slice - 3");
117 end if;
118
119 -- High < Low
120
121 Unb.Replace_Slice(TC_Unb_String, Low => 4, High => 1, By => "xxx");
122
123 if TC_Unb_String /= Unb.To_Unbounded_String("ABCxxxDEABCDE") then
124 Report.Failed("Incorrect results from Replace_Slice - 4");
125 end if;
126
127 Unb.Replace_Slice(TC_Unb_String, Low => 1, High => 0, By => "yyy");
128
129 if TC_Unb_String /= Unb.To_Unbounded_String("yyyABCxxxDEABCDE") then
130 Report.Failed("Incorrect results from Replace_Slice - 5");
131 end if;
132
133 Unb.Replace_Slice(TC_Unb_String,
134 Unb.Length(TC_Unb_String) + 1,
135 Unb.Length(TC_Unb_String),
136 By => "zzz");
137
138 if TC_Unb_String /= Unb.To_Unbounded_String("yyyABCxxxDEABCDEzzz") then
139 Report.Failed("Incorrect results from Replace_Slice - 6");
140 end if;
141
142
143 -- Procedure Insert
144
145 TC_Unb_String := Unb.To_Unbounded_String("Test String");
146
147 begin -- Before not in Source'First..Source'Last + 1
148 Unb.Insert(Source => TC_Unb_String,
149 Before => Unb.Length(TC_Unb_String) + 2,
150 New_Item => TC_String_5);
151 Report.Failed("Index_Error not raised by Insert when Before " &
152 "not in the range Source'First..Source'Last+1");
153 exception
154 when Index_Error => null; -- OK, expected exception.
155 when others =>
156 Report.Failed
157 ("Unexpected exception raised by Insert when Before not in " &
158 "the range Source'First..Source'Last+1");
159 end;
160
161 Unb.Insert(TC_Unb_String, 1, "**");
162
163 if TC_Unb_String /= Unb.To_Unbounded_String("**Test String") then
164 Report.Failed("Incorrect results from Insert - 1");
165 end if;
166
167 Unb.Insert(TC_Unb_String, Unb.Length(TC_Unb_String)+1, "**");
168
169 if TC_Unb_String /= Unb.To_Unbounded_String("**Test String**") then
170 Report.Failed("Incorrect results from Insert - 2");
171 end if;
172
173 Unb.Insert(TC_Unb_String, 8, "---");
174
175 if TC_Unb_String /= Unb.To_Unbounded_String("**Test ---String**") then
176 Report.Failed("Incorrect results from Insert - 3");
177 end if;
178
179 Unb.Insert(TC_Unb_String, 3, TC_Null_String);
180
181 if TC_Unb_String /= Unb.To_Unbounded_String("**Test ---String**") then
182 Report.Failed("Incorrect results from Insert - 4");
183 end if;
184
185
186 -- Procedure Overwrite
187
188 begin -- Position not in Source'First..Source'Last + 1
189 Unb.Overwrite(Source => TC_Unb_String,
190 Position => Unb.Length(TC_Unb_String) + 2,
191 New_Item => TC_String_5);
192 Report.Failed("Index_Error not raised by Overwrite when Position " &
193 "not in the range Source'First..Source'Last+1");
194 exception
195 when Index_Error => null; -- OK, expected exception.
196 when others =>
197 Report.Failed
198 ("Unexpected exception raised by Overwrite when Position not " &
199 "in the range Source'First..Source'Last+1");
200 end;
201
202 TC_Unb_String := Unb.To_Unbounded_String("Test String");
203
204 Unb.Overwrite(Source => TC_Unb_String,
205 Position => 1,
206 New_Item => "XXXX");
207
208 if TC_Unb_String /= Unb.To_Unbounded_String("XXXX String") then
209 Report.Failed("Incorrect results from Overwrite - 1");
210 end if;
211
212 Unb.Overwrite(TC_Unb_String, Unb.Length(TC_Unb_String)+1, "**");
213
214 if TC_Unb_String /= Unb.To_Unbounded_String("XXXX String**") then
215 Report.Failed("Incorrect results from Overwrite - 2");
216 end if;
217
218 Unb.Overwrite(TC_Unb_String, 3, TC_Null_String);
219
220 if TC_Unb_String /= Unb.To_Unbounded_String("XXXX String**") then
221 Report.Failed("Incorrect results from Overwrite - 3");
222 end if;
223
224 Unb.Overwrite(TC_Unb_String, 1, "abcdefghijklmn");
225
226 if TC_Unb_String /= Unb.To_Unbounded_String("abcdefghijklmn") then
227 Report.Failed("Incorrect results from Overwrite - 4");
228 end if;
229
230
231 -- Procedure Delete
232
233 TC_Unb_String := Unb.To_Unbounded_String("Test String");
234
235 -- From > Through (No change to Source)
236
237 Unb.Delete(Source => TC_Unb_String,
238 From => Unb.Length(TC_Unb_String),
239 Through => Unb.Length(TC_Unb_String)-1);
240
241 if TC_Unb_String /= Unb.To_Unbounded_String("Test String") then
242 Report.Failed("Incorrect results from Delete - 1");
243 end if;
244
245 Unb.Delete(TC_Unb_String, 1, 0);
246
247 if TC_Unb_String /= Unb.To_Unbounded_String("Test String") then
248 Report.Failed("Incorrect results from Delete - 2");
249 end if;
250
251 -- From <= Through
252
253 Unb.Delete(TC_Unb_String, 1, 5);
254
255 if TC_Unb_String /= Unb.To_Unbounded_String("String") then
256 Report.Failed("Incorrect results from Delete - 3");
257 end if;
258
259 Unb.Delete(TC_Unb_String, 3, 3);
260
261 if TC_Unb_String /= Unb.To_Unbounded_String("Sting") then
262 Report.Failed("Incorrect results from Delete - 4");
263 end if;
264
265
266 -- Procedure Trim
267
268 TC_Unb_String := Unb.To_Unbounded_String("No Spaces");
269
270 Unb.Trim(Source => TC_Unb_String, Side => Ada.Strings.Both);
271
272 if TC_Unb_String /= Unb.To_Unbounded_String("No Spaces") then
273 Report.Failed("Incorrect results from Trim - 1");
274 end if;
275
276 TC_Unb_String := Unb.To_Unbounded_String(" Leading Spaces ");
277
278 Unb.Trim(TC_Unb_String, Ada.Strings.Left);
279
280 if TC_Unb_String /= Unb.To_Unbounded_String("Leading Spaces ") then
281 Report.Failed("Incorrect results from Trim - 2");
282 end if;
283
284 TC_Unb_String := Unb.To_Unbounded_String(" Ending Spaces ");
285
286 Unb.Trim(TC_Unb_String, Ada.Strings.Right);
287
288 if TC_Unb_String /= Unb.To_Unbounded_String(" Ending Spaces") then
289 Report.Failed("Incorrect results from Trim - 3");
290 end if;
291
292 TC_Unb_String :=
293 Unb.To_Unbounded_String(" Spaces on both ends ");
294
295 Unb.Trim(TC_Unb_String, Ada.Strings.Both);
296
297 if TC_Unb_String /=
298 Unb.To_Unbounded_String("Spaces on both ends")
299 then
300 Report.Failed("Incorrect results from Trim - 4");
301 end if;
302
303
304 -- Procedure Trim (with Character Set parameters)
305
306 TC_Unb_String := Unb.To_Unbounded_String("lowerCASEletters");
307
308 Unb.Trim(Source => TC_Unb_String,
309 Left => Ada.Strings.Maps.Constants.Lower_Set,
310 Right => Ada.Strings.Maps.Constants.Lower_Set);
311
312 if TC_Unb_String /= Unb.To_Unbounded_String("CASE") then
313 Report.Failed("Incorrect results from Trim with Sets - 1");
314 end if;
315
316 TC_Unb_String := Unb.To_Unbounded_String("lowerCASEletters");
317
318 Unb.Trim(TC_Unb_String,
319 Ada.Strings.Maps.Constants.Upper_Set,
320 Ada.Strings.Maps.Constants.Upper_Set);
321
322 if TC_Unb_String /= Unb.To_Unbounded_String("lowerCASEletters") then
323 Report.Failed("Incorrect results from Trim with Sets - 2");
324 end if;
325
326 TC_Unb_String := Unb.To_Unbounded_String("012abcdefghGFEDCBA789ab");
327
328 Unb.Trim(TC_Unb_String,
329 Ada.Strings.Maps.Constants.Hexadecimal_Digit_Set,
330 Ada.Strings.Maps.Constants.Hexadecimal_Digit_Set);
331
332 if TC_Unb_String /= Unb.To_Unbounded_String("ghG") then
333 Report.Failed("Incorrect results from Trim with Sets - 3");
334 end if;
335
336
337 -- Procedure Head
338
339 -- Count <= Source'Length
340
341 TC_Unb_String := Unb.To_Unbounded_String("Test String");
342
343 Unb.Head(Source => TC_Unb_String,
344 Count => 0,
345 Pad => '*');
346
347 if TC_Unb_String /= Unb.Null_Unbounded_String then
348 Report.Failed("Incorrect results from Head - 1");
349 end if;
350
351 TC_Unb_String := Unb.To_Unbounded_String("Test String");
352
353 Unb.Head(Source => TC_Unb_String,
354 Count => 4,
355 Pad => '*');
356
357 if TC_Unb_String /= Unb.To_Unbounded_String("Test") then
358 Report.Failed("Incorrect results from Head - 2");
359 end if;
360
361 TC_Unb_String := Unb.To_Unbounded_String("Test String");
362
363 Unb.Head(Source => TC_Unb_String,
364 Count => Unb.Length(TC_Unb_String),
365 Pad => '*');
366
367 if TC_Unb_String /= Unb.To_Unbounded_String("Test String") then
368 Report.Failed("Incorrect results from Head - 3");
369 end if;
370
371 -- Count > Source'Length
372
373 TC_Unb_String := Unb.To_Unbounded_String("Test String");
374
375 Unb.Head(Source => TC_Unb_String,
376 Count => Unb.Length(TC_Unb_String) + 4,
377 Pad => '*');
378
379 if TC_Unb_String /= Unb.To_Unbounded_String("Test String****") then
380 Report.Failed("Incorrect results from Head - 4");
381 end if;
382
383 TC_Unb_String := Unb.Null_Unbounded_String;
384
385 Unb.Head(Source => TC_Unb_String,
386 Count => Unb.Length(TC_Unb_String) + 3,
387 Pad => '*');
388
389 if TC_Unb_String /= Unb.To_Unbounded_String("***") then
390 Report.Failed("Incorrect results from Head - 5");
391 end if;
392
393
394 -- Procedure Tail
395
396 -- Count <= Source'Length
397
398 TC_Unb_String := Unb.To_Unbounded_String("Test String");
399
400 Unb.Tail(Source => TC_Unb_String,
401 Count => 0,
402 Pad => '*');
403
404 if TC_Unb_String /= Unb.Null_Unbounded_String then
405 Report.Failed("Incorrect results from Tail - 1");
406 end if;
407
408 TC_Unb_String := Unb.To_Unbounded_String("Test String");
409
410 Unb.Tail(Source => TC_Unb_String,
411 Count => 6,
412 Pad => '*');
413
414 if TC_Unb_String /= Unb.To_Unbounded_String("String") then
415 Report.Failed("Incorrect results from Tail - 2");
416 end if;
417
418 TC_Unb_String := Unb.To_Unbounded_String("Test String");
419
420 Unb.Tail(Source => TC_Unb_String,
421 Count => Unb.Length(TC_Unb_String),
422 Pad => '*');
423
424 if TC_Unb_String /= Unb.To_Unbounded_String("Test String") then
425 Report.Failed("Incorrect results from Tail - 3");
426 end if;
427
428 -- Count > Source'Length
429
430 TC_Unb_String := Unb.To_Unbounded_String("Test String");
431
432 Unb.Tail(Source => TC_Unb_String,
433 Count => Unb.Length(TC_Unb_String) + 5,
434 Pad => 'x');
435
436 if TC_Unb_String /= Unb.To_Unbounded_String("xxxxxTest String") then
437 Report.Failed("Incorrect results from Tail - 4");
438 end if;
439
440 TC_Unb_String := Unb.Null_Unbounded_String;
441
442 Unb.Tail(Source => TC_Unb_String,
443 Count => Unb.Length(TC_Unb_String) + 3,
444 Pad => 'X');
445
446 if TC_Unb_String /= Unb.To_Unbounded_String("XXX") then
447 Report.Failed("Incorrect results from Tail - 5");
448 end if;
449
450
451 exception
452 when others => Report.Failed ("Exception raised in Test_Block");
453 end Test_Block;
454
455 Report.Result;
456
457 end CXA4032;