aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cxa/cxaa018.a
blob: 53b16fea4989acc75e44ba6c2b71b91cf15d9114 (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
-- CXAA018.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 the package Text_IO.Modular_IO
--      provide correct results.  
--
-- TEST DESCRIPTION:
--      This test checks that the subprograms defined in the 
--      Ada.Text_IO.Modular_IO package provide correct results.  
--      A modular type is defined and used to instantiate the generic
--      package Ada.Text_IO.Modular_IO.  Values of the modular type are
--      written to a Text_IO file, and to a series of string variables, using
--      different versions of the procedure Put from the instantiated IO
--      package.  These modular data items are retrieved from the file and
--      string variables using the appropriate instantiated version of
--      procedure Get.  A variety of Base and Width parameter values are
--      used in the procedure calls.
--      
-- APPLICABILITY CRITERIA: 
--      This test is applicable to all implementations that support Text_IO
--      processing and external files.
--
--       
-- CHANGE HISTORY:
--      03 Jul 95   SAIC    Initial prerelease version.
--      01 May 96   SAIC    Incorporated reviewer comments for ACVC 2.1.
--
--!

with Ada.Text_IO;
with System;
with Report;

procedure CXAA018 is
begin

   Report.Test ("CXAA018", "Check that the subprograms defined in "  &
                           "the package Text_IO.Modular_IO provide " & 
                           "correct results");

   Test_for_Text_IO_Support:
   declare
      Data_File     : Ada.Text_IO.File_Type;
      Data_Filename : constant String := Report.Legal_File_Name;
   begin

      -- An application creates a text file in mode Out_File, with the 
      -- intention of entering modular data into the file as appropriate.  
      -- In the event that the particular environment where the application 
      -- is running does not support Text_IO, Use_Error or Name_Error will be 
      -- raised on calls to Text_IO operations.  Either of these exceptions
      -- will be handled to produce a Not_Applicable result.

      Ada.Text_IO.Create (File => Data_File,
                          Mode => Ada.Text_IO.Out_File,
                          Name => Data_Filename);

      Test_Block:
      declare

         type Mod_Type is mod System.Max_Binary_Modulus; 
         -- Max_Binary_Modulus must be at least 2**16, which would result
         -- in a base range of 0..65535 (zero to one less than the given
         -- modulus) for this modular type.

         package Mod_IO is new Ada.Text_IO.Modular_IO(Mod_Type);
         use Ada.Text_IO, Mod_IO;
         use type Mod_Type;

         Number_Of_Modular_Items : constant := 6;
         Number_Of_Error_Items   : constant := 1;

         TC_Modular              : Mod_Type;
         TC_Last_Character_Read  : Positive;

         Modular_Array : array (1..Number_Of_Modular_Items) of Mod_Type := 
                                   ( 0, 97, 255, 1025, 12097, 65535 );


         procedure Load_File (The_File : in out Ada.Text_IO.File_Type) is
         begin
            -- This procedure does not create, open, or close the data file;
            -- The_File file object must be Open at this point.
            -- This procedure is designed to load Modular_Type data into a 
            -- data file. 
            --
            -- Use the Modular_IO procedure Put to enter modular data items
            -- into the data file.

            for i in 1..Number_Of_Modular_Items loop
               -- Use default Base parameter of 10.
               Mod_IO.Put(File  => Data_File, 
                          Item  => Modular_Array(i), 
                          Width => 6, 
                          Base  => Mod_IO.Default_Base);
            end loop;

            -- Enter data into the file such that on the corresponding "Get"
            -- of this data, Data_Error must be raised.  This value is outside
            -- the base range of Modular_Type.
            -- Text_IO is used to enter the value in the file.

            for i in 1..Number_Of_Error_Items loop
               Ada.Text_IO.Put(The_File, "-10");  
            end loop;

         end Load_File;



         procedure Process_File(The_File : in out Ada.Text_IO.File_Type) is
         begin
            -- This procedure does not create, open, or close the data file;
            -- The_File file object must be Open at this point.
            -- Use procedure Get (for Files) to extract the modular data from
            -- the Text_IO file.  

            for i in 1..Number_Of_Modular_Items loop
               Mod_IO.Get(The_File, TC_Modular, Width => 6);

               if TC_Modular /= Modular_Array(i) then
                  Report.Failed("Incorrect modular data read from file " &
                                "data item #" & Integer'Image(i));
               end if;
            end loop;

            -- The final item in the Data_File is a modular value that is
            -- outside the base range 0..Num'Last.  This value should raise
            -- Data_Error on an attempt to "Get" it from the file.

            for i in 1..Number_Of_Error_Items loop
               begin
                  Mod_IO.Get(The_File, TC_Modular, Mod_IO.Default_Width);
                  Report.Failed
                    ("Exception Data_Error not raised when Get "   &
                     "was used to read modular data outside base " &
                     "range of type, item # "                      & 
                     Integer'Image(i));
               exception
                  when Ada.Text_IO.Data_Error => 
                     null; -- OK, expected exception.
                  when others =>
                     Report.Failed("Unexpected exception raised when Get "  &
                                   "was used to read modular data outside " &
                                   "base range of type from Data_File, "    &
                                   "data item #" & Integer'Image(i));
               end;
            end loop;
       
         exception
            when others =>
              Report.Failed
                ("Unexpected exception raised in Process_File");
         end Process_File;



      begin  -- Test_Block.

         -- Place modular values into data file.

         Load_File(Data_File);
         Ada.Text_IO.Close(Data_File);

         -- Read modular values from data file.

         Ada.Text_IO.Open(Data_File, Ada.Text_IO.In_File, Data_Filename);
         Process_File(Data_File);

         -- Verify versions of Modular_IO procedures Put and Get for Strings.

         Modular_IO_in_Strings:
         declare
            TC_String_Array : array (1..Number_Of_Modular_Items) 
                              of String(1..30) := (others =>(others => ' '));
         begin

            -- Place modular values into strings using the Procedure Put, 
            -- Use a variety of different "Base" parameter values.
            -- Note: This version of Put uses the length of the given
            --       string as the value of the "Width" parameter.

            for i in 1..2 loop
               Mod_IO.Put(To   => TC_String_Array(i),
                          Item => Modular_Array(i),
                          Base => Mod_IO.Default_Base);
            end loop;
            for i in 3..4 loop
               Mod_IO.Put(TC_String_Array(i),
                          Modular_Array(i),
                          Base => 2);
            end loop;
            for i in 5..6 loop
               Mod_IO.Put(TC_String_Array(i), Modular_Array(i), 16);
            end loop;

            -- Get modular values from strings using the Procedure Get.
            -- Compare with expected modular values.

            for i in 1..Number_Of_Modular_Items loop

               Mod_IO.Get(From => TC_String_Array(i),
                          Item => TC_Modular,
                          Last => TC_Last_Character_Read);

               if TC_Modular /= Modular_Array(i) then
                  Report.Failed("Incorrect modular data value obtained "   &
                                "from String following use of Procedures " & 
                                "Put and Get from Strings, Modular_Array " &
                                "item #" & Integer'Image(i));
               end if;
            end loop;
         
         exception
            when others => 
               Report.Failed("Unexpected exception raised during the " &
                             "evaluation of Put and Get for Strings");
         end Modular_IO_in_Strings;

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


      -- Delete the external file.
      if Ada.Text_IO.Is_Open(Data_File) then
         Ada.Text_IO.Delete(Data_File);
      else
         Ada.Text_IO.Open(Data_File, 
                          Ada.Text_IO.In_File,
                          Data_Filename);
         Ada.Text_IO.Delete(Data_File);
      end if;

   exception

      -- Since Use_Error can be raised if, for the specified mode,
      -- the environment does not support Text_IO operations, the 
      -- following handlers are included:

      when Ada.Text_IO.Use_Error  =>
         Report.Not_Applicable ("Use_Error raised on Text_IO Create");

      when Ada.Text_IO.Name_Error =>
         Report.Not_Applicable ("Name_Error raised on Text_IO Create");

      when others                 =>
         Report.Failed ("Unexpected exception raised on text file Create");

   end Test_for_Text_IO_Support;

   Report.Result;

end CXAA018;