Excluding a Parameter from a Stub

Component Testing for C

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. Therefore, changing _in to _no in the DEFINE STUB means that you must remove the corresponding input value in each STUB check.

The easiest way to disable the check value is to add the _nocheck keyword before the _in.

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]);

#int create_file(char _in f[100]);

#int read_file(int _no fd, char _inout l[100]);

#int write_file(int _no fd, char _in l[100]);

#int close_file(int _no fd);

END DEFINE

...

STUB open_file ("file1")3

STUB create_file ("file2")4

STUB read_file (("","line 1"))1, (("line 1","line 2"))1,

& (("line2",""))0

STUB write_file ("line 1")1, ("line 2")1

STUB close_file ()1, ()1

If a stub is called and if it has not been declared in a scenario, an error is raised in the report because the number of the calls of each stub is always checked.