Topic
  • 8 replies
  • Latest Post - ‏2014-11-04T18:06:42Z by richard.france
SystemAdmin
SystemAdmin
2260 Posts

Pinned topic Constant pointer in the stub..

‏2005-10-19T17:11:19Z |
Does anyone know how to fix a stub call with a constant pointer. I can't seem to get it to run properly without having to overide the stub with a function of my own.

The c function call is : #void (int a, float b, const * const int a)

Its that "const * const" bit that is bothering me... Is there a way of stubbing that function call without having to overide the function in the ptu file?
Updated on 2010-10-08T07:22:28Z at 2010-10-08T07:22:28Z by Govind512
  • kulyan
    kulyan
    70 Posts

    Re: Constant pointer in the stub..

    ‏2005-10-20T14:54:59Z  
    The C programming language accepts the qualifier "const". To simulate functions taking const parameters, there's a specific syntax necessary.

    Solution
    The compiler checks whether variables declared as "const" are modified at run time. Take the following function in C programming language as an example:

    extern int ConstParam(const int param);

    It would be tempting to write the following inside Rational Test RealTime UnitTesting to stub it:

    DEFINE STUB Example
    #int ConstParam(const int _in param);
    END DEFINE

    When you compile this .ptu test script and compile the generated code you will get error messages. This is because the preprocessor generates variables used for testing the calls to the STUBs and these variables have the same type as the parameter to the function being stubbed. i.e. "const int". As these variables are const, they cannot be modified which provokes the compilation errors.

    To get around this problem the UnitTesting language allows you 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. The syntax is an '@' before the type modifier. So the example above becomes:

    DEFINE STUB Example
    #int ConstParam(@const int _in param);
    END DEFINE

    If your function takes a const pointer, then you don't need the '@'. For example

    DEFINE STUB Example
    #int ConstParam(const int _in *param);
    END DEFINE

    This technique can be used with any type modifier.

    Regards,
    Kalyan
  • SystemAdmin
    SystemAdmin
    2260 Posts

    Re: Constant pointer in the stub..

    ‏2005-10-21T22:14:02Z  
    • kulyan
    • ‏2005-10-20T14:54:59Z
    The C programming language accepts the qualifier "const". To simulate functions taking const parameters, there's a specific syntax necessary.

    Solution
    The compiler checks whether variables declared as "const" are modified at run time. Take the following function in C programming language as an example:

    extern int ConstParam(const int param);

    It would be tempting to write the following inside Rational Test RealTime UnitTesting to stub it:

    DEFINE STUB Example
    #int ConstParam(const int _in param);
    END DEFINE

    When you compile this .ptu test script and compile the generated code you will get error messages. This is because the preprocessor generates variables used for testing the calls to the STUBs and these variables have the same type as the parameter to the function being stubbed. i.e. "const int". As these variables are const, they cannot be modified which provokes the compilation errors.

    To get around this problem the UnitTesting language allows you 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. The syntax is an '@' before the type modifier. So the example above becomes:

    DEFINE STUB Example
    #int ConstParam(@const int _in param);
    END DEFINE

    If your function takes a const pointer, then you don't need the '@'. For example

    DEFINE STUB Example
    #int ConstParam(const int _in *param);
    END DEFINE

    This technique can be used with any type modifier.

    Regards,
    Kalyan
    My case is when the function takes in a parameter like this:
    void function (const int * const _in param)
    Any ideas?
  • Govind512
    Govind512
    34 Posts

    Re: Constant pointer in the stub..

    ‏2010-10-08T07:22:28Z  
    My case is when the function takes in a parameter like this:
    void function (const int * const _in param)
    Any ideas?
    Hi,
    Constant and typedef's we can not verify using RTRT for stub calls. In this case it is better to make that particular variable to "_no".

    Ex:

    void fun(const int* _no pram)
  • IswaryaVenkataraju
    IswaryaVenkataraju
    1 Post

    Re: Constant pointer in the stub..

    ‏2013-10-01T10:18:40Z  
    • kulyan
    • ‏2005-10-20T14:54:59Z
    The C programming language accepts the qualifier "const". To simulate functions taking const parameters, there's a specific syntax necessary.

    Solution
    The compiler checks whether variables declared as "const" are modified at run time. Take the following function in C programming language as an example:

    extern int ConstParam(const int param);

    It would be tempting to write the following inside Rational Test RealTime UnitTesting to stub it:

    DEFINE STUB Example
    #int ConstParam(const int _in param);
    END DEFINE

    When you compile this .ptu test script and compile the generated code you will get error messages. This is because the preprocessor generates variables used for testing the calls to the STUBs and these variables have the same type as the parameter to the function being stubbed. i.e. "const int". As these variables are const, they cannot be modified which provokes the compilation errors.

    To get around this problem the UnitTesting language allows you 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. The syntax is an '@' before the type modifier. So the example above becomes:

    DEFINE STUB Example
    #int ConstParam(@const int _in param);
    END DEFINE

    If your function takes a const pointer, then you don't need the '@'. For example

    DEFINE STUB Example
    #int ConstParam(const int _in *param);
    END DEFINE

    This technique can be used with any type modifier.

    Regards,
    Kalyan

    Hi,

      I am also facing problem in constant stub parameter..., the solution which u gave i.e 

    DEFINE STUB Example

    #int ConstParam(@const int _in param);

    END DEFINE

    It is not working for me.., and the general thing is whenever there is a constant parameter in the stub function RTRT is not allowing me to pass anything for that parameter inside the stub... 

    can you please suggest me some solutions ?

    Regards,

    Iswarya Venkataraju

  • kulyan
    kulyan
    70 Posts

    Re: Constant pointer in the stub..

    ‏2013-10-07T14:51:26Z  

    Hi,

      I am also facing problem in constant stub parameter..., the solution which u gave i.e 

    DEFINE STUB Example

    #int ConstParam(@const int _in param);

    END DEFINE

    It is not working for me.., and the general thing is whenever there is a constant parameter in the stub function RTRT is not allowing me to pass anything for that parameter inside the stub... 

    can you please suggest me some solutions ?

    Regards,

    Iswarya Venkataraju

    I have a better way now..

    Just define the following at the beginning of the test script

    #undef const

    #define const

     

    and at the end of test script

    #undef const

    #define const const

     

    That should be accepatble for testing.

  • ClaraC
    ClaraC
    4 Posts

    Re: Constant pointer in the stub..

    ‏2013-12-18T11:37:31Z  
    • kulyan
    • ‏2013-10-07T14:51:26Z

    I have a better way now..

    Just define the following at the beginning of the test script

    #undef const

    #define const

     

    and at the end of test script

    #undef const

    #define const const

     

    That should be accepatble for testing.

    Hi, this staments, where have i paste it?? Inside service?? or in the beginning of  my file?

     #undef const

    #define const

     

    I have the same problem. I've written a threath about a problem with conts pointer and _no defined . When I call the stub: FATALSHUDOWN.

    Someone can help me? please.

    This is the link: https://www.ibm.com/developerworks/community/forums/html/topic?id=3f74b2c7-0651-4343-ab84-5fb4745ce4b5

    Thanks!!

    KR

  • Jej64
    Jej64
    1 Post

    Re: Constant pointer in the stub..

    ‏2014-10-23T09:22:49Z  
    My case is when the function takes in a parameter like this:
    void function (const int * const _in param)
    Any ideas?

    Hi,

    Since 2005, have you found an answer about this problem of const * const?

    THank you.

  • richard.france
    richard.france
    862 Posts

    Re: Constant pointer in the stub..

    ‏2014-11-04T18:06:42Z  
    • ClaraC
    • ‏2013-12-18T11:37:31Z

    Hi, this staments, where have i paste it?? Inside service?? or in the beginning of  my file?

     #undef const

    #define const

     

    I have the same problem. I've written a threath about a problem with conts pointer and _no defined . When I call the stub: FATALSHUDOWN.

    Someone can help me? please.

    This is the link: https://www.ibm.com/developerworks/community/forums/html/topic?id=3f74b2c7-0651-4343-ab84-5fb4745ce4b5

    Thanks!!

    KR

    to stub and check the content of the parameter of function foo, make sure the prototype is somewhere visible by the script preprocessor (included by the PTU) otherwise write the prototype of this function into the PTU itself (like here).

    #void foo(const int * const param);

    -- here is my variable that will contains the value to check

    #int myValue;

    -- here is my const pointer that point constently to myValue
    #const int *Iptr=&myValue;

    --here is the stub definition
    #void foo(@const int _in param);

    here is the ELEMENT
    VAR myValue, init=1234, ev=init  -- initialise the content of the variable which is pointed to by the param
    STUB foo(1234) -- the check of the variable content which is pointed to by the param

    #foo(Iptr); // here is the immediate call to my stub with the const pointer