Topic
  • 3 replies
  • Latest Post - ‏2012-11-21T17:57:20Z by SystemAdmin
SystemAdmin
SystemAdmin
2260 Posts

Pinned topic How to write test case for different return values from STUB function

‏2012-11-15T16:52:29Z |
Hi,

I am using RTRT for C component testing with cygwin gcc compiler.

RTRT version : 7.0

I have functionUnderTest(). This functionUnderTest() calls stubFucntin(). The STUB has to be called three times and each time the stubFucntin() returns a different value and also the functionUnderTest() returns different value

I have written test case (in .ptu file) in RTRT as follows
HEADER SAUVSTD_BapApplIF_Hud_P4_000, ,

##include "Rte_ctASGLargeFSG_LSG4.h"
##include "SAUVSTD_Common_C0_000.h"
##include "SAUVSTD_BapApplIF_F0_000.h"
##include "SAUVSTD_BapApplIF_Hud_P4_000.h"

#struct {
  1. lsgId_t parg0;
  2. fctId_t parg1;
  3. BapError_et aeErrorCode;
#}BAP_ASR_RequestError_param;

DEFINE STUB TestFile

#Std_ReturnType BAP_ASR_RequestError(lsgId_t _no parg0, fctId_t _no parg1, BapError_et _no aeErrorCode) /* C:/Development/P0814/trunk/Product/Implementation/RTRT/header/Rte_ctASGLargeFSG_LSG4.h */
#{
#BAP_ASR_RequestError_param.parg0 = parg0;
#BAP_ASR_RequestError_param.parg1 = parg1;
#BAP_ASR_RequestError_param.aeErrorCode = aeErrorCode;
#}

SERVICE functionUnderTest
SERVICE_TYPE extern

-- Tested service parameters declarations
#BAIF_ERR_ID aeErrorCode;
-- By function returned type declaration
#BAIF_ERR_ID ret_1, ret_2, ret_3;

ENVIRONMENT ENV_functionUnderTest
VAR aeErrorCode, init = BAIF_ERR_OK, ev ==
VAR ret_1, init ==, ev = 0
VAR ret_2, init ==, ev = 14
VAR ret_3, init ==, ev = 16
END ENVIRONMENT -- ENV_functionUnderTest
USE ENV_functionUnderTest

TEST 1
FAMILY nominal

ELEMENT
STR BAP_ASR_RequestError_param, init ==, ev = {4, 18, 0}
STUB stubFucntin 1 => ()BapErr_OK, 2 => ()BapErr_InvalidState, 3 => ()BapErr_InvalidArg
#ret_1 = functionUnderTest(aeErrorCode);
#ret_2 = functionUnderTest(aeErrorCode);
#ret_3 = functionUnderTest(aeErrorCode);
-- retValue = functionUnderTest(aeErrorCode);
END ELEMENT

END TEST -- TEST 1

END SERVICE -- functionUnderTest

To loop over return values of functionUnderTest, I tried to use following

VAR retValue, init ==, ev in {0, 14, 16}

ELEMENT
STR BAP_ASR_RequestError_param, init ==, ev = {4, 18, 0}
STUB stubFucntin 1 => ()BapErr_OK, 2 => ()BapErr_InvalidState, 3 => ()BapErr_InvalidArg
retValue = functionUnderTest(aeErrorCode);
END ELEMENT

But it did not work, as for each expected value (variable retValue), the stubFucntin() return value is not matching.

What I want to achieve is following. Is it possible to acheive?

VAR stubRetValue, init in {0,0,0}, ev in {BapErr_OK, BapErr_InvalidState, BapErr_InvalidArg}
VAR retValue, init in {0,0,0}, ev in {0, 14, 16}

ELEMENT
STR BAP_ASR_RequestError_param, init ==, ev = {4, 18, 0}
-- Here I want to use dynamic allocation of return value
STUB stubFucntin()stubRetValue
retValue = functionUnderTest(aeErrorCode);
END ELEMENT

Please help me to optimize the test case. If it is not possible to optimize any more, please let me know

Thank you
klk
Updated on 2012-11-21T17:57:20Z at 2012-11-21T17:57:20Z by SystemAdmin
  • link33
    link33
    22 Posts

    Re: How to write test case for different return values from STUB function

    ‏2012-11-15T21:15:26Z  
    Hi,
    It seems that you have some problems in your script, or maybe i'm confusing with your explaination:
    1 - I dont know if the compilation is OK or not but in your stub definition BAP_ASR_RequestError, you are setting parameters to BAP_ASR_RequestError_param, but it is the name of your structure defined previously, not a data. You have to define a data with type BAP_ASR_RequestError_param (exemple: BAP_ASR_RequestError_param RequestError_pram;).
    2 - I think that you are confusing with the in statement. This statement is used to make multiple initialisation in the same test. In the following exemple : VAR Ma_Variable INIT IN {1, 2, 3}, EV = INIT
    The function under test is called three times with :
    1st call Ma_Variable = 1
    2nd call Ma_Variable = 2
    3rd call Ma_Variable = 3
    It is tantamount to write three tests with different values of Ma_Variable.
    3 - If the return value of your stub stubFucntin is set three times to the same variable, you cannot check the intermediate values, you can check only the last value set by the stub. It is the same for the return value of your function under test, you can check only the last value taken.
  • richard.france
    richard.france
    830 Posts

    Re: How to write test case for different return values from STUB function

    ‏2012-11-15T21:38:06Z  
    Your explanation are confusing....

    assuming:
    BAP_ASR_RequestError is your stubFucntin that need to be stubbed
    and your functionUnderTest call only once your BAP_ASR_RequestError
    You could write your Test ELEMENT like
    
    ELEMENT VAR stubRetValue, init in 
    {BapErr_OK, BapErr_InvalidState, BapErr_InvalidArg
    }, ev == VAR retValue,      init = 0,      ev (stubRetValue) in 
    {0, 14, 16
    } VAR aeErrorCode, init (stubRetValue) in 
    {ae1,ae2,ea3
    }, ev = init STR BAP_ASR_RequestError_param, init ==, ev = 
    {4, 18, 0
    } STUB stubFucntin()stubRetValue #retValue = functionUnderTest(aeErrorCode); END ELEMENT
    

    this test execute 3 times functionUnderTest with eaN as parameter you have to clarify yourself
    the stub is supposed to be called 1 time on each functionUnderTest execution
    the call parameters are the same for the 3 calls and are checked as 4,18,0
    1st exec the stub returns BapErr_OK and the functionUnderTest supposed to return 0
    2nd exec the stub returns BapErr_InvalidState and the functionUnderTest supposed to return 14
    "rd exec the stub returns BapErr_InvalidArg and the functionUnderTest supposed to return 16

    I hope this helps
  • SystemAdmin
    SystemAdmin
    2260 Posts

    Re: How to write test case for different return values from STUB function

    ‏2012-11-21T17:57:20Z  
    Hello Richard,

    Thank you very much for your reply. That's exactly what I want.

    Regards
    klk

    Hello link33,

    I am not confused with init.

    The reason why I used struct is to check the parameters of the STUB function.

    This I did because I changed all parameters of STUB function to type _no.

    Thank you very much
    klk