Octetstring Manipulation [message #1744345] |
Mon, 26 September 2016 04:34  |
Eclipse User |
|
|
|
Hi All,
I would like to add values to a variable of type octetstring in a loop.
var octetstring payload;
for(var integer v_ct :=1; v_ct<8; v_ct:=v_ct+1 ){
//TODO payload := '11' and in next loop payload := '1122' and so on ...
}
Unfortunately I couldn't find out to do this in TTCN3, can somebody help me ?
Thanks !
|
|
|
|
|
|
|
|
|
|
Re: Octetstring Manipulation [message #1746397 is a reply to message #1744801] |
Fri, 28 October 2016 03:03   |
Eclipse User |
|
|
|
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 03:06] by Moderator
|
|
|
Re: Octetstring Manipulation [message #1746421 is a reply to message #1746397] |
Fri, 28 October 2016 09:12   |
Eclipse User |
|
|
|
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 #1746876 is a reply to message #1746872] |
Mon, 07 November 2016 03:12  |
Eclipse User |
|
|
|
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.11351 seconds