Testing Tagged Records
Component Testing for Ada
Component Testing for Ada supports tagged record types. As with other classic records, you can omit a field in the initialization or evaluation part. You can also define tagged types with a discriminant part. In such cases, the only limitation is that of the discriminant.
Example
The following example illustrates tagged records. First, the source code:
Package Items Is
Type Item Is Tagged Record
X_Coord : Float;
Y_Coord : Float;
End Record;
Procedure foo_test;
End Items;
With Items; Use Items;
Package Forms Is
Type Point Is New Item With Null Record;
Type Circle Is New Item With Record
Radius : Float;
End Record;
Type Triangle Is New Item With Record
A,B,C : Float;
End Record;
Type Cylinder Is New Circle With Record
Height : Float;
End Record;
End Forms;
Following is the associated test script:
HEADER Items, ,
#With Items; Use Items;
#With Forms; Use Forms;
BEGIN Items
#I : Item := (1.0,0.5);
#C : Circle := (0.0,1.0,13.5);
#T : Triangle;
#P : Point;
#Cyl : Cylinder;
SERVICE Compute_Items
SERVICE_TYPE extern
TEST 1
FAMILY Nominal
ELEMENT
Var T, Init = (0.0,1.5,4.5,5.0,6.5), Ev = (I with A=>4.0, B=>5.0, C=>6.0)
Var P, Init = I, Ev = (Y_coord => 1.0, X_coord => 0.0)
Var I, Init = (0.0,1.0), Ev = Item(C)
Var P, Init = (I with NULL record), Ev = (Y_coord => 1.0, X_coord => 0.0)
End Element
END TEST -- Test 1
TEST 2
FAMILY Nominal
ELEMENT
Var I, Init = (2.0,3.0), Ev ==
Var T, Init = (2.0,3.0,4.0,5.0,6.0), Ev = (I with A=>4.0, B=>5.0, C=>6.0)
Var Cyl, Init = (2.0, 3.0, 4.0, 5.0), Ev ==
Var I, Init ==, Ev = Item(Cyl)
END ELEMENT
END TEST -- Test 2
END SERVICE -- Compute_Items
Related Topics
Testing Records | Testing a Record with Ada Expressions | Testing a Record with Another Record | Testing Records with Discriminants | No Test