2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / ada / acats / tests / cxa / cxa4003.a
blobcd57a929616a4d01170ad9e958c057e2eca3d552
1 -- CXA4003.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.
16 -- DISCLAIMER
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 --*
26 -- OBJECTIVE:
27 -- Check that the subprograms defined in package Ada.Strings.Fixed are
28 -- available, and that they produce correct results. Specifically,
29 -- check the subprograms Index, Index_Non_Blank, Head, Tail, Translate,
30 -- Find_Token, Move, Overwrite, and Replace_Slice.
32 -- TEST DESCRIPTION:
33 -- This test demonstrates how certain fixed string operations could be
34 -- used in string information processing. A procedure is defined that
35 -- will extract portions of a 50 character string that correspond to
36 -- certain data items (i.e., name, address, state, zip code). These
37 -- parsed items will then be added to the appropriate fields of data
38 -- base elements. These data base elements are then compared for
39 -- accuracy against a similar set of predefined data base elements.
41 -- A variety of fixed string processing subprograms are used in this
42 -- test. Each parsing operation uses a different combination
43 -- of the available subprograms to accomplish the same goal, therefore
44 -- continuity of approach to string parsing is not seen in this test.
45 -- However, a wide variety of possible approaches are demonstrated, while
46 -- exercising a large number of the total predefined subprograms of
47 -- package Ada.Strings.Fixed.
48 --
49 --
50 -- CHANGE HISTORY:
51 -- 06 Dec 94 SAIC ACVC 2.0
53 --!
55 with Ada.Strings.Fixed;
56 with Ada.Strings.Maps;
57 with Report;
59 procedure CXA4003 is
61 begin
63 Report.Test ("CXA4003", "Check that the subprograms defined in package " &
64 "Ada.Strings.Fixed are available, and that they " &
65 "produce correct results");
67 Test_Block:
68 declare
70 Number_Of_Info_Strings : constant Natural := 3;
71 DB_Size : constant Natural := Number_Of_Info_Strings;
72 Count : Natural := 0;
73 Finished_Processing : Boolean := False;
74 Blank_String : constant String := " ";
76 subtype Info_String_Type is String (1..50);
77 type Info_String_Storage_Type is
78 array (1..Number_Of_Info_Strings) of Info_String_Type;
81 subtype Name_Type is String (1..10);
82 subtype Street_Number_Type is String (1..5);
83 subtype Street_Name_Type is String (1..10);
84 subtype City_Type is String (1..10);
85 subtype State_Type is String (1..2);
86 subtype Zip_Code_Type is String (1..5);
88 type Data_Base_Element_Type is
89 record
90 Name : Name_Type := (others => ' ');
91 Street_Number : Street_Number_Type := (others => ' ');
92 Street_Name : Street_Name_Type := (others => ' ');
93 City : City_Type := (others => ' ');
94 State : State_Type := (others => ' ');
95 Zip_Code : Zip_Code_Type := (others => ' ');
96 end record;
98 type Data_Base_Type is array (1..DB_Size) of Data_Base_Element_Type;
100 Data_Base : Data_Base_Type;
104 Info_String_1 : Info_String_Type :=
105 "Joe_Jones 123 Sixth_St San_Diego CA 98765";
107 Info_String_2 : Info_String_Type :=
108 "Sam_Smith 56789 S._Seventh Carlsbad CA 92177";
110 Info_String_3 : Info_String_Type :=
111 "Jane_Brown 1219 Info_Lane Tuscon AZ 85643";
114 Info_Strings : Info_String_Storage_Type := (1 => Info_String_1,
115 2 => Info_String_2,
116 3 => Info_String_3);
120 TC_DB_Element_1 : Data_Base_Element_Type :=
121 ("Joe Jones ", "123 ", "Sixth St ", "San Diego ", "CA", "98765");
123 TC_DB_Element_2 : Data_Base_Element_Type :=
124 ("Sam Smith ", "56789", "S. Seventh", "Carlsbad ", "CA", "92177");
126 TC_DB_Element_3 : Data_Base_Element_Type :=
127 ("Jane Brown", "1219 ", "Info Lane ", "Tuscon ", "AZ", "85643");
129 TC_Data_Base : Data_Base_Type := (TC_DB_Element_1,
130 TC_DB_Element_2,
131 TC_DB_Element_3);
136 procedure Store_Information
137 (Info_String : in Info_String_Type;
138 DB_Record : in out Data_Base_Element_Type) is
140 package AS renames Ada.Strings;
141 use type AS.Maps.Character_Set;
143 UnderScore : AS.Maps.Character_Sequence := "_";
144 Blank : AS.Maps.Character_Sequence := " ";
146 Start,
147 Stop : Natural := 0;
149 Underscore_to_Blank_Map : constant AS.Maps.Character_Mapping :=
150 AS.Maps.To_Mapping(From => UnderScore,
151 To => Blank);
153 Numeric_Set : constant AS.Maps.Character_Set :=
154 AS.Maps.To_Set("0123456789");
156 Cal : constant AS.Maps.Character_Sequence := "CA";
157 California_Set : constant AS.Maps.Character_Set :=
158 AS.Maps.To_Set(Cal);
159 Arizona_Set : constant AS.Maps.Character_Set :=
160 AS.Maps.To_Set("AZ");
161 Nevada_Set : constant AS.Maps.Character_Set :=
162 AS.Maps.To_Set("NV");
164 begin
166 -- Find the starting position of the name field (first non-blank),
167 -- then, from that position, find the end of the name field (first
168 -- blank).
170 Start := AS.Fixed.Index_Non_Blank(Info_String);
171 Stop := AS.Fixed.Index (Info_String(Start..Info_String'Length),
172 AS.Maps.To_Set(' '),
173 AS.Inside,
174 AS.Forward) - 1 ;
176 -- Store the name field in the data base element field for "Name".
178 DB_Record.Name := AS.Fixed.Head(Info_String(1..Stop),
179 DB_Record.Name'Length);
181 -- Replace any underscore characters in the name field
182 -- that were used to separate first/middle/last names.
184 AS.Fixed.Translate (DB_Record.Name, Underscore_to_Blank_Map);
187 -- Continue the extraction process; now find the position of
188 -- the street number in the string.
190 Start := Stop + 1;
192 AS.Fixed.Find_Token(Info_String(Start..Info_String'Length),
193 Numeric_Set,
194 AS.Inside,
195 Start,
196 Stop);
198 -- Store the street number field in the appropriate data base
199 -- element.
200 -- No modification of the default parameters of procedure Move
201 -- is required.
203 AS.Fixed.Move(Source => Info_String(Start..Stop),
204 Target => DB_Record.Street_Number);
207 -- Continue the extraction process; find the street name in the
208 -- info string. Skip blanks to the start of the street name, then
209 -- search for the index of the next blank character in the string.
211 Start :=
212 AS.Fixed.Index_Non_Blank(Info_String(Stop+1..Info_String'Length));
214 Stop :=
215 AS.Fixed.Index(Info_String(Start..Info_String'Length),
216 Blank_String) - 1;
218 -- Store the street name in the appropriate data base element field.
220 AS.Fixed.Overwrite(DB_Record.Street_Name,
222 Info_String(Start..Stop));
224 -- Replace any underscore characters in the street name field
225 -- that were used as word separation.
227 DB_Record.Street_Name := AS.Fixed.Translate(DB_Record.Street_Name,
228 Underscore_to_Blank_Map);
231 -- Continue the extraction; remove the city name from the string.
233 Start :=
234 AS.Fixed.Index_Non_Blank(Info_String(Stop+1..Info_String'Length));
236 Stop :=
237 AS.Fixed.Index(Info_String(Start..Info_String'Length),
238 Blank_String) - 1;
240 -- Store the city name field in the appropriate data base element.
242 AS.Fixed.Replace_Slice(DB_Record.City,
244 DB_Record.City'Length,
245 Info_String(Start..Stop));
247 -- Replace any underscore characters in the city name field
248 -- that were used as word separation.
250 AS.Fixed.Translate (DB_Record.City, Underscore_to_Blank_Map);
253 -- Continue the extraction; remove the state identifier from the
254 -- info string.
256 Start := Stop + 1;
258 AS.Fixed.Find_Token(Info_String(Start..Info_String'Length),
259 AS.Maps."OR"(California_Set,
260 AS.Maps."OR"(Nevada_Set, Arizona_Set)),
261 AS.Inside,
262 Start,
263 Stop);
265 -- Store the state indicator into the data base element.
267 AS.Fixed.Move(Source => Info_String(Start..Stop),
268 Target => DB_Record.State,
269 Drop => Ada.Strings.Right,
270 Justify => Ada.Strings.Left,
271 Pad => AS.Space);
274 -- Continue the extraction process; remove the final data item in
275 -- the info string, the zip code, and place it into the
276 -- corresponding data base element.
278 DB_Record.Zip_Code := AS.Fixed.Tail(Info_String,
279 DB_Record.Zip_Code'Length);
281 exception
282 when AS.Length_Error =>
283 Report.Failed ("Length_Error raised in procedure");
284 when AS.Pattern_Error =>
285 Report.Failed ("Pattern_Error raised in procedure");
286 when AS.Translation_Error =>
287 Report.Failed ("Translation_Error raised in procedure");
288 when others =>
289 Report.Failed ("Exception raised in procedure");
290 end Store_Information;
293 begin
295 -- Loop thru the information strings, extract the name and address
296 -- information, place this info into elements of the data base.
298 while not Finished_Processing loop
300 Count := Count + 1;
302 Store_Information (Info_Strings(Count), Data_Base(Count));
304 Finished_Processing := (Count = Number_Of_Info_Strings);
306 end loop;
309 -- Verify that the string processing was successful.
311 for i in 1..DB_Size loop
312 if Data_Base(i) /= TC_Data_Base(i) then
313 Report.Failed
314 ("Data processing error on record " & Integer'Image(i));
315 end if;
316 end loop;
319 exception
320 when others => Report.Failed ("Exception raised in Test_Block");
321 end Test_Block;
324 Report.Result;
326 end CXA4003;