Stubbing separate compilation units

It is possible to create stubs for separate compilation units, such as procedures or packages, even for protected packages.

For the stubbing of a protected object to work, you must either:

To stub a protected object you must use the following syntax:

DEFINE STUB SEPARATE(<package>) <compilation unit>

...

END DEFINE

If the compilation unit does contain an entry statement, the entry itself cannot be stubbed. In this case you must define the entry body within the DEFINE STUB block as in the following example:

DEFINE STUB SEPARATE(<package>) <compilation unit>

# entry body E1 ... is ...

END DEFINE

Example

The following example is a .ptu test script implementing a stub of a separate compilation unit. It is available in the StubAda example project provided with the product.

HEADER PARENT, ,

#With PARENT;

BEGIN

  DEFINE STUB package

  END DEFINE

  DEFINE STUB SEPARATE(package) MY_VALUE

  END DEFINE

  SERVICE SOMETHING

  SERVICE_TYPE extern

    -- Declaration of service's parameters

    #X : INTEGER;

    #Ret : INTEGER;

    TEST 1

    FAMILY nominal

      ELEMENT

   -- stub of the protected object "get"

        STUB My_Value.Get()2

        Var X, Init = 0, ev = Init

        Var Ret, Init = 0, ev = 2

        #Ret := PARENT.SOMETHING(X);

      END ELEMENT

    END TEST -- TEST 1

  END SERVICE -- SOMETHING

Related Topics

Advanced stubs | Creating Complex Stubs