OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 294 jeremybenn
-- CXAA015.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 exception Status_Error is raised when an attempt is
28
--      made to create or open a file in Append_File mode when the file is
29
--      already open.
30
--      Check that the exception Name_Error is raised by procedure Open when
31
--      attempting to open a file in Append_File mode when the name supplied
32
--      as the filename does not correspond to an existing external file.
33
--
34
-- TEST DESCRIPTION:
35
--      A scenario is created that demonstrates the potential for the
36
--      inappropriate usage of text processing subprograms Create and Open,
37
--      resulting in the raising of Status_Error and Name_Error exceptions.
38
--      A count is kept to ensure that each anticipated exception is in fact
39
--      raised and handled properly.
40
--
41
-- APPLICABILITY CRITERIA:
42
--      This test is applicable only to implementations that support text
43
--      files.
44
--
45
--
46
-- CHANGE HISTORY:
47
--      06 Dec 94   SAIC    ACVC 2.0
48
--      28 Feb 97   PWB.CTA Allowed for non-support of some IO operations
49
--!
50
 
51
with Ada.Text_IO;
52
with Report;
53
 
54
procedure CXAA015 is
55
   use Ada;
56
   Text_File     : Text_IO.File_Type;
57
   Text_Filename : constant String :=
58
                              Report.Legal_File_Name ( Nam => "CXAA015" );
59
   Incomplete : exception;
60
 
61
begin
62
 
63
         Report.Test ("CXAA015", "Check that the appropriate exceptions "    &
64
                                 "are raised when procedures Create and "    &
65
                                 "Open are used to inappropriately operate " &
66
                                 "on files of mode Append_File");
67
 
68
         Test_for_Text_IO_Support:
69
         begin
70
 
71
-- An application creates a text file with mode Append_File.
72
-- Use_Error will be raised if Text_IO operations or external files are not
73
-- supported.
74
 
75
            Text_IO.Create (Text_File, Text_IO.Append_File, Text_Filename);
76
         exception
77
 
78
             when Text_IO.Use_Error | Text_IO.Name_Error =>
79
                Report.Not_Applicable
80
                   ( "Files not supported - Create as Append_File for Text_IO" );
81
                raise Incomplete;
82
 
83
         end Test_for_Text_IO_Support;
84
 
85
 
86
-- The application writes some amount of data to the file.
87
 
88
            for I in 1 .. 5 loop
89
               Text_IO.Put_Line (Text_File, "Data entered into the file");
90
            end loop;
91
 
92
            Operational_Test_Block:
93
            declare
94
               TC_Number_Of_Forced_Errors : constant Natural := 3;
95
               TC_Errors                  :          Natural := 0;
96
            begin
97
 
98
 
99
               Test_for_Create:
100
               begin
101
 
102
-- During the course of its processing, the application may (erroneously)
103
-- attempt to create the same file already in existence in Append_File mode.
104
-- This results in the raising of Status_Error.
105
 
106
                  Text_IO.Create (Text_File,
107
                                  Text_IO.Append_File,
108
                                  Text_Filename);
109
                  Report.Failed ("Exception not raised by Create");
110
 
111
-- An exception handler present within the application handles the exception
112
-- and processing can continue.
113
 
114
               exception
115
                  when Text_IO.Status_Error =>
116
                     TC_Errors := TC_Errors + 1;
117
                  when others =>
118
                     Report.Failed("Exception in Create processing");
119
               end Test_for_Create;
120
 
121
 
122
               First_Test_For_Open:
123
               begin
124
 
125
-- Again, during the course of its processing, the application incorrectly
126
-- attempts to Open a file (in Append_File mode) that is already open.
127
 
128
                  Text_IO.Open (Text_File, Text_IO.Append_File, Text_Filename);
129
                  Report.Failed ("Exception not raised by improper Open - 1");
130
 
131
-- Once again, an exception handler present within the application handles
132
-- the exception and processing continues.
133
 
134
               exception
135
                  when Text_IO.Status_Error =>
136
                     TC_Errors := TC_Errors + 1;
137
 
138
-- At some point in its processing, the application closes the file that is
139
-- currently open.
140
 
141
                     Text_IO.Close (Text_File);
142
                  when others =>
143
                     Report.Failed("Exception in Open processing - 1");
144
               end First_Test_For_Open;
145
 
146
 
147
               Open_With_Wrong_Filename:
148
               declare
149
                  TC_Wrong_Filename : constant String :=
150
                    Report.Legal_File_Name(2);
151
               begin
152
 
153
-- At this point, the application attempts to Open (in Append_File mode) the
154
-- file used in previous processing, but it attempts this Open using a name
155
-- string that does not correspond to any existing external file.
156
-- First make sure the file doesn't exist.  (If it did, then the check
157
-- for open in append mode wouldn't work.)
158
 
159
                  Verify_No_File:
160
                  begin
161
                     Text_IO.Open (Text_File,
162
                                   Text_IO.In_File,
163
                                   TC_Wrong_Filename);
164
                  exception
165
                     when Text_IO.Name_Error =>
166
                        null;
167
                     when others =>
168
                        Report.Failed ( "Unexpected exception on Open check" );
169
                  end Verify_No_File;
170
 
171
                  Delete_No_File:
172
                  begin
173
                     if Text_IO.Is_Open (Text_File) then
174
                        Text_IO.Delete (Text_File);
175
                     end if;
176
                  exception
177
                     when others =>
178
                       Report.Failed ( "Unexpected exception - Delete check" );
179
                  end Delete_No_File;
180
 
181
                  Text_IO.Open (Text_File,
182
                                Text_IO.Append_File,
183
                                TC_Wrong_Filename);
184
                  Report.Failed ("Exception not raised by improper Open - 2");
185
 
186
-- An exception handler for the Name_Error, present within the application,
187
-- catches the exception and processing continues.
188
 
189
               exception
190
                  when Text_IO.Name_Error =>
191
                     TC_Errors := TC_Errors + 1;
192
                  when others =>
193
                     Report.Failed("Exception in Open processing - 2");
194
               end Open_With_Wrong_Filename;
195
 
196
 
197
               if (TC_Errors /= TC_Number_Of_Forced_Errors) then
198
                  Report.Failed ("Incorrect number of exceptions handled");
199
               end if;
200
 
201
            end Operational_Test_Block;
202
 
203
            Deletion:
204
            begin
205
               -- Delete the external file.
206
               if Text_IO.Is_Open (Text_File) then
207
                  Text_IO.Delete (Text_File);
208
               else
209
                  Text_IO.Open (Text_File, Text_IO.In_File, Text_Filename);
210
                  Text_IO.Delete (Text_File);
211
               end if;
212
            exception
213
               when others =>
214
                  Report.Failed
215
                     ( "Delete not properly implemented for Text_IO" );
216
            end Deletion;
217
 
218
         Report.Result;
219
 
220
exception
221
   when Incomplete =>
222
      Report.Result;
223
   when others     =>
224
      Report.Failed ( "Unexpected exception" );
225
      Report.Result;
226
 
227
end CXAA015;

powered by: WebSVN 2.1.0

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