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
|
-- CXAC005.A
--
-- Grant of Unlimited Rights
--
-- The Ada Conformity Assessment Authority (ACAA) holds unlimited
-- rights in the software and documentation contained herein. Unlimited
-- rights are the same as those granted by the U.S. Government for older
-- parts of the Ada Conformity Assessment Test Suite, and are defined
-- in DFAR 252.227-7013(a)(19). By making this public release, the ACAA
-- intends to confer upon all recipients unlimited rights equal to those
-- held by the ACAA. 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 stream file positioning work as specified. (Defect Report
-- 8652/0055).
--
-- CHANGE HISTORY:
-- 12 FEB 2001 PHL Initial version.
-- 14 MAR 2001 RLB Readied for release; fixed Not_Applicable check
-- to terminate test gracefully.
--
--!
with Ada.Streams.Stream_Io;
use Ada.Streams;
with Ada.Exceptions;
use Ada.Exceptions;
with Report;
use Report;
procedure CXAC005 is
Incomplete : exception;
procedure TC_Assert (Condition : Boolean; Message : String) is
begin
if not Condition then
Failed (Message);
end if;
end TC_Assert;
package Checked_Stream_Io is
type File_Type (Max_Size : Stream_Element_Count) is limited private;
function Stream_Io_File (File : File_Type) return Stream_Io.File_Type;
procedure Create (File : in out File_Type;
Mode : in Stream_Io.File_Mode := Stream_Io.Out_File;
Name : in String := "";
Form : in String := "");
procedure Open (File : in out File_Type;
Mode : in Stream_Io.File_Mode;
Name : in String;
Form : in String := "");
procedure Close (File : in out File_Type);
procedure Delete (File : in out File_Type);
procedure Reset (File : in out File_Type;
Mode : in Stream_Io.File_Mode);
procedure Reset (File : in out File_Type);
procedure Read (File : in out File_Type;
Item : out Stream_Element_Array;
Last : out Stream_Element_Offset;
From : in Stream_Io.Positive_Count);
procedure Read (File : in out File_Type;
Item : out Stream_Element_Array;
Last : out Stream_Element_Offset);
procedure Write (File : in out File_Type;
Item : in Stream_Element_Array;
To : in Stream_Io.Positive_Count);
procedure Write (File : in out File_Type;
Item : in Stream_Element_Array);
procedure Set_Index (File : in out File_Type;
To : in Stream_Io.Positive_Count);
function Index (File : in File_Type) return Stream_Io.Positive_Count;
procedure Set_Mode (File : in out File_Type;
Mode : in Stream_Io.File_Mode);
private
type File_Type (Max_Size : Stream_Element_Count) is
record
File : Stream_Io.File_Type;
Index : Stream_Io.Positive_Count;
Contents :
Stream_Element_Array
(Stream_Element_Offset (Ident_Int (1)) .. Max_Size);
end record;
end Checked_Stream_Io;
package body Checked_Stream_Io is
use Stream_Io;
function Stream_Io_File (File : File_Type) return Stream_Io.File_Type is
begin
return File.File;
end Stream_Io_File;
procedure Create (File : in out File_Type;
Mode : in Stream_Io.File_Mode := Stream_Io.Out_File;
Name : in String := "";
Form : in String := "") is
begin
Stream_Io.Create (File.File, Mode, Name, Form);
File.Index := Stream_Io.Index (File.File);
if Mode = Append_File then
TC_Assert (File.Index = Stream_Io.Size (File.File) + 1,
"Index /= Size + 1 -- Create - Append_File");
else
TC_Assert (File.Index = 1, "Index /= 1 -- Create - " &
File_Mode'Image (Mode));
end if;
end Create;
procedure Open (File : in out File_Type;
Mode : in Stream_Io.File_Mode;
Name : in String;
Form : in String := "") is
begin
Stream_Io.Open (File.File, Mode, Name, Form);
File.Index := Stream_Io.Index (File.File);
if Mode = Append_File then
TC_Assert (File.Index = Stream_Io.Size (File.File) + 1,
"Index /= Size + 1 -- Open - Append_File");
else
TC_Assert (File.Index = 1, "Index /= 1 -- Open - " &
File_Mode'Image (Mode));
end if;
end Open;
procedure Close (File : in out File_Type) is
begin
Stream_Io.Close (File.File);
end Close;
procedure Delete (File : in out File_Type) is
begin
Stream_Io.Delete (File.File);
end Delete;
procedure Reset (File : in out File_Type;
Mode : in Stream_Io.File_Mode) is
begin
Stream_Io.Reset (File.File, Mode);
File.Index := Stream_Io.Index (File.File);
if Mode = Append_File then
TC_Assert (File.Index = Stream_Io.Size (File.File) + 1,
"Index /= Size + 1 -- Reset - Append_File");
else
TC_Assert (File.Index = 1, "Index /= 1 -- Reset - " &
File_Mode'Image (Mode));
end if;
end Reset;
procedure Reset (File : in out File_Type) is
begin
Reset (File, Stream_Io.Mode (File.File));
end Reset;
procedure Read (File : in out File_Type;
Item : out Stream_Element_Array;
Last : out Stream_Element_Offset;
From : in Stream_Io.Positive_Count) is
begin
Set_Index (File, From);
Read (File, Item, Last);
end Read;
procedure Read (File : in out File_Type;
Item : out Stream_Element_Array;
Last : out Stream_Element_Offset) is
Index : constant Stream_Element_Offset :=
Stream_Element_Offset (File.Index);
begin
Stream_Io.Read (File.File, Item, Last);
if Last < Item'Last then
TC_Assert (Item (Item'First .. Last) =
File.Contents (Index .. Index + Last - Item'First),
"Incorrect data read from file - 1");
TC_Assert (Count (Index + Last - Item'First) =
Stream_Io.Size (File.File),
"Read stopped before end of file");
File.Index := Count (Index + Last - Item'First) + 1;
else
TC_Assert (Item = File.Contents (Index .. Index + Item'Length - 1),
"Incorrect data read from file - 2");
File.Index := File.Index + Item'Length;
end if;
end Read;
procedure Write (File : in out File_Type;
Item : in Stream_Element_Array;
To : in Stream_Io.Positive_Count) is
begin
Set_Index (File, To);
Write (File, Item);
end Write;
procedure Write (File : in out File_Type;
Item : in Stream_Element_Array) is
Index : constant Stream_Element_Offset :=
Stream_Element_Offset (File.Index);
begin
Stream_Io.Write (File.File, Item);
File.Contents (Index .. Index + Item'Length - 1) := Item;
File.Index := File.Index + Item'Length;
TC_Assert (File.Index = Stream_Io.Index (File.File),
"Write failed to move the index");
end Write;
procedure Set_Index (File : in out File_Type;
To : in Stream_Io.Positive_Count) is
begin
Stream_Io.Set_Index (File.File, To);
File.Index := Stream_Io.Index (File.File);
TC_Assert (File.Index = To, "Set_Index failed");
end Set_Index;
function Index (File : in File_Type) return Stream_Io.Positive_Count is
New_Index : constant Count := Stream_Io.Index (File.File);
begin
TC_Assert (New_Index = File.Index, "Index changed unexpectedly");
return New_Index;
end Index;
procedure Set_Mode (File : in out File_Type;
Mode : in Stream_Io.File_Mode) is
Old_Index : constant Count := File.Index;
begin
Stream_Io.Set_Mode (File.File, Mode);
File.Index := Stream_Io.Index (File.File);
if Mode = Append_File then
TC_Assert (File.Index = Stream_Io.Size (File.File) + 1,
"Index /= Size + 1 -- Set_Mode - Append_File");
else
TC_Assert (File.Index = Old_Index, "Set_Mode changed the index");
end if;
end Set_Mode;
end Checked_Stream_Io;
package Csio renames Checked_Stream_Io;
F : Csio.File_Type (100);
S : Stream_Element_Array (1 .. 10);
Last : Stream_Element_Offset;
begin
Test ("CXAC005", "Check that stream file positioning work as specified");
declare
Name : constant String := Legal_File_Name;
begin
begin
Csio.Create (F, Name => Name);
exception
when others =>
Not_Applicable ("Files not supported - Creation with Out_File for Stream_IO");
raise Incomplete;
end;
for I in Stream_Element range 1 .. 10 loop
Csio.Write (F, ((1 => I + 2)));
end loop;
Csio.Write (F, (1 .. 15 => 11));
Csio.Write (F, (1 .. 15 => 12), To => 15);
Csio.Reset (F);
for I in Stream_Element range 1 .. 10 loop
Csio.Write (F, (1 => I));
end loop;
Csio.Write (F, (1 .. 15 => 13));
Csio.Write (F, (1 .. 15 => 14), To => 15);
Csio.Write (F, (1 => 90));
Csio.Set_Mode (F, Stream_Io.In_File);
Csio.Read (F, S, Last);
Csio.Read (F, S, Last, From => 3);
Csio.Read (F, S, Last, From => 28);
Csio.Set_Mode (F, Stream_Io.Append_File);
Csio.Write (F, (1 .. 5 => 88));
Csio.Close (F);
Csio.Open (F, Name => Name, Mode => Stream_Io.Append_File);
Csio.Write (F, (1 .. 3 => 33));
Csio.Set_Mode (F, Stream_Io.In_File);
Csio.Read (F, S, Last, From => 20);
Csio.Read (F, S, Last);
Csio.Reset (F, Stream_Io.Out_File);
Csio.Write (F, (1 .. 9 => 99));
-- Check the contents of the entire file.
declare
S : Stream_Element_Array
(1 .. Stream_Element_Offset
(Stream_Io.Size (Csio.Stream_Io_File (F))));
begin
Csio.Reset (F, Stream_Io.In_File);
Csio.Read (F, S, Last);
end;
Csio.Delete (F);
end;
Result;
exception
when Incomplete =>
Report.Result;
when E:others =>
Report.Failed ("Unexpected exception raised - " & Exception_Name (E) &
" - " & Exception_Message (E));
Report.Result;
end CXAC005;
|