2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / ada / acats / tests / cxa / cxa4032.a
blob031d01c6cb79be32a4b418a0842c9a6345241564
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.
16 -- DISCLAIMER
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 --*
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.
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.
48 --!
50 with Report;
51 with Ada.Strings;
52 with Ada.Strings.Maps;
53 with Ada.Strings.Maps.Constants;
54 with Ada.Strings.Unbounded;
56 procedure CXA4032 is
57 begin
59 Report.Test ("CXA4032", "Check that the subprograms defined in " &
60 "package Ada.Strings.Unbounded are available, " &
61 "and that they produce correct results");
63 Test_Block:
64 declare
66 package Unb renames Ada.Strings.Unbounded;
67 use Unb;
68 use Ada.Strings;
70 TC_Null_String : constant String := "";
71 TC_String_5 : String(1..5) := "ABCDE";
73 TC_Unb_String : Unb.Unbounded_String :=
74 Unb.To_Unbounded_String("Test String");
76 begin
78 -- Procedure Replace_Slice
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;
94 -- High >= Low
96 TC_Unb_String := Unb.To_Unbounded_String("Test String");
98 Unb.Replace_Slice(TC_Unb_String, 5, 5, TC_String_5);
100 if TC_Unb_String /= Unb.To_Unbounded_String("TestABCDEString") then
101 Report.Failed("Incorrect results from Replace_Slice - 1");
102 end if;
104 Unb.Replace_Slice(TC_Unb_String, 1, 4, TC_String_5);
106 if TC_Unb_String /= Unb.To_Unbounded_String("ABCDEABCDEString") then
107 Report.Failed("Incorrect results from Replace_Slice - 2");
108 end if;
110 Unb.Replace_Slice(TC_Unb_String,
111 11,
112 Unb.Length(TC_Unb_String),
113 TC_Null_String);
115 if TC_Unb_String /= Unb.To_Unbounded_String("ABCDEABCDE") then
116 Report.Failed("Incorrect results from Replace_Slice - 3");
117 end if;
119 -- High < Low
121 Unb.Replace_Slice(TC_Unb_String, Low => 4, High => 1, By => "xxx");
123 if TC_Unb_String /= Unb.To_Unbounded_String("ABCxxxDEABCDE") then
124 Report.Failed("Incorrect results from Replace_Slice - 4");
125 end if;
127 Unb.Replace_Slice(TC_Unb_String, Low => 1, High => 0, By => "yyy");
129 if TC_Unb_String /= Unb.To_Unbounded_String("yyyABCxxxDEABCDE") then
130 Report.Failed("Incorrect results from Replace_Slice - 5");
131 end if;
133 Unb.Replace_Slice(TC_Unb_String,
134 Unb.Length(TC_Unb_String) + 1,
135 Unb.Length(TC_Unb_String),
136 By => "zzz");
138 if TC_Unb_String /= Unb.To_Unbounded_String("yyyABCxxxDEABCDEzzz") then
139 Report.Failed("Incorrect results from Replace_Slice - 6");
140 end if;
143 -- Procedure Insert
145 TC_Unb_String := Unb.To_Unbounded_String("Test String");
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;
161 Unb.Insert(TC_Unb_String, 1, "**");
163 if TC_Unb_String /= Unb.To_Unbounded_String("**Test String") then
164 Report.Failed("Incorrect results from Insert - 1");
165 end if;
167 Unb.Insert(TC_Unb_String, Unb.Length(TC_Unb_String)+1, "**");
169 if TC_Unb_String /= Unb.To_Unbounded_String("**Test String**") then
170 Report.Failed("Incorrect results from Insert - 2");
171 end if;
173 Unb.Insert(TC_Unb_String, 8, "---");
175 if TC_Unb_String /= Unb.To_Unbounded_String("**Test ---String**") then
176 Report.Failed("Incorrect results from Insert - 3");
177 end if;
179 Unb.Insert(TC_Unb_String, 3, TC_Null_String);
181 if TC_Unb_String /= Unb.To_Unbounded_String("**Test ---String**") then
182 Report.Failed("Incorrect results from Insert - 4");
183 end if;
186 -- Procedure Overwrite
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;
202 TC_Unb_String := Unb.To_Unbounded_String("Test String");
204 Unb.Overwrite(Source => TC_Unb_String,
205 Position => 1,
206 New_Item => "XXXX");
208 if TC_Unb_String /= Unb.To_Unbounded_String("XXXX String") then
209 Report.Failed("Incorrect results from Overwrite - 1");
210 end if;
212 Unb.Overwrite(TC_Unb_String, Unb.Length(TC_Unb_String)+1, "**");
214 if TC_Unb_String /= Unb.To_Unbounded_String("XXXX String**") then
215 Report.Failed("Incorrect results from Overwrite - 2");
216 end if;
218 Unb.Overwrite(TC_Unb_String, 3, TC_Null_String);
220 if TC_Unb_String /= Unb.To_Unbounded_String("XXXX String**") then
221 Report.Failed("Incorrect results from Overwrite - 3");
222 end if;
224 Unb.Overwrite(TC_Unb_String, 1, "abcdefghijklmn");
226 if TC_Unb_String /= Unb.To_Unbounded_String("abcdefghijklmn") then
227 Report.Failed("Incorrect results from Overwrite - 4");
228 end if;
231 -- Procedure Delete
233 TC_Unb_String := Unb.To_Unbounded_String("Test String");
235 -- From > Through (No change to Source)
237 Unb.Delete(Source => TC_Unb_String,
238 From => Unb.Length(TC_Unb_String),
239 Through => Unb.Length(TC_Unb_String)-1);
241 if TC_Unb_String /= Unb.To_Unbounded_String("Test String") then
242 Report.Failed("Incorrect results from Delete - 1");
243 end if;
245 Unb.Delete(TC_Unb_String, 1, 0);
247 if TC_Unb_String /= Unb.To_Unbounded_String("Test String") then
248 Report.Failed("Incorrect results from Delete - 2");
249 end if;
251 -- From <= Through
253 Unb.Delete(TC_Unb_String, 1, 5);
255 if TC_Unb_String /= Unb.To_Unbounded_String("String") then
256 Report.Failed("Incorrect results from Delete - 3");
257 end if;
259 Unb.Delete(TC_Unb_String, 3, 3);
261 if TC_Unb_String /= Unb.To_Unbounded_String("Sting") then
262 Report.Failed("Incorrect results from Delete - 4");
263 end if;
266 -- Procedure Trim
268 TC_Unb_String := Unb.To_Unbounded_String("No Spaces");
270 Unb.Trim(Source => TC_Unb_String, Side => Ada.Strings.Both);
272 if TC_Unb_String /= Unb.To_Unbounded_String("No Spaces") then
273 Report.Failed("Incorrect results from Trim - 1");
274 end if;
276 TC_Unb_String := Unb.To_Unbounded_String(" Leading Spaces ");
278 Unb.Trim(TC_Unb_String, Ada.Strings.Left);
280 if TC_Unb_String /= Unb.To_Unbounded_String("Leading Spaces ") then
281 Report.Failed("Incorrect results from Trim - 2");
282 end if;
284 TC_Unb_String := Unb.To_Unbounded_String(" Ending Spaces ");
286 Unb.Trim(TC_Unb_String, Ada.Strings.Right);
288 if TC_Unb_String /= Unb.To_Unbounded_String(" Ending Spaces") then
289 Report.Failed("Incorrect results from Trim - 3");
290 end if;
292 TC_Unb_String :=
293 Unb.To_Unbounded_String(" Spaces on both ends ");
295 Unb.Trim(TC_Unb_String, Ada.Strings.Both);
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;
304 -- Procedure Trim (with Character Set parameters)
306 TC_Unb_String := Unb.To_Unbounded_String("lowerCASEletters");
308 Unb.Trim(Source => TC_Unb_String,
309 Left => Ada.Strings.Maps.Constants.Lower_Set,
310 Right => Ada.Strings.Maps.Constants.Lower_Set);
312 if TC_Unb_String /= Unb.To_Unbounded_String("CASE") then
313 Report.Failed("Incorrect results from Trim with Sets - 1");
314 end if;
316 TC_Unb_String := Unb.To_Unbounded_String("lowerCASEletters");
318 Unb.Trim(TC_Unb_String,
319 Ada.Strings.Maps.Constants.Upper_Set,
320 Ada.Strings.Maps.Constants.Upper_Set);
322 if TC_Unb_String /= Unb.To_Unbounded_String("lowerCASEletters") then
323 Report.Failed("Incorrect results from Trim with Sets - 2");
324 end if;
326 TC_Unb_String := Unb.To_Unbounded_String("012abcdefghGFEDCBA789ab");
328 Unb.Trim(TC_Unb_String,
329 Ada.Strings.Maps.Constants.Hexadecimal_Digit_Set,
330 Ada.Strings.Maps.Constants.Hexadecimal_Digit_Set);
332 if TC_Unb_String /= Unb.To_Unbounded_String("ghG") then
333 Report.Failed("Incorrect results from Trim with Sets - 3");
334 end if;
337 -- Procedure Head
339 -- Count <= Source'Length
341 TC_Unb_String := Unb.To_Unbounded_String("Test String");
343 Unb.Head(Source => TC_Unb_String,
344 Count => 0,
345 Pad => '*');
347 if TC_Unb_String /= Unb.Null_Unbounded_String then
348 Report.Failed("Incorrect results from Head - 1");
349 end if;
351 TC_Unb_String := Unb.To_Unbounded_String("Test String");
353 Unb.Head(Source => TC_Unb_String,
354 Count => 4,
355 Pad => '*');
357 if TC_Unb_String /= Unb.To_Unbounded_String("Test") then
358 Report.Failed("Incorrect results from Head - 2");
359 end if;
361 TC_Unb_String := Unb.To_Unbounded_String("Test String");
363 Unb.Head(Source => TC_Unb_String,
364 Count => Unb.Length(TC_Unb_String),
365 Pad => '*');
367 if TC_Unb_String /= Unb.To_Unbounded_String("Test String") then
368 Report.Failed("Incorrect results from Head - 3");
369 end if;
371 -- Count > Source'Length
373 TC_Unb_String := Unb.To_Unbounded_String("Test String");
375 Unb.Head(Source => TC_Unb_String,
376 Count => Unb.Length(TC_Unb_String) + 4,
377 Pad => '*');
379 if TC_Unb_String /= Unb.To_Unbounded_String("Test String****") then
380 Report.Failed("Incorrect results from Head - 4");
381 end if;
383 TC_Unb_String := Unb.Null_Unbounded_String;
385 Unb.Head(Source => TC_Unb_String,
386 Count => Unb.Length(TC_Unb_String) + 3,
387 Pad => '*');
389 if TC_Unb_String /= Unb.To_Unbounded_String("***") then
390 Report.Failed("Incorrect results from Head - 5");
391 end if;
394 -- Procedure Tail
396 -- Count <= Source'Length
398 TC_Unb_String := Unb.To_Unbounded_String("Test String");
400 Unb.Tail(Source => TC_Unb_String,
401 Count => 0,
402 Pad => '*');
404 if TC_Unb_String /= Unb.Null_Unbounded_String then
405 Report.Failed("Incorrect results from Tail - 1");
406 end if;
408 TC_Unb_String := Unb.To_Unbounded_String("Test String");
410 Unb.Tail(Source => TC_Unb_String,
411 Count => 6,
412 Pad => '*');
414 if TC_Unb_String /= Unb.To_Unbounded_String("String") then
415 Report.Failed("Incorrect results from Tail - 2");
416 end if;
418 TC_Unb_String := Unb.To_Unbounded_String("Test String");
420 Unb.Tail(Source => TC_Unb_String,
421 Count => Unb.Length(TC_Unb_String),
422 Pad => '*');
424 if TC_Unb_String /= Unb.To_Unbounded_String("Test String") then
425 Report.Failed("Incorrect results from Tail - 3");
426 end if;
428 -- Count > Source'Length
430 TC_Unb_String := Unb.To_Unbounded_String("Test String");
432 Unb.Tail(Source => TC_Unb_String,
433 Count => Unb.Length(TC_Unb_String) + 5,
434 Pad => 'x');
436 if TC_Unb_String /= Unb.To_Unbounded_String("xxxxxTest String") then
437 Report.Failed("Incorrect results from Tail - 4");
438 end if;
440 TC_Unb_String := Unb.Null_Unbounded_String;
442 Unb.Tail(Source => TC_Unb_String,
443 Count => Unb.Length(TC_Unb_String) + 3,
444 Pad => 'X');
446 if TC_Unb_String /= Unb.To_Unbounded_String("XXX") then
447 Report.Failed("Incorrect results from Tail - 5");
448 end if;
451 exception
452 when others => Report.Failed ("Exception raised in Test_Block");
453 end Test_Block;
455 Report.Result;
457 end CXA4032;