3 -- Grant of Unlimited Rights
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
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.
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.
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.
41 -- Testing of the function versions of many of the subprograms tested
42 -- here is performed in tests CXA4006-CXA4009.
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.
53 with Ada
.Strings
.Bounded
;
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");
72 -- Instantiations of Bounded String generic package.
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);
79 use type BS1
.Bounded_String
, BS20
.Bounded_String
,
80 BS40
.Bounded_String
, BS80
.Bounded_String
;
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
;
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
;
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
103 if BString_1
/= To_Bounded_String
("B") then
104 Report
.Failed
("Incorrect results from BS1 versions of " &
108 Append
(BString_20
, 'T'); -- Character.
109 Append
(BString_20
, "his string"); -- String.
111 To_Bounded_String
(" is complete."), -- Bounded string.
112 Drop
=> Ada
.Strings
.Right
); -- Drop 4 characters.
114 if BString_20
/= To_Bounded_String
("This string is compl") then
115 Report
.Failed
("Incorrect results from BS20 versions of " &
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
));
128 if not (BString_40
= String_40
and -- (Bounded_String, String)
129 BS80
."="(String_80
, BString_80
)) -- (String, Bounded_String)
131 Report
.Failed
("Incorrect results from function ""="" with " &
132 "string - bounded string parameter combinations");
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");
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)
148 Report
.Failed
("Incorrect results from function ""<"" with " &
149 "string - bounded string parameter combinations");
155 BString_20
:= BS20
.To_Bounded_String
("Sample string");
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)
161 Report
.Failed
("Incorrect results from function ""<="" with " &
162 "string - bounded string parameter combinations");
168 BString_40
:= BS40
.To_Bounded_String
("A MUCH LONGER SAMPLE STRING.");
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)
174 Report
.Failed
("Incorrect results from function "">"" with " &
175 "string - bounded string parameter combinations");
181 BString_80
:= BS80
.To_Bounded_String
(String_80
);
183 if not (BString_80
>= String_80
and
184 BS80
.To_Bounded_String
("Programming") >= "PROGRAMMING" and
185 "test" >= BS80
.To_Bounded_String
("tess"))
187 Report
.Failed
("Incorrect results from function "">="" with " &
188 "string - bounded string parameter combinations");
194 BString_20
:= BS20
.To_Bounded_String
(" Left Spaces ");
195 BS20
.Trim
(Source
=> BString_20
,
196 Side
=> Ada
.Strings
.Left
);
198 if "Left Spaces " /= BString_20
then
199 Report
.Failed
("Incorrect results from Procedure Trim with " &
203 BString_40
:= BS40
.To_Bounded_String
(" Right Spaces ");
204 BS40
.Trim
(BString_40
, Side
=> Ada
.Strings
.Right
);
206 if BString_40
/= " Right Spaces" then
207 Report
.Failed
("Incorrect results from Procedure Trim with " &
211 BString_20
:= BS20
.To_Bounded_String
(" Both Sides ");
212 BS20
.Trim
(BString_20
, Ada
.Strings
.Both
);
214 if BString_20
/= BS20
.To_Bounded_String
("Both Sides") then
215 Report
.Failed
("Incorrect results from Procedure Trim with " &
219 BString_80
:= BS80
.To_Bounded_String
("Centered Spaces");
220 BS80
.Trim
(BString_80
, Ada
.Strings
.Both
);
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");
230 BString_40
:= BS40
.To_Bounded_String
("Test String");
231 BS40
.Head
(Source
=> BString_40
,
232 Count
=> 4); -- Count < Source'Length
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");
239 BString_1
:= BS1
.To_Bounded_String
("X");
240 BS1
.Head
(BString_1
, BS1
.Length
(BString_1
)); -- Count = Source'Length
242 if BString_1
/= "X" then
243 Report
.Failed
("Incorrect results from Procedure Head with " &
244 "the Count parameter equal to Source'Length");
247 BString_20
:= BS20
.To_Bounded_String
("Sample string");
248 BS20
.Head
(BString_20
,
249 Count
=> BS20
.Max_Length
, -- Count > Source'Length
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");
257 BString_20
:= BS20
.To_Bounded_String
("Twenty Characters 20");
258 BS20
.Head
(BString_20
, 22, Pad
=> '*', Drop
=> Ada
.Strings
.Left
);
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");
266 BString_20
:= BS20
.To_Bounded_String
("Short String");
267 BS20
.Head
(BString_20
, 23, '-', Ada
.Strings
.Right
);
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");
278 BString_40
:= BS40
.To_Bounded_String
("Test String");
279 BS40
.Tail
(Source
=> BString_40
,
280 Count
=> 6); -- Count < Source'Length
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");
287 BString_1
:= BS1
.To_Bounded_String
("X");
288 BS1
.Tail
(BString_1
, BS1
.Length
(BString_1
)); -- Count = Source'Length
290 if BString_1
/= "X" then
291 Report
.Failed
("Incorrect results from Procedure Tail with " &
292 "the Count parameter equal to Source'Length");
295 BString_20
:= BS20
.To_Bounded_String
("Sample string");
296 BS20
.Tail
(BString_20
,
297 Count
=> BS20
.Max_Length
, -- Count > Source'Length
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");
305 BString_20
:= BS20
.To_Bounded_String
("Twenty Characters"); -- Len = 17
306 BS20
.Tail
(BString_20
, 22, Pad
=> '*', Drop
=> Ada
.Strings
.Left
);
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");
314 BString_20
:= BS20
.To_Bounded_String
("Maximum Length Chars");
315 BS20
.Tail
(BString_20
, 23, '-', Ada
.Strings
.Right
);
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");
324 when The_Error
: others =>
325 Report
.Failed
("The following exception was raised in the " &
326 "Test_Block: " & Exception_Name
(The_Error
));