The difference between the output of a testdriver and the output of trace statements, is the resulting view of the delivered data. To verify the interface output of a software unit, is a typical BlackBox test, because the inner behavior of the software remains invisible. To trace the interior activity of a component is a WhiteBox test.

 WhiteBox tests are useful, when a BlackBox test fails. If there is a large amount of code which has to be investigated, it is more efficient to look first into a detailed trace output, before searching the error with a debugger.

The following software unit is prepared for tracing:  

int CMath::diff_square(int a, int b)

{

   DINOUT("CMath::diff_square");

   DTRACE["a"] = a;

   DTRACE["b"] = b;

   int diff = a - b;

   DTRACE["diff"] = diff;

   int ret = diff * diff;

   DTRACE["ret"] = ret;

   return ret;

}

 

double CMath::line_length(int x1,int y1,int x2,int y2)

{

   DINOUT("CMath::line_length");

   DTRACE["x1"] = x1;

   DTRACE["y1"] = y1;

   DTRACE["x2"] = x2;

   DTRACE["y2"] = y2;

 

   int sum1 = diff_square(x1,x2);

   DTRACE["sum1"] = sum1;

   int sum2 = diff_square(y1,y2);

   DTRACE["sum2"] = sum2;

   double len = sqrt(sum1+sum2);

   DTRACE["len"] = len;

   return len;

}

Every method or function which should be traced, must start with the trace command DINOUT("name"). If this command is provided, all internal states can be traced with the DTRACE["state"] command. DTRACE commands without corresponding DINOUT startup will cause compile errors. Like DIN and DOUT, which are used for BlackBox testing, DTRACE is able to handle data of type int, double and char*. All other types which should be traced must be temporary converted to this basic ones.

The call CMath::line_length(18,22,37,20) will result in a trace output listed below. The trace data is printed into the resultfile, in front of the BlackBox output.

CMath::line_length()

{

       int x1 = 18

       int y1 = 22

       int x2 = 37

       int y2 = 20

       CMath::diff_square()

       {

               int a = 18

               int b = 37

               int diff = - 19

               int ret = 361

      }

       int sum1 = 361

       CMath::diff_square()

       {

               int a = 22

               int b = 20

               int diff = 2

               int ret = 4

       }

       int sum2 = 4

       double len = 19.104973

}

 

 

The CxxViewer allows to select specific parts of the software for tracing. It is possible to define a maximum call level and to specify a functionname as startup root for tracing. All trace commands are neglected till the moment when the specified root function is entered. At this stage, all trace commands are executed. When the subcall depth, counted from the startup root function, reaches the specified max level, the trace commands are  ignored again.

Every software unit, which should  implement trace statements, must include CxxTester.h and must be linked with the cxxlib.