Topic
  • 4 replies
  • Latest Post - ‏2012-11-15T22:01:22Z by richard.france
SystemAdmin
SystemAdmin
2260 Posts

Pinned topic Pointer problem in Stub

‏2012-11-14T14:40:12Z |
Hi everyone,

I have a problem with STUB in my tests.

We can read in RTRT Help :
"Note Any _out parameter is automatically a pointer, therefore the asterisk is not necessary."

Here is my problem :

DEFINE STUB esg_div_c
#int ET_LireBinaire(ET_T_IdCalculateur _no p_IdCalculateur, ET_T_IdRelatifDonnee _no p_IdRelatifDonnee, ET_T_ValeurBin _out Valeur);
#int TM_EtatTempoRedirigee(TM_T_Id _no p1, TM_T_Etat _out p2, TM_T_Delai _no p3, short _no p4);
END DEFINE

In TM_EtatTempoRedirigee :
TM_T_Etat is a typedef short

"TM_T_Etat _out p2" is ok, p2 is a pointer.

In ET_LireBinaire :

ET_T_ValeurBin is a typedef unsigned char

"ET_T_ValeurBin _out Valeur" is nok, Valeur is not a pointer.

Why ? Can you help me ?

I have a solution : "ET_T_ValeurBin _out *Valeur" make it works but I have this warning :

"warning C4047: '='ÿ: 'ET_T_ValeurBin' diffŠre de 'ET_T_ValeurBin *' dans les niveaux d'indirection"

It is not clean I can't let this warning unfixed.
Updated on 2012-11-15T22:01:22Z at 2012-11-15T22:01:22Z by richard.france
  • link33
    link33
    22 Posts

    Re: Pointer problem in Stub

    ‏2012-11-14T19:33:20Z  
    Hi,
    In tested code is your function ET_LireBinaire defined with the last parameter as pointer (ET_T_ValeurBin *Valeur) ? If it is, how do you force the value returned by this parameter ?
    You can use the _out statement in c testing only if this parameter is an address of a data, and for return value, you have to define a variable typed as ET_T_ValeurBin, your stub shall be set as follow :
    ET_T_ValeurBin RTRT_Out_valeur;
    STUB ET_LireBinaire 1 => (RTRT_Out_valeur)
  • SystemAdmin
    SystemAdmin
    2260 Posts

    Re: Pointer problem in Stub

    ‏2012-11-15T09:05:59Z  
    • link33
    • ‏2012-11-14T19:33:20Z
    Hi,
    In tested code is your function ET_LireBinaire defined with the last parameter as pointer (ET_T_ValeurBin *Valeur) ? If it is, how do you force the value returned by this parameter ?
    You can use the _out statement in c testing only if this parameter is an address of a data, and for return value, you have to define a variable typed as ET_T_ValeurBin, your stub shall be set as follow :
    ET_T_ValeurBin RTRT_Out_valeur;
    STUB ET_LireBinaire 1 => (RTRT_Out_valeur)
    Hi,

    ET_LireBinaire is an extern int and yes, the last parameter is ET_T_ValeurBin *Valeur

    When I create the test, the stub declaration is :
    
    #
    
    int ET_LireBinaire(ET_T_IdCalculateur _no p_IdCalculateur, ET_T_IdRelatifDonnee _no p_IdRelatifDonnee, ET_T_ValeurBin _out *Valeur);
    


    But like I always do with others stub, I delete the star before Valeur (Help says :"Note Any _out parameter is automatically a pointer, therefore the asterisk is not necessary.")
    If I don't do this, I have this warning :
    
    "warning C4047: '='ÿ: 'ET_T_ValeurBin' diffŠre de 'ET_T_ValeurBin *' dans les niveaux d'indirection"
    


    I use the stub like this :
    
    STUB ET_LireBinaire 1 => (ET_PRESENT_DISPO) OK
    

    And I have tried like this :
    
    STUB ET_LireBinaire 1 => ((ET_T_ValeurBin)ET_PRESENT_DISPO) OK
    


    ET_PRESENT_DISPO is constant and define like this
    
    #define ET_PRESENT_DISPO   3
    
  • link33
    link33
    22 Posts

    Re: Pointer problem in Stub

    ‏2012-11-15T21:33:50Z  
    Hi,

    ET_LireBinaire is an extern int and yes, the last parameter is ET_T_ValeurBin *Valeur

    When I create the test, the stub declaration is :
    <pre class="jive-pre"> # int ET_LireBinaire(ET_T_IdCalculateur _no p_IdCalculateur, ET_T_IdRelatifDonnee _no p_IdRelatifDonnee, ET_T_ValeurBin _out *Valeur); </pre>

    But like I always do with others stub, I delete the star before Valeur (Help says :"Note Any _out parameter is automatically a pointer, therefore the asterisk is not necessary.")
    If I don't do this, I have this warning :
    <pre class="jive-pre"> "warning C4047: '='ÿ: 'ET_T_ValeurBin' diffŠre de 'ET_T_ValeurBin *' dans les niveaux d'indirection" </pre>

    I use the stub like this :
    <pre class="jive-pre"> STUB ET_LireBinaire 1 => (ET_PRESENT_DISPO) OK </pre>
    And I have tried like this :
    <pre class="jive-pre"> STUB ET_LireBinaire 1 => ((ET_T_ValeurBin)ET_PRESENT_DISPO) OK </pre>

    ET_PRESENT_DISPO is constant and define like this
    <pre class="jive-pre"> #define ET_PRESENT_DISPO 3 </pre>
    Hi,
    If i understand the function ET_LireBinaire is defined in code as
    int ET_LireBinaire(ET_T_IdCalculateur p_IdCalculateur, ET_T_IdRelatifDonnee p_IdRelatifDonnee, ET_T_ValeurBin *Valeur).
    I beear out what is said in help, you have to remove the * when you define it as stub, i use it several times and it works.
    In stub call you have to return an ET_T_ValeurBin data type. This warning is abnormal, check that ET_PRESENT_DISPO is compliant with ET_T_ValeurBin type and that ET_LireBinaire function prototype is the same in all header files where it is defined.
  • richard.france
    richard.france
    908 Posts

    Re: Pointer problem in Stub

    ‏2012-11-15T22:01:22Z  
    • link33
    • ‏2012-11-15T21:33:50Z
    Hi,
    If i understand the function ET_LireBinaire is defined in code as
    int ET_LireBinaire(ET_T_IdCalculateur p_IdCalculateur, ET_T_IdRelatifDonnee p_IdRelatifDonnee, ET_T_ValeurBin *Valeur).
    I beear out what is said in help, you have to remove the * when you define it as stub, i use it several times and it works.
    In stub call you have to return an ET_T_ValeurBin data type. This warning is abnormal, check that ET_PRESENT_DISPO is compliant with ET_T_ValeurBin type and that ET_LireBinaire function prototype is the same in all header files where it is defined.
    function to STUB with pointer as parameter:
    You have to understand that stub definition should declar parameter AS they are tested.
    So
    If you want to check the pointer itself to NIL / NONIL then the STUB parameter can be declared as pointer
    If you want to check the pointed data against int value then the STUB parameter can be declared as int

    As soon as the STUB prototpe is different from the function prototype It is preferable to have function prototype visible fromp the PTU (on top of the PTU or the header file declaring this protype, included on top of the PTU).
    This way the preprocessor can see the checked value is an int and the parameter is a pointer and so the generated code read the pointer value before check it.

    I hope this clarify the STUB usage
    read the Online Documentation about Simulating Functions with char * parameters