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 exceptions propagate correctly from objects of
28 -- protected types. Check propagation from protected entry bodies.
31 -- Declare a package with a protected type, including entries and private
32 -- data, simulating a bounded buffer abstraction. In the main procedure,
33 -- perform entry calls on an object of the protected type that raises
35 -- Ensure that the exceptions are:
36 -- 1) raised and handled locally in the entry body
37 -- 2) raised in the entry body and handled/reraised to be handled
39 -- 3) raised in the entry body and propagated directly to the calling
44 -- 06 Dec 94 SAIC ACVC 2.0
48 package CB20004_0
is -- Package Buffer.
50 Max_Buffer_Size
: constant := 2;
54 Handled_In_Caller
: Boolean := False;
57 Data_Degradation
: exception;
59 type Data_Item
is range 0 .. 100;
61 type Item_Array_Type
is array (1 .. Max_Buffer_Size
) of Data_Item
;
63 protected type Bounded_Buffer
is
64 entry Put
(Item
: in Data_Item
);
65 entry Get
(Item
: out Data_Item
);
67 Item_Array
: Item_Array_Type
;
68 I
, J
: Integer range 1 .. Max_Buffer_Size
:= 1;
69 Count
: Integer range 0 .. Max_Buffer_Size
:= 0;
74 --=================================================================--
78 package body CB20004_0
is -- Package Buffer.
80 protected body Bounded_Buffer
is
82 entry Put
(Item
: in Data_Item
) when Count
< Max_Buffer_Size
is
85 Item_Array
(I
) := Item
* 8; -- Constraint_Error will be raised
86 elsif Item
> 5 then -- and handled in entry body.
87 raise Data_Over_5
; -- Exception handled/reraised in
88 else -- entry body, propagated to caller.
89 Item_Array
(I
) := Item
; -- Store data item in buffer.
90 I
:= (I
mod Max_Buffer_Size
) + 1;
94 when Constraint_Error
=>
95 Handled_In_Body
:= True;
97 Propagated_To_Caller
:= True;
98 raise; -- Propagate the exception to the caller.
102 entry Get
(Item
: out Data_Item
) when Count
> 0 is
104 Item
:= Item_Array
(J
);
105 J
:= (J
mod Max_Buffer_Size
) + 1;
108 raise Data_Degradation
; -- Exception to propagate to caller.
117 --=================================================================--
120 with CB20004_0
; -- Package Buffer.
125 package Buffer
renames CB20004_0
;
127 Data
: Buffer
.Data_Item
:= Buffer
.Data_Item
'First;
128 Data_Buffer
: Buffer
.Bounded_Buffer
; -- an object of protected type.
130 Handled_In_Caller
: Boolean := False; -- same name as boolean declared
131 -- in package Buffer.
134 Report
.Test
("CB20004", "Check that exceptions propagate correctly " &
135 "from objects of protected types" );
138 begin -- Data causes Constraint_Error.
139 Data_Buffer
.Put
(CB20004_0
.Data_Item
(Report
.Ident_Int
(51)));
142 when Constraint_Error
=>
143 Buffer
.Handled_In_Body
:= False; -- Improper exception handling
145 Report
.Failed
("Exception propagated to caller " &
146 " from Initial_Data_Block");
148 Report
.Failed
("Exception raised in processing and " &
149 "propagated to caller from Initial_Data_Block");
150 end Initial_Data_Block
;
155 -- Valid data. No exception.
156 Data_Buffer
.Put
(CB20004_0
.Data_Item
(Report
.Ident_Int
(3)));
158 -- Data will cause exception.
159 Data_Buffer
.Put
(7); -- Call protected object entry,
160 -- exception to be handled/
161 -- reraised in entry body.
162 Report
.Failed
("Data_Over_5 Exception not raised in processing");
164 when Buffer
.Data_Over_5
=>
165 if Buffer
.Propagated_To_Caller
then -- Reraised in entry body?
166 Buffer
.Handled_In_Caller
:= True;
168 Report
.Failed
("Exception not reraised in entry body");
171 Report
.Failed
("Exception raised in processing and propagated " &
172 "to caller from Data_Entry_Block");
173 end Data_Entry_Block
;
176 Data_Retrieval_Block
:
179 Data_Buffer
.Get
(Data
); -- Retrieval of buffer data, buffer now empty.
180 -- Exception will be raised in entry body, with
181 -- propagation to caller.
182 Report
.Failed
("Data_Degradation Exception not raised in processing");
184 when Buffer
.Data_Degradation
=>
185 Handled_In_Caller
:= True; -- Local Boolean used here.
187 Report
.Failed
("Exception raised in processing and propagated " &
188 "to caller from Data_Retrieval_Block");
189 end Data_Retrieval_Block
;
192 if not (Buffer
.Handled_In_Body
and -- Validate proper exception
193 Buffer
.Propagated_To_Caller
and -- handling in entry bodies.
194 Buffer
.Handled_In_Caller
and
197 Report
.Failed
("Improper exception handling by entry bodies");