[Previous] [Next] [Contents] [Index]


    Creating an ITEX Access Application

This chapter is intended to be an introduction to how to create an ITEX Access application, and it is expected to be read sequentially. As ITEX Access is a C++ application programmers interface, this chapter will contain several ITEX Access applications written in C++. The chapter includes general ITEX Access application concepts as well as specific examples.

For reference, the test suite that is used as input to the various ITEX Access applications, is included in TTCN-GR form at the end of this chapter together with the source code for each example.

Note:  UNIX only

ITEX Access is only available on UNIX.

Table of Contents 

ITEX Access

ITEX Access is a C++ application programmers interface. It is a platform for writing applications related to TTCN test suites such as:

ITEX Access is meant to be used by executable test suite developers, translator developers as well as test result analyzers.

In order to make this chapter as complete as possible and thereby cover as many different ITEX Access application domains as we can, this chapter contains several different examples, each described in its own section. However, before we start with the examples, we will explain some general concepts that apply to every ITEX Access application.

Note: 

This chapter is an ITEX Access primer and is not intended to provide a chapter in C++ programming.

General Concepts

The ITEX Access Application

An ITEX 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 an ITEX Access application. The second section describes how the traversing is done.

Basic Methods

When executing an ITEX 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 ITEX Access applications as shown below:

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

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:

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:

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 ITEX Access main function where argv[1] contains the name of the database:

Traversing the Access Tree

The traversing of a test suite is the "engine" that actually drives the ITEX 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 ITEX Access provides for starting the actual ITEX 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, ITEX 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 ITEX 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:

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. ITEX 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, ITEX Access provides a simple solution divided into four steps:

  1. The first step is to get a handle to the symbol table:

  2. AccessNode node = suite.find( name );
    
    
    This method will return a handle to the symbol table.
  3. 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:

  4. Boolean symbol_table_ok = node.ok();
    
    
  5. 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:

  6. 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;
    }
    

  7. The fourth step is to call the corresponding traverser function.

  8. 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; 
    }
    

Examples

This section provides all the examples in this chapter. It starts with a simple ITEX Access application and continues from there. Every example is discussed in its own subsection. In each subsection, only the interesting parts are discussed. A complete solution to every example can be found in Solutions to the Examples.

Every ITEX Access application can be seen as an application providing a solution to a problem. These problems are related to TTCN test suites in general, such as reporters or style checkers, encoders and decoders. Therefore, every example in this chapter will be preceded with a small discussion of the actual problem that the corresponding ITEX Access application shall solve. Of course, the problems discussed in this chapter will mainly be of a fictive nature, but they will reflect the simplicity of ITEX Access and the different implementation techniques and methods that ITEX Access provides.

In all examples, we assume that there exist 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.

The Identifiers

Objective

In every test suite there exists a set of identifiers. The objective of this example is to print out every identifier present in the test suite.

Solution 1

Every identifier present in an Access tree will be represented as an Access node of type Identifier. The solution will therefore only include one user defined method in the visitor class instance that, when entering the node Identifier, prints the content of that class. In this case it is the name of the identifier. The method is provided below.

This method will be called from ITEX Access every time the traverser enters the Identifier node. The name Identifier is the name of the Access node and the prefix tag Visit means that this is a visiting method.

As the task of an ITEX Access application is to traverse a test suite according to the traverser and call possibly user defined functions or methods, we need to create a traverser that will use the default traversing, but have the desired small change. This is done by sub classing as follows:

As identifiers are present everywhere in the Access tree, no change to the traversing order needs to be done. The default traverser will be used and the traversing will start from root.

The full solution is found in Solution 1.

Context

Objective

When executing the previous example, all identifiers in the given test suite will be printed. By looking at the output one might think that there should not be so many identifiers in the test suite, but the way in which the grammars are specified (both TTCN and ASN.1), nearly every grammar rule ends in a identifier. This example will explain the importance of calling the user defined function at their correct place, or to be more specific, in its right context.

Let us assume, with the previous example in mind, that we want to distinguish between TTCN PDU type definition identifiers and TTCN PDU constraint identifiers (the rest is of no concern). This can be achieved in several different ways. Below are two different solutions to this problem.

Solution 2

This first solution, looking at each identifiers type, will be implemented in the visiting method used in the previous example. However, it has to be extended to look at each identifier type and only print the appropriate ones. The updated method is found below.

Solution 3

The second solution will replace the used method with two new ones. The first method will print out every TTCN PDU type definition identifier. This will be done in the method VisitTTCN_PDU_TypeDef. The second, VisitTTCN_PDU_Constraint, will print out every TTCN PDU constraint identifier. In each method the Identifier Access node is reached by explicit addressing, that is, explicitly naming the path to the Access node Identifier. Their corresponding definitions are supplied below.

The definition of the visitor object is done as follows:

Comments

When executing the two examples above with the test suite in the end of this chapter as input, one will find that the output is not equivalent. The first solution will have some more output lines that the second one. By adding the following line to each method, one will detect in which table the identifier was found.

One will find that the extra lines of output in the first solution are produced from the Constraints Part and the Dynamic Part. This is true due to the fact that the type identifiers are being used in each constraint and the constraint identifiers are being used in the Constraint Reference column in each test case and test step table.

The full solutions are found in Solution 2 and Solution 3.

Translating TTCN

A very common and useful ITEX Access application is to translate a test suite to another target language. Examples are C, C++, Pascal etc. By doing this translation we can thereby create an executable test suite. To achieve this, one needs a TTCN translator that translates a TTCN test suite to the specific source code. This example will not be a full translator, but will rather show how such a translator can be written by using ITEX Access.

Objective

In this example, we will translate TTCN PDU type definitions to C where each PDU will be a unique C type. To achieve this, we need to have some kind of mapping between TTCN and C. One way to do this is to do a case study. First we will look at a TTCN PDU type definition in the table format and from that table extract how the corresponding C representation shall be. Then, a generic representation of all TTCN PDUs in C will be defined. This generic representation will then be implemented in ITEX Access, and thereby a generic TTCN PDU type definition to C translator will be implemented.

Solution 4

Let us have a look at a TTCN PDU type definition in table format. The table below, the TTCN PDU type definition SEND, is taken from the test suite attached to the end of this chapter.

Figure 192 : TTCN PDU Type Definition

Extracted pic [1]

A corresponding C representation of the above type could look something like:

That is, a structured type holding the same number of elements as the corresponding TTCN type definition. In this example, no consideration is taken to the PCO type. This is only done for simplicity and can of course be included in the type as well.

As one can see in this example there are a lot similarities between the TTCN definition and the C representation in terms of names of elements and their corresponding type. This helps us define a generic C representation of a TTCN PDU type definition as below:

The type and name of each element is taken from the corresponding names in the TTCN type definition and the type defined is named as in TTCN.

Now, the next step is to implement this generic type in ITEX Access! To do this, we divide the generic C type into three distinct elements; the header, the body and the footer.

The Header and Footer

The visitor method that traverses the TTCN PDU type definitions, will be the one responsible for generating the header and footer of the generated C structure definition. The method may look something like this:

This method will be called every time the traverser enters the Access node TTCN_PDU_TypeDef.

The Body

The body of the type definition, is a collection of rows where each row is translated identically. A row can be translated by defining the following method:

where get_type_str and get_id are two functions returning the type and the name of the element respectively. This method shall be called every time the traverser enters the Access node PDU_FieldDcl.

The full solution is found in Solution 4.

Summary

ITEX Access provides a platform for generating applications in the domain of TTCN, conformance testing and related applications such as translators, interpreters, analyzers, reporters, etc. ITEX Access is a C++ representation of the related grammars that spans the language TTCN. We hope that this chapter has revealed the basis of ITEX Access, the methods it supplies and how easy it is to use. All examples in this chapter have full solutions in Solutions to the Examples.

Solutions to the Examples

This section contains fully implemented solutions to each example given in the Examples. It will also contain the expected output when executing each ITEX Access application with the example test suite as input.

Makefile

This generic Makefile has been used for compilation and linking:

Solution 1

Code

Output

Solution 2

Code

Output

Solution 3

Code

Output

Solution 4

Code

Output


[Previous] [Next] [Contents] [Index]