annotate gcc/testsuite/ada/acats/tests/cxa/cxa4005.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 -- CXA4005.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.Fixed are
kono
parents:
diff changeset
28 -- available, and that they produce correct results. Specifically,
kono
parents:
diff changeset
29 -- check the subprograms Delete, Head, Insert, Overwrite, Replace_Slice,
kono
parents:
diff changeset
30 -- Tail, Trim, and "*".
kono
parents:
diff changeset
31 --
kono
parents:
diff changeset
32 -- TEST DESCRIPTION:
kono
parents:
diff changeset
33 -- This test, when combined with tests CXA4002-4 will provide coverage
kono
parents:
diff changeset
34 -- of the functionality found in Ada.Strings.Fixed.
kono
parents:
diff changeset
35 -- This test contains many small, specific test cases, situations that
kono
parents:
diff changeset
36 -- although common in user environments, are often difficult to generate
kono
parents:
diff changeset
37 -- in large numbers in a application-based test. They represent
kono
parents:
diff changeset
38 -- individual usage paradigms in-the-small.
kono
parents:
diff changeset
39 --
kono
parents:
diff changeset
40 --
kono
parents:
diff changeset
41 -- CHANGE HISTORY:
kono
parents:
diff changeset
42 -- 06 Dec 94 SAIC ACVC 2.0
kono
parents:
diff changeset
43 -- 11 Apr 95 SAIC Corrected acceptance conditions of certain
kono
parents:
diff changeset
44 -- subtests.
kono
parents:
diff changeset
45 -- 06 Nov 95 SAIC Fixed bugs for ACVC 2.0.1.
kono
parents:
diff changeset
46 -- 22 Feb 01 PHL Check that the lower bound of the result is 1.
kono
parents:
diff changeset
47 -- 13 Mar 01 RLB Fixed a couple of ACATS style violations;
kono
parents:
diff changeset
48 -- removed pointless checks of procedures.
kono
parents:
diff changeset
49 -- Added checks of other functions. These changes
kono
parents:
diff changeset
50 -- were made to test Defect Report 8652/0049, as
kono
parents:
diff changeset
51 -- reflected in Technical Corrigendum 1.
kono
parents:
diff changeset
52 --
kono
parents:
diff changeset
53 --!
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 with Report;
kono
parents:
diff changeset
56 with Ada.Strings;
kono
parents:
diff changeset
57 with Ada.Strings.Fixed;
kono
parents:
diff changeset
58 with Ada.Strings.Maps;
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 procedure CXA4005 is
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 type TC_Name_Holder is access String;
kono
parents:
diff changeset
63 Name : TC_Name_Holder;
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 function TC_Check (S : String) return String is
kono
parents:
diff changeset
66 begin
kono
parents:
diff changeset
67 if S'First /= 1 then
kono
parents:
diff changeset
68 Report.Failed ("Lower bound of result of function " & Name.all &
kono
parents:
diff changeset
69 " is" & Integer'Image (S'First));
kono
parents:
diff changeset
70 end if;
kono
parents:
diff changeset
71 return S;
kono
parents:
diff changeset
72 end TC_Check;
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 procedure TC_Set_Name (N : String) is
kono
parents:
diff changeset
75 begin
kono
parents:
diff changeset
76 Name := new String'(N);
kono
parents:
diff changeset
77 end TC_Set_Name;
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 begin
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 Report.Test("CXA4005", "Check that the subprograms defined in " &
kono
parents:
diff changeset
82 "package Ada.Strings.Fixed are available, " &
kono
parents:
diff changeset
83 "and that they produce correct results");
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 Test_Block:
kono
parents:
diff changeset
86 declare
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 package ASF renames Ada.Strings.Fixed;
kono
parents:
diff changeset
89 package Maps renames Ada.Strings.Maps;
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 Result_String,
kono
parents:
diff changeset
92 Delete_String,
kono
parents:
diff changeset
93 Insert_String,
kono
parents:
diff changeset
94 Trim_String,
kono
parents:
diff changeset
95 Overwrite_String : String(1..10) := (others => Ada.Strings.Space);
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 Source_String1 : String(1..5) := "abcde"; -- odd length string
kono
parents:
diff changeset
98 Source_String2 : String(1..6) := "abcdef"; -- even length string
kono
parents:
diff changeset
99 Source_String3 : String(1..12) := "abcdefghijkl";
kono
parents:
diff changeset
100 Source_String4 : String(1..12) := "abcdefghij "; -- last two ch pad
kono
parents:
diff changeset
101 Source_String5 : String(1..12) := " cdefghijkl"; -- first two ch pad
kono
parents:
diff changeset
102 Source_String6 : String(1..12) := "abcdefabcdef";
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 Location : Natural := 0;
kono
parents:
diff changeset
105 Slice_Start : Positive;
kono
parents:
diff changeset
106 Slice_End,
kono
parents:
diff changeset
107 Slice_Count : Natural := 0;
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 CD_Set : Maps.Character_Set := Maps.To_Set("cd");
kono
parents:
diff changeset
110 X_Set : Maps.Character_Set := Maps.To_Set('x');
kono
parents:
diff changeset
111 ABCD_Set : Maps.Character_Set := Maps.To_Set("abcd");
kono
parents:
diff changeset
112 A_to_F_Set : Maps.Character_Set := Maps.To_Set("abcdef");
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 CD_to_XY_Map : Maps.Character_Mapping :=
kono
parents:
diff changeset
115 Maps.To_Mapping(From => "cd", To => "xy");
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 begin
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 -- Procedure Replace_Slice
kono
parents:
diff changeset
120 -- The functionality of this procedure
kono
parents:
diff changeset
121 -- is similar to procedure Move, and
kono
parents:
diff changeset
122 -- is tested here in the same manner, evaluated
kono
parents:
diff changeset
123 -- with various combinations of parameters.
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 -- Index_Error propagation when Low > Source'Last + 1
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 begin
kono
parents:
diff changeset
128 ASF.Replace_Slice(Result_String,
kono
parents:
diff changeset
129 Result_String'Last + 2, -- should raise exception
kono
parents:
diff changeset
130 Result_String'Last,
kono
parents:
diff changeset
131 "xxxxxxx");
kono
parents:
diff changeset
132 Report.Failed("Index_Error not raised by Replace_Slice - 1");
kono
parents:
diff changeset
133 exception
kono
parents:
diff changeset
134 when Ada.Strings.Index_Error => null; -- OK, expected exception.
kono
parents:
diff changeset
135 when others =>
kono
parents:
diff changeset
136 Report.Failed("Incorrect exception from Replace_Slice - 1");
kono
parents:
diff changeset
137 end;
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 -- Index_Error propagation when High < Source'First - 1
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 begin
kono
parents:
diff changeset
142 ASF.Replace_Slice(Result_String(5..10),
kono
parents:
diff changeset
143 5,
kono
parents:
diff changeset
144 3, -- should raise exception since < 'First - 1.
kono
parents:
diff changeset
145 "xxxxxxx");
kono
parents:
diff changeset
146 Report.Failed("Index_Error not raised by Replace_Slice - 2");
kono
parents:
diff changeset
147 exception
kono
parents:
diff changeset
148 when Ada.Strings.Index_Error => null; -- OK, expected exception.
kono
parents:
diff changeset
149 when others =>
kono
parents:
diff changeset
150 Report.Failed("Incorrect exception from Replace_Slice - 2");
kono
parents:
diff changeset
151 end;
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 -- Justify = Left (default case)
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 Result_String := "XXXXXXXXXX";
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 ASF.Replace_Slice(Source => Result_String,
kono
parents:
diff changeset
158 Low => 1,
kono
parents:
diff changeset
159 High => 10,
kono
parents:
diff changeset
160 By => Source_String1); -- "abcde"
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 if Result_String /= "abcde " then
kono
parents:
diff changeset
163 Report.Failed("Incorrect result from Replace_Slice - Justify = Left");
kono
parents:
diff changeset
164 end if;
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 -- Justify = Right
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 ASF.Replace_Slice(Source => Result_String,
kono
parents:
diff changeset
169 Low => 1,
kono
parents:
diff changeset
170 High => Result_String'Last,
kono
parents:
diff changeset
171 By => Source_String2, -- "abcdef"
kono
parents:
diff changeset
172 Drop => Ada.Strings.Error,
kono
parents:
diff changeset
173 Justify => Ada.Strings.Right);
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 if Result_String /= " abcdef" then
kono
parents:
diff changeset
176 Report.Failed("Incorrect result from Replace_Slice - Justify=Right");
kono
parents:
diff changeset
177 end if;
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 -- Justify = Center (two cases, odd and even pad lengths)
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 ASF.Replace_Slice(Result_String,
kono
parents:
diff changeset
182 1,
kono
parents:
diff changeset
183 Result_String'Last,
kono
parents:
diff changeset
184 Source_String1, -- "abcde"
kono
parents:
diff changeset
185 Ada.Strings.Error,
kono
parents:
diff changeset
186 Ada.Strings.Center,
kono
parents:
diff changeset
187 'x'); -- non-default padding.
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 if Result_String /= "xxabcdexxx" then -- Unequal padding added right
kono
parents:
diff changeset
190 Report.Failed("Incorrect result, Replace_Slice - Justify=Center - 1");
kono
parents:
diff changeset
191 end if;
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 ASF.Replace_Slice(Result_String,
kono
parents:
diff changeset
194 1,
kono
parents:
diff changeset
195 Result_String'Last,
kono
parents:
diff changeset
196 Source_String2, -- "abcdef"
kono
parents:
diff changeset
197 Ada.Strings.Error,
kono
parents:
diff changeset
198 Ada.Strings.Center);
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 if Result_String /= " abcdef " then -- Equal padding added on L/R.
kono
parents:
diff changeset
201 Report.Failed("Incorrect result from Replace_Slice with " &
kono
parents:
diff changeset
202 "Justify = Center - 2");
kono
parents:
diff changeset
203 end if;
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 -- When the source string is longer than the target string, several
kono
parents:
diff changeset
206 -- cases can be examined, with the results depending on the value of
kono
parents:
diff changeset
207 -- the Drop parameter.
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 -- Drop = Left
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 ASF.Replace_Slice(Result_String,
kono
parents:
diff changeset
212 1,
kono
parents:
diff changeset
213 Result_String'Last,
kono
parents:
diff changeset
214 Source_String3, -- "abcdefghijkl"
kono
parents:
diff changeset
215 Drop => Ada.Strings.Left);
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 if Result_String /= "cdefghijkl" then
kono
parents:
diff changeset
218 Report.Failed("Incorrect result from Replace_Slice - Drop=Left");
kono
parents:
diff changeset
219 end if;
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221 -- Drop = Right
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 ASF.Replace_Slice(Result_String,
kono
parents:
diff changeset
224 1,
kono
parents:
diff changeset
225 Result_String'Last,
kono
parents:
diff changeset
226 Source_String3, -- "abcdefghijkl"
kono
parents:
diff changeset
227 Ada.Strings.Right);
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 if Result_String /= "abcdefghij" then
kono
parents:
diff changeset
230 Report.Failed("Incorrect result, Replace_Slice with Drop=Right");
kono
parents:
diff changeset
231 end if;
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 -- Drop = Error
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 -- The effect in this case depends on the value of the justify
kono
parents:
diff changeset
236 -- parameter, and on whether any characters in Source other than
kono
parents:
diff changeset
237 -- Pad would fail to be copied.
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239 -- Drop = Error, Justify = Left, right overflow characters are pad.
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 ASF.Replace_Slice(Result_String,
kono
parents:
diff changeset
242 1,
kono
parents:
diff changeset
243 Result_String'Last,
kono
parents:
diff changeset
244 Source_String4, -- "abcdefghij "
kono
parents:
diff changeset
245 Drop => Ada.Strings.Error,
kono
parents:
diff changeset
246 Justify => Ada.Strings.Left);
kono
parents:
diff changeset
247
kono
parents:
diff changeset
248 if not(Result_String = "abcdefghij") then -- leftmost 10 characters
kono
parents:
diff changeset
249 Report.Failed("Incorrect result, Replace_Slice - Drop = Error - 1");
kono
parents:
diff changeset
250 end if;
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252 -- Drop = Error, Justify = Right, left overflow characters are pad.
kono
parents:
diff changeset
253
kono
parents:
diff changeset
254 ASF.Replace_Slice(Source => Result_String,
kono
parents:
diff changeset
255 Low => 1,
kono
parents:
diff changeset
256 High => Result_String'Last,
kono
parents:
diff changeset
257 By => Source_String5, -- " cdefghijkl"
kono
parents:
diff changeset
258 Drop => Ada.Strings.Error,
kono
parents:
diff changeset
259 Justify => Ada.Strings.Right);
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 if Result_String /= "cdefghijkl" then -- rightmost 10 characters
kono
parents:
diff changeset
262 Report.Failed("Incorrect result, Replace_Slice - Drop = Error - 2");
kono
parents:
diff changeset
263 end if;
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 -- In other cases of Drop=Error, Length_Error is propagated, such as:
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 begin
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 ASF.Replace_Slice(Source => Result_String,
kono
parents:
diff changeset
270 Low => 1,
kono
parents:
diff changeset
271 High => Result_String'Last,
kono
parents:
diff changeset
272 By => Source_String3, -- "abcdefghijkl"
kono
parents:
diff changeset
273 Drop => Ada.Strings.Error);
kono
parents:
diff changeset
274
kono
parents:
diff changeset
275 Report.Failed("Length_Error not raised by Replace_Slice - 1");
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 exception
kono
parents:
diff changeset
278 when Ada.Strings.Length_Error => null; -- OK
kono
parents:
diff changeset
279 when others =>
kono
parents:
diff changeset
280 Report.Failed("Incorrect exception from Replace_Slice - 3");
kono
parents:
diff changeset
281 end;
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 -- Function Replace_Slice
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 TC_Set_Name ("Replace_Slice");
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 if TC_Check (ASF.Replace_Slice("abcde", 3, 3, "x"))
kono
parents:
diff changeset
289 /= "abxde" or -- High = Low
kono
parents:
diff changeset
290 TC_Check (ASF.Replace_Slice("abc", 2, 3, "xyz")) /= "axyz" or
kono
parents:
diff changeset
291 TC_Check (ASF.Replace_Slice("abcd", 4, 1, "xy"))
kono
parents:
diff changeset
292 /= "abcxyd" or -- High < Low
kono
parents:
diff changeset
293 TC_Check (ASF.Replace_Slice("abc", 2, 3, "x")) /= "ax" or
kono
parents:
diff changeset
294 TC_Check (ASF.Replace_Slice("a", 1, 1, "z")) /= "z"
kono
parents:
diff changeset
295 then
kono
parents:
diff changeset
296 Report.Failed("Incorrect result from Function Replace_Slice - 1");
kono
parents:
diff changeset
297 end if;
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 if TC_Check (ASF.Replace_Slice("abcde", 5, 5, "z"))
kono
parents:
diff changeset
300 /= "abcdz" or -- By length 1
kono
parents:
diff changeset
301 TC_Check (ASF.Replace_Slice("abc", 1, 3, "xyz"))
kono
parents:
diff changeset
302 /= "xyz" or -- High > Low
kono
parents:
diff changeset
303 TC_Check (ASF.Replace_Slice("abc", 3, 2, "xy"))
kono
parents:
diff changeset
304 /= "abxyc" or -- insert
kono
parents:
diff changeset
305 TC_Check (ASF.Replace_Slice("a", 1, 1, "xyz")) /= "xyz"
kono
parents:
diff changeset
306 then
kono
parents:
diff changeset
307 Report.Failed("Incorrect result from Function Replace_Slice - 2");
kono
parents:
diff changeset
308 end if;
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 -- Function Insert.
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 TC_Set_Name ("Insert");
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 declare
kono
parents:
diff changeset
317 New_String : constant String :=
kono
parents:
diff changeset
318 TC_Check (
kono
parents:
diff changeset
319 ASF.Insert(Source => Source_String1(2..5), -- "bcde"
kono
parents:
diff changeset
320 Before => 3,
kono
parents:
diff changeset
321 New_Item => Source_String2)); -- "abcdef"
kono
parents:
diff changeset
322 begin
kono
parents:
diff changeset
323 if New_String /= "babcdefcde" then
kono
parents:
diff changeset
324 Report.Failed("Incorrect result from Function Insert - 1");
kono
parents:
diff changeset
325 end if;
kono
parents:
diff changeset
326 end;
kono
parents:
diff changeset
327
kono
parents:
diff changeset
328 if TC_Check (ASF.Insert("a", 1, "z")) /= "za" or
kono
parents:
diff changeset
329 TC_Check (ASF.Insert("abc", 3, "")) /= "abc" or
kono
parents:
diff changeset
330 TC_Check (ASF.Insert("abc", 1, "z")) /= "zabc"
kono
parents:
diff changeset
331 then
kono
parents:
diff changeset
332 Report.Failed("Incorrect result from Function Insert - 2");
kono
parents:
diff changeset
333 end if;
kono
parents:
diff changeset
334
kono
parents:
diff changeset
335 begin
kono
parents:
diff changeset
336 if TC_Check (ASF.Insert(Source => Source_String1(2..5), -- "bcde"
kono
parents:
diff changeset
337 Before => Report.Ident_Int(7),
kono
parents:
diff changeset
338 New_Item => Source_String2)) -- "abcdef"
kono
parents:
diff changeset
339 /= "babcdefcde" then
kono
parents:
diff changeset
340 Report.Failed("Index_Error not raised by Insert - 3A");
kono
parents:
diff changeset
341 else
kono
parents:
diff changeset
342 Report.Failed("Index_Error not raised by Insert - 3B");
kono
parents:
diff changeset
343 end if;
kono
parents:
diff changeset
344 exception
kono
parents:
diff changeset
345 when Ada.Strings.Index_Error => null; -- OK, expected exception.
kono
parents:
diff changeset
346 when others =>
kono
parents:
diff changeset
347 Report.Failed("Incorrect exception from Insert - 3");
kono
parents:
diff changeset
348 end;
kono
parents:
diff changeset
349
kono
parents:
diff changeset
350
kono
parents:
diff changeset
351 -- Procedure Insert
kono
parents:
diff changeset
352
kono
parents:
diff changeset
353 -- Drop = Right
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 ASF.Insert(Source => Insert_String,
kono
parents:
diff changeset
356 Before => 6,
kono
parents:
diff changeset
357 New_Item => Source_String2, -- "abcdef"
kono
parents:
diff changeset
358 Drop => Ada.Strings.Right);
kono
parents:
diff changeset
359
kono
parents:
diff changeset
360 if Insert_String /= " abcde" then -- last char of New_Item dropped.
kono
parents:
diff changeset
361 Report.Failed("Incorrect result from Insert with Drop = Right");
kono
parents:
diff changeset
362 end if;
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 -- Drop = Left
kono
parents:
diff changeset
365
kono
parents:
diff changeset
366 ASF.Insert(Source => Insert_String, -- 10 char string
kono
parents:
diff changeset
367 Before => 2, -- 9 chars, 2..10 available
kono
parents:
diff changeset
368 New_Item => Source_String3, -- 12 characters long.
kono
parents:
diff changeset
369 Drop => Ada.Strings.Left); -- truncate from Left.
kono
parents:
diff changeset
370
kono
parents:
diff changeset
371 if Insert_String /= "l abcde" then -- 10 chars, leading blank.
kono
parents:
diff changeset
372 Report.Failed("Incorrect result from Insert with Drop=Left");
kono
parents:
diff changeset
373 end if;
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 -- Drop = Error
kono
parents:
diff changeset
376
kono
parents:
diff changeset
377 begin
kono
parents:
diff changeset
378 ASF.Insert(Source => Result_String, -- 10 chars
kono
parents:
diff changeset
379 Before => Result_String'Last,
kono
parents:
diff changeset
380 New_Item => "abcdefghijk",
kono
parents:
diff changeset
381 Drop => Ada.Strings.Error);
kono
parents:
diff changeset
382 Report.Failed("Exception not raised by Procedure Insert");
kono
parents:
diff changeset
383 exception
kono
parents:
diff changeset
384 when Ada.Strings.Length_Error => null; -- OK, expected exception
kono
parents:
diff changeset
385 when others =>
kono
parents:
diff changeset
386 Report.Failed("Incorrect exception raised by Procedure Insert");
kono
parents:
diff changeset
387 end;
kono
parents:
diff changeset
388
kono
parents:
diff changeset
389
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 -- Function Overwrite
kono
parents:
diff changeset
392
kono
parents:
diff changeset
393 TC_Set_Name ("Overwrite");
kono
parents:
diff changeset
394
kono
parents:
diff changeset
395 Overwrite_String := TC_Check (
kono
parents:
diff changeset
396 ASF.Overwrite(Result_String, -- 10 chars
kono
parents:
diff changeset
397 1, -- starting at pos=1
kono
parents:
diff changeset
398 Source_String3(1..10)));
kono
parents:
diff changeset
399
kono
parents:
diff changeset
400 if Overwrite_String /= Source_String3(1..10) then
kono
parents:
diff changeset
401 Report.Failed("Incorrect result from Function Overwrite - 1");
kono
parents:
diff changeset
402 end if;
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404
kono
parents:
diff changeset
405 if TC_Check (ASF.Overwrite("abcdef", 4, "xyz")) /= "abcxyz" or
kono
parents:
diff changeset
406 TC_Check (ASF.Overwrite("a", 1, "xyz"))
kono
parents:
diff changeset
407 /= "xyz" or -- chars appended
kono
parents:
diff changeset
408 TC_Check (ASF.Overwrite("abc", 3, " "))
kono
parents:
diff changeset
409 /= "ab " or -- blanks appended
kono
parents:
diff changeset
410 TC_Check (ASF.Overwrite("abcde", 1, "z" )) /= "zbcde"
kono
parents:
diff changeset
411 then
kono
parents:
diff changeset
412 Report.Failed("Incorrect result from Function Overwrite - 2");
kono
parents:
diff changeset
413 end if;
kono
parents:
diff changeset
414
kono
parents:
diff changeset
415
kono
parents:
diff changeset
416
kono
parents:
diff changeset
417 -- Procedure Overwrite, with truncation.
kono
parents:
diff changeset
418
kono
parents:
diff changeset
419 ASF.Overwrite(Source => Overwrite_String, -- 10 characters.
kono
parents:
diff changeset
420 Position => 1,
kono
parents:
diff changeset
421 New_Item => Source_String3, -- 12 characters.
kono
parents:
diff changeset
422 Drop => Ada.Strings.Left);
kono
parents:
diff changeset
423
kono
parents:
diff changeset
424 if Overwrite_String /= "cdefghijkl" then
kono
parents:
diff changeset
425 Report.Failed("Incorrect result from Overwrite with Drop=Left");
kono
parents:
diff changeset
426 end if;
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 -- The default drop value is Right, used here.
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 ASF.Overwrite(Source => Overwrite_String, -- 10 characters.
kono
parents:
diff changeset
431 Position => 1,
kono
parents:
diff changeset
432 New_Item => Source_String3); -- 12 characters.
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 if Overwrite_String /= "abcdefghij" then
kono
parents:
diff changeset
435 Report.Failed("Incorrect result from Overwrite with Drop=Right");
kono
parents:
diff changeset
436 end if;
kono
parents:
diff changeset
437
kono
parents:
diff changeset
438 -- Drop = Error
kono
parents:
diff changeset
439
kono
parents:
diff changeset
440 begin
kono
parents:
diff changeset
441 ASF.Overwrite(Source => Overwrite_String, -- 10 characters.
kono
parents:
diff changeset
442 Position => 1,
kono
parents:
diff changeset
443 New_Item => Source_String3, -- 12 characters.
kono
parents:
diff changeset
444 Drop => Ada.Strings.Error);
kono
parents:
diff changeset
445 Report.Failed("Exception not raised by Procedure Overwrite");
kono
parents:
diff changeset
446 exception
kono
parents:
diff changeset
447 when Ada.Strings.Length_Error => null; -- OK, expected exception.
kono
parents:
diff changeset
448 when others =>
kono
parents:
diff changeset
449 Report.Failed
kono
parents:
diff changeset
450 ("Incorrect exception raised by Procedure Overwrite");
kono
parents:
diff changeset
451 end;
kono
parents:
diff changeset
452
kono
parents:
diff changeset
453 Overwrite_String := "ababababab";
kono
parents:
diff changeset
454 ASF.Overwrite(Overwrite_String, Overwrite_String'Last, "z");
kono
parents:
diff changeset
455 ASF.Overwrite(Overwrite_String, Overwrite_String'First,"z");
kono
parents:
diff changeset
456 ASF.Overwrite(Overwrite_String, 5, "zz");
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 if Overwrite_String /= "zbabzzabaz" then
kono
parents:
diff changeset
459 Report.Failed("Incorrect result from Procedure Overwrite");
kono
parents:
diff changeset
460 end if;
kono
parents:
diff changeset
461
kono
parents:
diff changeset
462
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464 -- Function Delete
kono
parents:
diff changeset
465
kono
parents:
diff changeset
466 TC_Set_Name ("Delete");
kono
parents:
diff changeset
467
kono
parents:
diff changeset
468 declare
kono
parents:
diff changeset
469 New_String1 : constant String := -- This returns a 4 char string.
kono
parents:
diff changeset
470 TC_Check (ASF.Delete(Source => Source_String3,
kono
parents:
diff changeset
471 From => 3,
kono
parents:
diff changeset
472 Through => 10));
kono
parents:
diff changeset
473 New_String2 : constant String := -- This returns Source.
kono
parents:
diff changeset
474 TC_Check (ASF.Delete(Source_String3, 10, 3));
kono
parents:
diff changeset
475 begin
kono
parents:
diff changeset
476 if New_String1 /= "abkl" or
kono
parents:
diff changeset
477 New_String2 /= Source_String3
kono
parents:
diff changeset
478 then
kono
parents:
diff changeset
479 Report.Failed("Incorrect result from Function Delete - 1");
kono
parents:
diff changeset
480 end if;
kono
parents:
diff changeset
481 end;
kono
parents:
diff changeset
482
kono
parents:
diff changeset
483 if TC_Check (ASF.Delete("a", 1, 1))
kono
parents:
diff changeset
484 /= "" or -- Source length = 1
kono
parents:
diff changeset
485 TC_Check (ASF.Delete("abc", 1, 2))
kono
parents:
diff changeset
486 /= "c" or -- From = Source'First
kono
parents:
diff changeset
487 TC_Check (ASF.Delete("abc", 3, 3))
kono
parents:
diff changeset
488 /= "ab" or -- From = Source'Last
kono
parents:
diff changeset
489 TC_Check (ASF.Delete("abc", 3, 1))
kono
parents:
diff changeset
490 /= "abc" -- From > Through
kono
parents:
diff changeset
491 then
kono
parents:
diff changeset
492 Report.Failed("Incorrect result from Function Delete - 2");
kono
parents:
diff changeset
493 end if;
kono
parents:
diff changeset
494
kono
parents:
diff changeset
495
kono
parents:
diff changeset
496
kono
parents:
diff changeset
497 -- Procedure Delete
kono
parents:
diff changeset
498
kono
parents:
diff changeset
499 -- Justify = Left
kono
parents:
diff changeset
500
kono
parents:
diff changeset
501 Delete_String := Source_String3(1..10); -- Initialize to "abcdefghij"
kono
parents:
diff changeset
502
kono
parents:
diff changeset
503 ASF.Delete(Source => Delete_String,
kono
parents:
diff changeset
504 From => 6,
kono
parents:
diff changeset
505 Through => Delete_String'Last,
kono
parents:
diff changeset
506 Justify => Ada.Strings.Left,
kono
parents:
diff changeset
507 Pad => 'x'); -- pad with char 'x'
kono
parents:
diff changeset
508
kono
parents:
diff changeset
509 if Delete_String /= "abcdexxxxx" then
kono
parents:
diff changeset
510 Report.Failed("Incorrect result from Delete - Justify = Left");
kono
parents:
diff changeset
511 end if;
kono
parents:
diff changeset
512
kono
parents:
diff changeset
513 -- Justify = Right
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 ASF.Delete(Source => Delete_String, -- Remove x"s from end and
kono
parents:
diff changeset
516 From => 6, -- shift right.
kono
parents:
diff changeset
517 Through => Delete_String'Last,
kono
parents:
diff changeset
518 Justify => Ada.Strings.Right,
kono
parents:
diff changeset
519 Pad => 'x'); -- pad with char 'x' on left.
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 if Delete_String /= "xxxxxabcde" then
kono
parents:
diff changeset
522 Report.Failed("Incorrect result from Delete - Justify = Right");
kono
parents:
diff changeset
523 end if;
kono
parents:
diff changeset
524
kono
parents:
diff changeset
525 -- Justify = Center
kono
parents:
diff changeset
526
kono
parents:
diff changeset
527 ASF.Delete(Source => Delete_String,
kono
parents:
diff changeset
528 From => 1,
kono
parents:
diff changeset
529 Through => 5,
kono
parents:
diff changeset
530 Justify => Ada.Strings.Center,
kono
parents:
diff changeset
531 Pad => 'z');
kono
parents:
diff changeset
532
kono
parents:
diff changeset
533 if Delete_String /= "zzabcdezzz" then -- extra pad char on right side.
kono
parents:
diff changeset
534 Report.Failed("Incorrect result from Delete - Justify = Center");
kono
parents:
diff changeset
535 end if;
kono
parents:
diff changeset
536
kono
parents:
diff changeset
537
kono
parents:
diff changeset
538
kono
parents:
diff changeset
539 -- Function Trim
kono
parents:
diff changeset
540 -- Use non-identity character sets to perform the trim operation.
kono
parents:
diff changeset
541
kono
parents:
diff changeset
542 TC_Set_Name ("Trim");
kono
parents:
diff changeset
543
kono
parents:
diff changeset
544 Trim_String := "cdabcdefcd";
kono
parents:
diff changeset
545
kono
parents:
diff changeset
546 -- Remove the "cd" from each end of the string. This will not effect
kono
parents:
diff changeset
547 -- the "cd" slice at 5..6.
kono
parents:
diff changeset
548
kono
parents:
diff changeset
549 declare
kono
parents:
diff changeset
550 New_String : constant String :=
kono
parents:
diff changeset
551 TC_Check (ASF.Trim(Source => Trim_String,
kono
parents:
diff changeset
552 Left => CD_Set, Right => CD_Set));
kono
parents:
diff changeset
553 begin
kono
parents:
diff changeset
554 if New_String /= Source_String2 then -- string "abcdef"
kono
parents:
diff changeset
555 Report.Failed("Incorrect result from Trim with character sets");
kono
parents:
diff changeset
556 end if;
kono
parents:
diff changeset
557 end;
kono
parents:
diff changeset
558
kono
parents:
diff changeset
559 if TC_Check (ASF.Trim("abcdef", Maps.Null_Set, Maps.Null_Set))
kono
parents:
diff changeset
560 /= "abcdef" then
kono
parents:
diff changeset
561 Report.Failed("Incorrect result from Trim with Null sets");
kono
parents:
diff changeset
562 end if;
kono
parents:
diff changeset
563
kono
parents:
diff changeset
564 if TC_Check (ASF.Trim("cdxx", CD_Set, X_Set)) /= "" then
kono
parents:
diff changeset
565 Report.Failed("Incorrect result from Trim, string removal");
kono
parents:
diff changeset
566 end if;
kono
parents:
diff changeset
567
kono
parents:
diff changeset
568
kono
parents:
diff changeset
569 -- Procedure Trim
kono
parents:
diff changeset
570
kono
parents:
diff changeset
571 -- Justify = Right
kono
parents:
diff changeset
572
kono
parents:
diff changeset
573 ASF.Trim(Source => Trim_String,
kono
parents:
diff changeset
574 Left => CD_Set,
kono
parents:
diff changeset
575 Right => CD_Set,
kono
parents:
diff changeset
576 Justify => Ada.Strings.Right,
kono
parents:
diff changeset
577 Pad => 'x');
kono
parents:
diff changeset
578
kono
parents:
diff changeset
579 if Trim_String /= "xxxxabcdef" then
kono
parents:
diff changeset
580 Report.Failed("Incorrect result from Trim with Justify = Right");
kono
parents:
diff changeset
581 end if;
kono
parents:
diff changeset
582
kono
parents:
diff changeset
583 -- Justify = Left
kono
parents:
diff changeset
584
kono
parents:
diff changeset
585 ASF.Trim(Source => Trim_String,
kono
parents:
diff changeset
586 Left => X_Set,
kono
parents:
diff changeset
587 Right => Maps.Null_Set,
kono
parents:
diff changeset
588 Justify => Ada.Strings.Left,
kono
parents:
diff changeset
589 Pad => Ada.Strings.Space);
kono
parents:
diff changeset
590
kono
parents:
diff changeset
591 if Trim_String /= "abcdef " then -- Padded with 4 blanks on right.
kono
parents:
diff changeset
592 Report.Failed("Incorrect result from Trim with Justify = Left");
kono
parents:
diff changeset
593 end if;
kono
parents:
diff changeset
594
kono
parents:
diff changeset
595 -- Justify = Center
kono
parents:
diff changeset
596
kono
parents:
diff changeset
597 ASF.Trim(Source => Trim_String,
kono
parents:
diff changeset
598 Left => ABCD_Set,
kono
parents:
diff changeset
599 Right => CD_Set,
kono
parents:
diff changeset
600 Justify => Ada.Strings.Center,
kono
parents:
diff changeset
601 Pad => 'x');
kono
parents:
diff changeset
602
kono
parents:
diff changeset
603 if Trim_String /= "xxef xx" then -- Padded with 2 pad chars on L/R
kono
parents:
diff changeset
604 Report.Failed("Incorrect result from Trim with Justify = Center");
kono
parents:
diff changeset
605 end if;
kono
parents:
diff changeset
606
kono
parents:
diff changeset
607
kono
parents:
diff changeset
608
kono
parents:
diff changeset
609 -- Function Head, demonstrating use of padding.
kono
parents:
diff changeset
610
kono
parents:
diff changeset
611 TC_Set_Name ("Head");
kono
parents:
diff changeset
612
kono
parents:
diff changeset
613 -- Use the characters of Source_String1 ("abcde") and pad the
kono
parents:
diff changeset
614 -- last five characters of Result_String with 'x' characters.
kono
parents:
diff changeset
615
kono
parents:
diff changeset
616
kono
parents:
diff changeset
617 Result_String := TC_CHeck (ASF.Head(Source_String1, 10, 'x'));
kono
parents:
diff changeset
618
kono
parents:
diff changeset
619 if Result_String /= "abcdexxxxx" then
kono
parents:
diff changeset
620 Report.Failed("Incorrect result from Function Head with padding");
kono
parents:
diff changeset
621 end if;
kono
parents:
diff changeset
622
kono
parents:
diff changeset
623 if TC_Check (ASF.Head(" ab ", 2)) /= " " or
kono
parents:
diff changeset
624 TC_Check (ASF.Head("a", 6, 'A')) /= "aAAAAA" or
kono
parents:
diff changeset
625 TC_Check (ASF.Head("abcdefgh", 3, 'x')) /= "abc" or
kono
parents:
diff changeset
626 TC_Check (ASF.Head(ASF.Head("abc ", 7, 'x'), 10, 'X'))
kono
parents:
diff changeset
627 /= "abc xxXXX"
kono
parents:
diff changeset
628 then
kono
parents:
diff changeset
629 Report.Failed("Incorrect result from Function Head");
kono
parents:
diff changeset
630 end if;
kono
parents:
diff changeset
631
kono
parents:
diff changeset
632
kono
parents:
diff changeset
633
kono
parents:
diff changeset
634 -- Function Tail, demonstrating use of padding.
kono
parents:
diff changeset
635
kono
parents:
diff changeset
636 TC_Set_Name ("Tail");
kono
parents:
diff changeset
637
kono
parents:
diff changeset
638 -- Use the characters of Source_String1 ("abcde") and pad the
kono
parents:
diff changeset
639 -- first five characters of Result_String with 'x' characters.
kono
parents:
diff changeset
640
kono
parents:
diff changeset
641 Result_String := TC_Check (ASF.Tail(Source_String1, 10, 'x'));
kono
parents:
diff changeset
642
kono
parents:
diff changeset
643 if Result_String /= "xxxxxabcde" then
kono
parents:
diff changeset
644 Report.Failed("Incorrect result from Function Tail with padding");
kono
parents:
diff changeset
645 end if;
kono
parents:
diff changeset
646
kono
parents:
diff changeset
647 if TC_Check (ASF.Tail("abcde ", 5))
kono
parents:
diff changeset
648 /= "cde " or -- blanks, back
kono
parents:
diff changeset
649 TC_Check (ASF.Tail(" abc ", 8, ' '))
kono
parents:
diff changeset
650 /= " abc " or -- blanks, front/back
kono
parents:
diff changeset
651 TC_Check (ASF.Tail("", 5, 'Z'))
kono
parents:
diff changeset
652 /= "ZZZZZ" or -- pad characters only
kono
parents:
diff changeset
653 TC_Check (ASF.Tail("abc", 0))
kono
parents:
diff changeset
654 /= "" or -- null result
kono
parents:
diff changeset
655 TC_Check (ASF.Tail("abcdefgh", 3))
kono
parents:
diff changeset
656 /= "fgh" or
kono
parents:
diff changeset
657 TC_Check (ASF.Tail(ASF.Tail(" abc ", 6, 'x'),
kono
parents:
diff changeset
658 10,
kono
parents:
diff changeset
659 'X')) /= "XXXXx abc "
kono
parents:
diff changeset
660 then
kono
parents:
diff changeset
661 Report.Failed("Incorrect result from Function Tail");
kono
parents:
diff changeset
662 end if;
kono
parents:
diff changeset
663
kono
parents:
diff changeset
664
kono
parents:
diff changeset
665 -- Function "*" - with (Natural, String) parameters
kono
parents:
diff changeset
666
kono
parents:
diff changeset
667 TC_Set_Name ("""*""");
kono
parents:
diff changeset
668
kono
parents:
diff changeset
669 if TC_Check (ASF."*"(3, Source_String1)) /= "abcdeabcdeabcde" or
kono
parents:
diff changeset
670 TC_Check (ASF."*"(2, Source_String2)) /= Source_String6 or
kono
parents:
diff changeset
671 TC_Check (ASF."*"(4, Source_String1(1..2))) /= "abababab" or
kono
parents:
diff changeset
672 TC_Check (ASF."*"(0, Source_String1)) /= ""
kono
parents:
diff changeset
673 then
kono
parents:
diff changeset
674 Report.Failed("Incorrect result from Function ""*"" with strings");
kono
parents:
diff changeset
675 end if;
kono
parents:
diff changeset
676
kono
parents:
diff changeset
677 exception
kono
parents:
diff changeset
678 when others => Report.Failed("Exception raised in Test_Block");
kono
parents:
diff changeset
679 end Test_Block;
kono
parents:
diff changeset
680
kono
parents:
diff changeset
681 Report.Result;
kono
parents:
diff changeset
682
kono
parents:
diff changeset
683 end CXA4005;