IBM Support

STUB of return type char* returning a NULL pointer in a Test RealTime test script

Question & Answer


Question

Your function under test calls another function. The latter returns a pointer to a character or a NULL pointer. This function has the following prototype: char * returnCharPointer(void); How do you stub the function and in some tests make it return NULL? In other tests you need to return the address of a character. When you write: STUB returnCharPointer() NIL IBM Rational Test RealTime does not return NULL. The result is that the test always fails.

Cause

By default the Component Testing for C test script compiler considers that the data type (type) "char*" is a C string. The test script compiler interprets NIL as returning an empty string. Therefore you cannot make the stub return a NULL pointer.

Answer

You need to change the test script compilers default action to return a NULL pointer for the stub.

To change the default behavior for types the instruction FORMAT is available. However you can only use the FORMAT instruction on types that you declare with typedef. You cannot change the behavior for basic types by using the FORMAT instruction.

Therfore these are the steps to follow.

  1. You declare a type in the test script based on the basic type.
  2. You declare the STUB as returning this new type.
  3. you change the behavior of this new type by using the FORMAT instruction.

The beginning of the test script now looks like this:



HEADER source ,,

BEGIN

#typedef char* PCHAR;

#extern PCHAR returnCharPointer(void);

FORMAT PCHAR = unsigned char*

DEFINE STUB source

#PCHAR returnCharPointer(void);

END DEFINE



The default behavior of the test script compiler for the type unsigned char* is to test the value of the pointer. This is what you want in this case.

You can now write in your test cases:

      STUB returnCharPointer() NIL


Then the stubbed function will return a NULL pointer as expected. Likewise, if you write the following code, you get a pointer to the aCharacter variable.



#char aCharacter;

      VAR aCharacter, init = 'K', ev = init
     STUB returnCharPointer() &aCharacter



Disclaimer

All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.


[{"Product":{"code":"SSSHUF","label":"Rational Test RealTime"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Component Testing: C","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"7.0;7.0.0.1;7.0.5;7.0.5.1;7.5","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

More support for:
Rational Test RealTime

Software version:
7.0, 7.0.0.1, 7.0.5, 7.0.5.1, 7.5

Operating system(s):
AIX, HP-UX, Linux, Solaris, Windows

Document number:
625531

Modified date:
16 June 2018

UID

swg21383723

Manage My Notification Subscriptions