Shorthand notations are used in TTCN-3 to make testers life easier, and the code more readable ... but sometimes using them can create hard to solve maintenance problems.
For example, if we have a function that send a text message
// send a character string
private function f_charstringSender( )
runs on altstepExample_CT
{
portname_PT.send( "akarmi" );
}
What does the following piece of code do ? :
vl_ptc.start( f_charstringSender() );
timer TL_timer;
TL_timer.start(60.0);
TL_timer.timeout;
The answer might seem simple.
We start start a function on a component, which will send out a text message.
At the same time the test waits for 60 seconds before continuing.
But there is a trick.
Lets add an other simple function to receive the message
private altstep as_charstringHandler()
runs on altstepExample_CT
{
var charstring vl_temp;
[] portname_PT.receive(charstring: *) -> value vl_temp {
action("charstring received");
}
}
And activate it before the timer
var default vl_default := activate(as_charstringHandler());
Without changing the code with the timer, we have seriously altered its behaviour.
Instead of waiting for 60 seconds the timer will "expire" immediately.
What might be the reason for this?
In TTCN-3 there are several statements (including the timer.timout) which are actually only a shorthand notation for an altstep.
So our TL_timer.timeout statement is actually
alt {
[] TL_timer.timeout;
}
As we have also activated an alt statement for receiving a text message, according to the default handling mechanism of TTCN-3 our TL_timer.timeout statement will actually behave as if it was written something like this:
alt {
[] TL_timer.timeout;
[] portname_PT.receive(charstring: *) ....
}
By activating an altstep for the component the test is running on, we enabled the timer to also handle messages comming from the network.
To sum up when using shorthand notations in your tests be aware that:
- they might look simple and innocent
- but might actually do whatever
- based on the altsteps that can be hard to identify from the code as they might be activate in the runtime based on dynamic criteria
- and this change can happen after you have tested and delivered your code. If you have these shorthands in your library code that is used by others in their tests, the altsteps that change the behaviour of your code might not even be present anywhere in your code. An independent library used in the same test as your, can activate them without knowing about your.