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