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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [ada/] [acats/] [tests/] [cxg/] [cxg1003.a] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 149 jeremybenn
-- CXG1003.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 the package Text_IO.Complex_IO
28
--      provide correct results.
29
--
30
-- TEST DESCRIPTION:
31
--      The generic package Ada.Numerics.Generic_Complex_Types is instantiated
32
--      with a real type (new Float). The resulting new package is used as
33
--      the generic actual to package Complex_IO.
34
--      Two different versions of Put and Get are examined in this test,
35
--      those that input/output complex data values from/to Text_IO files,
36
--      and those that input/output complex data values from/to strings.
37
--      Two procedures are defined to perform the file data manipulations;
38
--      one to place complex data into the file, and one to retrieve the data
39
--      from the file and verify its correctness.
40
--      Complex data is also put into string variables using the Procedure
41
--      Put for strings, and this data is then retrieved and reconverted into
42
--      complex values using the Get procedure.
43
--
44
--
45
-- APPLICABILITY CRITERIA:
46
--      This test is only applicable to implementations that:
47
--         support Annex G,
48
--         support Text_IO and external files
49
--
50
--
51
-- CHANGE HISTORY:
52
--      06 Dec 94   SAIC    ACVC 2.0
53
--      29 Dec 94   SAIC    Modified Width parameter in Get function calls.
54
--      16 Nov 95   SAIC    Corrected visibility problems for ACVC 2.0.1.
55
--      29 Sep 96   SAIC    Incorporated reviewer comments.
56
--
57
--!
58
 
59
with Ada.Text_IO.Complex_IO;
60
with Ada.Numerics.Generic_Complex_Types;
61
with Report;
62
 
63
procedure CXG1003 is
64
begin
65
 
66
   Report.Test ("CXG1003", "Check that the subprograms defined in " &
67
                           "the package Text_IO.Complex_IO " &
68
                           "provide correct results");
69
 
70
   Test_for_Text_IO_Support:
71
   declare
72
      use Ada;
73
 
74
      Data_File     : Ada.Text_IO.File_Type;
75
      Data_Filename : constant String := Report.Legal_File_Name;
76
 
77
   begin
78
 
79
      -- An application creates a text file in mode Out_File, with the
80
      -- intention of entering complex data into the file as appropriate.
81
      -- In the event that the particular environment where the application
82
      -- is running does not support Text_IO, Use_Error or Name_Error will be
83
      -- raised on calls to Text_IO operations.  Either of these exceptions
84
      -- will be handled to produce a Not_Applicable result.
85
 
86
      Text_IO.Create (File => Data_File,
87
                      Mode => Ada.Text_IO.Out_File,
88
                      Name => Data_Filename);
89
 
90
      Test_Block:
91
      declare
92
 
93
         TC_Verbose : Boolean := False;
94
 
95
         type Real_Type is new Float;
96
 
97
         package Complex_Pack is new
98
           Ada.Numerics.Generic_Complex_Types(Real_Type);
99
 
100
         package C_IO is new Ada.Text_IO.Complex_IO(Complex_Pack);
101
 
102
         use Ada.Text_IO, C_IO;
103
         use type Complex_Pack.Complex;
104
 
105
         Number_Of_Complex_Items : constant := 6;
106
         Number_Of_Error_Items   : constant := 2;
107
 
108
         TC_Complex              : Complex_Pack.Complex;
109
         TC_Last_Character_Read  : Positive;
110
 
111
         Complex_Array : array (1..Number_Of_Complex_Items)
112
           of Complex_Pack.Complex := ( (3.0, 9.0),
113
                                        (4.0, 7.0),
114
                                        (5.0, 6.0),
115
                                        (6.0, 3.0),
116
                                        (2.0, 5.0),
117
                                        (3.0, 7.0) );
118
 
119
 
120
         procedure Load_Data_File (The_File : in out Text_IO.File_Type) is
121
            use Ada.Text_IO;
122
         begin
123
            -- This procedure does not create, open, or close the data file;
124
            -- The_File file object must be Open at this point.
125
            -- This procedure is designed to load complex data into a data
126
            -- file twice, first using Text_IO, then Complex_IO.  In this
127
            -- first case, the complex data values are entered as strings,
128
            -- assuming a variety of legal formats, as provided in the
129
            -- reference manual.
130
 
131
            Put_Line(The_File, "(3.0, 9.0)");
132
            Put_Line(The_File, "+4. +7.");    -- Relaxed real literal format.
133
            Put_Line(The_File, "(5.0 6.)");
134
            Put_Line(The_File, "6., 3.0");
135
            Put_Line(The_File, "  (  2.0  ,  5.0  )  ");
136
            Put_Line(The_File, "(");           -- Complex data separated over
137
            Put_Line(The_File, "3.0");         -- several (5) lines.
138
            Put_Line(The_File, " , ");
139
            Put_Line(The_File, "7.0  ");
140
            Put_Line(The_File, ")");
141
 
142
            if TC_Verbose then
143
               Report.Comment("Complex values entered into data file using " &
144
                              "Text_IO, Procedure Load_Data_File");
145
            end if;
146
 
147
            -- Use the Complex_IO procedure Put to enter Complex data items
148
            -- into the data file.
149
            -- Note: Data is being entered into the file for the *second* time
150
            --       at this point. (Using Complex_IO here, Text_IO above)
151
 
152
            for i in 1..Number_Of_Complex_Items loop
153
               C_IO.Put(File => The_File,
154
                        Item => Complex_Array(i),
155
                        Fore => 1,
156
                        Aft  => 1,
157
                        Exp  => 0);
158
            end loop;
159
 
160
            if TC_Verbose then
161
               Report.Comment("Complex values entered into data file using " &
162
                              "Complex_IO, Procedure Load_Data_File");
163
            end if;
164
 
165
            Put_Line(The_File, "(5A,3)");      -- data to raise Data_Error.
166
            Put_Line(The_File, "(3.0,,8.0)");  -- data to raise Data_Error.
167
 
168
         end Load_Data_File;
169
 
170
 
171
 
172
         procedure Process_Data_File (The_File : in out Text_IO.File_Type) is
173
             TC_Complex : Complex_Pack.Complex := (0.0, 0.0);
174
             TC_Width   : Integer := 0;
175
         begin
176
            -- This procedure does not create, open, or close the data file;
177
            -- The_File file object must be Open at this point.
178
            -- Use procedure Get (for Files) to extract the complex data from
179
            -- the Text_IO file.  This data was placed into the file using
180
            -- Text_IO.
181
 
182
 
183
            for i in 1..Number_Of_Complex_Items loop
184
 
185
               C_IO.Get(The_File, TC_Complex, TC_Width);
186
 
187
               if TC_Complex /= Complex_Array(i) then
188
                  Report.Failed("Incorrect complex data read from file " &
189
                                "when using Text_IO procedure Get, "     &
190
                                "data item #" & Integer'Image(i));
191
               end if;
192
            end loop;
193
 
194
            if TC_Verbose then
195
               Report.Comment("First set of complex values extracted " &
196
                              "from data file using Complex_IO, "      &
197
                              "Procedure Process_Data_File");
198
            end if;
199
 
200
            -- Use procedure Get (for Files) to extract the complex data from
201
            -- the Text_IO file.  This data was placed into the file using
202
            -- procedure Complex_IO.Put.
203
            -- Note: Data is being extracted from the file for the *second*
204
            --       time at this point (Using Complex_IO here, Text_IO above)
205
 
206
            for i in 1..Number_Of_Complex_Items loop
207
 
208
               C_IO.Get(The_File, TC_Complex, TC_Width);
209
 
210
               if TC_Complex /= Complex_Array(i) then
211
                  Report.Failed("Incorrect complex data read from file " &
212
                                "when using Complex_IO procedure Get, "  &
213
                                "data item #" & Integer'Image(i));
214
               end if;
215
            end loop;
216
 
217
            if TC_Verbose then
218
               Report.Comment("Second set of complex values extracted " &
219
                              "from data file using Complex_IO, "       &
220
                              "Procedure Process_Data_File");
221
            end if;
222
 
223
            -- The final items in the Data_File are complex values with
224
            -- incorrect syntax, which should raise Data_Error on an attempt
225
            -- to read them from the file.
226
            TC_Width := 10;
227
            for i in 1..Number_Of_Error_Items loop
228
               begin
229
                  C_IO.Get(The_File, TC_Complex, TC_Width);
230
                  Report.Failed
231
                    ("Exception Data_Error not raised when Complex_IO.Get " &
232
                     "was used to read complex data with incorrect "        &
233
                     "syntax from the Data_File, data item #"               &
234
                     Integer'Image(i));
235
               exception
236
                  when Ada.Text_IO.Data_Error => -- OK, expected exception.
237
                     Text_IO.Skip_Line(The_File);
238
                  when others =>
239
                     Report.Failed
240
                       ("Unexpected exception raised when Complex_IO.Get " &
241
                        "was used to read complex data with incorrect "    &
242
                        "syntax from the Data_File, data item #"           &
243
                         Integer'Image(i));
244
               end;
245
            end loop;
246
 
247
            if TC_Verbose then
248
               Report.Comment("Erroneous set of complex values extracted " &
249
                              "from data file using Complex_IO, "          &
250
                              "Procedure Process_Data_File");
251
            end if;
252
 
253
 
254
         exception
255
            when others =>
256
              Report.Failed
257
                ("Unexpected exception raised in Process_Data_File");
258
         end Process_Data_File;
259
 
260
 
261
 
262
      begin  -- Test_Block.
263
 
264
         -- Place complex values into data file.
265
 
266
         Load_Data_File(Data_File);
267
         Text_IO.Close(Data_File);
268
 
269
         if TC_Verbose then
270
            Report.Comment("Data file loaded with Complex values");
271
         end if;
272
 
273
         -- Read complex values from data file.
274
 
275
         Text_IO.Open(Data_File, Text_IO.In_File, Data_Filename);
276
         Process_Data_File(Data_File);
277
 
278
         if TC_Verbose then
279
            Report.Comment("Complex values extracted from data file");
280
         end if;
281
 
282
 
283
 
284
         -- Verify versions of Procedures Put and Get for Strings.
285
 
286
         declare
287
            TC_String_Array : array (1..Number_Of_Complex_Items)
288
                              of String(1..15) := (others =>(others => ' '));
289
         begin
290
 
291
            -- Place complex values into strings using the Procedure Put.
292
 
293
            for i in 1..Number_Of_Complex_Items loop
294
               C_IO.Put(To   => TC_String_Array(i),
295
                        Item => Complex_Array(i),
296
                        Aft  => 1,
297
                        Exp  => 0);
298
            end loop;
299
 
300
            if TC_Verbose then
301
               Report.Comment("Complex values placed into string array");
302
            end if;
303
 
304
            -- Check the format of the strings containing a complex number.
305
            -- The resulting strings are of 15 character length, with the
306
            -- real component left justified within the string, followed by
307
            -- a comma, and with the imaginary component and closing
308
            -- parenthesis right justified in the string, with blank fill
309
            -- for the balance of the string.
310
 
311
            if TC_String_Array(1) /= "(3.0,      9.0)" or
312
               TC_String_Array(2) /= "(4.0,      7.0)" or
313
               TC_String_Array(3) /= "(5.0,      6.0)" or
314
               TC_String_Array(4) /= "(6.0,      3.0)" or
315
               TC_String_Array(5) /= "(2.0,      5.0)" or
316
               TC_String_Array(6) /= "(3.0,      7.0)"
317
            then
318
               Report.Failed("Incorrect format for complex values that " &
319
                             "have been placed into string variables "   &
320
                             "using the Complex_IO.Put procedure for "   &
321
                             "strings");
322
            end if;
323
 
324
            if TC_Verbose then
325
               Report.Comment("String format of Complex values verified");
326
            end if;
327
 
328
            -- Get complex values from strings using the Procedure Get.
329
            -- Compare with expected complex values.
330
 
331
            for i in 1..Number_Of_Complex_Items loop
332
 
333
               C_IO.Get(From => TC_String_Array(i),
334
                        Item => TC_Complex,
335
                        Last => TC_Last_Character_Read);
336
 
337
               if TC_Complex /= Complex_Array(i) then
338
                  Report.Failed("Incorrect complex data value obtained "   &
339
                                "from String following use of Procedures " &
340
                                "Put and Get from Strings, Complex_Array " &
341
                                "item #" & Integer'Image(i));
342
               end if;
343
            end loop;
344
 
345
            if TC_Verbose then
346
               Report.Comment("Complex values removed from String array");
347
            end if;
348
 
349
            -- Verify that Layout_Error is raised if the given string is
350
            -- too short to hold the formatted output.
351
            Layout_Error_On_Put:
352
            declare
353
               Much_Too_Short : String(1..2);
354
               Complex_Value  : Complex_Pack.Complex := (5.0, 0.0);
355
            begin
356
               C_IO.Put(Much_Too_Short, Complex_Value);
357
               Report.Failed("Layout_Error not raised by Procedure Put " &
358
                             "when the given string was too short to "   &
359
                             "hold the formatted output");
360
            exception
361
               when Layout_Error => null;  -- OK, expected exception.
362
               when others =>
363
                  Report.Failed
364
                    ("Unexpected exception raised by Procedure Put when " &
365
                     "the given string was too short to hold the "        &
366
                     "formatted output");
367
            end Layout_Error_On_Put;
368
 
369
            if TC_Verbose then
370
               Report.Comment("Layout Errors verified");
371
            end if;
372
 
373
         exception
374
            when others =>
375
               Report.Failed("Unexpected exception raised during the " &
376
                             "evaluation of Put and Get for Strings");
377
         end;
378
 
379
 
380
         -- Place complex values into strings using a variety of legal
381
         -- complex data formats.
382
         declare
383
 
384
            type String_Ptr is access String;
385
 
386
            TC_Complex_String_Array :
387
              array (1..Number_Of_Complex_Items) of String_Ptr :=
388
              (new String'( "(3.0, 9.0  )"           ),
389
               new String'( "+4.0  +7.0"             ),
390
               new String'( "(5.0 6.0)"              ),
391
               new String'( "6.0, 3.0"               ),
392
               new String'( "  (   2.0   , 5.0  )  " ),
393
               new String'( "(3.0              7.0)" ));
394
 
395
            -- The following array contains Positive values that correspond
396
            -- to the last character that will be read by Procedure Get when
397
            -- given each of the above strings as input.
398
 
399
            TC_Last_Char_Array : array (1..Number_Of_Complex_Items)
400
               of Positive := (12,10,9,8,20,22);
401
 
402
         begin
403
 
404
            -- Get complex values from strings using the Procedure Get.
405
            -- Compare with expected complex values.
406
 
407
            for i in 1..Number_Of_Complex_Items loop
408
 
409
               C_IO.Get(TC_Complex_String_Array(i).all,
410
                        TC_Complex,
411
                        TC_Last_Character_Read);
412
 
413
               if TC_Complex /= Complex_Array(i) then
414
                  Report.Failed
415
                    ("Incorrect complex data value obtained from " &
416
                     "Procedure Get with complex data input of: "  &
417
                     TC_Complex_String_Array(i).all);
418
               end if;
419
 
420
               if TC_Last_Character_Read /= TC_Last_Char_Array(i) then
421
                  Report.Failed
422
                    ("Incorrect value returned as the last character of " &
423
                     "the input string processed by Procedure Get, "      &
424
                     "string value : " & TC_Complex_String_Array(i).all   &
425
                     "  expected last character value read : "            &
426
                     Positive'Image(TC_Last_Char_Array(i))                &
427
                     "  last character value read : "                     &
428
                     Positive'Image(TC_Last_Character_Read));
429
               end if;
430
 
431
            end loop;
432
 
433
            if TC_Verbose then
434
               Report.Comment("Complex values removed from strings and " &
435
                              "verified against expected values");
436
            end if;
437
 
438
         exception
439
            when others =>
440
               Report.Failed("Unexpected exception raised during the " &
441
                             "evaluation of Get for Strings");
442
         end;
443
 
444
      exception
445
         when others => Report.Failed ("Exception raised in Test_Block");
446
      end Test_Block;
447
 
448
 
449
      -- Delete the external file.
450
      if Ada.Text_IO.Is_Open(Data_File) then
451
         Ada.Text_IO.Delete(Data_File);
452
      else
453
         Ada.Text_IO.Open(Data_File,
454
                          Ada.Text_IO.In_File,
455
                          Data_Filename);
456
         Ada.Text_IO.Delete(Data_File);
457
      end if;
458
 
459
   exception
460
 
461
      -- Since Use_Error can be raised if, for the specified mode,
462
      -- the environment does not support Text_IO operations, the
463
      -- following handlers are included:
464
 
465
      when Ada.Text_IO.Use_Error  =>
466
         Report.Not_Applicable ("Use_Error raised on Text_IO Create");
467
 
468
      when Ada.Text_IO.Name_Error  =>
469
         Report.Not_Applicable ("Name_Error raised on Text_IO Create");
470
 
471
      when others             =>
472
         Report.Failed ("Unexpected exception raised on text file Create");
473
 
474
   end Test_for_Text_IO_Support;
475
 
476
   Report.Result;
477
 
478
end CXG1003;

powered by: WebSVN 2.1.0

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