Stubbing functions with varying parameters

Component Testing for Ada

In some cases, functions may be designed to accept a variable number of parameters on each call.

You can still stub these functions with the Component Testing feature by using the '...' syntax indicating that there may be additional parameters of unknown type and name.

In this case, Component Testing can only test the validity of the first parameter.

Example

The standard printf function is a good a example of a function that can take a variable number of parameters:

int printf (const char* param, ...);

 

Here is an example including a STUB of the printf function:

HEADER add, 1, 1

#extern int add(int a, int b);

##include <stdio.h>

BEGIN

DEFINE STUB MulitParam

#int printf (const char param[200], ...);

END DEFINE

SERVICE add

  #int a, b, c;

  TEST 1

  FAMILY nominal

      ELEMENT

          VAR a, init = 1, ev = init

          VAR b, init = 3, ev = init

          VAR c, init = 0, ev = 4

          STUB printf("hello %s\n")12

          #c = add(a,b);

      END ELEMENT

  END TEST

END SERVICE

 

Related Topics

Advanced StubsNative Code in StubsExcluding a Parameter from a StubSimulating Generic UnitsSimulating Functions with _inout Mode ArraysSeparate Body Stub