background image
<< Advanced Ada Testing | Test Program Entry Point >>
<< Advanced Ada Testing | Test Program Entry Point >>

Testing Generic Compilation Units

Automated Testing
Testing Generic Compilation Units
Types and objects in a generic unit depend on generic formal parameters that are not
known by the Test Script Compiler. Therefore, Component Testing for Ada cannot
directly test a generic package.
To test a generic package, you must first instanciate the package and then call the
instance. Such instances must appear in compilation units or at the beginning of the
test script, as follows:
WITH <generic>;
PACKAGE <instance> IS NEW <generic> (...);
Testing an instance of a generic package, however, causes problems in cases where
the test driver procedure must be generated separately from the tested package.
To avoid this, you need to generate the test driver separately and call it as a
procedure of the instance.
In the .ptu test script, replace the BEGIN line with the following statement:
BEGIN GENERIC(<Generic_Package>, <Instance>), <Procedure_Name>
where
<Generic_Package>
is the name of the generic unit under test, and
<Instance>
is the name of the instanciated unit from the generic. The
<Procedure_Name>
parameter is not mandatory. Component Testing uses Attol_Test by default.
This Syntax automatically generates a separate procedure
<Procedure_Name>
of
<Generic_Package>
and then calls the procedure
<Instance>
.
<Procedure_Name>
,
which is code generated by the Component Testing Preprocessor).
Note This technique also allows testing of private types within the generic
package.
Example
Consider the following Ada compilation unit:
Generic
Type t is private ;
Procedure swap(x,y :in out t) ;
Procedure swap(x,y :in out t) is
Z :t ;
Begin
Z := x ;
X := y;
Y := z;
End swap ;
With swap ;
Procedure swap_integer is new swap(integer) ;
You can test the
swap_integer
procedure just like any other procedure:
HEADER swap_integer,,
#with swap_integer;
BEGIN
SERVICE swap_integer
#x,y:integer;
117