Advanced Stubs
Test RealTime - User Guide
STUB write_file 1=>(4,"line")1,others=>(4,"")1
Advanced Stubs
This section covers some of the more complex notions when dealing with stub
simulations in Component Testing for Ada.
Creating Complex Stubs
If necessary, you can make stub operation more complex by inserting native Ada
code into the body of the simulated function. You can do this easily by adding the
lines of native code after the prototype.
Example
The following stub definition makes extensive use of native Ada code.
DEFINE STUB file
#function open_file(f:string) return file_t is
#begin
# raise file_error;
#end;
END DEFINE
Excluding a Parameter from a Stub
You can specify in the stub definition that a particular parameter is not to be tested or
given a value. This is done using a modifier of type no instead of in, out or in out.
Note You must be careful when using _no on an output parameter, as no
value will be assigned. It will then be difficult to predict the behavior of the
function under test on returning from the stub.
Example
In this example, the
f
parameters to
read_file
and
write_file
are never tested.
DEFINE STUB file
#procedure read_file(f: _no file_t; l:out string; res:out
BOOLEAN);
#procedure write_file(f: _no file_t, l : string);
END DEFINE
Simulating Generic Units
You can stub a generic unit like an ordinary one, as follows:
DEFINE STUB STUB_NAME < dimension>
# optional declarations
END DEFINE
The Unit Testing Ada Test Compiler will generate a stub body for this unit to
perform the desired simulations.
Simulating Functions with _inout Mode Arrays
To stub a function taking an array in _inout mode, you must provide storage space
for the actual parameters of the function.
114