3 -- Grant of Unlimited Rights
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
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.
27 -- Check that the use of 'Class'Output and 'Class'Input allow stream
28 -- manipulation of objects of non-limited class-wide types.
31 -- This test demonstrates the uses of 'Class'Output and 'Class'Input
32 -- in moving objects of a particular class to and from a stream file.
33 -- A procedure uses a class-wide parameter to move objects of specific
34 -- types in the class to the stream, using the 'Class'Output attribute
35 -- of the root type of the class. A function returns a class-wide object,
36 -- using the 'Class'Input attribute of the root type of the class to
37 -- extract the object from the stream.
38 -- A field-by-field comparison of record objects is performed to validate
39 -- the data read from the stream. Operator precedence rules are used
40 -- in the comparison rather than parentheses.
42 -- APPLICABILITY CRITERIA:
43 -- This test is applicable to all implementations capable of supporting
44 -- external Stream_IO files.
48 -- 06 Dec 94 SAIC ACVC 2.0
49 -- 14 Nov 95 SAIC Corrected prefix of 'Tag attribute for ACVC 2.0.1.
50 -- 24 Aug 96 SAIC Changed a call to "Create" to "Reset".
51 -- 26 Feb 97 CTA.PWB Allowed for non-support of some IO operations.
54 with FXACC00
, Ada
.Streams
.Stream_IO
, Ada
.Tags
, Report
;
58 Order_File
: Ada
.Streams
.Stream_IO
.File_Type
;
59 Order_Stream
: Ada
.Streams
.Stream_IO
.Stream_Access
;
60 Order_Filename
: constant String :=
61 Report
.Legal_File_Name
( Nam
=> "CXACC01" );
62 Incomplete
: exception;
66 Report
.Test
("CXACC01", "Check that the use of 'Class'Output " &
67 "and 'Class'Input allow stream manipulation " &
68 "of objects of non-limited class-wide types");
70 Test_for_Stream_IO_Support
:
73 -- If an implementation does not support Stream_IO in a particular
74 -- environment, the exception Use_Error or Name_Error will be raised on
75 -- calls to various Stream_IO operations. This block statement
76 -- encloses a call to Create, which should produce an exception in a
77 -- non-supportive environment. These exceptions will be handled to
78 -- produce a Not_Applicable result.
80 Ada
.Streams
.Stream_IO
.Create
(Order_File
,
81 Ada
.Streams
.Stream_IO
.Out_File
,
86 when Ada
.Streams
.Stream_IO
.Use_Error | Ada
.Streams
.Stream_IO
.Name_Error
=>
88 ( "Files not supported - Create as Out_File for Stream_IO" );
91 end Test_for_Stream_IO_Support
;
93 Operational_Test_Block
:
96 -- Store tag values associated with objects of tagged types.
98 TC_Box_Office_Tag
: constant String :=
99 Ada
.Tags
.External_Tag
(FXACC00
.Ticket_Request
'Tag);
101 TC_Summer_Tag
: constant String :=
102 Ada
.Tags
.External_Tag
(FXACC00
.Subscriber_Request
'Tag);
104 TC_Mayoral_Tag
: constant String :=
105 Ada
.Tags
.External_Tag
(FXACC00
.VIP_Request
'Tag);
107 TC_Late_Tag
: constant String :=
108 Ada
.Tags
.External_Tag
(FXACC00
.Last_Minute_Request
'Tag);
110 -- The following procedure will take an object of the Ticket_Request
111 -- class and output it to the stream. Objects of any extended type
112 -- in the class can be output to the stream with this procedure.
114 procedure Order_Entry
(Order
: FXACC00
.Ticket_Request
'Class) is
116 FXACC00
.Ticket_Request
'Class'Output (Order_Stream, Order);
120 -- The following function will retrieve from the stream an object of
121 -- the Ticket_Request class.
123 function Order_Retrieval return FXACC00.Ticket_Request'Class is
125 return FXACC00.Ticket_Request'Class'Input
(Order_Stream
);
130 Order_Stream
:= Ada
.Streams
.Stream_IO
.Stream
(Order_File
);
132 -- Store the data objects in the stream.
133 -- Each of the objects is of a different type within the class.
135 Order_Entry
(FXACC00
.Box_Office_Request
); -- Object of root type
136 Order_Entry
(FXACC00
.Summer_Subscription
); -- Obj. of extended type
137 Order_Entry
(FXACC00
.Mayoral_Ticket_Request
); -- Obj. of extended type
138 Order_Entry
(FXACC00
.Late_Request
); -- Object of twice
141 -- Reset mode of stream to In_File prior to reading data from it.
144 Ada
.Streams
.Stream_IO
.Reset
(Order_File
,
145 Ada
.Streams
.Stream_IO
.In_File
);
147 when Ada
.Streams
.Stream_IO
.Use_Error
=>
148 Report
.Not_Applicable
149 ( "Reset to In_File not supported for Stream_IO - 1" );
158 -- Declare variables of the root type class,
159 -- and initialize them with class-wide objects returned from
160 -- the stream as function result.
162 Order_1
: Ticket_Request
'Class := Order_Retrieval
;
163 Order_2
: Ticket_Request
'Class := Order_Retrieval
;
164 Order_3
: Ticket_Request
'Class := Order_Retrieval
;
165 Order_4
: Ticket_Request
'Class := Order_Retrieval
;
167 -- Declare objects of the specific types from within the class
168 -- that correspond to the types of the data written to the
169 -- stream. Perform a type conversion on the class-wide objects.
171 Ticket_Order
: Ticket_Request
:=
172 Ticket_Request
(Order_1
);
173 Subscriber_Order
: Subscriber_Request
:=
174 Subscriber_Request
(Order_2
);
175 VIP_Order
: VIP_Request
:=
176 VIP_Request
(Order_3
);
177 Last_Minute_Order
: Last_Minute_Request
:=
178 Last_Minute_Request
(Order_4
);
182 -- Perform a field-by-field comparison of all the class-wide
183 -- objects input from the stream with specific type objects
184 -- originally written to the stream.
186 if Ticket_Order
.Location
/=
187 Box_Office_Request
.Location
or
188 Ticket_Order
.Number_Of_Tickets
/=
189 Box_Office_Request
.Number_Of_Tickets
191 Report
.Failed
("Ticket_Request object validation failure");
194 if Subscriber_Order
.Location
/=
195 Summer_Subscription
.Location
or
196 Subscriber_Order
.Number_Of_Tickets
/=
197 Summer_Subscription
.Number_Of_Tickets
or
198 Subscriber_Order
.Subscription_Number
/=
199 Summer_Subscription
.Subscription_Number
201 Report
.Failed
("Subscriber_Request object validation failure");
204 if VIP_Order
.Location
/=
205 Mayoral_Ticket_Request
.Location
or
206 VIP_Order
.Number_Of_Tickets
/=
207 Mayoral_Ticket_Request
.Number_Of_Tickets
or
209 Mayoral_Ticket_Request
.Rank
211 Report
.Failed
("VIP_Request object validation failure");
214 if Last_Minute_Order
.Location
/=
215 Late_Request
.Location
or
216 Last_Minute_Order
.Number_Of_Tickets
/=
217 Late_Request
.Number_Of_Tickets
or
218 Last_Minute_Order
.Rank
/=
220 Last_Minute_Order
.Special_Consideration
/=
221 Late_Request
.Special_Consideration
or
222 Last_Minute_Order
.Donation
/=
223 Late_Request
.Donation
225 Report
.Failed
("Last_Minute_Request object validation failure");
228 -- Verify tag values from before and after processing.
229 -- The 'Tag attribute is used with objects of a class-wide type.
231 if TC_Box_Office_Tag
/=
232 Ada
.Tags
.External_Tag
(Order_1
'Tag)
234 Report
.Failed
("Failed tag comparison - 1");
238 Ada
.Tags
.External_Tag
(Order_2
'Tag)
240 Report
.Failed
("Failed tag comparison - 2");
244 Ada
.Tags
.External_Tag
(Order_3
'Tag)
246 Report
.Failed
("Failed tag comparison - 3");
250 Ada
.Tags
.External_Tag
(Order_4
'Tag)
252 Report
.Failed
("Failed tag comparison - 4");
255 end Process_Order_Block
;
257 -- After all the data has been correctly extracted, the file
260 if not Ada
.Streams
.Stream_IO
.End_Of_File
(Order_File
) then
261 Report
.Failed
("Stream file not empty");
267 when Constraint_Error
=>
268 Report
.Failed
("Constraint_Error raised in Operational Block");
270 Report
.Failed
("Exception raised in Operational Test Block");
271 end Operational_Test_Block
;
275 if Ada
.Streams
.Stream_IO
.Is_Open
(Order_File
) then
276 Ada
.Streams
.Stream_IO
.Delete
(Order_File
);
278 Ada
.Streams
.Stream_IO
.Open
(Order_File
,
279 Ada
.Streams
.Stream_IO
.Out_File
,
281 Ada
.Streams
.Stream_IO
.Delete
(Order_File
);
286 ( "Delete not properly implemented for Stream_IO" );
296 Report
.Failed
( "Unexpected exception" );