IBM
Contents Index Previous Next



General Concepts


The TTCN Access Application

A TTCN Access application is typically an application that produces some kind of output during the traversing of an Access tree. The Access tree, tree for short, is a tree oriented representation of a test suite. This tree is stored in the database <TestSuite>.itex where <TestSuite> is the user given name of the database.

The first section introduces the basic methods. These include the main function and how to initialize a test suite in a TTCN Access application. The second section describes how the traversing is done.

Basic Methods

When executing a TTCN Access application there are some basic methods that have to be applied before and after traversing the tree. First of all, to be able to get all the definitions needed, the header files ITEXAccessClasses.hh and ITEXAccessVisitor.hh have to be included. These files must be included in all TTCN Access applications as shown below:

#include <ITEXAccessClasses.hh>
#include <ITEXAccessVisitor.hh>

Once this is done, we need to create an instance of the AccessSuite class. This can be done as follows:

AccessSuite suite;

The AccessSuite class can be seen as a handle to the Access tree and the symbol table. It will be used for opening and closing the database and for finding specific, named Access objects stored in the symbol table.

To open a database for reading, the following method has to be called:

Boolean open_ok = suite.open( arg );

where arg is a string containing the name of the database that shall be opened. This method must always be applied to the database before traversing the Access tree. The method returns a boolean value stating whether the database could be opened or not. To close a database the following method must be called:

Boolean close_ok = suite.close();

This method requires no database name to be given as the database that will be closed is associated with suite. The method returns a boolean value stating whether the database could be closed or not. Below is a generic TTCN Access main function where argv[1] contains the name of the database:

#include <ITEXAccessClasses.hh>
#include <ITEXAccessVisitor.hh>

int main( int argc, char **argv )
{
  AccessSuite suite;
  
  if ( suite.open( argv[ 1 ] ) )  	      // OK open database?
    {
      // Write your Access application here
      // Typically start the traverser

     if ( suite.close( ) )  	 	 	 	       // OK close database?
       return 1;	 
     else	 	 	    	       // Error close database!
       return 0;
     }
   else	 	 	 	       //Error open database!
       return -1; 
}

Traversing the Access Tree

The traversing of a test suite is the "engine" that actually drives the TTCN Access application to execute.

The previous section was only concerned with opening and closing of the database. This section will describe and explain the different methods that TTCN Access provides for starting the actual TTCN Access application, i.e. starting the traversing from different nodes in the Access tree.

To be able to allow the user to traverse the tree in a simple way, TTCN Access provides a visitor class that can be customized in a flexible way by the user. The class is called AccessVisitor and provides different ways of traversing.

In all the examples discussed in the following sub sections, we assume that we have a global instance of the class AccessSuite called suite, a global instance of the class AccessVisitor called visitor and that a test suite has been opened as described in the previous section.

Traversing from the Root of the Tree

As TTCN Access can be seen as a huge tree, the basic method for traversing will be to start traversing from the root. This will result in a traversing that will traverse the full Access tree starting from top. This is performed by calling the method:

Boolean root_ok = visitor.Visit( suite );

It is an error to try to traverse a database that has not been previously opened.

Traversing by Reference

In some cases it is desirable to start traversing from a specific table, i.e. a test case or a type definition. TTCN Access provides means for this in terms of using its symbol table.

The symbol table handles global entities, that is elements that must be globally unique within a test suite according to the TTCN standard (9646-3). Such elements are all variable names, all type names, all test case names, etc.

To start traversing the Access tree from a specific element, TTCN Access provides a simple solution divided into four steps:

  1. The first step is to get a handle to the symbol table:
    AccessNode node = suite.find( name );
    
    
    
    This method will return a handle to the symbol table.
  2. The second step is to verify that this handle holds an element present in the symbol table. This is performed by applying the following method:
    Boolean symbol_table_ok = node.ok();
    
    
    
  3. Assuming that the argument name was a global name in the test suite, we still do not know what kind of element it is. It could for example be a TTCN PDU type definition, a test case or a test step. The handle to the symbol table provides a method for finding the Access type of its corresponding element. The third step will be to ask the symbol table what type its corresponding element has:
    Choices::Choice type = node.choice();
    
    
    
    This method will return an enumerated value of type Choices::Choice revealing the type of the element. As there are several different Access types, this type check is best solved in a switch statements. Assuming that the name can be either a test case or a TTCN PDU type definition, the following switch statement will detect that.
    switch( node.choice( ) )
    
    {
    
      case Choices::c_TTCN_PDU_TypeDef:
    
    	 //
    
    	 // do something
    
    	 //
    
    	 break;
    
      case Choices::c_TestCase:
    
    	 //
    
    	 // do something else
    
    	 //
    
    	 break;
    
      default:
    
    	 //
    
    	 // do something default
    
    	 //
    
    	 break;
    
    }
    
  4. The fourth step is to call the corresponding traverser function.
    Below is a complete example that will traverse a test suite starting from a specific element. The example assumes that the function main( ) is called with two arguments where the first is the name of the database and the second is the name of the element that the traversing shall start from. This application can only handle TTCN PDU type definitions and test cases.
    int main( int argc, char **argv )
    
    {
    
      AccessSuite suite;
    
      AccessVisitor visitor;
    
    
    
      if ( suite.open( argv[ 1 ] ) )       	 // OK open database?
    
        {
    
          //Get the handle
    
    
    
          AccessNode node = suite.find( arg[ 2 ] );	 
    
    
    
          if ( node.ok( ) )	 	 	 	       // Handle ok?
    
            visitor.Visit( node );
    
          else	 	 	  	       // Error in symbol table
    
            return -2
    
    	 
    
          if ( suite.close( ) ) 	 	 	 	       // OK close database?
    
    	 return 1;	 
    
          else	 	 	 	       // Error close database!
    
    	 return 0;
    
         }
    
       else                               	 // Error open database!
    
         return -1; 
    
    }
    

http://www.ibm.com/rational
Contents Index Previous Next