Component Testing for C
Stub simulation is based on the idea certain functions are to be simulated and are therefore replaced with other functions which are generated in the test driver. These generated functions, or stubs, have the same interface as the simulated functions, but the body of the functions is replaced.
These stubs have the following roles:
Store input values to simulated functions
Assign output values from simulated functions
To be able to generate these stubs, the Test Script Compiler needs to know:
The prototypes of the functions that are to be simulated
the method of passing each parameter (input, output, or input/output).
When using the Component Testing Wizard, you specify the functions that you want to stub. This automatically adds the corresponding code to the .ptu test script. On execution of the test, Component Testing for C generates the stub in the test driver, which includes:
a variable array for the input values of the stub
a variable array for the output values of the stub
a body declaration for the stub function
When generating a stub for a function, Test RealTime considers the first prototype of the function that is encountered, which can be:
The declaration of the function in an included header file.
The declaration DEFINE STUB statement in the .ptu test script.
This means that the declaration of the function contained in the DEFINE STUB statement is ignored if the function was previously declared in a header file.
If an existing body of stubbed function is encountered, Test RealTime renames the existing body to atl_stub_<function-name> and the stubbed version of the function is used in the test driver.
Passing parameters by pointer can lead to problems of ambiguity regarding the data actually passed to the function. For example, a parameter that is described in a prototype by int *x can be passed in the following way:
int *x as input ==> f(x)
int x as output or input/output ==> f(&x)
int x[10] as input ==> f(x)
int x[10] as output or input/output ==> f(x)
Therefore, to describe the stubs, you should specify the following:
The data type in the calling function
The method of passing the data
Example
An example project called Stub C is available from the Examples section of the Start page. This example demonstrates the use of stubs in Component Testing for C. See Example projects for more information.
Related Topics
Stub Definition in C | Stub Usage in C | Sizing Stubs | Replacing Stubs | Advanced Stubs | Example projects