Functions Using const Parameters

Component Testing for C

Functions using const parameters sometimes produce compilation errors when stubbed withHCL® OneTest Embedded.

This is because the preprocessor generates variables that are used for testing calls to the STUBs. These variables have the same type as the parameter to the function being stubbed: const int. These const variables cannot be modified, causing the compilation errors.

To work around this problem, you can to indicate that type modifiers for a STUB parameter should be used in the function definition, but not in the declaration of the variables used to control the STUBs.

To do this, add an @ character as a prefix to the the type modifier. If your function takes a const pointer, then you don't need the @ prefix:

This technique can be used with any type modifier.

Example

Consider the following function:

extern int ConstParam(const int param);

To stub the function, you would normally write the following lines in the .ptu test script. These will produce compilation error messages:

DEFINE STUB Example

#int ConstParam(const int _in param);

END DEFINE

Instead, use the following syntax to define the stub:

DEFINE STUB Example

#int ConstParam(@const int _in param);

END DEFINE

If your function takes a const pointer:

DEFINE STUB Example

#int ConstParam(const int _in *param);

END DEFINE