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 the subprograms defined in package Ada.Strings.Bounded are
28 -- available, and that they produce correct results. Specifically, check
29 -- the subprograms Append, Count, Element, Find_Token, Head,
30 -- Index_Non_Blank, Replace_Element, Replicate, Tail, To_Bounded_String,
31 -- "&", ">", "<", ">=", "<=", and "*".
34 -- This test, when taken in conjunction with tests CXA400[6,8,9], will
35 -- constitute a test of all the functionality contained in package
36 -- Ada.Strings.Bounded. This test uses a variety of the
37 -- subprograms defined in the bounded string package in ways typical
38 -- of common usage. Different combinations of available subprograms
39 -- are used to accomplish similar bounded string processing goals.
43 -- 06 Dec 94 SAIC ACVC 2.0
44 -- 22 Dec 94 SAIC Changed obsolete constant to Ada.Strings.Space.
49 with Ada
.Strings
.Bounded
;
50 with Ada
.Strings
.Maps
;
57 Report
.Test
("CXA4007", "Check that the subprograms defined in package " &
58 "Ada.Strings.Bounded are available, and that " &
59 "they produce correct results");
64 package BS80
is new Ada
.Strings
.Bounded
.Generic_Bounded_Length
(80);
65 use type BS80
.Bounded_String
;
67 Part1
: constant String := "Rum";
68 Part2
: Character := 'p';
69 Part3
: BS80
.Bounded_String
:= BS80
.To_Bounded_String
("el");
70 Part4
: Character := 's';
71 Part5
: BS80
.Bounded_String
:= BS80
.To_Bounded_String
("tilt");
72 Part6
: String(1..3) := "ski";
79 Token_String
: BS80
.Bounded_String
;
81 CharA
: Character := 'A';
82 CharB
: Character := 'B';
83 CharC
: Character := 'C';
84 CharD
: Character := 'D';
85 CharE
: Character := 'E';
86 CharF
: Character := 'F';
88 ABStr
: String(1..15) := "AAAAABBBBBBBBBB";
89 StrB
: String(1..2) := "BB";
90 StrE
: String(1..2) := "EE";
95 -- Evaluation of the overloaded forms of the "&" operator defined
96 -- for instantiations of Bounded Strings.
98 Full_Catenate_String
:=
99 BS80
."&"(Part2
, -- Char & Bnd Str
100 BS80
."&"(Part3
, -- Bnd Str & Bnd Str
101 BS80
."&"(Part4
, -- Char & Bnd Str
102 BS80
."&"(Part5
, -- Bnd Str & Bnd Str
103 BS80
.To_Bounded_String
(Part6
)))));
105 Full_Catenate_String
:=
106 Part1
& Full_Catenate_String
; -- Str & Bnd Str
107 Full_Catenate_String
:=
108 Full_Catenate_String
& 'n'; -- Bnd Str & Char
111 -- Evaluation of the overloaded forms of function Append.
113 Full_Append_String
:=
114 BS80
.Append
(Part2
, -- Char,Bnd
115 BS80
.Append
(Part3
, -- Bnd, Bnd
116 BS80
.Append
(Part4
, -- Char,Bnd
117 BS80
.Append
(BS80
.To_String
(Part5
), -- Str,Bnd
118 BS80
.To_Bounded_String
(Part6
)))));
120 Full_Append_String
:=
121 BS80
.Append
(BS80
.To_Bounded_String
(Part1
), -- Bnd , Str
122 BS80
.To_String
(Full_Append_String
));
124 Full_Append_String
:=
125 BS80
.Append
(Left
=> Full_Append_String
,
126 Right
=> 'n'); -- Bnd, Char
129 -- Validate the resulting bounded strings.
131 if Full_Catenate_String
< Full_Append_String
or
132 Full_Catenate_String
> Full_Append_String
or
133 not (Full_Catenate_String
= Full_Append_String
and
134 Full_Catenate_String
<= Full_Append_String
and
135 Full_Catenate_String
>= Full_Append_String
)
137 Report
.Failed
("Incorrect results from bounded string catenation" &
142 -- Evaluate the overloaded forms of the Constructor function "*" and
143 -- the Replicate function.
145 Constructed_String
:=
146 (2 * CharA
) & -- "AA"
147 (2 * StrB
) & -- "AABBBB"
148 (3 * BS80
."*"(2, CharC
)) & -- "AABBBBCCCCCC"
150 BS80
.Replicate
(2, CharD
)) & -- "AABBBBCCCCCCDDDDDD"
151 BS80
.Replicate
(2, StrE
) & -- "AABBBBCCCCCCDDDDDDEEEE"
152 BS80
.Replicate
(2, CharF
); -- "AABBBBCCCCCCDDDDDDEEEEFF"
155 -- Use of Function Replicate that involves dropping characters. The
156 -- attempt to replicate the 15 character string six times will exceed
157 -- the 80 character bound of the string. Therefore, the result should
158 -- be the catenation of 5 copies of the 15 character string, followed
159 -- by 5 'A' characters (the first five characters of the 6th
160 -- replication) with the remaining characters of the 6th replication
164 BS80
.Replicate
(Count
=> 6,
165 Item
=> ABStr
, -- "AAAAABBBBBBBBBB"
166 Drop
=> Ada
.Strings
.Right
);
168 if BS80
.Element
(Drop_String
, 1) /= 'A' or
169 BS80
.Element
(Drop_String
, 6) /= 'B' or
170 BS80
.Element
(Drop_String
, 76) /= 'A' or
171 BS80
.Element
(Drop_String
, 80) /= 'A'
173 Report
.Failed
("Incorrect result from Replicate with Drop");
177 -- Use function Index_Non_Blank in the evaluation of the
178 -- Constructed_String.
180 if BS80
.Index_Non_Blank
(Constructed_String
, Ada
.Strings
.Forward
) /=
181 BS80
.To_String
(Constructed_String
)'First or
182 BS80
.Index_Non_Blank
(Constructed_String
, Ada
.Strings
.Backward
) /=
183 BS80
.Length
(Constructed_String
)
185 Report
.Failed
("Incorrect results from constructor functions");
192 -- Define character set objects for use with the Count function.
193 -- Constructed_String = "AABBBBCCCCCCDDDDDDEEEEFF" from above.
195 A_Set
: Ada
.Strings
.Maps
.Character_Set
:=
196 Ada
.Strings
.Maps
.To_Set
(BS80
.Element
(Constructed_String
,1));
197 B_Set
: Ada
.Strings
.Maps
.Character_Set
:=
198 Ada
.Strings
.Maps
.To_Set
(BS80
.Element
(Constructed_String
,3));
199 C_Set
: Ada
.Strings
.Maps
.Character_Set
:=
200 Ada
.Strings
.Maps
.To_Set
(BS80
.Element
(Constructed_String
,7));
201 D_Set
: Ada
.Strings
.Maps
.Character_Set
:=
202 Ada
.Strings
.Maps
.To_Set
(BS80
.Element
(Constructed_String
,13));
203 E_Set
: Ada
.Strings
.Maps
.Character_Set
:=
204 Ada
.Strings
.Maps
.To_Set
(BS80
.Element
(Constructed_String
,19));
205 F_Set
: Ada
.Strings
.Maps
.Character_Set
:=
206 Ada
.Strings
.Maps
.To_Set
(BS80
.Element
(Constructed_String
,23));
214 -- Evaluate the results from function Count by comparing the number
215 -- of A's to the number of F's, B's to E's, and C's to D's in the
216 -- Constructed_String.
217 -- There should be an equal number of each of the characters that
218 -- are being compared (i.e., 2 A's and F's, 4 B's and E's, etc)
220 if BS80
.Count
(Constructed_String
, A_Set
) /=
221 BS80
.Count
(Constructed_String
, F_Set
) or
222 BS80
.Count
(Constructed_String
, B_Set
) /=
223 BS80
.Count
(Constructed_String
, E_Set
) or
224 not (BS80
.Count
(Constructed_String
, C_Set
) =
225 BS80
.Count
(Constructed_String
, D_Set
))
227 Report
.Failed
("Incorrect result from function Count");
231 -- Evaluate the functions Head, Tail, and Find_Token.
232 -- Create the Token_String from the Constructed_String above.
235 BS80
.Tail
(BS80
.Head
(Constructed_String
, 3), 2) & -- "AB" &
236 BS80
.Head
(BS80
.Tail
(Constructed_String
, 13), 2) & -- "CD" &
237 BS80
.Head
(BS80
.Tail
(Constructed_String
, 3), 2); -- "EF"
239 if Token_String
/= BS80
.To_Bounded_String
("ABCDEF") then
240 Report
.Failed
("Incorrect result from Catenation of Token_String");
244 -- Find the starting/ending position of the first A in the
245 -- Token_String (both should be 1, only one A appears in string).
246 -- The Function Head uses the default pad character to return a
247 -- bounded string longer than its input parameter bounded string.
249 BS80
.Find_Token
(BS80
.Head
(Token_String
, 10), -- Default pad.
255 if Start
/= 1 and Stop
/= 1 then
256 Report
.Failed
("Incorrect result from Find_Token - 1");
260 -- Find the starting/ending position of the first non-AB slice in
261 -- the "head" five characters of Token_String (slice CDE at
264 BS80
.Find_Token
(BS80
.Head
(Token_String
, 5), -- "ABCDE"
265 Ada
.Strings
.Maps
."OR"(A_Set
, B_Set
), -- Set (AB)
270 if Start
/= 3 and Stop
/= 5 then
271 Report
.Failed
("Incorrect result from Find_Token - 2");
275 -- Find the starting/ending position of the first CD slice in
276 -- the "tail" eight characters (including two pad characters)
277 -- of Token_String (slice CD at positions 5-6 of the tail
278 -- portion specified)
280 BS80
.Find_Token
(BS80
.Tail
(Token_String
, 8,
281 Ada
.Strings
.Space
), -- " ABCDEF"
282 Ada
.Strings
.Maps
."OR"(C_Set
, D_Set
), -- Set (CD)
287 if Start
/= 5 and Stop
/= 6 then
288 Report
.Failed
("Incorrect result from Find_Token - 3");
292 -- Evaluate the Replace_Element procedure.
294 -- Token_String = "ABCDEF"
296 BS80
.Replace_Element
(Token_String
, 3, BS80
.Element
(Token_String
,4));
298 -- Token_String = "ABDDEF"
300 BS80
.Replace_Element
(Source
=> Token_String
,
302 By
=> BS80
.Element
(Token_String
, 5));
304 -- Token_String = "AEDDEF"
306 BS80
.Replace_Element
(Token_String
,
308 BS80
.Element
(BS80
.Tail
(Token_String
, 2), 2));
310 -- Token_String = "FEDDEF"
311 -- Evaluate this result.
313 if BS80
.Element
(Token_String
, BS80
.To_String
(Token_String
)'First) /=
314 BS80
.Element
(Token_String
, BS80
.To_String
(Token_String
)'Last) or
315 BS80
.Count
(Token_String
, D_Set
) /=
316 BS80
.Count
(Token_String
, E_Set
) or
317 BS80
.Index_Non_Blank
(BS80
.Head
(Token_String
,6)) /=
318 BS80
.Index_Non_Blank
(BS80
.Tail
(Token_String
,6)) or
319 BS80
.Head
(Token_String
, 1) /=
320 BS80
.Tail
(Token_String
, 1)
322 Report
.Failed
("Incorrect result from operations in combination");
328 when others => Report
.Failed
("Exception raised in Test_Block");