1 |
720 |
jeremybenn |
-- CB41001.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 'Identity attribute returns the unique identity of an
|
28 |
|
|
-- exception. Check that the Raise_Exception procedure can raise an
|
29 |
|
|
-- exception that is specified through the use of the 'Identity attribute,
|
30 |
|
|
-- and that Reraise_Occurrence can re-raise an exception occurrence
|
31 |
|
|
-- using an exception choice parameter.
|
32 |
|
|
--
|
33 |
|
|
-- TEST DESCRIPTION:
|
34 |
|
|
-- This test uses the capability of the 'Identity attribute, which
|
35 |
|
|
-- returns the unique identity of an exception, as an Exception_Id
|
36 |
|
|
-- result. This result is used as an input parameter to the procedure
|
37 |
|
|
-- Raise_Exception. The exception that results is handled, propagated
|
38 |
|
|
-- using the Reraise_Occurrence procedure, and handled again.
|
39 |
|
|
-- The above actions are performed for both a user-defined and a
|
40 |
|
|
-- predefined exception.
|
41 |
|
|
--
|
42 |
|
|
--
|
43 |
|
|
-- CHANGE HISTORY:
|
44 |
|
|
-- 06 Dec 94 SAIC ACVC 2.0
|
45 |
|
|
-- 11 Nov 96 SAIC ACVC 2.1: Modified Propagate_User_Exception.
|
46 |
|
|
--
|
47 |
|
|
--!
|
48 |
|
|
|
49 |
|
|
with Report;
|
50 |
|
|
with Ada.Exceptions;
|
51 |
|
|
|
52 |
|
|
procedure CB41001 is
|
53 |
|
|
|
54 |
|
|
begin
|
55 |
|
|
|
56 |
|
|
Report.Test ("CB41001", "Check that the 'Identity attribute returns " &
|
57 |
|
|
"the unique identity of an exception. Check " &
|
58 |
|
|
"that the 'Identity attribute is of type " &
|
59 |
|
|
"Exception_Id. Check that the " &
|
60 |
|
|
"Raise_Exception procedure can raise an " &
|
61 |
|
|
"exception that is specified through the " &
|
62 |
|
|
"use of the 'Identity attribute");
|
63 |
|
|
Test_Block:
|
64 |
|
|
declare
|
65 |
|
|
|
66 |
|
|
Check_Points : constant := 5;
|
67 |
|
|
|
68 |
|
|
type Check_Point_Array_Type is array (1..Check_Points) of Boolean;
|
69 |
|
|
|
70 |
|
|
-- Global array used to track the processing path through the test.
|
71 |
|
|
TC_Check_Points : Check_Point_Array_Type := (others => False);
|
72 |
|
|
|
73 |
|
|
A_User_Defined_Exception : Exception;
|
74 |
|
|
An_Exception_ID : Ada.Exceptions.Exception_Id :=
|
75 |
|
|
Ada.Exceptions.Null_Id;
|
76 |
|
|
|
77 |
|
|
procedure Propagate_User_Exception is
|
78 |
|
|
Hidden_Exception : Exception;
|
79 |
|
|
begin
|
80 |
|
|
-- Use the 'Identity function to store the unique identity of a
|
81 |
|
|
-- user defined exception into a variable of type Exception_Id.
|
82 |
|
|
|
83 |
|
|
An_Exception_ID := A_User_Defined_Exception'Identity;
|
84 |
|
|
|
85 |
|
|
-- Raise this user defined exception using the result of the
|
86 |
|
|
-- 'Identity attribute.
|
87 |
|
|
|
88 |
|
|
Ada.Exceptions.Raise_Exception(E => An_Exception_Id);
|
89 |
|
|
|
90 |
|
|
Report.Failed("User defined exception not raised by " &
|
91 |
|
|
"procedure Propagate_User_Exception");
|
92 |
|
|
|
93 |
|
|
exception
|
94 |
|
|
when Proc_Excpt : A_User_Defined_Exception => -- Expected exception.
|
95 |
|
|
begin
|
96 |
|
|
|
97 |
|
|
-- By raising a different exception at this point, the
|
98 |
|
|
-- information associated with A_User_Defined_Exception must
|
99 |
|
|
-- be correctly stacked internally.
|
100 |
|
|
|
101 |
|
|
Ada.Exceptions.Raise_Exception(Hidden_Exception'Identity);
|
102 |
|
|
Report.Failed("Hidden_Exception not raised by " &
|
103 |
|
|
"procedure Propagate_User_Exception");
|
104 |
|
|
exception
|
105 |
|
|
when others =>
|
106 |
|
|
TC_Check_Points(1) := True;
|
107 |
|
|
|
108 |
|
|
-- Reraise the original exception, which will be propagated
|
109 |
|
|
-- outside the scope of this procedure.
|
110 |
|
|
|
111 |
|
|
Ada.Exceptions.Reraise_Occurrence(Proc_Excpt);
|
112 |
|
|
Report.Failed("User defined exception not reraised");
|
113 |
|
|
|
114 |
|
|
end;
|
115 |
|
|
|
116 |
|
|
when others =>
|
117 |
|
|
Report.Failed("Unexpected exception raised by " &
|
118 |
|
|
"Procedure Propagate_User_Exception");
|
119 |
|
|
end Propagate_User_Exception;
|
120 |
|
|
|
121 |
|
|
begin
|
122 |
|
|
|
123 |
|
|
User_Exception_Block:
|
124 |
|
|
begin
|
125 |
|
|
-- Call procedure to raise, handle, and reraise a user defined
|
126 |
|
|
-- exception.
|
127 |
|
|
Propagate_User_Exception;
|
128 |
|
|
|
129 |
|
|
Report.Failed("User defined exception not propagated from " &
|
130 |
|
|
"procedure Propagate_User_Exception");
|
131 |
|
|
|
132 |
|
|
exception
|
133 |
|
|
when A_User_Defined_Exception => -- Expected exception.
|
134 |
|
|
TC_Check_Points(2) := True;
|
135 |
|
|
when others =>
|
136 |
|
|
Report.Failed
|
137 |
|
|
("Unexpected exception handled in User_Exception_Block");
|
138 |
|
|
end User_Exception_Block;
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
Predefined_Exception_Block:
|
142 |
|
|
begin
|
143 |
|
|
|
144 |
|
|
Inner_Block:
|
145 |
|
|
begin
|
146 |
|
|
|
147 |
|
|
begin
|
148 |
|
|
-- Use the 'Identity attribute as an input parameter to the
|
149 |
|
|
-- Raise_Exception procedure.
|
150 |
|
|
|
151 |
|
|
Ada.Exceptions.Raise_Exception(Constraint_Error'Identity);
|
152 |
|
|
Report.Failed("Constraint_Error not raised in Inner_Block");
|
153 |
|
|
|
154 |
|
|
exception
|
155 |
|
|
when Excpt : Constraint_Error => -- Expected exception.
|
156 |
|
|
TC_Check_Points(3) := True;
|
157 |
|
|
|
158 |
|
|
-- Reraise the exception.
|
159 |
|
|
Ada.Exceptions.Reraise_Occurrence(X => Excpt);
|
160 |
|
|
Report.Failed("Predefined exception not raised from " &
|
161 |
|
|
"within the exception handler - 1");
|
162 |
|
|
when others =>
|
163 |
|
|
Report.Failed("Incorrect result from attempt to raise " &
|
164 |
|
|
"Constraint_Error using the 'Identity " &
|
165 |
|
|
"attribute - 1");
|
166 |
|
|
end;
|
167 |
|
|
|
168 |
|
|
Report.Failed("Constraint_Error not reraised in Inner_Block");
|
169 |
|
|
|
170 |
|
|
exception
|
171 |
|
|
when Block_Excpt : Constraint_Error => -- Expected exception.
|
172 |
|
|
TC_Check_Points(4) := True;
|
173 |
|
|
|
174 |
|
|
-- Reraise the exception in a scope where the exception
|
175 |
|
|
-- was not originally raised.
|
176 |
|
|
|
177 |
|
|
Ada.Exceptions.Reraise_Occurrence(X => Block_Excpt);
|
178 |
|
|
Report.Failed("Predefined exception not raised from " &
|
179 |
|
|
"within the exception handler - 2");
|
180 |
|
|
|
181 |
|
|
when others =>
|
182 |
|
|
Report.Failed("Incorrect result from attempt to raise " &
|
183 |
|
|
"Constraint_Error using the 'Identity " &
|
184 |
|
|
"attribute - 2");
|
185 |
|
|
end Inner_Block;
|
186 |
|
|
|
187 |
|
|
Report.Failed("Exception not propagated from Inner_Block");
|
188 |
|
|
|
189 |
|
|
exception
|
190 |
|
|
when Constraint_Error => -- Expected exception.
|
191 |
|
|
TC_Check_Points(5) := True;
|
192 |
|
|
when others =>
|
193 |
|
|
Report.Failed("Unexpected exception handled after second " &
|
194 |
|
|
"reraise of Constraint_Error");
|
195 |
|
|
end Predefined_Exception_Block;
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
-- Verify the processing path taken through the test.
|
199 |
|
|
|
200 |
|
|
for i in 1..Check_Points loop
|
201 |
|
|
if not TC_Check_Points(i) then
|
202 |
|
|
Report.Failed("Incorrect processing path taken through test, " &
|
203 |
|
|
"didn't pass check point #" & Integer'Image(i));
|
204 |
|
|
end if;
|
205 |
|
|
end loop;
|
206 |
|
|
|
207 |
|
|
exception
|
208 |
|
|
when others => Report.Failed ("Exception raised in Test_Block");
|
209 |
|
|
end Test_Block;
|
210 |
|
|
|
211 |
|
|
Report.Result;
|
212 |
|
|
|
213 |
|
|
end CB41001;
|