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
|
-- C410001.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 evaluating an access to subprogram variable containing
-- the value null causes the exception Constraint_Error.
-- Check that the default value for objects of access to subprogram
-- types is null.
--
-- TEST DESCRIPTION:
-- This test defines a few simple access_to_subprogram types, and
-- objects of those types. It checks that the default values for
-- these objects is null, and that an attempt to make a subprogram
-- call via one of this objects containing a null value causes the
-- predefined exception Constraint_Error. The check is performed
--- both with the default null value, and with an explicitly assigned
-- null value, after the object has been used to successfully designate
-- and call a subprogram.
--
--
-- CHANGE HISTORY:
-- 05 APR 96 SAIC Initial version
-- 04 NOV 96 SAIC Revised for 2.1 release
-- 26 FEB 97 PWB.CTA Initialized variable before passing to function
--!
----------------------------------------------------------------- C410001_0
package C410001_0 is
-- used to "switch state" in the software
Expect_Exception : Boolean;
-- define a minimal mixture of access_to_subprogram types
type Proc_Ref is access procedure;
type Func_Ref is access function(I:Integer) return Integer;
type Proc_Para_Ref is access procedure(P:Proc_Ref);
type Func_Para_Ref is access function(F:Func_Ref) return Integer;
type Prot_Proc_Ref is access protected procedure;
type Prot_Func_Ref is access protected function return Boolean;
-- define some subprograms for them to reference
procedure Proc;
function Func(I:Integer) return Integer;
procedure Proc_Para( Param : Proc_Ref );
function Func_Para( Param : Func_Ref ) return Integer;
protected Prot_Obj is
procedure Prot_Proc;
function Prot_Func return Boolean;
end Prot_Obj;
end C410001_0;
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
with Report;
package body C410001_0 is
-- Note that some failing cases will cause duplicate failure messages;
-- rather than have the procedure/function bodies be null, the error
-- checking code makes for a reasonable anti-optimization feature.
procedure Proc is
begin
if Expect_Exception then
Report.Failed("Expected exception did not occur: Proc");
end if;
end Proc;
function Func(I:Integer) return Integer is
begin
if Expect_Exception then
Report.Failed("Expected exception did not occur: Func");
end if;
return Report.Ident_Int(I);
end Func;
procedure Proc_Para( Param : Proc_Ref ) is
begin
Param.all; -- call by explicit dereference
if Expect_Exception then
Report.Failed("Expected exception did not occur: Proc_Para");
end if;
exception
when Constraint_Error =>
if not Expect_Exception then
Report.Failed("Unexpected Constraint_Error: Proc_Para");
end if; -- else null; expected the exception
when others => Report.Failed("Unexpected exception: Proc_Para");
end Proc_Para;
function Func_Para( Param : Func_Ref ) return Integer is
begin
return Param(1); -- call by implicit dereference
if Expect_Exception then
Report.Failed("Expected exception did not occur: Func_Para");
end if;
return 1; -- really just to avoid warnings
exception
when Constraint_Error =>
if not Expect_Exception then
Report.Failed("Unexpected Constraint_Error: Func_Para");
return 0;
else
return 1995; -- any value other than this is unexpected
end if;
when others => Report.Failed("Unexpected exception: Func_Para");
return -42;
end Func_Para;
protected body Prot_Obj is
procedure Prot_Proc is
begin
if Expect_Exception then
Report.Failed("Expected exception did not occur: Prot_Proc");
end if;
end Prot_Proc;
function Prot_Func return Boolean is
begin
if Expect_Exception then
Report.Failed("Expected exception did not occur: Prot_Func");
end if;
return Report.Ident_Bool( True );
end Prot_Func;
end Prot_Obj;
end C410001_0;
------------------------------------------------------------------- C410001
with Report;
with TCTouch;
with C410001_0;
procedure C410001 is
Proc_Ref_Var : C410001_0.Proc_Ref;
Func_Ref_Var : C410001_0.Func_Ref;
Proc_Para_Ref_Var : C410001_0.Proc_Para_Ref;
Func_Para_Ref_Var : C410001_0.Func_Para_Ref;
type Enclosure is record
Prot_Proc_Ref_Var : C410001_0.Prot_Proc_Ref;
Prot_Func_Ref_Var : C410001_0.Prot_Func_Ref;
end record;
Enclosed : Enclosure;
Valid_Proc : C410001_0.Proc_Ref := C410001_0.Proc'Access;
Valid_Func : C410001_0.Func_Ref := C410001_0.Func'Access;
procedure Make_Calls( Expecting_Exceptions : Boolean ) is
type Case_Numbers is range 1..6;
Some_Integer : Integer := 0;
begin
for Cases in Case_Numbers loop
Catch_Exception : begin
case Cases is
when 1 => Proc_Ref_Var.all;
when 2 => Some_Integer := Func_Ref_Var.all( Some_Integer );
when 3 => Proc_Para_Ref_Var( Valid_Proc );
when 4 => Some_Integer := Func_Para_Ref_Var( Valid_Func );
when 5 => Enclosed.Prot_Proc_Ref_Var.all;
when 6 => TCTouch.Assert( Enclosed.Prot_Func_Ref_Var.all
/= Expecting_Exceptions,
"Case 6");
end case;
if Expecting_Exceptions then
Report.Failed("Exception expected: Case"
& Case_Numbers'Image(Cases) );
end if;
exception
when Constraint_Error =>
if not Expecting_Exceptions then
Report.Failed("Constraint_Error not expected: Case"
& Case_Numbers'Image(Cases) );
end if;
when others =>
Report.Failed("Wrong/Bad Exception: Case"
& Case_Numbers'Image(Cases) );
end Catch_Exception;
end loop;
end Make_Calls;
begin -- Main test procedure.
Report.Test ("C410001", "Check that evaluating an access to subprogram " &
"variable containing the value null causes the " &
"exception Constraint_Error. Check that the " &
"default value for objects of access to " &
"subprogram types is null" );
-- check that the default values are null
declare
use C410001_0; -- make all "="'s visible for all types
begin
TCTouch.Assert( Proc_Ref_Var = null, "Proc_Ref_Var = null" );
TCTouch.Assert( Func_Ref_Var = null, "Func_Ref_Var = null" );
TCTouch.Assert( Proc_Para_Ref_Var = null, "Proc_Para_Ref_Var = null" );
TCTouch.Assert( Func_Para_Ref_Var = null, "Func_Para_Ref_Var = null" );
TCTouch.Assert( Enclosed.Prot_Proc_Ref_Var = null,
"Enclosed.Prot_Proc_Ref_Var = null" );
TCTouch.Assert( Enclosed.Prot_Func_Ref_Var = null,
"Enclosed.Prot_Func_Ref_Var = null" );
end;
-- check that calls via the default values cause Constraint_Error
C410001_0.Expect_Exception := True;
Make_Calls( Expecting_Exceptions => True );
-- assign non-null values to the objects
Proc_Ref_Var := C410001_0.Proc'Access;
Func_Ref_Var := C410001_0.Func'Access;
Proc_Para_Ref_Var := C410001_0.Proc_Para'Access;
Func_Para_Ref_Var := C410001_0.Func_Para'Access;
Enclosed := (C410001_0.Prot_Obj.Prot_Proc'Access,
C410001_0.Prot_Obj.Prot_Func'Access);
-- check that the calls perform normally
C410001_0.Expect_Exception := False;
Make_Calls( Expecting_Exceptions => False );
-- check that a passed null value causes Constraint_Error
C410001_0.Expect_Exception := True;
Proc_Para_Ref_Var( null );
TCTouch.Assert( Func_Para_Ref_Var( null ) = 1995,
"Func_Para_Ref_Var( null )");
-- assign the null value to the objects
Proc_Ref_Var := null;
Func_Ref_Var := null;
Proc_Para_Ref_Var := null;
Func_Para_Ref_Var := null;
Enclosed := (null,null);
-- check that calls now again cause Constraint_Error
C410001_0.Expect_Exception := True;
Make_Calls( Expecting_Exceptions => True );
Report.Result;
end C410001;
|