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.Unbounded versions of subprograms Translate
28 -- (procedure and function), Index, and Count, which use a
29 -- Maps.Character_Mapping_Function input parameter, produce correct
33 -- This test examines the operation of the four subprograms contained
34 -- in the Ada.Strings.Unbounded package that use a
35 -- Character_Mapping_Function parameter to provide the mapping
37 -- Two Character_Mapping_Function objects are defined that reference
38 -- subprograms contained in the Ada.Characters.Handling package;
39 -- To_Lower will return the lower-case form of the character provided
40 -- as the input parameter, To_Upper will return the upper-case form
41 -- of the character input parameter (provided there is an upper-case
43 -- In several instances in this test, the character handling functions
44 -- are referenced directly in the parameter list of the subprograms
45 -- under test, demonstrating another form of expected common usage.
47 -- Results of all subprograms are compared with expected results.
49 -- This test, when taken in conjunction with tests CXA4010, CXA4011,
50 -- CXA4031, and CXA4032 will constitute a test of all the functionality
51 -- contained in package Ada.Strings.Unbounded. This test uses a variety
52 -- of the subprograms defined in the unbounded string package in ways
53 -- typical of common usage.
57 -- 21 Feb 95 SAIC Initial prerelease version
58 -- 21 Apr 95 SAIC Modified header commentary.
62 with Ada
.Strings
.Unbounded
;
63 with Ada
.Strings
.Maps
;
64 with Ada
.Characters
.Handling
;
65 with Ada
.Characters
.Latin_1
;
72 Report
.Test
("CXA4030", "Check that Ada.Strings.Unbounded versions " &
73 "of subprograms Translate (procedure and " &
74 "function), Index, and Count, which use a " &
75 "Maps.Character_Mapping_Function input " &
76 "parameter, produce correct results");
81 package Unb
renames Ada
.Strings
.Unbounded
;
82 use type Unb
.Unbounded_String
;
87 -- The following strings are used in examination of the Translation
90 New_Character_String
: Unb
.Unbounded_String
:=
91 Unb
.To_Unbounded_String
(
94 Latin_1
.LC_AE_Diphthong
&
95 Latin_1
.LC_C_Cedilla
&
97 Latin_1
.LC_I_Circumflex
&
98 Latin_1
.LC_Icelandic_Eth
&
100 Latin_1
.LC_O_Oblique_Stroke
&
101 Latin_1
.LC_Icelandic_Thorn
);
104 TC_New_Character_String
: Unb
.Unbounded_String
:=
105 Unb
.To_Unbounded_String
(
108 Latin_1
.UC_AE_Diphthong
&
109 Latin_1
.UC_C_Cedilla
&
111 Latin_1
.UC_I_Circumflex
&
112 Latin_1
.UC_Icelandic_Eth
&
114 Latin_1
.UC_O_Oblique_Stroke
&
115 Latin_1
.UC_Icelandic_Thorn
);
118 -- In this test, access objects are defined to refer to two functions
119 -- from the Ada.Characters.Handling package. These access objects
120 -- will be provided as parameters to the subprograms under test.
121 -- Note: There will be several examples in this test of these character
122 -- handling functions being referenced directly within the
123 -- parameter list of the subprograms under test.
125 Map_To_Lower_Case_Ptr
: Maps
.Character_Mapping_Function
:=
126 Handling
.To_Lower
'Access;
128 Map_To_Upper_Case_Ptr
: Maps
.Character_Mapping_Function
:=
129 Handling
.To_Upper
'Access;
133 -- Function Index, Forward direction search.
134 -- Note: Several of the following cases use the default value
135 -- Forward for the Going parameter.
137 if Unb
.Index
(Source
=> Unb
.To_Unbounded_String
(
138 "The library package Strings.Unbounded"),
140 Going
=> Ada
.Strings
.Forward
,
141 Mapping
=> Map_To_Lower_Case_Ptr
) /= 29 or
143 Unb
.Index
(Unb
.To_Unbounded_String
(
144 "THE RAIN IN SPAIN FALLS MAINLY ON THE PLAIN"),
146 Mapping
=> Map_To_Lower_Case_Ptr
) /= 6 or
148 Unb
.Index
(Unb
.To_Unbounded_String
("maximum number"),
151 Handling
.To_Lower
'Access) /= 6 or
153 Unb
.Index
(Unb
.To_Unbounded_String
("CoMpLeTeLy MiXeD CaSe StRiNg"),
156 Map_To_Upper_Case_Ptr
) /= 12 or
158 Unb
.Index
(Unb
.To_Unbounded_String
(
159 "STRING WITH NO MATCHING PATTERNS"),
161 Mapping
=> Map_To_Lower_Case_Ptr
) /= 0 or
163 Unb
.Index
(Unb
.To_Unbounded_String
("THIS STRING IS IN UPPER CASE"),
166 Handling
.To_Upper
'Access) /= 3 or
168 Unb
.Index
(Unb
.Null_Unbounded_String
,
170 Mapping
=> Map_To_Lower_Case_Ptr
) /= 0 or
172 Unb
.Index
(Unb
.To_Unbounded_String
("AAABBBaaabbb"),
174 Mapping
=> Handling
.To_Lower
'Access) /= 2
176 Report
.Failed
("Incorrect results from Function Index, going " &
177 "in Forward direction, using a Character Mapping " &
178 "Function parameter");
183 -- Function Index, Backward direction search.
185 if Unb
.Index
(Unb
.To_Unbounded_String
("Case of a Mixed Case String"),
187 Ada
.Strings
.Backward
,
188 Map_To_Lower_Case_Ptr
) /= 17 or
190 Unb
.Index
(Unb
.To_Unbounded_String
("Case of a Mixed Case String"),
192 Ada
.Strings
.Backward
,
193 Mapping
=> Map_To_Upper_Case_Ptr
) /= 17 or
195 Unb
.Index
(Unb
.To_Unbounded_String
("rain, Rain, and more RAIN"),
197 Ada
.Strings
.Backward
,
198 Handling
.To_Lower
'Access) /= 22 or
200 Unb
.Index
(Unb
.To_Unbounded_String
("RIGHT place, right time"),
202 Ada
.Strings
.Backward
,
203 Handling
.To_Upper
'Access) /= 14 or
205 Unb
.Index
(Unb
.To_Unbounded_String
("WOULD MATCH BUT FOR THE CASE"),
206 "WOULD MATCH BUT FOR THE CASE",
207 Going
=> Ada
.Strings
.Backward
,
208 Mapping
=> Map_To_Lower_Case_Ptr
) /= 0
210 Report
.Failed
("Incorrect results from Function Index, going " &
211 "in Backward direction, using a Character Mapping " &
212 "Function parameter");
217 -- Function Index, Pattern_Error if Pattern = Null_String
221 Null_String
: constant String := "";
222 TC_Natural
: Natural := 1000;
224 TC_Natural
:= Index
(To_Unbounded_String
("A Valid Unbounded String"),
226 Going
=> Ada
.Strings
.Forward
,
227 Mapping
=> Handling
.To_Lower
'Access);
228 Report
.Failed
("Pattern_Error not raised by Function Index when " &
229 "given a null pattern string");
231 when Pattern_Error
=> null; -- OK, expected exception.
233 Report
.Failed
("Incorrect exception raised by Function Index " &
234 "using a Character Mapping Function parameter " &
235 "when given a null pattern string");
242 if Unb
.Count
(Source
=> Unb
.To_Unbounded_String
("ABABABA"),
244 Mapping
=> Map_To_Lower_Case_Ptr
) /= 2 or
246 Unb
.Count
(Unb
.To_Unbounded_String
("ABABABA"),
248 Mapping
=> Map_To_Lower_Case_Ptr
) /= 0 or
250 Unb
.Count
(Unb
.To_Unbounded_String
("This IS a MISmatched issue"),
252 Handling
.To_Lower
'Access) /= 4 or
254 Unb
.Count
(Unb
.To_Unbounded_String
("ABABABA"),
256 Map_To_Upper_Case_Ptr
) /= 2 or
258 Unb
.Count
(Unb
.To_Unbounded_String
("This IS a MISmatched issue"),
260 Mapping
=> Map_To_Upper_Case_Ptr
) /= 0 or
262 Unb
.Count
(Unb
.To_Unbounded_String
(
263 "She sells sea shells by the sea shore"),
265 Handling
.To_Lower
'Access) /= 8 or
267 Unb
.Count
(Unb
.Null_Unbounded_String
,
269 Map_To_Upper_Case_Ptr
) /= 0
271 Report
.Failed
("Incorrect results from Function Count, using " &
272 "a Character Mapping Function parameter");
277 -- Function Count, Pattern_Error if Pattern = Null_String
280 use Ada
.Strings
.Unbounded
;
281 Null_Pattern_String
: constant String := "";
282 TC_Natural
: Natural := 1000;
284 TC_Natural
:= Count
(To_Unbounded_String
("A Valid String"),
286 Map_To_Lower_Case_Ptr
);
287 Report
.Failed
("Pattern_Error not raised by Function Count using " &
288 "a Character Mapping Function parameter when " &
289 "given a null pattern string");
291 when Pattern_Error
=> null; -- OK, expected exception.
293 Report
.Failed
("Incorrect exception raised by Function Count " &
294 "using a Character Mapping Function parameter " &
295 "when given a null pattern string");
300 -- Function Translate.
302 if Unb
.Translate
(Source
=> Unb
.To_Unbounded_String
(
303 "A Sample Mixed Case String"),
304 Mapping
=> Map_To_Lower_Case_Ptr
) /=
305 Unb
.To_Unbounded_String
("a sample mixed case string") or
307 Unb
.Translate
(Unb
.To_Unbounded_String
("ALL LOWER CASE"),
308 Handling
.To_Lower
'Access) /=
309 Unb
.To_Unbounded_String
("all lower case") or
311 Unb
.Translate
(Unb
.To_Unbounded_String
("end with lower case"),
312 Map_To_Lower_Case_Ptr
) /=
313 Unb
.To_Unbounded_String
("end with lower case") or
315 Unb
.Translate
(Unb
.Null_Unbounded_String
,
316 Handling
.To_Lower
'Access) /=
317 Unb
.Null_Unbounded_String
or
319 Unb
.Translate
(Unb
.To_Unbounded_String
("start with lower case"),
320 Map_To_Upper_Case_Ptr
) /=
321 Unb
.To_Unbounded_String
("START WITH LOWER CASE") or
323 Unb
.Translate
(Unb
.To_Unbounded_String
("ALL UPPER CASE STRING"),
324 Handling
.To_Upper
'Access) /=
325 Unb
.To_Unbounded_String
("ALL UPPER CASE STRING") or
327 Unb
.Translate
(Unb
.To_Unbounded_String
(
328 "LoTs Of MiXeD CaSe ChArAcTeRs"),
329 Map_To_Upper_Case_Ptr
) /=
330 Unb
.To_Unbounded_String
("LOTS OF MIXED CASE CHARACTERS") or
332 Unb
.Translate
(New_Character_String
,
333 Handling
.To_Upper
'Access) /=
334 TC_New_Character_String
337 Report
.Failed
("Incorrect results from Function Translate, using " &
338 "a Character Mapping Function parameter");
343 -- Procedure Translate.
347 use Ada
.Strings
.Unbounded
;
348 use Ada
.Characters
.Handling
;
350 Str_1
: Unbounded_String
:=
351 To_Unbounded_String
("AN ALL UPPER CASE STRING");
352 Str_2
: Unbounded_String
:=
353 To_Unbounded_String
("A Mixed Case String");
354 Str_3
: Unbounded_String
:=
355 To_Unbounded_String
("a string with lower case letters");
356 TC_Str_1
: constant Unbounded_String
:= Str_1
;
357 TC_Str_3
: constant Unbounded_String
:= Str_3
;
361 Translate
(Source
=> Str_1
, Mapping
=> Map_To_Lower_Case_Ptr
);
363 if Str_1
/= To_Unbounded_String
("an all upper case string") then
364 Report
.Failed
("Incorrect result from Procedure Translate - 1");
367 Translate
(Source
=> Str_1
, Mapping
=> Map_To_Upper_Case_Ptr
);
369 if Str_1
/= TC_Str_1
then
370 Report
.Failed
("Incorrect result from Procedure Translate - 2");
373 Translate
(Str_2
, Mapping
=> Map_To_Lower_Case_Ptr
);
375 if Str_2
/= To_Unbounded_String
("a mixed case string") then
376 Report
.Failed
("Incorrect result from Procedure Translate - 3");
379 Translate
(Str_2
, Mapping
=> To_Upper
'Access);
381 if Str_2
/= To_Unbounded_String
("A MIXED CASE STRING") then
382 Report
.Failed
("Incorrect result from Procedure Translate - 4");
385 Translate
(Str_3
, To_Lower
'Access);
387 if Str_3
/= TC_Str_3
then
388 Report
.Failed
("Incorrect result from Procedure Translate - 5");
391 Translate
(Str_3
, To_Upper
'Access);
394 To_Unbounded_String
("A STRING WITH LOWER CASE LETTERS")
396 Report
.Failed
("Incorrect result from Procedure Translate - 6");
399 Translate
(New_Character_String
, Map_To_Upper_Case_Ptr
);
401 if New_Character_String
/= TC_New_Character_String
then
402 Report
.Failed
("Incorrect result from Procedure Translate - 6");
409 when others => Report
.Failed
("Exception raised in Test_Block");