Home > User Support > CoverageMaster winAMS FAQ
Question:
How to create the stub function when the same function is called more than once and the behavior of the function tested changes depending the values returned by each call?
Example of a sub_func() called twice
 int a, b, c, d;
                void func(int x)
                {
                    a = sub_func(x); // 1st call
                    if ( a ) b++;
                    c = sub_func(b); // 2nd call
                    if ( c ) d++;
                }
Answer:
Use array variables to store the arguments received and for returning values as function. The number of elements in the array should be sufficient for the number of times the function is called. The following is an example of the stub function created for the above example sub_func().
Example of stub function for sub_func()
              
              int DBG_func_arg[2]; // function argument array
                int DBG_func_ret[2]; // function return array
                int DBG_func_idx;    // array index 
                
                int AMSTB_sub_func(int k)
                {
                    DBG_func_arg[DBG_func_idx] = k; // copy the argument value into the function argument array
                    return DBG_func_ret[DBG_func_idx++]; // return the function return array, increment the index
                }
Regarding the test data, refer to the example CSV PDF file.
          
Other technical tips in GAIO's web site can be searched for using the links below.
Search key word link: Stub 
              Technical Tips Google Search