OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [ada/] [acats/] [tests/] [cxa/] [cxa4003.a] - Blame information for rev 294

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 294 jeremybenn
-- 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.
15
--
16
--                                    DISCLAIMER
17
--
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
--*
25
--
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.
31
--
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.
40
--
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
52
--
53
--!
54
 
55
with Ada.Strings.Fixed;
56
with Ada.Strings.Maps;
57
with Report;
58
 
59
procedure CXA4003 is
60
 
61
begin
62
 
63
   Report.Test ("CXA4003", "Check that the subprograms defined in package "  &
64
                           "Ada.Strings.Fixed are available, and that they " &
65
                           "produce correct results");
66
 
67
   Test_Block:
68
   declare
69
 
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  := " ";
75
 
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;
79
 
80
 
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);
87
 
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;
97
 
98
      type Data_Base_Type is array (1..DB_Size) of Data_Base_Element_Type;
99
 
100
      Data_Base : Data_Base_Type;
101
 
102
      ---
103
 
104
      Info_String_1 : Info_String_Type :=
105
        "Joe_Jones 123   Sixth_St   San_Diego    CA   98765";
106
 
107
      Info_String_2 : Info_String_Type :=
108
        "Sam_Smith 56789  S._Seventh   Carlsbad  CA   92177";
109
 
110
      Info_String_3 : Info_String_Type :=
111
        "Jane_Brown 1219   Info_Lane  Tuscon     AZ   85643";
112
 
113
 
114
      Info_Strings : Info_String_Storage_Type := (1 => Info_String_1,
115
                                                  2 => Info_String_2,
116
                                                  3 => Info_String_3);
117
 
118
 
119
 
120
      TC_DB_Element_1 : Data_Base_Element_Type :=
121
        ("Joe Jones ", "123  ", "Sixth St  ", "San Diego ", "CA", "98765");
122
 
123
      TC_DB_Element_2 : Data_Base_Element_Type :=
124
        ("Sam Smith ", "56789", "S. Seventh", "Carlsbad  ", "CA", "92177");
125
 
126
      TC_DB_Element_3 : Data_Base_Element_Type :=
127
        ("Jane Brown", "1219 ", "Info Lane ", "Tuscon    ", "AZ", "85643");
128
 
129
      TC_Data_Base : Data_Base_Type := (TC_DB_Element_1,
130
                                        TC_DB_Element_2,
131
                                        TC_DB_Element_3);
132
 
133
      ---
134
 
135
 
136
      procedure Store_Information
137
         (Info_String : in     Info_String_Type;
138
          DB_Record   : in out Data_Base_Element_Type) is
139
 
140
         package AS renames Ada.Strings;
141
         use type AS.Maps.Character_Set;
142
 
143
         UnderScore  : AS.Maps.Character_Sequence := "_";
144
         Blank       : AS.Maps.Character_Sequence := " ";
145
 
146
         Start,
147
         Stop  : Natural := 0;
148
 
149
         Underscore_to_Blank_Map : constant AS.Maps.Character_Mapping :=
150
                            AS.Maps.To_Mapping(From => UnderScore,
151
                                               To   => Blank);
152
 
153
         Numeric_Set    : constant AS.Maps.Character_Set :=
154
                            AS.Maps.To_Set("0123456789");
155
 
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");
163
 
164
      begin
165
 
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).
169
 
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 ;
175
 
176
         -- Store the name field in the data base element field for "Name".
177
 
178
         DB_Record.Name := AS.Fixed.Head(Info_String(1..Stop),
179
                                         DB_Record.Name'Length);
180
 
181
         -- Replace any underscore characters in the name field
182
         -- that were used to separate first/middle/last names.
183
 
184
         AS.Fixed.Translate (DB_Record.Name, Underscore_to_Blank_Map);
185
 
186
 
187
         -- Continue the extraction process; now find the position of
188
         -- the street number in the string.
189
 
190
         Start := Stop + 1;
191
 
192
         AS.Fixed.Find_Token(Info_String(Start..Info_String'Length),
193
                             Numeric_Set,
194
                             AS.Inside,
195
                             Start,
196
                             Stop);
197
 
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.
202
 
203
         AS.Fixed.Move(Source => Info_String(Start..Stop),
204
                       Target => DB_Record.Street_Number);
205
 
206
 
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.
210
 
211
         Start :=
212
           AS.Fixed.Index_Non_Blank(Info_String(Stop+1..Info_String'Length));
213
 
214
         Stop :=
215
           AS.Fixed.Index(Info_String(Start..Info_String'Length),
216
                          Blank_String) - 1;
217
 
218
         -- Store the street name in the appropriate data base element field.
219
 
220
         AS.Fixed.Overwrite(DB_Record.Street_Name,
221
                            1,
222
                            Info_String(Start..Stop));
223
 
224
         -- Replace any underscore characters in the street name field
225
         -- that were used as word separation.
226
 
227
         DB_Record.Street_Name := AS.Fixed.Translate(DB_Record.Street_Name,
228
                                                     Underscore_to_Blank_Map);
229
 
230
 
231
         -- Continue the extraction; remove the city name from the string.
232
 
233
         Start :=
234
           AS.Fixed.Index_Non_Blank(Info_String(Stop+1..Info_String'Length));
235
 
236
         Stop :=
237
           AS.Fixed.Index(Info_String(Start..Info_String'Length),
238
                          Blank_String) - 1;
239
 
240
         -- Store the city name field in the appropriate data base element.
241
 
242
         AS.Fixed.Replace_Slice(DB_Record.City,
243
                                1,
244
                                DB_Record.City'Length,
245
                                Info_String(Start..Stop));
246
 
247
         -- Replace any underscore characters in the city name field
248
         -- that were used as word separation.
249
 
250
         AS.Fixed.Translate (DB_Record.City, Underscore_to_Blank_Map);
251
 
252
 
253
         -- Continue the extraction; remove the state identifier from the
254
         -- info string.
255
 
256
         Start := Stop + 1;
257
 
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);
264
 
265
         -- Store the state indicator into the data base element.
266
 
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);
272
 
273
 
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.
277
 
278
         DB_Record.Zip_Code := AS.Fixed.Tail(Info_String,
279
                                             DB_Record.Zip_Code'Length);
280
 
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;
291
 
292
 
293
   begin
294
 
295
      -- Loop thru the information strings, extract the name and address
296
      -- information, place this info into elements of the data base.
297
 
298
      while not Finished_Processing loop
299
 
300
         Count := Count + 1;
301
 
302
         Store_Information (Info_Strings(Count), Data_Base(Count));
303
 
304
         Finished_Processing := (Count = Number_Of_Info_Strings);
305
 
306
      end loop;
307
 
308
 
309
      -- Verify that the string processing was successful.
310
 
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;
317
 
318
 
319
   exception
320
      when others => Report.Failed ("Exception raised in Test_Block");
321
   end Test_Block;
322
 
323
 
324
   Report.Result;
325
 
326
end CXA4003;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.