aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/ada/acats/tests/cxa/cxa4003.a
blob: cd57a929616a4d01170ad9e958c057e2eca3d552 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
-- CXA4003.A
--
--                             Grant of Unlimited Rights
--
--     Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
--     F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained 
--     unlimited rights in the software and documentation contained herein.
--     Unlimited rights are defined in DFAR 252.227-7013(a)(19).  By making 
--     this public release, the Government intends to confer upon all 
--     recipients unlimited rights  equal to those held by the Government.  
--     These rights include rights to use, duplicate, release or disclose the 
--     released technical data and computer software in whole or in part, in 
--     any manner and for any purpose whatsoever, and to have or permit others 
--     to do so.
--
--                                    DISCLAIMER
--
--     ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
--     DISCLOSED ARE AS IS.  THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED 
--     WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
--     SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE 
--     OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
--     PARTICULAR PURPOSE OF SAID MATERIAL.
--*
--
-- OBJECTIVE:
--      Check that the subprograms defined in package Ada.Strings.Fixed are
--      available, and that they produce correct results.  Specifically, 
--      check the subprograms Index, Index_Non_Blank, Head, Tail, Translate, 
--      Find_Token, Move, Overwrite, and Replace_Slice.
--
-- TEST DESCRIPTION:
--      This test demonstrates how certain fixed string operations could be
--      used in string information processing.  A procedure is defined that
--      will extract portions of a 50 character string that correspond to
--      certain data items (i.e., name, address, state, zip code). These
--      parsed items will then be added to the appropriate fields of data
--      base elements.  These data base elements are then compared for
--      accuracy against a similar set of predefined data base elements.
--
--      A variety of fixed string processing subprograms are used in this
--      test.  Each parsing operation uses a different combination
--      of the available subprograms to accomplish the same goal, therefore
--      continuity of approach to string parsing is not seen in this test.
--      However, a wide variety of possible approaches are demonstrated, while
--      exercising a large number of the total predefined subprograms of
--      package Ada.Strings.Fixed.
--      
--       
-- CHANGE HISTORY:
--      06 Dec 94   SAIC    ACVC 2.0
--
--!

with Ada.Strings.Fixed;
with Ada.Strings.Maps;
with Report;

procedure CXA4003 is

begin

   Report.Test ("CXA4003", "Check that the subprograms defined in package "  &
                           "Ada.Strings.Fixed are available, and that they " &
                           "produce correct results");

   Test_Block:
   declare

      Number_Of_Info_Strings : constant Natural := 3;
      DB_Size                : constant Natural := Number_Of_Info_Strings;
      Count                  : Natural          := 0;
      Finished_Processing    : Boolean          := False;
      Blank_String           : constant String  := " ";

      subtype Info_String_Type         is String (1..50);
      type    Info_String_Storage_Type is 
        array (1..Number_Of_Info_Strings) of Info_String_Type;


      subtype Name_Type                is String (1..10);
      subtype Street_Number_Type       is String (1..5);
      subtype Street_Name_Type         is String (1..10);
      subtype City_Type                is String (1..10);
      subtype State_Type               is String (1..2);
      subtype Zip_Code_Type            is String (1..5);

      type Data_Base_Element_Type is
         record
            Name          : Name_Type          := (others => ' ');
            Street_Number : Street_Number_Type := (others => ' ');
            Street_Name   : Street_Name_Type   := (others => ' ');
            City          : City_Type          := (others => ' ');
            State         : State_Type         := (others => ' ');
            Zip_Code      : Zip_Code_Type      := (others => ' ');
         end record;

      type Data_Base_Type is array (1..DB_Size) of Data_Base_Element_Type;

      Data_Base : Data_Base_Type;

      ---

      Info_String_1 : Info_String_Type := 
        "Joe_Jones 123   Sixth_St   San_Diego    CA   98765"; 

      Info_String_2 : Info_String_Type := 
        "Sam_Smith 56789  S._Seventh   Carlsbad  CA   92177";

      Info_String_3 : Info_String_Type := 
        "Jane_Brown 1219   Info_Lane  Tuscon     AZ   85643";


      Info_Strings : Info_String_Storage_Type := (1 => Info_String_1,
                                                  2 => Info_String_2,
                                                  3 => Info_String_3);



      TC_DB_Element_1 : Data_Base_Element_Type := 
        ("Joe Jones ", "123  ", "Sixth St  ", "San Diego ", "CA", "98765");

      TC_DB_Element_2 : Data_Base_Element_Type := 
        ("Sam Smith ", "56789", "S. Seventh", "Carlsbad  ", "CA", "92177");

      TC_DB_Element_3 : Data_Base_Element_Type := 
        ("Jane Brown", "1219 ", "Info Lane ", "Tuscon    ", "AZ", "85643");

      TC_Data_Base : Data_Base_Type := (TC_DB_Element_1,
                                        TC_DB_Element_2,
                                        TC_DB_Element_3);

      ---


      procedure Store_Information 
         (Info_String : in     Info_String_Type;
          DB_Record   : in out Data_Base_Element_Type) is

         package AS renames Ada.Strings;
         use type AS.Maps.Character_Set;

         UnderScore  : AS.Maps.Character_Sequence := "_";
         Blank       : AS.Maps.Character_Sequence := " ";

         Start,
         Stop  : Natural := 0;

         Underscore_to_Blank_Map : constant AS.Maps.Character_Mapping := 
                            AS.Maps.To_Mapping(From => UnderScore, 
                                               To   => Blank);

         Numeric_Set    : constant AS.Maps.Character_Set :=
                            AS.Maps.To_Set("0123456789");

         Cal            : constant AS.Maps.Character_Sequence := "CA";
         California_Set : constant AS.Maps.Character_Set := 
                            AS.Maps.To_Set(Cal);
         Arizona_Set    : constant AS.Maps.Character_Set := 
                            AS.Maps.To_Set("AZ");
         Nevada_Set     : constant AS.Maps.Character_Set := 
                            AS.Maps.To_Set("NV");

      begin

         -- Find the starting position of the name field (first non-blank),
         -- then, from that position, find the end of the name field (first
         -- blank).

         Start := AS.Fixed.Index_Non_Blank(Info_String); 
         Stop  := AS.Fixed.Index (Info_String(Start..Info_String'Length),
                                  AS.Maps.To_Set(' '),
                                  AS.Inside,
                                  AS.Forward) - 1 ;

         -- Store the name field in the data base element field for "Name".

         DB_Record.Name := AS.Fixed.Head(Info_String(1..Stop), 
                                         DB_Record.Name'Length);

         -- Replace any underscore characters in the name field
         -- that were used to separate first/middle/last names.

         AS.Fixed.Translate (DB_Record.Name, Underscore_to_Blank_Map);

         
         -- Continue the extraction process; now find the position of
         -- the street number in the string.

         Start := Stop + 1;

         AS.Fixed.Find_Token(Info_String(Start..Info_String'Length),
                             Numeric_Set,
                             AS.Inside,
                             Start,
                             Stop);

         -- Store the street number field in the appropriate data base 
         -- element.
         -- No modification of the default parameters of procedure Move
         -- is required.

         AS.Fixed.Move(Source => Info_String(Start..Stop),
                       Target => DB_Record.Street_Number);


         -- Continue the extraction process; find the street name in the
         -- info string.  Skip blanks to the start of the street name, then
         -- search for the index of the next blank character in the string.

         Start :=
           AS.Fixed.Index_Non_Blank(Info_String(Stop+1..Info_String'Length)); 

         Stop := 
           AS.Fixed.Index(Info_String(Start..Info_String'Length),
                          Blank_String) - 1; 

         -- Store the street name in the appropriate data base element field.

         AS.Fixed.Overwrite(DB_Record.Street_Name, 
                            1, 
                            Info_String(Start..Stop));
                           
         -- Replace any underscore characters in the street name field
         -- that were used as word separation.

         DB_Record.Street_Name := AS.Fixed.Translate(DB_Record.Street_Name, 
                                                     Underscore_to_Blank_Map);


         -- Continue the extraction; remove the city name from the string.

         Start :=
           AS.Fixed.Index_Non_Blank(Info_String(Stop+1..Info_String'Length)); 

         Stop := 
           AS.Fixed.Index(Info_String(Start..Info_String'Length), 
                          Blank_String) - 1; 

         -- Store the city name field in the appropriate data base element.

         AS.Fixed.Replace_Slice(DB_Record.City, 
                                1,
                                DB_Record.City'Length,
                                Info_String(Start..Stop));
                           
         -- Replace any underscore characters in the city name field
         -- that were used as word separation.

         AS.Fixed.Translate (DB_Record.City, Underscore_to_Blank_Map);


         -- Continue the extraction; remove the state identifier from the 
         -- info string.

         Start := Stop + 1;

         AS.Fixed.Find_Token(Info_String(Start..Info_String'Length),
                             AS.Maps."OR"(California_Set,
                               AS.Maps."OR"(Nevada_Set, Arizona_Set)),
                             AS.Inside,
                             Start,
                             Stop);

         -- Store the state indicator into the data base element.

         AS.Fixed.Move(Source  => Info_String(Start..Stop),
                       Target  => DB_Record.State,
                       Drop    => Ada.Strings.Right,
                       Justify => Ada.Strings.Left,
                       Pad     => AS.Space);


         -- Continue the extraction process; remove the final data item in 
         -- the info string, the zip code, and place it into the 
         -- corresponding data base element.

         DB_Record.Zip_Code := AS.Fixed.Tail(Info_String, 
                                             DB_Record.Zip_Code'Length);

      exception 
         when AS.Length_Error      =>
            Report.Failed ("Length_Error raised in procedure");
         when AS.Pattern_Error     =>
            Report.Failed ("Pattern_Error raised in procedure");
         when AS.Translation_Error =>
            Report.Failed ("Translation_Error raised in procedure");
         when others            =>
            Report.Failed ("Exception raised in procedure");
      end Store_Information;


   begin

      -- Loop thru the information strings, extract the name and address
      -- information, place this info into elements of the data base.

      while not Finished_Processing loop

         Count := Count + 1;

         Store_Information (Info_Strings(Count), Data_Base(Count));

         Finished_Processing := (Count = Number_Of_Info_Strings);

      end loop;


      -- Verify that the string processing was successful.

      for i in 1..DB_Size loop
         if Data_Base(i) /= TC_Data_Base(i) then
            Report.Failed 
              ("Data processing error on record " & Integer'Image(i));
         end if;
      end loop;


   exception
      when others => Report.Failed ("Exception raised in Test_Block");
   end Test_Block;


   Report.Result;

end CXA4003;