background image
<< Replacing Stubs | Functions Containing Type Modifiers >>
<< Replacing Stubs | Functions Containing Type Modifiers >>

Creating Complex Stubs in C

Automated Testing
Advanced Stubs
This section covers some of the more complex notions when dealing with stub
simulations in Component Testing for Ada.
Creating Complex Stubs in C
If necessary, you can make stub operation more complex by inserting native code
into the body of the simulated function. You can do this easily by adding the lines of
native code after the prototype, as shown in the following example:
DEFINE STUB file
#int fic_errno;
#char fic_err_msg[100];
#int open_file(char _in f[100])
# { errno = fic_errno; }
#int create_file(char _in f[100])
# { errno = fic_errno; }
#int read_file(int _in fd, char _out l[100])
# { errno = fic_errno; }
#int write_file(int fd, char _in l[100])
# { errno = fic_errno; }
#int close_file(int fd)
# { errno = fic_errno; }
END DEFINE
Excluding a Parameter from a Stub
Stub Definition
You can specify in the stub definition that a particular parameter is not to be tested or
given a value. You do this using a modifier of type _no instead of _in, _out or _inout,
as shown in the following example:
DEFINE STUB file
#int open_file(char _in f[100]);
#int create_file(char _in f[100]);
#int read_file(int _no fd, char _out l[100]);
#int write_file(int _no fd, char _in l[100]);
#int close_file(int fd);
END DEFINE
In this example, the fd parameters to read_file and write_file are never tested.
Note You need to be careful when using _no on an output parameter, as no
value will be assigned to it. It will then be difficult to predict the behavior of
the function under test on returning from the stub.
Stub Usage
Parameters that have not been tested (preceded by _no) are completely ignored in the
stub description. The two values of the input/output parameters are located between
brackets as shown in the following example:
DEFINE STUB file
#int open_file(char _in f[100]);
147