Using Stubs

Component Testing for Ada

Range of Values of STUB Parameters

When using stubs, you may need to define an authorized range for each STUB parameter. Furthermore, you can summarize several calls in one line associated with this parameter.

Write such STUB lines as follows:

STUB F 1..10 => (1<->5)30

This expression means that the STUB F will be called 10 times with its parameter having a value between 1 and 5, and its return value is always 30.

You can combine this with several lines; the result looks like the following example:

STUB F 1..10 => (1<->5)30,

& 11..19 => (1<->5)0,

& 20..30 => (<->) 1,

& others =>(<->)-1

To check that a STUB is never called, even if an ENVIRONMENT containing the STUB is used, use the the following syntax:

STUB F 0=>(<->)

Raise-exception Stubs

You can force to raise a user-defined (or pre-defined) exception when a STUB is called with particular values.

The appropriate syntax is as follows:

STUB P(1E+307<->1E+308) RAISE STORAGE_ERROR

If the STUB F happens to be called with its parameter between 1E+307 and 1E+308, the exception STORAGE_ERROR will be raised during execution of the application; the test will be FALSE otherwise.

Suppose that the current stubbed unit contains at least one overloaded sub-program. When calling this particular STUB, you will need to qualify the procedure or function. You can do this easily by writing the STUB as follows:

STUB A.F (1<->2:REAL)RAISE STANDARD.CONSTRAINT_ERROR

The STUB A.F is called once and will raise a CONSTRAINT_ERROR if its parameter, of type REAL, has a value between 1 and 2.

Compilation Sequence

The Ada Test Script Compiler generates three files:

  • <testname> _fct_simule.ada for the body of simulated functions and procedures

  • <testname> _var_simule.ada for the declaration of simulation variables

  • <testname> _var_simule_B.ada for the body of test procedures

You must compile your packages in the following order:

  1. Simulated unit (specification)
  2. <testname> _var_simule.ada
  3. <testname> _var_simule_B.ada
  4. Test program
  5. <testname> _fct_simule.ada

Replacing Stubs

Stubs can be used to replace a component that is still in development. Later in the development process, you might want to replaced a stubbed component with the actual source code.

To replace a stub with actual source code:

  1. Right-click the test node and select Add Child and Files
  2. Add the source code files that will replace the Stubbed functions.
  3. If you do not want a new file to be instrumented, right-click the file select Properties. Set the Instrumentation property to No.
  4. Open the .ptu test script, and remove the STUB sections from your script file.

Related Topics

Stub Simulation | Defining Stubs | Sizing Stubs | Ada Syntax Extensions | Advanced Stubs (Ada)