|
Re: Octetstring Manipulation [message #1744350 is a reply to message #1744345] |
Mon, 26 September 2016 09:10 |
|
Hi Johannes,
module test
{
control{
var octetstring payload:=''O;
for(var integer v_ct :=1; v_ct<8; v_ct:=v_ct+1 ) {
payload := payload& hex2oct(int2hex(v_ct,1)&int2hex(v_ct,1));
log(payload)
}
}
}
11:11:34.141011 Execution of control part in module test started.
11:11:34.141097 '11'O
11:11:34.142409 '1122'O
11:11:34.142428 '112233'O
11:11:34.142445 '11223344'O
11:11:34.142461 '1122334455'O
11:11:34.142479 '112233445566'O
11:11:34.142497 '11223344556677'O
11:11:34.142519 Execution of control part in module test finished.
BR Elemer
|
|
|
|
|
Re: Octetstring Manipulation [message #1744454 is a reply to message #1744450] |
Tue, 27 September 2016 07:56 |
|
Hi Johannes,
yes there is; omit should be considered as a special value.
In receiving templates, you can use wildcards: '?' has the significance of any value (including the zero length value -empty string- in case of strings) and "*" represents any value or omit.
In structures, only optional fields can be given a value of omit.
I hope this makes it clearer
BR
Elemer
|
|
|
|
|
Re: Octetstring Manipulation [message #1744801 is a reply to message #1744675] |
Fri, 30 September 2016 10:00 |
|
Hi Johannes,
in this context "?" denotes one element of a string , so '?'O is an octetstring of length one ( this is two hex characters , e.g. '1F'O) ;
for any length (including length zero ) , a "*" should be used, so '*'O denotes an octetstring of an arbitrary length (including ''O) .
So the correct expression would be
template Frame frame1 (octetstring p_payload ) := {
payload := '*'O &p_payload // Some bytes are doesn't matter but the last have to be equal p_payload
}
But , unfortunately concatenation of wildcards has not been implemented; we will look into it.
However, "?" and "*" can be used inside the octetstring , so
something like:
template Frame frame2 := {
payload := '*1234567ABC'O
}
or
template Frame frame3 := {
payload := '*12345F??'O
}
will be working.
Best regards
Elemer
|
|
|
Re: Octetstring Manipulation [message #1746397 is a reply to message #1744801] |
Fri, 28 October 2016 07:03 |
Johannes Bro Messages: 56 Registered: June 2015 |
Member |
|
|
Hi All,
first thanks for the detailed description. But I have to come back to this topic. As you already mentioned your example is only working when you type explicit the value of the octetstring. In my case I need to check partly a octetstring variable. Therefore I had a look to the TTCN standard and there is a function to create a substring of a string.
See at chapter string Manipulation at http://www.blukaktus.com/TTCN3QRC_viewme.pdf. I tried it out with titan but it seems not to be supported, isn't it ?
As approach I created my own "substr" function for octetstrings, see below. Concerning this function, I would like to know what is the best practice to create a error in case of index/counter is less than zero or index+count is creater as the length of the input octeststring:
module test {
function f_suboctstr ( in octetstring octstr, in integer index, in integer count ) return octetstring {
var octetstring retOctstr := ''O;
if((lengthof(octstr)>=count+index) and (index >= 0) and (index >= 0)){
for( var integer i :=0; i<count; i:=i+1){
retOctstr := retOctstr& octstr[index+i];
}
}
else{
setverdict(fail, "Disallowed ussage of f_suboctstr");
}
return retOctstr;
}
control{
var octetstring test:='AABBCC'O;
test := f_suboctstr (test,1,2);
log(test)
}
}
[Updated on: Fri, 28 October 2016 07:06] Report message to a moderator
|
|
|
Re: Octetstring Manipulation [message #1746421 is a reply to message #1746397] |
Fri, 28 October 2016 13:12 |
|
Hi Johannes,
substr is fully supported as specified in the standard.
As for your question, I guess the best practice is to use an out parameter for the resulting octetstring
and an integer return to specify the result:
var octetstring v_res
var integer v_ret
function f_suboctstr ( in octetstring octstr, in integer index, in integer count, out octetstring p_res)
return integer { //returns 0 if everything is OK
p_res:=...
}
v_ret:=f_suboctstr('AABBCC'O,1,2,v_res)
v_ret=0 indicates successful execution
if v_ret == 0, v_res will store the result
Best regards
Elemer
|
|
|
|
|
Re: Octetstring Manipulation [message #1746750 is a reply to message #1746748] |
Fri, 04 November 2016 07:56 |
|
Hi Johannes,
the-recommended by standard -way of dealing with errors is to set the verdict to error;
substr itself will throw an error in certain situations will result in the verdict being set to error.
Best regards
Elemer
|
|
|
|
Re: Octetstring Manipulation [message #1746876 is a reply to message #1746872] |
Mon, 07 November 2016 08:12 |
|
Sorry , Johannes,
I have misled you here;
I have checked the standard and it explicitly says that:
"The setverdict operation shall only be used with the values pass, fail, inconc and none. It shall not
be used to assign the value error, this is set by the test system only to indicate runtime errors. "
so I remembered wrongly.
Technically, there is the option of writing an external function that triggers an error.
However, I would not recommend that; dynamic test case error is quite a dramatic way to end;
Situations like you mentioned can be treated nicely in the code without a recourse to error.
Best regards
Elemer
|
|
|
Powered by
FUDForum. Page generated in 0.05986 seconds