annotate gcc/testsuite/ada/acats/tests/cxa/cxa4009.a @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 -- CXA4009.A
kono
parents:
diff changeset
2 --
kono
parents:
diff changeset
3 -- Grant of Unlimited Rights
kono
parents:
diff changeset
4 --
kono
parents:
diff changeset
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
kono
parents:
diff changeset
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
kono
parents:
diff changeset
7 -- unlimited rights in the software and documentation contained herein.
kono
parents:
diff changeset
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
kono
parents:
diff changeset
9 -- this public release, the Government intends to confer upon all
kono
parents:
diff changeset
10 -- recipients unlimited rights equal to those held by the Government.
kono
parents:
diff changeset
11 -- These rights include rights to use, duplicate, release or disclose the
kono
parents:
diff changeset
12 -- released technical data and computer software in whole or in part, in
kono
parents:
diff changeset
13 -- any manner and for any purpose whatsoever, and to have or permit others
kono
parents:
diff changeset
14 -- to do so.
kono
parents:
diff changeset
15 --
kono
parents:
diff changeset
16 -- DISCLAIMER
kono
parents:
diff changeset
17 --
kono
parents:
diff changeset
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
kono
parents:
diff changeset
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
kono
parents:
diff changeset
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
kono
parents:
diff changeset
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
kono
parents:
diff changeset
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
kono
parents:
diff changeset
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
kono
parents:
diff changeset
24 --*
kono
parents:
diff changeset
25 --
kono
parents:
diff changeset
26 -- OBJECTIVE:
kono
parents:
diff changeset
27 -- Check that the subprograms defined in package Ada.Strings.Bounded are
kono
parents:
diff changeset
28 -- available, and that they produce correct results, especially under
kono
parents:
diff changeset
29 -- conditions where truncation of the result is required. Specifically,
kono
parents:
diff changeset
30 -- check the subprograms Overwrite (function and procedure), Delete,
kono
parents:
diff changeset
31 -- Function Trim (blanks), Trim (Set characters, function and procedure),
kono
parents:
diff changeset
32 -- Head, Tail, and Replicate (characters and strings).
kono
parents:
diff changeset
33 --
kono
parents:
diff changeset
34 -- TEST DESCRIPTION:
kono
parents:
diff changeset
35 -- This test, in conjunction with tests CXA4006, CXA4007, and CXA4008,
kono
parents:
diff changeset
36 -- will provide coverage of the most common usages of the functionality
kono
parents:
diff changeset
37 -- found in the Ada.Strings.Bounded package. It deals in large part
kono
parents:
diff changeset
38 -- with truncation effects and options. This test contains many small,
kono
parents:
diff changeset
39 -- specific test cases, situations that are often difficult to generate
kono
parents:
diff changeset
40 -- in large numbers in an application-based test. These cases represent
kono
parents:
diff changeset
41 -- specific usage paradigms in-the-small.
kono
parents:
diff changeset
42 --
kono
parents:
diff changeset
43 --
kono
parents:
diff changeset
44 -- CHANGE HISTORY:
kono
parents:
diff changeset
45 -- 06 Dec 94 SAIC ACVC 2.0
kono
parents:
diff changeset
46 -- 10 Apr 95 SAIC Corrected errors in Procedure Overwrite subtests.
kono
parents:
diff changeset
47 -- 01 Nov 95 SAIC Fixed bugs for ACVC 2.0.1.
kono
parents:
diff changeset
48 --
kono
parents:
diff changeset
49 --!
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 with Report;
kono
parents:
diff changeset
52 with Ada.Strings.Bounded;
kono
parents:
diff changeset
53 with Ada.Strings.Maps;
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 procedure CXA4009 is
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 begin
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 Report.Test("CXA4009", "Check that the subprograms defined in " &
kono
parents:
diff changeset
60 "package Ada.Strings.Bounded are available, " &
kono
parents:
diff changeset
61 "and that they produce correct results, " &
kono
parents:
diff changeset
62 "especially under conditions where " &
kono
parents:
diff changeset
63 "truncation of the result is required");
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 Test_Block:
kono
parents:
diff changeset
66 declare
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 package AS renames Ada.Strings;
kono
parents:
diff changeset
69 package ASB renames Ada.Strings.Bounded;
kono
parents:
diff changeset
70 package Maps renames Ada.Strings.Maps;
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 package B10 is new ASB.Generic_Bounded_Length(Max => 10);
kono
parents:
diff changeset
73 use type B10.Bounded_String;
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 Result_String : B10.Bounded_String;
kono
parents:
diff changeset
76 Test_String : B10.Bounded_String;
kono
parents:
diff changeset
77 AtoE_Bnd_Str : B10.Bounded_String := B10.To_Bounded_String("abcde");
kono
parents:
diff changeset
78 FtoJ_Bnd_Str : B10.Bounded_String := B10.To_Bounded_String("fghij");
kono
parents:
diff changeset
79 AtoJ_Bnd_Str : B10.Bounded_String :=
kono
parents:
diff changeset
80 B10.To_Bounded_String("abcdefghij");
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 Location : Natural := 0;
kono
parents:
diff changeset
83 Total_Count : Natural := 0;
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 CD_Set : Maps.Character_Set := Maps.To_Set("cd");
kono
parents:
diff changeset
86 XY_Set : Maps.Character_Set := Maps.To_Set("xy");
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 begin
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 -- Function Overwrite with Truncation
kono
parents:
diff changeset
92 -- Drop = Error (Default).
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 begin
kono
parents:
diff changeset
95 Test_String := AtoJ_Bnd_Str;
kono
parents:
diff changeset
96 Result_String :=
kono
parents:
diff changeset
97 B10.Overwrite(Source => Test_String, -- "abcdefghij"
kono
parents:
diff changeset
98 Position => 9,
kono
parents:
diff changeset
99 New_Item => "xyz",
kono
parents:
diff changeset
100 Drop => AS.Error);
kono
parents:
diff changeset
101 Report.Failed("Exception not raised by Function Overwrite");
kono
parents:
diff changeset
102 exception
kono
parents:
diff changeset
103 when AS.Length_Error => null; -- Expected exception raised.
kono
parents:
diff changeset
104 when others =>
kono
parents:
diff changeset
105 Report.Failed("Incorrect exception raised by Function Overwrite");
kono
parents:
diff changeset
106 end;
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 -- Drop = Left
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 Result_String :=
kono
parents:
diff changeset
111 B10.Overwrite(Source => Test_String, -- "abcdefghij"
kono
parents:
diff changeset
112 Position => B10.Length(Test_String), -- 10
kono
parents:
diff changeset
113 New_Item => "xyz",
kono
parents:
diff changeset
114 Drop => Ada.Strings.Left);
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 if B10.To_String(Result_String) /= "cdefghixyz" then -- drop a,b
kono
parents:
diff changeset
117 Report.Failed
kono
parents:
diff changeset
118 ("Incorrect result from Function Overwrite, Drop = Left");
kono
parents:
diff changeset
119 end if;
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 -- Drop = Right
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 Result_String := B10.Overwrite(Test_String, -- "abcdefghij"
kono
parents:
diff changeset
124 3,
kono
parents:
diff changeset
125 "xxxyyyzzz",
kono
parents:
diff changeset
126 Ada.Strings.Right);
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 if B10.To_String(Result_String) /= "abxxxyyyzz" then -- one 'z' dropped
kono
parents:
diff changeset
129 Report.Failed
kono
parents:
diff changeset
130 ("Incorrect result from Function Overwrite, Drop = Right");
kono
parents:
diff changeset
131 end if;
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 -- Additional cases of function Overwrite.
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 if B10.Overwrite(B10.To_Bounded_String("a"), -- Source length = 1
kono
parents:
diff changeset
136 1,
kono
parents:
diff changeset
137 " abc ") /=
kono
parents:
diff changeset
138 B10.To_Bounded_String(" abc ") or
kono
parents:
diff changeset
139 B10.Overwrite(B10.Null_Bounded_String, -- Null source
kono
parents:
diff changeset
140 1,
kono
parents:
diff changeset
141 "abcdefghij") /=
kono
parents:
diff changeset
142 AtoJ_Bnd_Str or
kono
parents:
diff changeset
143 B10.Overwrite(AtoE_Bnd_Str,
kono
parents:
diff changeset
144 B10.To_String(AtoE_Bnd_Str)'First,
kono
parents:
diff changeset
145 " ") /= -- New_Item = 1
kono
parents:
diff changeset
146 B10.To_Bounded_String(" bcde")
kono
parents:
diff changeset
147 then
kono
parents:
diff changeset
148 Report.Failed("Incorrect result from Function Overwrite");
kono
parents:
diff changeset
149 end if;
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 -- Procedure Overwrite
kono
parents:
diff changeset
154 -- Correct usage, no truncation.
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 Test_String := AtoE_Bnd_Str; -- "abcde"
kono
parents:
diff changeset
157 B10.Overwrite(Test_String, 2, "xyz");
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 if Test_String /= B10.To_Bounded_String("axyze") then
kono
parents:
diff changeset
160 Report.Failed("Incorrect result from Procedure Overwrite - 1");
kono
parents:
diff changeset
161 end if;
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 Test_String := B10.To_Bounded_String("abc");
kono
parents:
diff changeset
164 B10.Overwrite(Test_String, 2, ""); -- New_Item is null string.
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 if Test_String /= B10.To_Bounded_String("abc") then
kono
parents:
diff changeset
167 Report.Failed("Incorrect result from Procedure Overwrite - 2");
kono
parents:
diff changeset
168 end if;
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 -- Drop = Error (Default).
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 begin
kono
parents:
diff changeset
173 Test_String := AtoJ_Bnd_Str;
kono
parents:
diff changeset
174 B10.Overwrite(Source => Test_String, -- "abcdefghij"
kono
parents:
diff changeset
175 Position => 8,
kono
parents:
diff changeset
176 New_Item => "uvwxyz");
kono
parents:
diff changeset
177 Report.Failed("Exception not raised by Procedure Overwrite");
kono
parents:
diff changeset
178 exception
kono
parents:
diff changeset
179 when AS.Length_Error => null; -- Expected exception raised.
kono
parents:
diff changeset
180 when others =>
kono
parents:
diff changeset
181 Report.Failed("Incorrect exception raised by Procedure Overwrite");
kono
parents:
diff changeset
182 end;
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 -- Drop = Left
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 Test_String := AtoJ_Bnd_Str;
kono
parents:
diff changeset
187 B10.Overwrite(Source => Test_String, -- "abcdefghij"
kono
parents:
diff changeset
188 Position => B10.Length(Test_String) - 2, -- 8
kono
parents:
diff changeset
189 New_Item => "uvwxyz",
kono
parents:
diff changeset
190 Drop => Ada.Strings.Left);
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 if B10.To_String(Test_String) /= "defguvwxyz" then -- drop a-c
kono
parents:
diff changeset
193 Report.Failed
kono
parents:
diff changeset
194 ("Incorrect result from Procedure Overwrite, Drop = Left");
kono
parents:
diff changeset
195 end if;
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 -- Drop = Right
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 Test_String := AtoJ_Bnd_Str;
kono
parents:
diff changeset
200 B10.Overwrite(Test_String, -- "abcdefghij"
kono
parents:
diff changeset
201 3,
kono
parents:
diff changeset
202 "xxxyyyzzz",
kono
parents:
diff changeset
203 Ada.Strings.Right);
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 if B10.To_String(Test_String) /= "abxxxyyyzz" then -- one 'z' dropped
kono
parents:
diff changeset
206 Report.Failed
kono
parents:
diff changeset
207 ("Incorrect result from Procedure Overwrite, Drop = Right");
kono
parents:
diff changeset
208 end if;
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 -- Function Delete
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 if B10.Delete(Source => AtoJ_Bnd_Str, -- "abcdefghij"
kono
parents:
diff changeset
215 From => 3,
kono
parents:
diff changeset
216 Through => 8) /=
kono
parents:
diff changeset
217 B10."&"(B10.Head(AtoJ_Bnd_Str, 2),
kono
parents:
diff changeset
218 B10.Tail(AtoJ_Bnd_Str, 2)) or
kono
parents:
diff changeset
219 B10.Delete(AtoJ_Bnd_Str, 6, B10.Length(AtoJ_Bnd_Str)) /=
kono
parents:
diff changeset
220 AtoE_Bnd_Str or
kono
parents:
diff changeset
221 B10.Delete(AtoJ_Bnd_Str, 1, 5) /=
kono
parents:
diff changeset
222 FtoJ_Bnd_Str or
kono
parents:
diff changeset
223 B10.Delete(AtoE_Bnd_Str, 4, 5) /=
kono
parents:
diff changeset
224 B10.Delete(AtoJ_Bnd_Str, 4, B10.Length(AtoJ_Bnd_Str))
kono
parents:
diff changeset
225 then
kono
parents:
diff changeset
226 Report.Failed("Incorrect result from Function Delete - 1");
kono
parents:
diff changeset
227 end if;
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 if B10.Delete(B10.To_Bounded_String("a"), 1, 1) /=
kono
parents:
diff changeset
230 B10.Null_Bounded_String or
kono
parents:
diff changeset
231 B10.Delete(AtoE_Bnd_Str,
kono
parents:
diff changeset
232 5,
kono
parents:
diff changeset
233 B10.To_String(AtoE_Bnd_Str)'First) /=
kono
parents:
diff changeset
234 AtoE_Bnd_Str or
kono
parents:
diff changeset
235 B10.Delete(AtoE_Bnd_Str,
kono
parents:
diff changeset
236 B10.To_String(AtoE_Bnd_Str)'Last,
kono
parents:
diff changeset
237 B10.To_String(AtoE_Bnd_Str)'Last) /=
kono
parents:
diff changeset
238 B10.To_Bounded_String("abcd")
kono
parents:
diff changeset
239 then
kono
parents:
diff changeset
240 Report.Failed("Incorrect result from Function Delete - 2");
kono
parents:
diff changeset
241 end if;
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 -- Function Trim
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 declare
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 Text : B10.Bounded_String := B10.To_Bounded_String("Text");
kono
parents:
diff changeset
250 type Bnd_Array_Type is array (1..5) of B10.Bounded_String;
kono
parents:
diff changeset
251 Bnd_Array : Bnd_Array_Type :=
kono
parents:
diff changeset
252 (B10.To_Bounded_String(" Text"),
kono
parents:
diff changeset
253 B10.To_Bounded_String("Text "),
kono
parents:
diff changeset
254 B10.To_Bounded_String(" Text "),
kono
parents:
diff changeset
255 B10.To_Bounded_String("Text Text"), -- Ensure no inter-string
kono
parents:
diff changeset
256 B10.To_Bounded_String(" Text Text")); -- trimming of blanks.
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 begin
kono
parents:
diff changeset
259
kono
parents:
diff changeset
260 for i in Bnd_Array_Type'Range loop
kono
parents:
diff changeset
261 case i is
kono
parents:
diff changeset
262 when 4 =>
kono
parents:
diff changeset
263 if B10.Trim(Bnd_Array(i), AS.Both) /=
kono
parents:
diff changeset
264 Bnd_Array(i) then -- no change
kono
parents:
diff changeset
265 Report.Failed("Incorrect result from Function Trim - 4");
kono
parents:
diff changeset
266 end if;
kono
parents:
diff changeset
267 when 5 =>
kono
parents:
diff changeset
268 if B10.Trim(Bnd_Array(i), AS.Both) /=
kono
parents:
diff changeset
269 B10."&"(Text, B10."&"(' ', Text)) then
kono
parents:
diff changeset
270 Report.Failed("Incorrect result from Function Trim - 5");
kono
parents:
diff changeset
271 end if;
kono
parents:
diff changeset
272 when others =>
kono
parents:
diff changeset
273 if B10.Trim(Bnd_Array(i), AS.Both) /= Text then
kono
parents:
diff changeset
274 Report.Failed("Incorrect result from Function Trim - " &
kono
parents:
diff changeset
275 Integer'Image(i));
kono
parents:
diff changeset
276 end if;
kono
parents:
diff changeset
277 end case;
kono
parents:
diff changeset
278 end loop;
kono
parents:
diff changeset
279
kono
parents:
diff changeset
280 end;
kono
parents:
diff changeset
281
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 -- Function Trim using Sets
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 -- Trim characters in sets from both sides of the bounded string.
kono
parents:
diff changeset
287 if B10.Trim(Source => B10.To_Bounded_String("ddabbaxx"),
kono
parents:
diff changeset
288 Left => CD_Set,
kono
parents:
diff changeset
289 Right => XY_Set) /=
kono
parents:
diff changeset
290 B10.To_Bounded_String("abba")
kono
parents:
diff changeset
291 then
kono
parents:
diff changeset
292 Report.Failed
kono
parents:
diff changeset
293 ("Incorrect result from Fn Trim - Sets, Left & Right side - 1");
kono
parents:
diff changeset
294 end if;
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 -- Ensure that the characters in the set provided as the actual to
kono
parents:
diff changeset
297 -- parameter Right are not trimmed from the left side of the bounded
kono
parents:
diff changeset
298 -- string; likewise for the opposite side. Only "cd" trimmed from left
kono
parents:
diff changeset
299 -- side, and only "xy" trimmed from right side.
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 if B10.Trim(B10.To_Bounded_String("cdxyabcdxy"), CD_Set, XY_Set) /=
kono
parents:
diff changeset
302 B10.To_Bounded_String("xyabcd")
kono
parents:
diff changeset
303 then
kono
parents:
diff changeset
304 Report.Failed
kono
parents:
diff changeset
305 ("Incorrect result from Fn Trim - Sets, Left & Right side - 2");
kono
parents:
diff changeset
306 end if;
kono
parents:
diff changeset
307
kono
parents:
diff changeset
308 -- Ensure that characters contained in the sets are not trimmed from
kono
parents:
diff changeset
309 -- the "interior" of the bounded string, just the appropriate ends.
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311 if B10.Trim(B10.To_Bounded_String("cdabdxabxy"), CD_Set, XY_Set) /=
kono
parents:
diff changeset
312 B10.To_Bounded_String("abdxab")
kono
parents:
diff changeset
313 then
kono
parents:
diff changeset
314 Report.Failed
kono
parents:
diff changeset
315 ("Incorrect result from Fn Trim - Sets, Left & Right side - 3");
kono
parents:
diff changeset
316 end if;
kono
parents:
diff changeset
317
kono
parents:
diff changeset
318 -- Trim characters in set from right side only. No change to Left side.
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 if B10.Trim(B10.To_Bounded_String("abxyzddcd"), XY_Set, CD_Set) /=
kono
parents:
diff changeset
321 B10.To_Bounded_String("abxyz")
kono
parents:
diff changeset
322 then
kono
parents:
diff changeset
323 Report.Failed
kono
parents:
diff changeset
324 ("Incorrect result from Fn Trim - Sets, Right side");
kono
parents:
diff changeset
325 end if;
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 -- Trim no characters on either side of the bounded string.
kono
parents:
diff changeset
328
kono
parents:
diff changeset
329 Result_String := B10.Trim(AtoJ_Bnd_Str, CD_Set, XY_Set);
kono
parents:
diff changeset
330 if Result_String /= AtoJ_Bnd_Str then
kono
parents:
diff changeset
331 Report.Failed("Incorrect result from Fn Trim - Sets, Neither side");
kono
parents:
diff changeset
332 end if;
kono
parents:
diff changeset
333
kono
parents:
diff changeset
334 if B10.Trim(AtoE_Bnd_Str, Maps.Null_Set, Maps.Null_Set) /=
kono
parents:
diff changeset
335 AtoE_Bnd_Str or
kono
parents:
diff changeset
336 B10.Trim(B10.To_Bounded_String("dcddcxyyxx"),
kono
parents:
diff changeset
337 CD_Set,
kono
parents:
diff changeset
338 XY_Set) /=
kono
parents:
diff changeset
339 B10.Null_Bounded_String
kono
parents:
diff changeset
340 then
kono
parents:
diff changeset
341 Report.Failed("Incorrect result from Function Trim");
kono
parents:
diff changeset
342 end if;
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345
kono
parents:
diff changeset
346 -- Procedure Trim using Sets
kono
parents:
diff changeset
347
kono
parents:
diff changeset
348 -- Trim characters in sets from both sides of the bounded string.
kono
parents:
diff changeset
349
kono
parents:
diff changeset
350 Test_String := B10.To_Bounded_String("dcabbayx");
kono
parents:
diff changeset
351 B10.Trim(Source => Test_String,
kono
parents:
diff changeset
352 Left => CD_Set,
kono
parents:
diff changeset
353 Right => XY_Set);
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 if Test_String /= B10.To_Bounded_String("abba") then
kono
parents:
diff changeset
356 Report.Failed
kono
parents:
diff changeset
357 ("Incorrect result from Proc Trim - Sets, Left & Right side - 1");
kono
parents:
diff changeset
358 end if;
kono
parents:
diff changeset
359
kono
parents:
diff changeset
360 -- Ensure that the characters in the set provided as the actual to
kono
parents:
diff changeset
361 -- parameter Right are not trimmed from the left side of the bounded
kono
parents:
diff changeset
362 -- string; likewise for the opposite side. Only "cd" trimmed from left
kono
parents:
diff changeset
363 -- side, and only "xy" trimmed from right side.
kono
parents:
diff changeset
364
kono
parents:
diff changeset
365 Test_String := B10.To_Bounded_String("cdxyabcdxy");
kono
parents:
diff changeset
366 B10.Trim(Test_String, CD_Set, XY_Set);
kono
parents:
diff changeset
367
kono
parents:
diff changeset
368 if Test_String /= B10.To_Bounded_String("xyabcd") then
kono
parents:
diff changeset
369 Report.Failed
kono
parents:
diff changeset
370 ("Incorrect result from Proc Trim - Sets, Left & Right side - 2");
kono
parents:
diff changeset
371 end if;
kono
parents:
diff changeset
372
kono
parents:
diff changeset
373 -- Ensure that characters contained in the sets are not trimmed from
kono
parents:
diff changeset
374 -- the "interior" of the bounded string, just the appropriate ends.
kono
parents:
diff changeset
375
kono
parents:
diff changeset
376 Test_String := B10.To_Bounded_String("cdabdxabxy");
kono
parents:
diff changeset
377 B10.Trim(Test_String, CD_Set, XY_Set);
kono
parents:
diff changeset
378
kono
parents:
diff changeset
379 if not (Test_String = B10.To_Bounded_String("abdxab")) then
kono
parents:
diff changeset
380 Report.Failed
kono
parents:
diff changeset
381 ("Incorrect result from Proc Trim - Sets, Left & Right side - 3");
kono
parents:
diff changeset
382 end if;
kono
parents:
diff changeset
383
kono
parents:
diff changeset
384 -- Trim characters in set from Left side only. No change to Right side.
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386 Test_String := B10.To_Bounded_String("cccdabxyz");
kono
parents:
diff changeset
387 B10.Trim(Test_String, CD_Set, XY_Set);
kono
parents:
diff changeset
388
kono
parents:
diff changeset
389 if Test_String /= B10.To_Bounded_String("abxyz") then
kono
parents:
diff changeset
390 Report.Failed
kono
parents:
diff changeset
391 ("Incorrect result from Proc Trim for Sets, Left side only");
kono
parents:
diff changeset
392 end if;
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 -- Trim no characters on either side of the bounded string.
kono
parents:
diff changeset
395
kono
parents:
diff changeset
396 Test_String := AtoJ_Bnd_Str;
kono
parents:
diff changeset
397 B10.Trim(Test_String, CD_Set, CD_Set);
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 if Test_String /= AtoJ_Bnd_Str then
kono
parents:
diff changeset
400 Report.Failed("Incorrect result from Proc Trim-Sets, Neither side");
kono
parents:
diff changeset
401 end if;
kono
parents:
diff changeset
402
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404
kono
parents:
diff changeset
405 -- Function Head with Truncation
kono
parents:
diff changeset
406 -- Drop = Error (Default).
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 begin
kono
parents:
diff changeset
409 Result_String := B10.Head(Source => AtoJ_Bnd_Str, -- max length
kono
parents:
diff changeset
410 Count => B10.Length(AtoJ_Bnd_Str) + 1,
kono
parents:
diff changeset
411 Pad => 'X');
kono
parents:
diff changeset
412 Report.Failed("Length_Error not raised by Function Head");
kono
parents:
diff changeset
413 exception
kono
parents:
diff changeset
414 when AS.Length_Error => null; -- Expected exception raised.
kono
parents:
diff changeset
415 when others =>
kono
parents:
diff changeset
416 Report.Failed("Incorrect exception raised by Function Head");
kono
parents:
diff changeset
417 end;
kono
parents:
diff changeset
418
kono
parents:
diff changeset
419 -- Drop = Left
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 -- Pad characters (5) are appended to the right end of the string
kono
parents:
diff changeset
422 -- (which is initially at its maximum length), then the first five
kono
parents:
diff changeset
423 -- characters of the intermediate result are dropped to conform to
kono
parents:
diff changeset
424 -- the maximum size limit of the bounded string (10).
kono
parents:
diff changeset
425
kono
parents:
diff changeset
426 Result_String := B10.Head(B10.To_Bounded_String("ABCDEFGHIJ"),
kono
parents:
diff changeset
427 15,
kono
parents:
diff changeset
428 'x',
kono
parents:
diff changeset
429 Ada.Strings.Left);
kono
parents:
diff changeset
430
kono
parents:
diff changeset
431 if Result_String /= B10.To_Bounded_String("FGHIJxxxxx") then
kono
parents:
diff changeset
432 Report.Failed("Incorrect result from Function Head, Drop = Left");
kono
parents:
diff changeset
433 end if;
kono
parents:
diff changeset
434
kono
parents:
diff changeset
435 -- Drop = Right
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437 -- Pad characters (6) are appended to the left end of the string
kono
parents:
diff changeset
438 -- (which is initially at one less than its maximum length), then the
kono
parents:
diff changeset
439 -- last five characters of the intermediate result are dropped
kono
parents:
diff changeset
440 -- (which in this case are the pad characters) to conform to the
kono
parents:
diff changeset
441 -- maximum size limit of the bounded string (10).
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 Result_String := B10.Head(B10.To_Bounded_String("ABCDEFGHI"),
kono
parents:
diff changeset
444 15,
kono
parents:
diff changeset
445 'x',
kono
parents:
diff changeset
446 Ada.Strings.Right);
kono
parents:
diff changeset
447
kono
parents:
diff changeset
448 if Result_String /= B10.To_Bounded_String("ABCDEFGHIx") then
kono
parents:
diff changeset
449 Report.Failed("Incorrect result from Function Head, Drop = Right");
kono
parents:
diff changeset
450 end if;
kono
parents:
diff changeset
451
kono
parents:
diff changeset
452 -- Additional cases.
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 if B10.Head(B10.Null_Bounded_String, 5) /=
kono
parents:
diff changeset
455 B10.To_Bounded_String(" ") or
kono
parents:
diff changeset
456 B10.Head(AtoE_Bnd_Str,
kono
parents:
diff changeset
457 B10.Length(AtoE_Bnd_Str)) /=
kono
parents:
diff changeset
458 AtoE_Bnd_Str
kono
parents:
diff changeset
459 then
kono
parents:
diff changeset
460 Report.Failed("Incorrect result from Function Head");
kono
parents:
diff changeset
461 end if;
kono
parents:
diff changeset
462
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464
kono
parents:
diff changeset
465 -- Function Tail with Truncation
kono
parents:
diff changeset
466 -- Drop = Error (Default Case)
kono
parents:
diff changeset
467
kono
parents:
diff changeset
468 begin
kono
parents:
diff changeset
469 Result_String := B10.Tail(Source => AtoJ_Bnd_Str, -- max length
kono
parents:
diff changeset
470 Count => B10.Length(AtoJ_Bnd_Str) + 1,
kono
parents:
diff changeset
471 Pad => Ada.Strings.Space,
kono
parents:
diff changeset
472 Drop => Ada.Strings.Error);
kono
parents:
diff changeset
473 Report.Failed("Length_Error not raised by Function Tail");
kono
parents:
diff changeset
474 exception
kono
parents:
diff changeset
475 when AS.Length_Error => null; -- Expected exception raised.
kono
parents:
diff changeset
476 when others =>
kono
parents:
diff changeset
477 Report.Failed("Incorrect exception raised by Function Tail");
kono
parents:
diff changeset
478 end;
kono
parents:
diff changeset
479
kono
parents:
diff changeset
480 -- Drop = Left
kono
parents:
diff changeset
481
kono
parents:
diff changeset
482 -- Pad characters (5) are appended to the left end of the string
kono
parents:
diff changeset
483 -- (which is initially at two less than its maximum length), then
kono
parents:
diff changeset
484 -- the first three characters of the intermediate result (in this
kono
parents:
diff changeset
485 -- case, 3 pad characters) are dropped.
kono
parents:
diff changeset
486
kono
parents:
diff changeset
487 Result_String := B10.Tail(B10.To_Bounded_String("ABCDEFGH"), -- 8 ch
kono
parents:
diff changeset
488 13,
kono
parents:
diff changeset
489 'x',
kono
parents:
diff changeset
490 Ada.Strings.Left);
kono
parents:
diff changeset
491
kono
parents:
diff changeset
492 if Result_String /= B10.To_Bounded_String("xxABCDEFGH") then
kono
parents:
diff changeset
493 Report.Failed("Incorrect result from Function Tail, Drop = Left");
kono
parents:
diff changeset
494 end if;
kono
parents:
diff changeset
495
kono
parents:
diff changeset
496 -- Drop = Right
kono
parents:
diff changeset
497
kono
parents:
diff changeset
498 -- Pad characters (3) are appended to the left end of the string
kono
parents:
diff changeset
499 -- (which is initially at its maximum length), then the last three
kono
parents:
diff changeset
500 -- characters of the intermediate result are dropped.
kono
parents:
diff changeset
501
kono
parents:
diff changeset
502 Result_String := B10.Tail(B10.To_Bounded_String("ABCDEFGHIJ"),
kono
parents:
diff changeset
503 13,
kono
parents:
diff changeset
504 'x',
kono
parents:
diff changeset
505 Ada.Strings.Right);
kono
parents:
diff changeset
506
kono
parents:
diff changeset
507 if Result_String /= B10.To_Bounded_String("xxxABCDEFG") then
kono
parents:
diff changeset
508 Report.Failed("Incorrect result from Function Tail, Drop = Right");
kono
parents:
diff changeset
509 end if;
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 -- Additional cases.
kono
parents:
diff changeset
512
kono
parents:
diff changeset
513 if B10.Tail(B10.Null_Bounded_String, 3, ' ') /=
kono
parents:
diff changeset
514 B10.To_Bounded_String(" ") or
kono
parents:
diff changeset
515 B10.Tail(AtoE_Bnd_Str,
kono
parents:
diff changeset
516 B10.To_String(AtoE_Bnd_Str)'First) /=
kono
parents:
diff changeset
517 B10.To_Bounded_String("e")
kono
parents:
diff changeset
518 then
kono
parents:
diff changeset
519 Report.Failed("Incorrect result from Function Tail");
kono
parents:
diff changeset
520 end if;
kono
parents:
diff changeset
521
kono
parents:
diff changeset
522
kono
parents:
diff changeset
523
kono
parents:
diff changeset
524 -- Function Replicate (#, Char) with Truncation
kono
parents:
diff changeset
525 -- Drop = Error (Default).
kono
parents:
diff changeset
526
kono
parents:
diff changeset
527 begin
kono
parents:
diff changeset
528 Result_String := B10.Replicate(Count => B10.Max_Length + 5,
kono
parents:
diff changeset
529 Item => 'A',
kono
parents:
diff changeset
530 Drop => AS.Error);
kono
parents:
diff changeset
531 Report.Failed
kono
parents:
diff changeset
532 ("Length_Error not raised by Replicate for characters");
kono
parents:
diff changeset
533 exception
kono
parents:
diff changeset
534 when AS.Length_Error => null; -- Expected exception raised.
kono
parents:
diff changeset
535 when others =>
kono
parents:
diff changeset
536 Report.Failed
kono
parents:
diff changeset
537 ("Incorrect exception raised by Replicate for characters");
kono
parents:
diff changeset
538 end;
kono
parents:
diff changeset
539
kono
parents:
diff changeset
540 -- Drop = Left, Right
kono
parents:
diff changeset
541 -- Since this version of Replicate uses character parameters, the
kono
parents:
diff changeset
542 -- result after truncation from left or right will appear the same.
kono
parents:
diff changeset
543 -- The result will be a 10 character bounded string, composed of 10
kono
parents:
diff changeset
544 -- "Item" characters.
kono
parents:
diff changeset
545
kono
parents:
diff changeset
546 if B10.Replicate(Count => 20, Item => 'A', Drop => Ada.Strings.Left) /=
kono
parents:
diff changeset
547 B10.Replicate(15, 'A', Ada.Strings.Right)
kono
parents:
diff changeset
548 then
kono
parents:
diff changeset
549 Report.Failed("Incorrect result from Replicate for characters - 1");
kono
parents:
diff changeset
550 end if;
kono
parents:
diff changeset
551
kono
parents:
diff changeset
552 -- Blank-filled 10 character bounded strings.
kono
parents:
diff changeset
553
kono
parents:
diff changeset
554 if B10.Replicate(B10.Max_Length + 1, ' ', Drop => Ada.Strings.Left) /=
kono
parents:
diff changeset
555 B10.Replicate(B10.Max_Length, Ada.Strings.Space)
kono
parents:
diff changeset
556 then
kono
parents:
diff changeset
557 Report.Failed("Incorrect result from Replicate for characters - 2");
kono
parents:
diff changeset
558 end if;
kono
parents:
diff changeset
559
kono
parents:
diff changeset
560 -- Additional cases.
kono
parents:
diff changeset
561
kono
parents:
diff changeset
562 if B10.Replicate(0, 'a') /= B10.Null_Bounded_String or
kono
parents:
diff changeset
563 B10.Replicate(1, 'a') /= B10.To_Bounded_String("a")
kono
parents:
diff changeset
564 then
kono
parents:
diff changeset
565 Report.Failed("Incorrect result from Replicate for characters - 3");
kono
parents:
diff changeset
566 end if;
kono
parents:
diff changeset
567
kono
parents:
diff changeset
568
kono
parents:
diff changeset
569
kono
parents:
diff changeset
570 -- Function Replicate (#, String) with Truncation
kono
parents:
diff changeset
571 -- Drop = Error (Default).
kono
parents:
diff changeset
572
kono
parents:
diff changeset
573 begin
kono
parents:
diff changeset
574 Result_String := B10.Replicate(Count => 5, -- result would be 15.
kono
parents:
diff changeset
575 Item => "abc");
kono
parents:
diff changeset
576 Report.Failed
kono
parents:
diff changeset
577 ("Length_Error not raised by Replicate for strings");
kono
parents:
diff changeset
578 exception
kono
parents:
diff changeset
579 when AS.Length_Error => null; -- Expected exception raised.
kono
parents:
diff changeset
580 when others =>
kono
parents:
diff changeset
581 Report.Failed
kono
parents:
diff changeset
582 ("Incorrect exception raised by Replicate for strings");
kono
parents:
diff changeset
583 end;
kono
parents:
diff changeset
584
kono
parents:
diff changeset
585 -- Drop = Left
kono
parents:
diff changeset
586
kono
parents:
diff changeset
587 Result_String := B10.Replicate(3, "abcd", Drop => Ada.Strings.Left);
kono
parents:
diff changeset
588
kono
parents:
diff changeset
589 if Result_String /= B10.To_Bounded_String("cdabcdabcd") then
kono
parents:
diff changeset
590 Report.Failed
kono
parents:
diff changeset
591 ("Incorrect result from Replicate for strings, Drop = Left");
kono
parents:
diff changeset
592 end if;
kono
parents:
diff changeset
593
kono
parents:
diff changeset
594 -- Drop = Right
kono
parents:
diff changeset
595
kono
parents:
diff changeset
596 Result_String := B10.Replicate(3, "abcd", Drop => Ada.Strings.Right);
kono
parents:
diff changeset
597
kono
parents:
diff changeset
598 if Result_String /= B10.To_Bounded_String("abcdabcdab") then
kono
parents:
diff changeset
599 Report.Failed
kono
parents:
diff changeset
600 ("Incorrect result from Replicate for strings, Drop = Right");
kono
parents:
diff changeset
601 end if;
kono
parents:
diff changeset
602
kono
parents:
diff changeset
603 -- Additional cases.
kono
parents:
diff changeset
604
kono
parents:
diff changeset
605 if B10.Replicate(10, "X") /= B10.To_Bounded_String("XXXXXXXXXX") or
kono
parents:
diff changeset
606 B10.Replicate(10, "") /= B10.Null_Bounded_String or
kono
parents:
diff changeset
607 B10.Replicate( 0, "ab") /= B10.Null_Bounded_String
kono
parents:
diff changeset
608 then
kono
parents:
diff changeset
609 Report.Failed("Incorrect result from Replicate for strings");
kono
parents:
diff changeset
610 end if;
kono
parents:
diff changeset
611
kono
parents:
diff changeset
612
kono
parents:
diff changeset
613 exception
kono
parents:
diff changeset
614 when others => Report.Failed("Exception raised in Test_Block");
kono
parents:
diff changeset
615 end Test_Block;
kono
parents:
diff changeset
616
kono
parents:
diff changeset
617 Report.Result;
kono
parents:
diff changeset
618
kono
parents:
diff changeset
619 end CXA4009;