Commit 506275e1 authored by Botond Baranyi's avatar Botond Baranyi
Browse files

Fixed RAW 'presence' attribute on embedded record types (bug 547385)



Change-Id: I4ad435e466b16385565408b6cdced2398e151771
Signed-off-by: Botond Baranyi's avatarBotond Baranyi <botond.baranyi@ericsson.com>
parent 2b1732c4
......@@ -2281,42 +2281,44 @@ namespace Common {
}
}
}
for(int a=0;a<rawattrib->presence.nElements;a++){ //PRESENCE
Type *t=this;
bool hiba=false;
for(int b=0;b<rawattrib->presence.keyList[a].keyField->nElements;b++){
Identifier *idf=rawattrib->presence.keyList[a].keyField->names[b];
if(!t->is_secho()){
error("Invalid fieldmember type in RAW parameter PRESENCE"
" for the record %s."
,get_typename().c_str());
hiba=true;
break;
}
if(!t->has_comp_withName(*idf)){
error("Invalid fieldname in RAW parameter"
" PRESENCE for the record %s: %s"
,get_typename().c_str()
,rawattrib->presence.keyList[a].keyField->names[b]
->get_dispname().c_str());
hiba=true;
break;
if (ownertype != OT_COMP_FIELD) {
for(int a=0;a<rawattrib->presence.nElements;a++){ //PRESENCE
Type *t=this;
bool hiba=false;
for(int b=0;b<rawattrib->presence.keyList[a].keyField->nElements;b++){
Identifier *idf=rawattrib->presence.keyList[a].keyField->names[b];
if(!t->is_secho()){
error("Invalid fieldmember type in RAW parameter PRESENCE"
" for the record %s."
,get_typename().c_str());
hiba=true;
break;
}
if(!t->has_comp_withName(*idf)){
error("Invalid fieldname in RAW parameter"
" PRESENCE for the record %s: %s"
,get_typename().c_str()
,rawattrib->presence.keyList[a].keyField->names[b]
->get_dispname().c_str());
hiba=true;
break;
}
t=t->get_comp_byName(*idf)->get_type()->get_type_refd_last();
}
t=t->get_comp_byName(*idf)->get_type()->get_type_refd_last();
}
if(!hiba){
Error_Context cntx(this, "In Raw parameter PRESENCE");
Value *v = rawattrib->presence.keyList[a].v_value;
v->set_my_scope(get_my_scope());
v->set_my_governor(t);
t->chk_this_value_ref(v);
self_ref = t->chk_this_value(v, 0, EXPECTED_CONSTANT,
INCOMPLETE_NOT_ALLOWED, OMIT_NOT_ALLOWED, SUB_CHK);
Value::valuetype_t vt = v->get_valuetype();
if (vt == Value::V_ENUM || vt == Value::V_REFD) {
Free(rawattrib->presence.keyList[a].value);
rawattrib->presence.keyList[a].value =
mcopystr(v->get_single_expr().c_str());
if(!hiba){
Error_Context cntx(this, "In Raw parameter PRESENCE");
Value *v = rawattrib->presence.keyList[a].v_value;
v->set_my_scope(get_my_scope());
v->set_my_governor(t);
t->chk_this_value_ref(v);
self_ref = t->chk_this_value(v, 0, EXPECTED_CONSTANT,
INCOMPLETE_NOT_ALLOWED, OMIT_NOT_ALLOWED, SUB_CHK);
Value::valuetype_t vt = v->get_valuetype();
if (vt == Value::V_ENUM || vt == Value::V_REFD) {
Free(rawattrib->presence.keyList[a].value);
rawattrib->presence.keyList[a].value =
mcopystr(v->get_single_expr().c_str());
}
}
}
}
......
......@@ -1465,7 +1465,7 @@ void Type::generate_code_Choice(output_struct *target)
if (dummy_raw) {
rawattrib = new RawAST(get_default_raw_fieldlength());
}
copy_rawAST_to_struct(rawattrib,&(sdef.raw));
copy_rawAST_to_struct(rawattrib,&(sdef.raw), true);
// building taglist
for(int c=0;c<rawattrib->taglist.nElements;c++){
if(rawattrib->taglist.tag[c].nElements)
......@@ -1967,7 +1967,7 @@ void Type::generate_code_Se(output_struct *target)
if (dummy_raw) {
rawattrib = new RawAST(get_default_raw_fieldlength());
}
copy_rawAST_to_struct(rawattrib,&(sdef.raw));
copy_rawAST_to_struct(rawattrib,&(sdef.raw), ownertype != OT_COMP_FIELD);
// building taglist
for(int c=0;c<rawattrib->taglist.nElements;c++) {
if(rawattrib->taglist.tag[c].nElements)
......@@ -2045,31 +2045,33 @@ void Type::generate_code_Se(output_struct *target)
}
}
// building presence list
for(int a=0;a<rawattrib->presence.nElements;a++) {
rawAST_coding_field_list* presences=sdef.raw.presence.fields+a;
presences->nElements=
rawattrib->presence.keyList[a].keyField->nElements;
presences->value=rawattrib->presence.keyList[a].value;
presences->fields=(rawAST_coding_fields*)
Malloc(presences->nElements*sizeof(rawAST_coding_fields));
Type *t = this;
for (int b = 0; b < presences->nElements; b++) {
Identifier *idf = rawattrib->presence.keyList[a].keyField->names[b];
size_t comp_index = t->get_comp_index_byName(*idf);
CompField *cf = t->get_comp_byIndex(comp_index);
presences->fields[b].nthfield = comp_index;
presences->fields[b].nthfieldname = idf->get_name().c_str();
if (t->typetype == T_CHOICE_T)
presences->fields[b].fieldtype = UNION_FIELD;
else if (cf->get_is_optional())
presences->fields[b].fieldtype = OPTIONAL_FIELD;
else presences->fields[b].fieldtype = MANDATORY_FIELD;
Type *field_type = cf->get_type();
presences->fields[b].type =
pool.add(field_type->get_genname_value(my_scope));
presences->fields[b].typedescr =
pool.add(field_type->get_genname_typedescriptor(my_scope));
t = field_type->get_type_refd_last();
if (ownertype != OT_COMP_FIELD) {
for(int a=0;a<rawattrib->presence.nElements;a++) {
rawAST_coding_field_list* presences=sdef.raw.presence.fields+a;
presences->nElements=
rawattrib->presence.keyList[a].keyField->nElements;
presences->value=rawattrib->presence.keyList[a].value;
presences->fields=(rawAST_coding_fields*)
Malloc(presences->nElements*sizeof(rawAST_coding_fields));
Type *t = this;
for (int b = 0; b < presences->nElements; b++) {
Identifier *idf = rawattrib->presence.keyList[a].keyField->names[b];
size_t comp_index = t->get_comp_index_byName(*idf);
CompField *cf = t->get_comp_byIndex(comp_index);
presences->fields[b].nthfield = comp_index;
presences->fields[b].nthfieldname = idf->get_name().c_str();
if (t->typetype == T_CHOICE_T)
presences->fields[b].fieldtype = UNION_FIELD;
else if (cf->get_is_optional())
presences->fields[b].fieldtype = OPTIONAL_FIELD;
else presences->fields[b].fieldtype = MANDATORY_FIELD;
Type *field_type = cf->get_type();
presences->fields[b].type =
pool.add(field_type->get_genname_value(my_scope));
presences->fields[b].typedescr =
pool.add(field_type->get_genname_typedescriptor(my_scope));
t = field_type->get_type_refd_last();
}
}
}
for(int c=0;c<rawattrib->ext_bit_goup_num;c++){
......@@ -2085,7 +2087,7 @@ void Type::generate_code_Se(output_struct *target)
Type *t_field_last = t_field->get_type_refd_last();
RawAST *rawpar = t_field->rawattrib;
if(rawpar) {
copy_rawAST_to_struct(rawpar,&(sdef.elements[i].raw));
copy_rawAST_to_struct(rawpar,&(sdef.elements[i].raw), true);
for(int j=0; j<rawpar->lengthto_num;j++){
Identifier *idf=rawpar->lengthto[j];
sdef.elements[i].raw.lengthto[j]=get_comp_index_byName(*idf);
......@@ -2389,7 +2391,7 @@ void Type::generate_code_SeOf(output_struct *target)
if (dummy_raw) {
rawattrib = new RawAST(get_default_raw_fieldlength());
}
copy_rawAST_to_struct(rawattrib,&(sofdef.raw));
copy_rawAST_to_struct(rawattrib,&(sofdef.raw), true);
if (dummy_raw) {
delete rawattrib;
rawattrib = NULL;
......
......@@ -217,7 +217,7 @@ void RawAST::print_RawAST(){
(stringformat == CharCoding::UTF16 ? "UTF-16" : "unknown"));
}
void copy_rawAST_to_struct(RawAST *from, raw_attrib_struct *to){
void copy_rawAST_to_struct(RawAST *from, raw_attrib_struct *to, bool copy_presences){
to->fieldlength=from->fieldlength;
to->comp=from->comp;
to->byteorder=from->byteorder;
......@@ -262,7 +262,7 @@ void copy_rawAST_to_struct(RawAST *from, raw_attrib_struct *to){
to->taglist.list[i].fields = NULL;
}
} else to->taglist.list = NULL;
to->presence.nElements = from->presence.nElements;
to->presence.nElements = copy_presences ? from->presence.nElements : 0;
if (to->presence.nElements > 0)
to->presence.fields = static_cast<rawAST_coding_field_list*>(
Malloc(to->presence.nElements * sizeof(rawAST_coding_field_list)) );
......
......@@ -172,7 +172,8 @@ extern int parse_rawAST(RawAST *par, TextAST *textpar, XerAttributes *xerpar,
int l_multip, const Common::Module* mod, bool &raw_found, bool &text_found,
bool &xer_found, bool &ber_found, bool &json_found,
Common::Type::MessageEncodingType_t par_codec = Common::Type::CT_UNDEF);
extern void copy_rawAST_to_struct(RawAST *from, raw_attrib_struct *to);
extern void copy_rawAST_to_struct(RawAST *from, raw_attrib_struct *to,
bool copy_presences);
extern void free_raw_attrib_struct(raw_attrib_struct *raw);
extern int compare_raw_attrib(RawAST *a, RawAST *b);
......
Bug547385
Bug547385.exe
Bug547385*.cc
Bug547385*.hh
*.d
compile
Bug547385*.log
/******************************************************************************
* Copyright (c) 2000-2019 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
*
* Contributors:
* Baranyi, Botond – initial implementation
*
******************************************************************************/
module Bug547385 {
type record Rec {
integer f1,
record {
integer v2
} f2 optional
}
with {
encode "RAW";
variant (f2) "PRESENCE(f1 = 0)";
}
type component CT {}
testcase tc1() runs on CT {
var Rec x := { f1 := 0, f2 := { v2 := 10 } };
var bitstring enc_exp := oct2bit('000A'O);
var bitstring enc := encvalue(x);
if (enc != enc_exp) {
setverdict(fail, "Encoding failed. Expected: ", bit2oct(enc_exp), ", got: ", bit2oct(enc));
}
var Rec dec;
var integer res := decvalue(enc_exp, dec);
if (res != 0) {
setverdict(fail, "Decoding failed. Result: ", res);
}
else if (dec != x) {
setverdict(fail, "Decoding failed. Expected: ", x, ", got: ", dec);
}
else {
setverdict(pass);
}
}
testcase tc2() runs on CT {
var Rec x := { f1 := 2, f2 := omit };
var bitstring enc_exp := oct2bit('02'O);
var bitstring enc := encvalue(x);
if (enc != enc_exp) {
setverdict(fail, "Encoding failed. Expected: ", bit2oct(enc_exp), ", got: ", bit2oct(enc));
}
var Rec dec;
var integer res := decvalue(enc_exp, dec);
if (res != 0) {
setverdict(fail, "Decoding failed. Result: ", res);
}
else if (dec != x) {
setverdict(fail, "Decoding failed. Expected: ", x, ", got: ", dec);
}
else {
setverdict(pass);
}
}
control {
execute(tc1());
execute(tc2());
}
}
##############################################################################
# Copyright (c) 2000-2019 Ericsson Telecom AB
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v2.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
#
# Contributors:
# Botond, Baranyi
#
##############################################################################
TOPDIR := ../..
include ../../Makefile.regression
# WARNING! This Makefile can be used with GNU make only.
# Other versions of make may report syntax errors in it.
#
# Do NOT touch this line...
#
.PHONY: all archive check clean dep objects
.SUFFIXES: .d
#
# Set these variables...
#
# Flags for dependency generation
CXXDEPFLAGS = -MM
ifeq ($(PLATFORM), WIN32)
# Silence linker warnings.
# Overridden by Makefile.cfg
endif
# Flags for the TTCN-3 and ASN.1 compiler:
COMPILER_FLAGS +=
# Execution mode: (either ttcn3 or ttcn3-parallel)
TTCN3_LIB = ttcn3$(RT2_SUFFIX)$(DYNAMIC_SUFFIX)
#
# You may change these variables. Add your files if necessary...
#
# TTCN-3 modules of this project:
TTCN3_MODULES = Bug547385.ttcn
# ASN.1 modules of this project:
ASN1_MODULES =
# C++ source & header files generated from the TTCN-3 & ASN.1 modules of
# this project:
GENERATED_SOURCES = $(TTCN3_MODULES:.ttcn=.cc) $(ASN1_MODULES:.asn=.cc)
GENERATED_HEADERS = $(GENERATED_SOURCES:.cc=.hh)
ifdef SPLIT_TO_SLICES
POSTFIXES := $(foreach file, $(SPLIT_TO_SLICES), $(addsuffix $(file), _part_))
POSTFIXES := $(foreach file, $(POSTFIXES), $(addprefix $(file), .cc))
GENERATED_SOURCES2 := $(foreach file, $(GENERATED_SOURCES:.cc=), $(addprefix $(file), $(POSTFIXES)))
GENERATED_SOURCES += $(GENERATED_SOURCES2)
endif
# C/C++ Source & header files of Test Ports, external functions and
# other modules:
USER_SOURCES =
USER_HEADERS = $(USER_SOURCES:.cc=.hh)
# Object files of this project that are needed for the executable test suite:
OBJECTS = $(GENERATED_OBJECTS) $(USER_OBJECTS)
GENERATED_OBJECTS = $(GENERATED_SOURCES:.cc=.o)
USER_OBJECTS = $(USER_SOURCES:.cc=.o)
DEPFILES = $(USER_OBJECTS:.o=.d) $(GENERATED_OBJECTS:.o=.d)
# The name of the executable test suite:
TARGET = Bug547385$(EXESUFFIX)
# Rules for building the executable...
#
all: $(TARGET)
objects: $(OBJECTS) ;
$(TARGET): $(OBJECTS)
if $(CXX) $(LDFLAGS) -o $@ $^ \
-L$(TTCN3_DIR)/lib -l$(TTCN3_LIB) \
-L$(OPENSSL_DIR)/lib -lcrypto \
-L$(XMLDIR)/lib $($(PLATFORM)_LIBS); \
then : ; else $(TTCN3_DIR)/bin/titanver $(OBJECTS); exit 1; fi
.cc.o .c.o:
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
.cc.d .c.d:
@echo Creating dependency file for '$<'; set -e; \
$(CXX) $(CXXDEPFLAGS) $(CPPFLAGS) $(CXXFLAGS) $< \
| sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \
[ -s $@ ] || rm -f $@
$(GENERATED_SOURCES) $(GENERATED_HEADERS): compile
@if [ ! -f $@ ]; then $(RM) compile; $(MAKE) compile; fi
compile: $(TTCN3_MODULES) $(ASN1_MODULES)
$(TTCN3_COMPILER) $(COMPILER_FLAGS) $^ - $?
touch $@
clean:
-$(RM) $(TARGET) $(OBJECTS) $(GENERATED_HEADERS) \
$(GENERATED_SOURCES) compile $(DEPFILES) \
tags *.log
distclean: clean
-$(RM) $(DEPFILES)
dep: $(GENERATED_SOURCES) $(USER_SOURCES) ;
ifeq ($(findstring n,$(MAKEFLAGS)),)
ifeq ($(filter clean distclean check compile archive diag,$(MAKECMDGOALS)),)
-include $(DEPFILES)
endif
endif
diag:
$(TTCN3_COMPILER) -v 2>&1
$(TTCN3_DIR)/bin/mctr_cli -v 2>&1
$(CXX) -v 2>&1
@echo TTCN3_DIR=$(TTCN3_DIR)
@echo OPENSSL_DIR=$(OPENSSL_DIR)
@echo XMLDIR=$(XMLDIR)
@echo PLATFORM=$(PLATFORM)
#
# Add your rules here if necessary...
#
run: $(TARGET) ./config.cfg
./$^
###############################################################################
# Copyright (c) 2000-2019 Ericsson Telecom AB
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v2.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
#
# Contributors:
# Botond, Baranyi
#
###############################################################################
[LOGGING]
LogFile := "Bug547385.log"
FileMask := LOG_ALL
ConsoleMask := TTCN_ERROR | TTCN_TESTCASE | TTCN_STATISTICS
LogSourceInfo := Yes
[EXECUTE]
Bug547385.control
[TESTPORT_PARAMETERS]
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