ALLINSIGHT

Home of the AlmostImplementedException

Basic datatypes in TTCN-3

Like in any programming language, TTCN-3 provides different data types. In this post I’ll show you the different types and the special things you can do with them.

Let’s start with an overview of all types and a short description. Later on I will explain what is meant with “subtypes”.

Simple basic types
Keyword

Values

Description

Subtypes
integer

-infinity to infinity

positive and negative whole numbers

list, range
float

-infinity to infinity

positive and negative floating-point numbers

list, range
boolean

true or false

list
verdicttype

pass, fail, inconc, none and error

is used for test results

list

Integer and float are the only numeric-types in TTCC-3 and both have no limitations (unless you define it in a subtype)
What a boolean-type is should be clear. Only true and false are allowed values.
Verdicttype is a special TTCN-3 type to indicate the result of a test case or of a test component.
Possible values are:
pass for positive results,
fail for negative results,
inconc for inconclusive results,
error to indicate an error while executing the test case,
and none for no result at all.

String types
Keyword

Values

Description

Subtypes
bitstring

0 or 1

String of bits

list, length
hexstring

hex-decimal value

String of hex-decimal values

list, length
octetstring

hex-decimal value

String of hex-decimal values with an even number of digits (2 digits are 1 byte)

list, length
charstring

any graphical character from ascii 32 (Space) to 126 (Tilde)

String of allowed characters

list, length, range, pattern
universal charstring

any character

String of any character in UTF-32. Each is represented by 4 bytes

list, length, range, pattern

Bitstring, hexstring and octetstring can be used to store and transfer binary data, but only octetstring is determined for that. Bit- and hexstring can be used bitwise respectively 4-bitwise.
Example:
[ttcn3 inline=”true”]var bitstring mybitstring := ‘100100101101’B;[/ttcn3]
[ttcn3 inline=”true”]var hexstring myhexstring := ’09A8B’H;[/ttcn3]
[ttcn3 inline=”true”]var octetstring myoctetstring := ’09A8B8’O;[/ttcn3]

Charstring and universal charstring are the only types to store plain strings. Unfortunately charstring only allow characters from ASCII 32 to 126, which means you can’t use special characters like ΓΌ or even a line break (\n). For that you have to use the universal charstring which uses UTF-32, but then you can’t read the result that easily, because of awkward presentation of a universal charstring

Structured types
Keyword

Description

Subtypes
record

used for custom data types (ordered)

list
record of

used for a list of other data types (ordered)

list, length
set

used for custom data types (unordered)

list
set of

used for a list of other data types (unordered)

list, length
enumerated

enumeration of values

list
union

combination of multiple data types (only one can be used)

list

If you want to define your own data types you’ll need one of the above.
Record and set can be used to define complex type. In set the order of the fields doesn’t matter.
If you need a list of a simple or complex type, you can use record of or set of (again unsorted)
Enumerated can be used like enum in Java or C# to define a set of values which can be used.
Union types can be used to combine two or more data types, but only one of them can be used. (something similar to a choice in XML)

Special types
Keyword

Description

Subtypes
anytype

combines any known data type, but only one can be used

list
address

reference of a component or SUT

port

component

default

manages the use of altsteps (de-/activate)

A very special data type is anytpe. This one is like an union of all basic, string and custom types. And again you can only use one of them.
[ttcn3 inline=”true”]var anytype myany := {charstring:=”hello”};[/ttcn3]

Address, port and component are special types to define the architecture of the test system and will, like default be discussed in a later post.

All of those data types above can be combined to create custom complex types

Subtypes

All data types allow different kinds of subtyping where you can set your own boundaries.

List

With list you can limit the allowed values of a data type to the ones you specify.
[ttcn3 inline=”true”]type integer simpleInt (1, 2, 3); // only 1, 2 or 3 are allowed[/ttcn3]
[ttcn3 inline=”true”]type boolean trueBool (true); // a boolean that only allow true :D[/ttcn3]

Ranges

With a range you can again limit the allowed values, but without specifying every value.
[ttcn3 inline=”true”]type integer positiveInt (0 .. infinity); //only positive integers[/ttcn3]
[ttcn3 inline=”true”]type integer byte (0 .. 255); //only 0 to 255 (a byte)[/ttcn3]
[ttcn3 inline=”true”]type charstring aToZ (“a” .. “z”); //only character a to z (case insensitive)[/ttcn3]

Length

For string-values you can set a minimal and maximal length:
[ttcn3 inline=”true”]type bitstring myByte length (8); // string with a length of exactly 8[/ttcn3]
[ttcn3 inline=”true”]type charstring myChar length (4 .. 8); // string with a length of 4 to 8[/ttcn3]

You can set a length for record of and set of too:
[ttcn3 inline=”true”]type record length(5) of integer myIntList; // a list of integer with 5 elements.[/ttcn3]

Pattern

Pattern are only allowed for charstring and universal charstring and will be explained in detail later.
[ttcn3 inline=”true”]type charstring allInSightString (pattern “all*Sight”); //allows only strings which starts with “all” and ends with “Sight”.[/ttcn3]

You can combine all of those subtypes to generate the data type you want. But be aware that different rules may contradict each other
[ttcn3 inline=”true”]type charstring myFunnyChar (pattern “[a-z]#(4,8)”) length (1 .. 6); // a charstring which allows characters from a to z with a string length of 4 to 6[/ttcn3]

Share :

Leave a Reply

Your email address will not be published. Required fields are marked *