Testing Pointers against Pointer Structure Elements

Component Testing for C

To test pointers against structure elements which are also pointers, specify for each pointer the variable it is pointing to.

For example, consider the following code:

typedef struct st_Test

{

int a;

int b;

struct st_Test *Ptr1;

}st_Toto;

int FunctionTest (st_Toto *p_toto)

{

int res=0;

if (p_toto != 0)

{

if(p_toto->Ptr1 == 0)

{

res = 1;

}

}

else

{

res = 2;

}

return(res);

}

To test the pointer p_toto, write the following test script:

SERVICE TestFunction

SERVICE_TYPE extern

-- Tested service parameter declarations

#st_toto *p_toto;

-- By function returned type declaration

#int ret_TestFunction;

ENVIRONMENT ENV_TestFunction

VAR ret_TestFunction, init = 0, ev = init

END ENVIRONMENT -- ENV_TestFunction

USE ENV_TestFunction

TEST 1

FAMILY nominal

ELEMENT

STR *p_toto, init = { a => 0, b => 0, Ptr1 => NIL }, ev= init

STR *p_toto->Ptr1, init = {a=>2,b=>32, Ptr1=>NIL}, ev= init

VAR ret_TestFunction, init = 0, ev = init

#ret_TestFunction = TestFunction(p_toto);

END ELEMENT

END TEST -- TEST 1

FIN SERVICE -- TestFunction