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 a storage pool may be user_determined, and that storage
28 -- is allocated by calling Allocate.
30 -- Check that a storage.pool may be specified using 'Storage_Pool
31 -- and that S'Storage_Pool denotes the storage pool of the type S.
34 -- The package System.Storage_Pools is exercised by two very similar
35 -- packages which define a tree type and exercise it in a simple manner.
36 -- One package uses a user defined pool. The other package uses a
37 -- storage pool assigned by the implementation; Storage_Size is
38 -- specified for this pool.
39 -- The dispatching procedures Allocate and Deallocate are tested as an
40 -- intentional side effect of the tree packages.
42 -- For completeness, the actions of the tree packages are checked for
46 -- The following files comprise this test:
48 -- FDB0A00.A (foundation code)
53 -- 02 JUN 95 SAIC Initial version
54 -- 07 MAY 96 SAIC Removed ambiguity with CDB0A02
55 -- 13 FEB 97 PWB.CTA Corrected lexically ordered string literal
58 ---------------------------------------------------------------- CDB0A01_1
60 ---------------------------------------------------------- FDB0A00.Pool1
62 package FDB0A00
.Pool1
is
63 User_Pool
: Stack_Heap
( 5_000
);
66 ---------------------------------------------------------- FDB0A00.Comparator
68 with System
.Storage_Pools
;
69 package FDB0A00
.Comparator
is
71 function "="( A
,B
: System
.Storage_Pools
.Root_Storage_Pool
'Class )
74 end FDB0A00
.Comparator
;
76 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
79 package body FDB0A00
.Comparator
is
81 function "="( A
,B
: System
.Storage_Pools
.Root_Storage_Pool
'Class )
83 use type System
.Address
;
85 return A
'Address = B
'Address;
88 end FDB0A00
.Comparator
;
90 ---------------------------------------------------------------- CDB0A01_2
96 type User_Pool_Tree
is access Cell
;
98 for User_Pool_Tree
'Storage_Pool use FDB0A00
.Pool1
.User_Pool
;
102 Left
,Right
: User_Pool_Tree
;
105 procedure Insert
( Item
: Character; On_Tree
: in out User_Pool_Tree
);
107 procedure Traverse
( The_Tree
: User_Pool_Tree
);
109 procedure Defoliate
( The_Tree
: in out User_Pool_Tree
);
113 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
116 with Unchecked_Deallocation
;
117 package body CDB0A01_2
is
118 procedure Deallocate
is new Unchecked_Deallocation
(Cell
,User_Pool_Tree
);
120 -- Sort: zeros on the left, ones on the right...
121 procedure Insert
( Item
: Character; On_Tree
: in out User_Pool_Tree
) is
123 if On_Tree
= null then
124 On_Tree
:= new Cell
'(Item,null,null);
125 elsif Item > On_Tree.Data then
126 Insert(Item,On_Tree.Right);
128 Insert(Item,On_Tree.Left);
132 procedure Traverse( The_Tree : User_Pool_Tree ) is
134 if The_Tree = null then
135 null; -- how very symmetrical
137 Traverse(The_Tree.Left);
138 TCTouch.Touch(The_Tree.Data);
139 Traverse(The_Tree.Right);
143 procedure Defoliate( The_Tree : in out User_Pool_Tree ) is
146 if The_Tree.Left /= null then
147 Defoliate(The_Tree.Left);
150 if The_Tree.Right /= null then
151 Defoliate(The_Tree.Right);
154 Deallocate(The_Tree);
160 ---------------------------------------------------------------- CDB0A01_3
166 type System_Pool_Tree is access Cell;
168 for System_Pool_Tree'Storage_Size use 2000;
170 -- assumptions: Cell is <= 20 storage_units
171 -- Tree building exercise requires O(15) cells
172 -- 2000 > 20 * 15 by a generous margin
176 Left,Right : System_Pool_Tree;
179 procedure Insert( Item: Character; On_Tree : in out System_Pool_Tree );
181 procedure Traverse( The_Tree : System_Pool_Tree );
183 procedure Defoliate( The_Tree : in out System_Pool_Tree );
187 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
190 with Unchecked_Deallocation;
191 package body CDB0A01_3 is
192 procedure Deallocate is new Unchecked_Deallocation(Cell,System_Pool_Tree);
194 -- Sort: zeros on the left, ones on the right...
195 procedure Insert( Item: Character; On_Tree : in out System_Pool_Tree ) is
197 if On_Tree = null then
198 On_Tree := new Cell'(Item
,null,null);
199 elsif Item
> On_Tree
.Data
then
200 Insert
(Item
,On_Tree
.Right
);
202 Insert
(Item
,On_Tree
.Left
);
206 procedure Traverse
( The_Tree
: System_Pool_Tree
) is
208 if The_Tree
= null then
209 null; -- how very symmetrical
211 Traverse
(The_Tree
.Left
);
212 TCTouch
.Touch
(The_Tree
.Data
);
213 Traverse
(The_Tree
.Right
);
217 procedure Defoliate
( The_Tree
: in out System_Pool_Tree
) is
220 if The_Tree
.Left
/= null then
221 Defoliate
(The_Tree
.Left
);
224 if The_Tree
.Right
/= null then
225 Defoliate
(The_Tree
.Right
);
228 Deallocate
(The_Tree
);
234 ------------------------------------------------------------------ CDB0A01
238 with FDB0A00
.Comparator
;
245 Banyan
: CDB0A01_2
.User_Pool_Tree
;
246 Torrey
: CDB0A01_3
.System_Pool_Tree
;
248 use type CDB0A01_2
.User_Pool_Tree
;
249 use type CDB0A01_3
.System_Pool_Tree
;
251 Countess
: constant String := "Ada Augusta Lovelace";
252 Cenosstu
: constant String := " AALaaacdeeglostuuv";
253 Insertion
: constant String := "AAAAAAAAAAAAAAAAAAAA";
254 Deallocation
: constant String := "DDDDDDDDDDDDDDDDDDDD";
256 begin -- Main test procedure.
258 Report
.Test
("CDB0A01", "Check that a storage pool may be " &
259 "user_determined, and that storage is " &
260 "allocated by calling Allocate. Check that " &
261 "a storage.pool may be specified using " &
262 "'Storage_Pool and that S'Storage_Pool denotes " &
263 "the storage pool of the type S" );
265 -- Check that S'Storage_Pool denotes the storage pool for the type S.
268 FDB0A00
.Comparator
."="(FDB0A00
.Pool1
.User_Pool
,
269 CDB0A01_2
.User_Pool_Tree
'Storage_Pool ),
270 "'Storage_Pool not correct for CDB0A01_2.User_Pool_Tree");
273 FDB0A00
.Comparator
."="(FDB0A00
.Pool1
.User_Pool
,
274 CDB0A01_3
.System_Pool_Tree
'Storage_Pool ),
275 "'Storage_Pool not correct for CDB0A01_3.System_Pool_Tree");
277 -- Check that storage is allocated by calling Allocate.
279 for Count
in Countess
'Range loop
280 CDB0A01_2
.Insert
( Countess
(Count
), Banyan
);
282 TCTouch
.Validate
(Insertion
, "Allocate calls via CDB0A01_2" );
284 for Count
in Countess
'Range loop
285 CDB0A01_3
.Insert
( Countess
(Count
), Torrey
);
287 TCTouch
.Validate
("", "Allocate calls via CDB0A01_3" );
289 CDB0A01_2
.Traverse
(Banyan
);
290 TCTouch
.Validate
(Cenosstu
, "Traversal of Banyan" );
292 CDB0A01_3
.Traverse
(Torrey
);
293 TCTouch
.Validate
(Cenosstu
, "Traversal of Torrey" );
295 CDB0A01_2
.Defoliate
(Banyan
);
296 TCTouch
.Validate
(Deallocation
, "Deforestation of Banyan" );
297 TCTouch
.Assert
(Banyan
= null, "Banyan Deallocation result not null");
299 CDB0A01_3
.Defoliate
(Torrey
);
300 TCTouch
.Validate
("", "Deforestation of Torrey" );
301 TCTouch
.Assert
(Torrey
= null, "Torrey Deallocation result not null");