1 |
294 |
jeremybenn |
-- CXA4028.A
|
2 |
|
|
--
|
3 |
|
|
-- Grant of Unlimited Rights
|
4 |
|
|
--
|
5 |
|
|
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
|
6 |
|
|
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
|
7 |
|
|
-- unlimited rights in the software and documentation contained herein.
|
8 |
|
|
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
|
9 |
|
|
-- this public release, the Government intends to confer upon all
|
10 |
|
|
-- recipients unlimited rights equal to those held by the Government.
|
11 |
|
|
-- These rights include rights to use, duplicate, release or disclose the
|
12 |
|
|
-- released technical data and computer software in whole or in part, in
|
13 |
|
|
-- any manner and for any purpose whatsoever, and to have or permit others
|
14 |
|
|
-- to do so.
|
15 |
|
|
--
|
16 |
|
|
-- DISCLAIMER
|
17 |
|
|
--
|
18 |
|
|
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
|
19 |
|
|
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
|
20 |
|
|
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
|
21 |
|
|
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
|
22 |
|
|
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
|
23 |
|
|
-- PARTICULAR PURPOSE OF SAID MATERIAL.
|
24 |
|
|
--*
|
25 |
|
|
--
|
26 |
|
|
-- OBJECTIVE:
|
27 |
|
|
-- Check that Ada.Strings.Bounded procedures Append, Head, Tail, and
|
28 |
|
|
-- Trim, and relational operator functions "=", ">", ">=", "<", "<="
|
29 |
|
|
-- with parameter combinations of type String and Bounded_String,
|
30 |
|
|
-- produce correct results.
|
31 |
|
|
--
|
32 |
|
|
-- TEST DESCRIPTION:
|
33 |
|
|
-- This test examines the operation of several subprograms from within
|
34 |
|
|
-- the Ada.Strings.Bounded package. Four different instantiations of
|
35 |
|
|
-- Ada.Strings.Bounded.Generic_Bounded_Length provide packages defined
|
36 |
|
|
-- to manipulate bounded strings of lengths 1, 20, 40, and 80.
|
37 |
|
|
-- Examples of the above mentioned procedures and relational operators
|
38 |
|
|
-- from each of these instantiations are tested, with results compared
|
39 |
|
|
-- against expected output.
|
40 |
|
|
--
|
41 |
|
|
-- Testing of the function versions of many of the subprograms tested
|
42 |
|
|
-- here is performed in tests CXA4006-CXA4009.
|
43 |
|
|
--
|
44 |
|
|
--
|
45 |
|
|
-- CHANGE HISTORY:
|
46 |
|
|
-- 16 Feb 95 SAIC Initial prerelease version
|
47 |
|
|
-- 10 Mar 95 SAIC Incorporated reviewer comments.
|
48 |
|
|
-- 15 Apr 96 SAIC Incorporated reviewer comments for ACVC 2.1.
|
49 |
|
|
--
|
50 |
|
|
--!
|
51 |
|
|
|
52 |
|
|
with Ada.Exceptions;
|
53 |
|
|
with Ada.Strings.Bounded;
|
54 |
|
|
with Report;
|
55 |
|
|
|
56 |
|
|
procedure CXA4028 is
|
57 |
|
|
|
58 |
|
|
begin
|
59 |
|
|
|
60 |
|
|
Report.Test ("CXA4028", "Check that Ada.Strings.Bounded procedures " &
|
61 |
|
|
"Append, Head, Tail, and Trim, and relational " &
|
62 |
|
|
"operator functions =, >, >=, <, <= with " &
|
63 |
|
|
"parameter combinations of type String and " &
|
64 |
|
|
"Bounded_String, produce correct results");
|
65 |
|
|
|
66 |
|
|
Test_Block:
|
67 |
|
|
declare
|
68 |
|
|
|
69 |
|
|
use Ada.Exceptions;
|
70 |
|
|
use Ada.Strings;
|
71 |
|
|
|
72 |
|
|
-- Instantiations of Bounded String generic package.
|
73 |
|
|
|
74 |
|
|
package BS1 is new Ada.Strings.Bounded.Generic_Bounded_Length(1);
|
75 |
|
|
package BS20 is new Ada.Strings.Bounded.Generic_Bounded_Length(20);
|
76 |
|
|
package BS40 is new Ada.Strings.Bounded.Generic_Bounded_Length(40);
|
77 |
|
|
package BS80 is new Ada.Strings.Bounded.Generic_Bounded_Length(80);
|
78 |
|
|
|
79 |
|
|
use type BS1.Bounded_String, BS20.Bounded_String,
|
80 |
|
|
BS40.Bounded_String, BS80.Bounded_String;
|
81 |
|
|
|
82 |
|
|
String_1 : String(1..1) := "A";
|
83 |
|
|
String_20 : String(1..20) := "ABCDEFGHIJKLMNOPQRST";
|
84 |
|
|
String_40 : String(1..40) := "abcdefghijklmnopqrst" & String_20;
|
85 |
|
|
String_80 : String(1..80) := String_40 & String_40;
|
86 |
|
|
|
87 |
|
|
BString_1 : BS1.Bounded_String := BS1.Null_Bounded_String;
|
88 |
|
|
BString_20 : BS20.Bounded_String := BS20.Null_Bounded_String;
|
89 |
|
|
BString_40 : BS40.Bounded_String := BS40.Null_Bounded_String;
|
90 |
|
|
BString_80 : BS80.Bounded_String := BS80.Null_Bounded_String;
|
91 |
|
|
|
92 |
|
|
begin
|
93 |
|
|
|
94 |
|
|
-- Procedure Append.
|
95 |
|
|
|
96 |
|
|
declare
|
97 |
|
|
use BS1, BS20;
|
98 |
|
|
begin
|
99 |
|
|
Append(Source => BString_1, New_Item => To_Bounded_String("A"));
|
100 |
|
|
Append(BString_1, "B", Ada.Strings.Left);
|
101 |
|
|
Append(BString_1, 'C', Drop => Ada.Strings.Right); -- Drop appended
|
102 |
|
|
-- character.
|
103 |
|
|
if BString_1 /= To_Bounded_String("B") then
|
104 |
|
|
Report.Failed("Incorrect results from BS1 versions of " &
|
105 |
|
|
"procedure Append");
|
106 |
|
|
end if;
|
107 |
|
|
|
108 |
|
|
Append(BString_20, 'T'); -- Character.
|
109 |
|
|
Append(BString_20, "his string"); -- String.
|
110 |
|
|
Append(BString_20,
|
111 |
|
|
To_Bounded_String(" is complete."), -- Bounded string.
|
112 |
|
|
Drop => Ada.Strings.Right); -- Drop 4 characters.
|
113 |
|
|
|
114 |
|
|
if BString_20 /= To_Bounded_String("This string is compl") then
|
115 |
|
|
Report.Failed("Incorrect results from BS20 versions of " &
|
116 |
|
|
"procedure Append");
|
117 |
|
|
end if;
|
118 |
|
|
end;
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
-- Operator "=".
|
122 |
|
|
|
123 |
|
|
BString_40 := BS40.To_Bounded_String(String_40);
|
124 |
|
|
BString_80 := BS80.To_Bounded_String(
|
125 |
|
|
BS40.To_String(BString_40) &
|
126 |
|
|
BS40.To_String(BString_40));
|
127 |
|
|
|
128 |
|
|
if not (BString_40 = String_40 and -- (Bounded_String, String)
|
129 |
|
|
BS80."="(String_80, BString_80)) -- (String, Bounded_String)
|
130 |
|
|
then
|
131 |
|
|
Report.Failed("Incorrect results from function ""="" with " &
|
132 |
|
|
"string - bounded string parameter combinations");
|
133 |
|
|
end if;
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
-- Operator "<".
|
137 |
|
|
|
138 |
|
|
BString_1 := BS1.To_Bounded_String("cat", -- string "c" only.
|
139 |
|
|
Drop => Ada.Strings.Right);
|
140 |
|
|
BString_20 := BS20.To_Bounded_String("Santa Claus");
|
141 |
|
|
|
142 |
|
|
if BString_1 < "C" or -- (Bounded_String, String)
|
143 |
|
|
BS1."<"(BString_1,"c") or -- (Bounded_String, String)
|
144 |
|
|
"x" < BString_1 or -- (String, Bounded_String)
|
145 |
|
|
BString_20 < "Santa " or -- (Bounded_String, String)
|
146 |
|
|
"Santa and his Elves" < BString_20 -- (String, Bounded_String)
|
147 |
|
|
then
|
148 |
|
|
Report.Failed("Incorrect results from function ""<"" with " &
|
149 |
|
|
"string - bounded string parameter combinations");
|
150 |
|
|
end if;
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
-- Operator "<=".
|
154 |
|
|
|
155 |
|
|
BString_20 := BS20.To_Bounded_String("Sample string");
|
156 |
|
|
|
157 |
|
|
if BString_20 <= "Sample strin" or -- (Bounded_String, String)
|
158 |
|
|
"sample string" <= BString_20 or -- (String, Bounded_String)
|
159 |
|
|
not("Sample string" <= BString_20) -- (String, Bounded_String)
|
160 |
|
|
then
|
161 |
|
|
Report.Failed("Incorrect results from function ""<="" with " &
|
162 |
|
|
"string - bounded string parameter combinations");
|
163 |
|
|
end if;
|
164 |
|
|
|
165 |
|
|
|
166 |
|
|
-- Operator ">".
|
167 |
|
|
|
168 |
|
|
BString_40 := BS40.To_Bounded_String("A MUCH LONGER SAMPLE STRING.");
|
169 |
|
|
|
170 |
|
|
if BString_40 > "A much longer sample string" or -- (Bnd_Str, Str)
|
171 |
|
|
String_20 > BS40.To_Bounded_String(String_40) or -- (Str, Bnd_Str)
|
172 |
|
|
BS40.To_Bounded_String("ABCDEFGH") > "abcdefgh" -- (Str, Bnd_Str)
|
173 |
|
|
then
|
174 |
|
|
Report.Failed("Incorrect results from function "">"" with " &
|
175 |
|
|
"string - bounded string parameter combinations");
|
176 |
|
|
end if;
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
-- Operator ">=".
|
180 |
|
|
|
181 |
|
|
BString_80 := BS80.To_Bounded_String(String_80);
|
182 |
|
|
|
183 |
|
|
if not (BString_80 >= String_80 and
|
184 |
|
|
BS80.To_Bounded_String("Programming") >= "PROGRAMMING" and
|
185 |
|
|
"test" >= BS80.To_Bounded_String("tess"))
|
186 |
|
|
then
|
187 |
|
|
Report.Failed("Incorrect results from function "">="" with " &
|
188 |
|
|
"string - bounded string parameter combinations");
|
189 |
|
|
end if;
|
190 |
|
|
|
191 |
|
|
|
192 |
|
|
-- Procedure Trim
|
193 |
|
|
|
194 |
|
|
BString_20 := BS20.To_Bounded_String(" Left Spaces ");
|
195 |
|
|
BS20.Trim(Source => BString_20,
|
196 |
|
|
Side => Ada.Strings.Left);
|
197 |
|
|
|
198 |
|
|
if "Left Spaces " /= BString_20 then
|
199 |
|
|
Report.Failed("Incorrect results from Procedure Trim with " &
|
200 |
|
|
"Side = Left");
|
201 |
|
|
end if;
|
202 |
|
|
|
203 |
|
|
BString_40 := BS40.To_Bounded_String(" Right Spaces ");
|
204 |
|
|
BS40.Trim(BString_40, Side => Ada.Strings.Right);
|
205 |
|
|
|
206 |
|
|
if BString_40 /= " Right Spaces" then
|
207 |
|
|
Report.Failed("Incorrect results from Procedure Trim with " &
|
208 |
|
|
"Side = Right");
|
209 |
|
|
end if;
|
210 |
|
|
|
211 |
|
|
BString_20 := BS20.To_Bounded_String(" Both Sides ");
|
212 |
|
|
BS20.Trim(BString_20, Ada.Strings.Both);
|
213 |
|
|
|
214 |
|
|
if BString_20 /= BS20.To_Bounded_String("Both Sides") then
|
215 |
|
|
Report.Failed("Incorrect results from Procedure Trim with " &
|
216 |
|
|
"Side = Both");
|
217 |
|
|
end if;
|
218 |
|
|
|
219 |
|
|
BString_80 := BS80.To_Bounded_String("Centered Spaces");
|
220 |
|
|
BS80.Trim(BString_80, Ada.Strings.Both);
|
221 |
|
|
|
222 |
|
|
if BString_80 /= BS80.To_Bounded_String("Centered Spaces") then
|
223 |
|
|
Report.Failed("Incorrect results from Procedure Trim with " &
|
224 |
|
|
"no blank spaces on the ends of the string");
|
225 |
|
|
end if;
|
226 |
|
|
|
227 |
|
|
|
228 |
|
|
-- Procedure Head
|
229 |
|
|
|
230 |
|
|
BString_40 := BS40.To_Bounded_String("Test String");
|
231 |
|
|
BS40.Head(Source => BString_40,
|
232 |
|
|
Count => 4); -- Count < Source'Length
|
233 |
|
|
|
234 |
|
|
if BString_40 /= BS40.To_Bounded_String("Test") then
|
235 |
|
|
Report.Failed("Incorrect results from Procedure Head with " &
|
236 |
|
|
"the Count parameter less than Source'Length");
|
237 |
|
|
end if;
|
238 |
|
|
|
239 |
|
|
BString_1 := BS1.To_Bounded_String("X");
|
240 |
|
|
BS1.Head(BString_1, BS1.Length(BString_1)); -- Count = Source'Length
|
241 |
|
|
|
242 |
|
|
if BString_1 /= "X" then
|
243 |
|
|
Report.Failed("Incorrect results from Procedure Head with " &
|
244 |
|
|
"the Count parameter equal to Source'Length");
|
245 |
|
|
end if;
|
246 |
|
|
|
247 |
|
|
BString_20 := BS20.To_Bounded_String("Sample string");
|
248 |
|
|
BS20.Head(BString_20,
|
249 |
|
|
Count => BS20.Max_Length, -- Count > Source'Length
|
250 |
|
|
Pad => '*');
|
251 |
|
|
|
252 |
|
|
if BString_20 /= BS20.To_Bounded_String("Sample string*******") then
|
253 |
|
|
Report.Failed("Incorrect results from Procedure Head with " &
|
254 |
|
|
"the Count parameter greater than Source'Length");
|
255 |
|
|
end if;
|
256 |
|
|
|
257 |
|
|
BString_20 := BS20.To_Bounded_String("Twenty Characters 20");
|
258 |
|
|
BS20.Head(BString_20, 22, Pad => '*', Drop => Ada.Strings.Left);
|
259 |
|
|
|
260 |
|
|
if BString_20 /= "enty Characters 20**" then
|
261 |
|
|
Report.Failed("Incorrect results from Procedure Head with " &
|
262 |
|
|
"the Count parameter greater than Source'Length, " &
|
263 |
|
|
"and the Drop parameter = Left");
|
264 |
|
|
end if;
|
265 |
|
|
|
266 |
|
|
BString_20 := BS20.To_Bounded_String("Short String");
|
267 |
|
|
BS20.Head(BString_20, 23, '-', Ada.Strings.Right);
|
268 |
|
|
|
269 |
|
|
if ("Short String--------") /= BString_20 then
|
270 |
|
|
Report.Failed("Incorrect results from Procedure Head with " &
|
271 |
|
|
"the Count parameter greater than Source'Length, " &
|
272 |
|
|
"and the Drop parameter = Right");
|
273 |
|
|
end if;
|
274 |
|
|
|
275 |
|
|
|
276 |
|
|
-- Procedure Tail
|
277 |
|
|
|
278 |
|
|
BString_40 := BS40.To_Bounded_String("Test String");
|
279 |
|
|
BS40.Tail(Source => BString_40,
|
280 |
|
|
Count => 6); -- Count < Source'Length
|
281 |
|
|
|
282 |
|
|
if BString_40 /= BS40.To_Bounded_String("String") then
|
283 |
|
|
Report.Failed("Incorrect results from Procedure Tail with " &
|
284 |
|
|
"the Count parameter less than Source'Length");
|
285 |
|
|
end if;
|
286 |
|
|
|
287 |
|
|
BString_1 := BS1.To_Bounded_String("X");
|
288 |
|
|
BS1.Tail(BString_1, BS1.Length(BString_1)); -- Count = Source'Length
|
289 |
|
|
|
290 |
|
|
if BString_1 /= "X" then
|
291 |
|
|
Report.Failed("Incorrect results from Procedure Tail with " &
|
292 |
|
|
"the Count parameter equal to Source'Length");
|
293 |
|
|
end if;
|
294 |
|
|
|
295 |
|
|
BString_20 := BS20.To_Bounded_String("Sample string");
|
296 |
|
|
BS20.Tail(BString_20,
|
297 |
|
|
Count => BS20.Max_Length, -- Count > Source'Length
|
298 |
|
|
Pad => '*');
|
299 |
|
|
|
300 |
|
|
if BString_20 /= BS20.To_Bounded_String("*******Sample string") then
|
301 |
|
|
Report.Failed("Incorrect results from Procedure Tail with " &
|
302 |
|
|
"the Count parameter greater than Source'Length");
|
303 |
|
|
end if;
|
304 |
|
|
|
305 |
|
|
BString_20 := BS20.To_Bounded_String("Twenty Characters"); -- Len = 17
|
306 |
|
|
BS20.Tail(BString_20, 22, Pad => '*', Drop => Ada.Strings.Left);
|
307 |
|
|
|
308 |
|
|
if BString_20 /= "***Twenty Characters" then
|
309 |
|
|
Report.Failed("Incorrect results from Procedure Tail with " &
|
310 |
|
|
"the Count parameter greater than Source'Length, " &
|
311 |
|
|
"and the Drop parameter = Left");
|
312 |
|
|
end if;
|
313 |
|
|
|
314 |
|
|
BString_20 := BS20.To_Bounded_String("Maximum Length Chars");
|
315 |
|
|
BS20.Tail(BString_20, 23, '-', Ada.Strings.Right);
|
316 |
|
|
|
317 |
|
|
if ("---Maximum Length Ch") /= BString_20 then
|
318 |
|
|
Report.Failed("Incorrect results from Procedure Tail with " &
|
319 |
|
|
"the Count parameter greater than Source'Length, " &
|
320 |
|
|
"and the Drop parameter = Right");
|
321 |
|
|
end if;
|
322 |
|
|
|
323 |
|
|
exception
|
324 |
|
|
when The_Error : others =>
|
325 |
|
|
Report.Failed ("The following exception was raised in the " &
|
326 |
|
|
"Test_Block: " & Exception_Name(The_Error));
|
327 |
|
|
end Test_Block;
|
328 |
|
|
|
329 |
|
|
Report.Result;
|
330 |
|
|
|
331 |
|
|
end CXA4028;
|