Commit 603b99b3 authored by BenceJanosSzabo's avatar BenceJanosSzabo
Browse files

TEXT: Fixed incorrect decode union field error (Bug 522412)



Change-Id: I1f4d73bcebc9adc06a8059a0a8f86dd662e676b7
Signed-off-by: default avatarBenceJanosSzabo <bence.janos.szabo@ericsson.com>
parent 9e11ac64
......@@ -10,6 +10,7 @@
* Delic, Adam
* Raduly, Csaba
* Szabados, Kristof
* Szabo, Bence Janos
* Szabo, Janos Zoltan – initial implementation
* Szalai, Gabor
*
......@@ -84,7 +85,7 @@ int Token_Match::match_begin(TTCN_Buffer& buff) const
{
int retval=-1;
int ret_val=-1;
if(null_match){
if(null_match){
if (TTCN_EncDec::get_error_behavior(TTCN_EncDec::ET_LOG_MATCHING) !=
TTCN_EncDec::EB_IGNORE) {
char msg[ERRMSG_BUFSIZE2];
......@@ -210,7 +211,6 @@ Limit_Token_List::Limit_Token_List(){
size_of_list=16;
list=(const Token_Match **)Malloc(size_of_list*sizeof(Token_Match *));
last_match=(int *)Malloc(size_of_list*sizeof(int));
last_ret_val=-1;
last_pos=NULL;
}
......@@ -241,24 +241,24 @@ int Limit_Token_List::match(TTCN_Buffer& buff, size_t lim){
//TTCN_Logger::log(TTCN_Logger::DEBUG_ENCDEC,"Limit Token begin: %s\n\r",(const char*)buff.get_read_data());
if(last_pos!=NULL){
int diff=curr_pos-last_pos;
// Diff is negative if we started to decode one field of an union but
// ultimately it was not correct and we try with another field of an union.
// So take the absolute value of diff in this case to adjust last_match.
if (diff < 0) diff *= -1;
if(diff){
for(size_t a=0;a<num_of_tokens;a++){
last_match[a]-=diff;
}
last_ret_val-=diff;
}
}
last_pos=curr_pos;
// if(last_ret_val<0){
for(size_t a=0;a<num_of_tokens-lim;a++){
if(last_match[a]<0) last_match[a]=list[a]->match_first(buff);
if(last_match[a]>=0){
if(ret_val==-1) ret_val=last_match[a];
else if(last_match[a]<ret_val) ret_val=last_match[a];
}
for(size_t a=0;a<num_of_tokens-lim;a++){
if(last_match[a]<0) last_match[a]=list[a]->match_first(buff);
if(last_match[a]>=0){
if(ret_val==-1) ret_val=last_match[a];
else if(last_match[a]<ret_val) ret_val=last_match[a];
}
last_ret_val=ret_val;
// }
}
if (TTCN_EncDec::get_error_behavior(TTCN_EncDec::ET_LOG_MATCHING)!=
TTCN_EncDec::EB_IGNORE) {
TTCN_Logger::log(TTCN_Logger::DEBUG_ENCDEC,
......
......@@ -8,6 +8,7 @@
* Contributors:
* Balasko, Jeno
* Raduly, Csaba
* Szabo, Bence Janos
* Szabo, Janos Zoltan – initial implementation
* Szalai, Gabor
*
......@@ -106,7 +107,6 @@ private:
size_t size_of_list;
const Token_Match **list;
int *last_match;
int last_ret_val;
const char* last_pos;
/// Copy constructor disabled
Limit_Token_List(const Limit_Token_List&);
......
......@@ -9,6 +9,7 @@
.* Balasko, Jeno
.* Kovacs, Ferenc
.* Szabados, Kristof
.* Szabo, Bence Janos
.*
.******************************************************************************/
:text.
......@@ -1211,6 +1212,103 @@ type integer myint5 with { encode "TEXT"; variant "TEXT_CODING(length=25)" }
Overall verdict: pass
<END_TC>
:exmp.
.*---------------------------------------------------------------------*
:h3.Decode second field of union
.*---------------------------------------------------------------------*
:xmp tab=0.
<TC - Decode second field of union>
<STATIC>
type charstring Version (pattern "\d.\d") with {
encode "TEXT";
variant "BEGIN('ABCD ')"
}
type record Command {
charstring code,
charstring id,
charstring string,
Version ver
} with {
encode "TEXT";
variant "SEPARATOR(' ', '[\t ]+')"
variant "END('\r\n', '([\r\n])|(\r\n)')"
}
type record Response {
charstring code,
charstring id,
charstring string optional
} with {
encode "TEXT";
variant "SEPARATOR(' ', '[\t ]+')"
variant "END('\r\n', '([\r\n])|(\r\n)')"
}
type union Message {
Command command,
Response response
} with {
encode "TEXT";
variant "BEGIN('')"
}
type record Whole {
integer i,
Message mess
} with {
encode "TEXT";
variant "SEPARATOR(' ', '[\t ]+')"
variant "BEGIN('')"
}
external function enc_Response(in Response id) return charstring
with { extension "prototype(convert) encode(TEXT)" };
external function dec_Response(in charstring id) return Response
with { extension "prototype(convert) decode(TEXT)" };
external function enc_Message(in Message id) return charstring
with { extension "prototype(convert) encode(TEXT)" };
external function dec_Message(in charstring id) return Message
with { extension "prototype(convert) decode(TEXT)" };
external function enc_Whole(in Whole id) return charstring
with { extension "prototype(convert) encode(TEXT)" };
external function dec_Whole(in charstring id) return Whole
with { extension "prototype(convert) decode(TEXT)" };
<TTCN_TC:EXEC>
var Response pdu := { code := "510", id := "23", string := "FAIL" }
var charstring cs := "510 23 FAIL\r\n";
if (not match(pdu, dec_Response(cs))) {
setverdict(fail);
}
var Message mess := { response := { code := "510", id := "23", string := "FAIL" } }
if (not match(mess, dec_Message(cs))) {
setverdict(fail);
}
var Whole wh := { i := 1, mess := { response := { code := "510", id := "23", string := "FAIL" } } }
cs := "1 510 23 FAIL\r\n";
log(match(wh, dec_Whole(cs)))
if (not match(wh, dec_Whole(cs))) {
setverdict(fail);
}
setverdict(pass);
<RESULT>
Overall verdict: pass
<END_TC>
:exmp.
.*---------------------------------------------------------------------*
:h1.REFERENCES
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment