background image
<< Advanced Stubs | Advanced Ada Testing >>
<< Advanced Stubs | Advanced Ada Testing >>

DEFINE STUB

Automated Testing
The function prototype in the .ptu test script remains as usual:
#extern void function(unsigned char *table);
The DEFINE STUB statement however is slightly modified:
DEFINE STUB Funct
#void function(unsigned char _inout table[10]);
END DEFINE
The declaration of the pointer as an array with explicit size is necessary to memorize
the actual parameters when calling the stubbed function. For each call you must
specify the exact number of required array elements.
ELEMENT
STUB Funct.function 1 => (({'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 0x0},
& {'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a', 0x0}))
#call_the_code_under_test();
END ELEMENT
This naming convention compares the actual values and not the pointers.
The following line shows how to pass _inout parameters:
({<in_parameter>},{<out_parameter>})
Simulating Functions with Varying Parameters
In some cases, functions may be designed to accept a variable number of parameters
on each call.
You can still stub these functions with the Component Testing feature by using the
'...' syntax indicating that there may be additional parameters of unknown type and
name.
In this case, Component Testing can only test the validity of the first parameter.
Example
The standard
printf
function is a good a example of a function that can take a variable
number of parameters:
int printf (const char* param, ...);
Here is an example including a STUB of the
printf
function:
HEADER add, 1, 1
#extern int add(int a, int b);
##include <stdio.h>
BEGIN
DEFINE STUB MulitParam
#int printf (const char param[200], ...);
END DEFINE
SERVICE add
#int a, b, c;
TEST 1
FAMILY nominal
ELEMENT
115