Native Code

Syntax

# <single-line C++ code>

C++# <single-line C++ code>

#{ <multiple-line C++ code> }#

C++#{ <multiple-line C++ code> }#

Location

C++ Test Driver Script, PROLOGUE, EPILOGUE, TEST CASE, PROC, STUB, CHECK EXCEPTION

Description

<single-line C++ code> and <multiple-line C++ code> are made of one or several C++ statements. They must conform to the syntax expected by the host compiler and must be relevant to the current context.

Macros may be used, but it is recommended to define them only at the root-level of the C++ Test Driver Script.

Native code is copied as is in the generated test driver source.

Only global declarations are allowed inside the C++ Test Driver Script.

Inside a PROLOGUE statement, the declaration's scope is that of the surrounding structure (TEST CLASS or TEST SUITE). Elsewhere, the scope is local (visible from the declaration to the end of the C++ Test Script Language block).

the sequence #} is different from }#:

Warning: The use of return, goto, or any other jump instruction is not allowed in native code. If jump instructions are used, unexpected results will occur.

Native code may generate an error when it raises an unexpected exception. Use the CHECK EXCEPTION statement to specify exceptions.

Example

##include <myclass.h>

#{

       static int counter;

       extern void initialize (MyClass &);

       static const int MAX=200;

}#

TEST CLASS A {

       ON ERROR EXIT;

       PROLOGUE {

              #MyClass mc;

              #initialize (mc);

              #for (counter=0; counter < MAX; counter++) {

       }

       TEST CASE 1 {

              #void *temp;

              #temp = mc.create ();

              #mc.unref (temp);

              CHECK mc.empty ();

       }

       TEST CASE 2 {

              #{

                     void *temp[MAX];

                     for (int i = 0; i<counter; i++)

                     {

                            temp[i] = mc.create ();

                     }

                     for (int i = 0; i<counter; i++)

                     {

                            mc.unref (temp[i]);

                     }

                     CHECK mc.empty ();

              }#

       }

       EPILOGUE {

              #} //end of for

       }

}

RUN {

       A.1;

       A.2;

}

 

In this example, a loop is defined around the components of the test class A. The loop starts in PROLOGUE, and ends in EPILOGUE. The execution of test class A will run nothing, because there is no RUN statement in this test class. However, the two test cases may be run separately, as it is shown in the above example.

The execution sequence is: A.PROLOGUE, A.1 (200 times), A.EPILOGUE, A.PROLOGUE, A.2 (200 times), A.EPILOGUE.