3 -- Grant of Unlimited Rights
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687 and
6 -- F08630-91-C-0015, the U.S. Government obtained unlimited rights in the
7 -- software and documentation contained herein. Unlimited rights are
8 -- defined in DFAR 252.227-7013(a)(19). By making this public release,
9 -- the Government intends to confer upon all recipients unlimited rights
10 -- equal to those held by the Government. These rights include rights to
11 -- use, duplicate, release or disclose the released technical data and
12 -- computer software in whole or in part, in any manner and for any purpose
13 -- whatsoever, and to have or permit others to do so.
17 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
18 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
19 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
20 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
21 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
22 -- PARTICULAR PURPOSE OF SAID MATERIAL.
26 -- Check that task discriminants that have an access subtype may be
29 -- Note that discriminants in Ada 83 never can be dereferenced with
30 -- selection or indexing, as they cannot have an access type.
33 -- A protected object is defined to create a simple buffer.
34 -- Two task types are defined, one to put values into the buffer,
35 -- and one to remove them. The tasks are passed a buffer object as
36 -- a discriminant with an access subtype. The producer task type includes
37 -- a discriminant to determine the values to product. The consumer task
38 -- type includes a value to save the results.
39 -- Two producer and one consumer tasks are declared, and the results
43 -- 10 Mar 99 RLB Created test.
47 package C910003_Pack
is
49 type Item_Type
is range 1 .. 100; -- In a real application, this probably
50 -- would be a record type.
52 type Item_Array
is array (Positive range <>) of Item_Type
;
54 protected type Buffer
is
55 entry Put
(Item
: in Item_Type
);
56 entry Get
(Item
: out Item_Type
);
57 function TC_Items_Buffered
return Item_Array
;
59 Saved_Item
: Item_Type
;
60 Empty
: Boolean := True;
61 TC_Items
: Item_Array
(1 .. 10);
62 TC_Last
: Natural := 0;
65 type Buffer_Access_Type
is access Buffer
;
67 PRODUCE_COUNT
: constant := 2; -- Number of items to produce.
69 task type Producer
(Buffer_Access
: Buffer_Access_Type
;
70 Start_At
: Item_Type
);
71 -- Produces PRODUCE_COUNT items. Starts when activated.
73 type TC_Item_Array_Access_Type
is access Item_Array
(1 .. PRODUCE_COUNT
*2);
75 task type Consumer
(Buffer_Access
: Buffer_Access_Type
;
76 Results
: TC_Item_Array_Access_Type
) is
77 -- Stores PRODUCE_COUNT*2 items consumed in Results. Starts when
79 entry Wait_until_Done
;
86 package body C910003_Pack
is
88 protected body Buffer
is
89 entry Put
(Item
: in Item_Type
) when Empty
is
93 TC_Last
:= TC_Last
+ 1;
94 TC_Items
(TC_Last
) := Item
;
97 entry Get
(Item
: out Item_Type
) when not Empty
is
103 function TC_Items_Buffered
return Item_Array
is
105 return TC_Items
(1..TC_Last
);
106 end TC_Items_Buffered
;
111 task body Producer
is
112 -- Produces PRODUCE_COUNT items. Starts when activated.
114 for I
in 1 .. Report
.Ident_Int
(PRODUCE_COUNT
) loop
115 Buffer_Access
.Put
(Start_At
+ (Item_Type
(I
)-1)*2);
120 task body Consumer
is
121 -- Stores PRODUCE_COUNT*2 items consumed in Results. Starts when
124 for I
in 1 .. Report
.Ident_Int
(PRODUCE_COUNT
*2) loop
125 Buffer_Access
.Get
(Results
(I
));
126 -- Buffer_Access and Results are both dereferenced.
129 -- Check the results (and function call with a prefix dereference).
130 if Results
.all(Report
.Ident_Int
(1)) /= Buffer_Access
.all.TC_Items_Buffered
(Report
.Ident_Int
(1)) then
131 Report
.Failed
("First item mismatch");
133 if Results
(Report
.Ident_Int
(2)) /= Buffer_Access
.TC_Items_Buffered
(Report
.Ident_Int
(2)) then
134 Report
.Failed
("Second item mismatch");
136 accept Wait_until_Done
; -- Tell main that we're done.
149 Report
.Test
("C910003", "Check that tasks discriminants of access types can be dereferenced");
152 declare -- encapsulate the test
154 Buffer_Access
: C910003_Pack
.Buffer_Access_Type
:=
155 new C910003_Pack
.Buffer
;
157 TC_Results
: C910003_Pack
.TC_Item_Array_Access_Type
:=
158 new C910003_Pack
.Item_Array
(1 .. C910003_Pack
.PRODUCE_COUNT
*2);
160 Producer_1
: C910003_Pack
.Producer
(Buffer_Access
, 12);
161 Producer_2
: C910003_Pack
.Producer
(Buffer_Access
, 23);
163 Consumer
: C910003_Pack
.Consumer
(Buffer_Access
, TC_Results
);
165 use type C910003_Pack
.Item_Array
; -- For /=.
168 Consumer
.Wait_until_Done
;
169 if TC_Results
.all /= Buffer_Access
.TC_Items_Buffered
then
170 Report
.Failed
("Different items buffered than returned - Main");
172 if (TC_Results
.all /= (12, 14, 23, 25) and
173 TC_Results
.all /= (12, 23, 14, 25) and
174 TC_Results
.all /= (12, 23, 25, 14) and
175 TC_Results
.all /= (23, 12, 14, 25) and
176 TC_Results
.all /= (23, 12, 25, 14) and
177 TC_Results
.all /= (23, 25, 12, 14)) then
178 -- Above are the only legal results.
179 Report
.Failed
("Wrong results");
181 end; -- encapsulation