background image
<< Passing Parameters | Stub Usage >>
<< Passing Parameters | Stub Usage >>

Modifying Stub Variable Values

Test RealTime - User Guide
·
The _out parameters will not be tested but will be given values by a new
expression in the stub.
·
The _inout parameters will be tested and then given values by a new
expression.
Any returned parameters are always taken to be _out parameters.
You must always define stubs after the BEGIN instruction and outside any SERVICE
block.
Modifying Stub Variable Values
You can define stubs so that the variable pointed to is updated with different values
in each test case. For example, to stub the following function:
extern void function_b(unsigned char * param_1);
Declare the stub as follows:
DEFINE STUB code_c
#void function_b(unsigned char _out param_1);
END DEFINE
Note Any _out parameter is automatically a pointer, therefore the asterisk is
not necessary.
To return '255' in the first test case and 'a' in the second test case, you would write the
following in your test script:
SERVICE function_a
SERVICE_TYPE extern
-- By function returned type declaration
#int ret_function_a;
TEST 1
FAMILY nominal
ELEMENT
VAR ret_function_a, init = 0, ev = 1
STUB function_b (255)
#ret_function_a = function_a();
END ELEMENT
END TEST -- TEST 1
TEST 2
FAMILY nominal
ELEMENT
VAR ret_function_a, init = 1, ev = 0
STUB function_b ('a')
#ret_function_a = function_a();
END ELEMENT
END TEST -- TEST 2
END SERVICE -- function_a
Simulating Global Variables
The simulated file can also contain global variables that are used by the functions
under test. In this case, as with simulated functions, you can simulate the global
variables by declaring them in the DEFINE STUB block, as shown in the following
example:
144