Component Testing for Ada
The following example highlights the simulation of all functions and procedures declared in the specification of file_io. A new body is generated for file_io in file <testname>_fct_simule.ada.
HEADER file, 1, 1
BEGIN
DEFINE STUB file_io
END DEFINE
You must always define stubs after the BEGIN instruction and outside any SERVICE block.
You can stub a generic unit like an ordinary unit with the following restrictions:
Parameters of a procedure or function, and function return types of a type declared in a generic unit or parameter of this unit must use the _NO mode.
For example, if you want to stub the following generic package:
GENERIC
TYPE TYPE_PARAM is .....;
Package GEN is
TYPE TYPE_INTO is ....;
procedure PROC(x:TYPE_PARAM,y:in out TYPE_INTO,Z:out integer);
function FUNC return TYPE_INTO;
end GEN;
Use the following stub definition:
DEFINE STUB GEN
# procedure PROC(x: _NO TYPE_PARAM,y: _NO TYPE_INTO,Z:out integer);
# function FUNC return _NO TYPE_INTO;
END DEFINE
You can add a body to procedures and functions to process any parameters that required the _NO mode.
Note With some compilers, when stubbing a unit by using a WITH operator on the generic package, cross dependencies may occur.
It some cases, you might need to define the body stub separately, with a proprietary behavior. Declare the stub separately as shown in the following example, and then you can define a body for it:
DEFINE STUB <STUB NAME>
# procedure My_Procedure(...) is separate ;
END DEFINE
The Ada Test Script Compiler will not generate a body for the service My_Procedure, but will expect you to do so.
Related Topics
Stub Simulation | Using Stubs | Sizing Stubs | Ada Syntax Extensions | Advanced Stubs (Ada)