aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cxa/cxaa017.a
blob: 17d0922cc2404d937842cd81777dd7e748dbfd42 (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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
-- CXAA017.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 Ada.Text_IO function Look_Ahead sets parameter End_Of_Line
--      to True if at the end of a line; otherwise check that it returns the
--      next character from a file (without consuming it), while setting 
--      End_Of_Line to False.  
--      
--      Check that Ada.Text_IO function Get_Immediate will return the next
--      control or graphic character in parameter Item from the specified 
--      file.  Check that the version of Ada.Text_IO function Get_Immediate 
--      with the Available parameter will, if a character is available in the
--      specified file, return the character in parameter Item, and set 
--      parameter Available to True.
--      
-- TEST DESCRIPTION:
--      This test exercises specific capabilities of two Text_IO subprograms, 
--      Look_Ahead and Get_Immediate.  A file is prepared that contains a 
--      variety of graphic and control characters on several lines.
--      In processing this file, a call to Look_Ahead is performed to ensure
--      that characters are available, then individual characters are 
--      extracted from the current line using Get_Immediate.  The characters
--      returned from both subprogram calls are compared with the expected
--      character result.  Processing on each file line continues until
--      Look_Ahead indicates that the end of the line is next.  Separate
--      verification is performed to ensure that all characters of each line
--      are processed, and that the Available and End_Of_Line parameters
--      of the subprograms are properly set in the appropriate instances.
--      
-- APPLICABILITY CRITERIA: 
--      This test is applicable to implementations capable of supporting
--      external Text_IO files.
--
--       
-- CHANGE HISTORY:
--      30 May 95   SAIC    Initial prerelease version.
--      01 May 96   SAIC    Incorporated reviewer comments for ACVC 2.1.
--      26 Feb 97   PWB.CTA Allowed for non-support of some IO operations.
--!

with Ada.Text_IO;
package CXAA017_0 is

   User_Defined_Input_File : aliased Ada.Text_IO.File_Type;

end CXAA017_0;


with CXAA017_0; use CXAA017_0;
with Ada.Characters.Latin_1;
with Ada.Exceptions;
with Ada.Text_IO;  
with Report;

procedure CXAA017 is
   
   use Ada.Characters.Latin_1;
   use Ada.Exceptions;
   use Ada.Text_IO;

   Non_Applicable_System : exception;
   No_Reset            : exception;

begin

   Report.Test ("CXAA017", "Check that Ada.Text_IO subprograms "         &
                           "Look_Ahead and Get_Immediate are available " &
                           "and produce correct results");

   Test_Block:
   declare

      User_Input_Ptr    : File_Access := User_Defined_Input_File'Access;

      UDLA_Char,          -- Acronym UDLA => "User Defined Look Ahead"
      UDGI_Char,          -- Acronym UDGI => "User Defined Get Immediate"
      TC_Char           : Character := Ada.Characters.Latin_1.NUL;

      UDLA_End_Of_Line,
      UDGI_Available    : Boolean   := False;

      Char_Pos          : Natural;

      -- This string contains five ISO 646 Control characters and six ISO 646 
      -- Graphic characters:
      TC_String_1  : constant String := STX       & 
                                        SI        & 
                                        DC2       & 
                                        CAN       & 
                                        US        & 
                                        Space     & 
                                        Ampersand & 
                                        Solidus   & 
                                        'A'       & 
                                        LC_X      & 
                                        DEL; 

      -- This string contains two ISO 6429 Control and six ISO 6429 Graphic
      -- characters:
      TC_String_2  : constant String := IS4                         & 
                                        SCI                         & 
                                        Yen_Sign                    & 
                                        Masculine_Ordinal_Indicator & 
                                        UC_I_Grave                  & 
                                        Multiplication_Sign         & 
                                        LC_C_Cedilla                & 
                                        LC_Icelandic_Thorn;

      TC_Number_Of_Strings : constant := 2;

      type String_Access_Type    is access constant String;
      type String_Ptr_Array_Type is 
        array (1..TC_Number_Of_Strings) of String_Access_Type;

      TC_String_Ptr_Array : String_Ptr_Array_Type := 
                              (new String'(TC_String_1),
                               new String'(TC_String_2));



      procedure Create_New_File (The_File : in out File_Type;
                                 Mode     : in     File_Mode;
                                 Next     : in     Integer) is
      begin
         Create (The_File, Mode, Report.Legal_File_Name(Next));
      exception
         -- The following two exceptions can be raised if a system is not
         -- capable of supporting external Text_IO files.  The handler will
         -- raise a user-defined exception which will result in a 
         -- Not_Applicable result for the test.
         when Use_Error | Name_Error => raise Non_Applicable_System;
      end Create_New_File;



      procedure Load_File (The_File : in out File_Type) is
      -- This procedure will load several strings into the file denoted
      -- by the input parameter.  A call to New_Line will add line/page
      -- termination characters, which will be available  for processing
      -- along with the text in the file.
      begin
         Put_Line (The_File, TC_String_Ptr_Array(1).all);
         New_Line (The_File, Spacing => 1);
         Put_Line (The_File, TC_String_Ptr_Array(2).all);
      end Load_File;


   begin

      -- Create user-defined text file that will serve as the appropriate
      -- sources of input to the procedures under test.

      Create_New_File (User_Defined_Input_File, Out_File, 1);

      -- Enter several lines of text into the new input file. 
      -- The characters that make up these text strings will be processed 
      -- using the procedures being exercised in this test.

      Load_File (User_Defined_Input_File);

      -- Check that Mode_Error is raised by Look_Ahead and Get_Immedidate 
      -- if the mode of the file object is not In_File.
      -- Currently, the file mode is Out_File.

      begin
         Look_Ahead(User_Defined_Input_File, UDLA_Char, UDLA_End_Of_Line);
         Report.Failed("Mode_Error not raised by Look_Ahead");
         Report.Comment("This char should never be printed: " & UDLA_Char); 
      exception
         when Mode_Error => null;  -- OK, expected exception.
         when The_Error : others => 
            Report.Failed ("The following exception was raised during the " &
                           "check that Look_Ahead raised Mode_Error when "  &
                           "provided a file object that is not in In_File " &
                           "mode: " & Exception_Name(The_Error));
      end;

      begin
         Get_Immediate(User_Defined_Input_File, UDGI_Char);
         Report.Failed("Mode_Error not raised by Get_Immediate");
         Report.Comment("This char should never be printed: " & UDGI_Char);
      exception
         when Mode_Error => null;  -- OK, expected exception.
         when The_Error : others => 
            Report.Failed ("The following exception was raised during the " &
                           "check that Get_Immediate raised Mode_Error "    &
                           "when provided a file object that is not in "    &
                           "In_File mode: " & Exception_Name(The_Error));
      end;


      -- The file will then be reset to In_File mode to properly function as 
      -- a source of input.

      Reset1:
      begin
         Reset (User_Defined_Input_File, In_File);
      exception
         when Ada.Text_IO.Use_Error =>
            Report.Not_Applicable
               ( "Reset to In_File not supported for Text_IO" );
            raise No_Reset;
      end Reset1;

      -- Process the input file, exercising various Text_IO
      -- functionality, and validating the results at each step.
      -- Note: The designated File_Access object is used in processing
      --       the New_Default_Input_File in the second loop below.

      -- Process characters in first line of text of each file.

      Char_Pos := 1;

      -- Check that the first line is not blank.

      Look_Ahead(User_Defined_Input_File, UDLA_Char, UDLA_End_Of_Line);

      while not UDLA_End_Of_Line loop

         -- Use the Get_Immediate procedure on the file to get the next 
         -- available character on the current line.

         Get_Immediate(User_Defined_Input_File, UDGI_Char);

         -- Check that the characters returned by both procedures are the
         -- same, and that they match the expected character from the file.

         if UDLA_Char /= TC_String_Ptr_Array(1).all(Char_Pos) or
            UDGI_Char /= TC_String_Ptr_Array(1).all(Char_Pos) 
         then
            Report.Failed("Incorrect retrieval of character " &
                          Integer'Image(Char_Pos) & " of first string");
         end if;

         -- Increment the character position counter.
         Char_Pos := Char_Pos + 1;

         -- Check the next character on the line.  If at the end of line,
         -- the processing flow will exit the While loop.

         Look_Ahead(User_Defined_Input_File, UDLA_Char, UDLA_End_Of_Line);

      end loop;

      -- Check to ensure that the "end of line" results returned from the 
      -- Look_Ahead procedure (used to exit the above While loop) corresponds
      -- with the result of Function End_Of_Line.

      if not End_Of_Line(User_Defined_Input_File)
      then
         Report.Failed("Result of procedure Look_Ahead that indicated "    &
                       "being at the end of the line does not correspond " &
                       "with the result of function End_Of_Line");
      end if;

      -- Check that all characters in the string were processed.

      if Char_Pos-1 /= TC_String_1'Length then
         Report.Failed("Not all of the characters on the first line " &
                       "were processed");
      end if;


      -- Call procedure Skip_Line to advance beyond the end of the first line.

      Skip_Line(User_Defined_Input_File);


      -- Process the second line in the file (a blank line).

      Look_Ahead(User_Input_Ptr.all, UDLA_Char, UDLA_End_Of_Line);

      if not UDLA_End_Of_Line then
         Report.Failed("Incorrect end of line determination from procedure " &
                       "Look_Ahead when processing a blank line");
      end if;

      -- Call procedure Skip_Line to advance beyond the end of the second line.

      Skip_Line(User_Input_Ptr.all);


      -- Process characters in the third line of the file (second line 
      -- of text)
      -- Note: The version of Get_Immediate used in processing this line has 
      --       the Boolean parameter Available.

      Char_Pos := 1;

      -- Check whether the line is blank (i.e., at end of line, page, or file).

      Look_Ahead(User_Input_Ptr.all, UDLA_Char, UDLA_End_Of_Line);

      while not UDLA_End_Of_Line loop

         -- Use the Get_Immediate procedure on the file to get access to the
         -- next character on the current line.

         Get_Immediate(User_Input_Ptr.all, UDGI_Char, UDGI_Available);

         -- Check that the Available parameter of Get_Immediate was set
         -- to indicate that a character was available in the file.
         -- Check that the characters returned by both procedures are the 
         -- same, and they all match the expected character from the file.

         if not UDGI_Available                                or
            UDLA_Char /= TC_String_Ptr_Array(2).all(Char_Pos) or
            UDGI_Char /= TC_String_Ptr_Array(2).all(Char_Pos) 
         then
            Report.Failed("Incorrect retrieval of character " &
                          Integer'Image(Char_Pos) & " of second string");
         end if;

         -- Increment the character position counter.

         Char_Pos := Char_Pos + 1;

         -- Check the next character on the line.  If at the end of line,
         -- the processing flow will exit the While loop.

         Look_Ahead(User_Input_Ptr.all, UDLA_Char, UDLA_End_Of_Line);

      end loop;

      -- Check to ensure that the "end of line" results returned from the 
      -- Look_Ahead procedure (used to exit the above While loop) corresponds
      -- with the result of Function End_Of_Line.

      if not End_Of_Line(User_Defined_Input_File)
      then
         Report.Failed("Result of procedure Look_Ahead that indicated "    &
                       "being at the end of the line does not correspond " &
                       "with the result of function End_Of_Line");
      end if;

      -- Check that all characters in the second string were processed.

      if Char_Pos-1 /= TC_String_2'Length then
         Report.Failed("Not all of the characters on the second line " &
                       "were processed");
      end if;


      Deletion:
      begin
         -- Delete the user defined file.

         if Is_Open(User_Defined_Input_File) then
            Delete(User_Defined_Input_File);
         else
            Open(User_Defined_Input_File, Out_File, Report.Legal_File_Name(1));
            Delete(User_Defined_Input_File);
         end if;
      exception
         when others =>
            Report.Failed
               ( "Delete not properly implemented for Text_IO" );
      end Deletion;


   exception

      when No_Reset =>
         null;

      when Non_Applicable_System =>
         Report.Not_Applicable("System not capable of supporting external " &
                               "text files -- Name_Error/Use_Error raised " &
                               "during text file creation");
      when The_Error : others => 
         Report.Failed ("The following exception was raised in the " &
                        "Test_Block: " & Exception_Name(The_Error));
   end Test_Block;

   Report.Result;

end CXAA017;