Commit f0c59450 authored by Botond Baranyi's avatar Botond Baranyi Committed by Adam Knapp

XML enc/dec: global namespace variants no longer overwrite inherited namespace...

XML enc/dec: global namespace variants no longer overwrite inherited namespace variants (issue #545)
Signed-off-by: Botond Baranyi's avatarBotond Baranyi <botond.baranyi@ericsson.com>
parent 5674aff5
...@@ -1075,6 +1075,7 @@ void Type::chk_this_variant(const Ttcn::SingleWithAttrib* swa, bool global) ...@@ -1075,6 +1075,7 @@ void Type::chk_this_variant(const Ttcn::SingleWithAttrib* swa, bool global)
jsonattrib = new JsonAST(t_refd->jsonattrib); jsonattrib = new JsonAST(t_refd->jsonattrib);
new_json = true; new_json = true;
} }
bool xer_namespace_before = xerattrib->namespace_.uri != 0;
int ret = parse_rawAST(rawattrib, textattrib, xerattrib, berattrib, jsonattrib, int ret = parse_rawAST(rawattrib, textattrib, xerattrib, berattrib, jsonattrib,
swa->get_attribSpec(), get_length_multiplier(), my_scope->get_scope_mod(), swa->get_attribSpec(), get_length_multiplier(), my_scope->get_scope_mod(),
raw_found, text_found, xer_found, ber_found, json_found, coding); raw_found, text_found, xer_found, ber_found, json_found, coding);
...@@ -1092,6 +1093,9 @@ void Type::chk_this_variant(const Ttcn::SingleWithAttrib* swa, bool global) ...@@ -1092,6 +1093,9 @@ void Type::chk_this_variant(const Ttcn::SingleWithAttrib* swa, bool global)
break; break;
case CT_XER: case CT_XER:
mismatch = !xer_found; mismatch = !xer_found;
if (!xer_namespace_before && xerattrib->namespace_.uri != 0 && global) {
xerattrib->namespace_.global_variant = true;
}
break; break;
case CT_JSON: case CT_JSON:
mismatch = !json_found; mismatch = !json_found;
......
...@@ -68,6 +68,7 @@ XerAttributes::XerAttributes() ...@@ -68,6 +68,7 @@ XerAttributes::XerAttributes()
{ {
//__asm("int3"); //__asm("int3");
//fprintf(stderr, "XER attributes(%p) new\n", (void*)this); //fprintf(stderr, "XER attributes(%p) new\n", (void*)this);
namespace_.global_variant = false;
} }
void FreeNamespaceRestriction(NamespaceRestriction& nsr) void FreeNamespaceRestriction(NamespaceRestriction& nsr)
...@@ -121,6 +122,7 @@ void XerAttributes::FreeNamespace(NamespaceSpecification &ns) { ...@@ -121,6 +122,7 @@ void XerAttributes::FreeNamespace(NamespaceSpecification &ns) {
ns.uri = 0; ns.uri = 0;
Free(ns.prefix); Free(ns.prefix);
ns.prefix = 0; ns.prefix = 0;
ns.global_variant = false;
} }
void XerAttributes::FreeNameChange(XerAttributes::NameChange& n) { void XerAttributes::FreeNameChange(XerAttributes::NameChange& n) {
...@@ -324,7 +326,9 @@ other.print("other"); ...@@ -324,7 +326,9 @@ other.print("other");
} }
} }
if (other.namespace_.uri != 0) { if (other.namespace_.uri != 0 &&
// global namespace variants should no longer overwrite inherited namespace variants (issue #545)
(namespace_.uri == 0 || !other.namespace_.global_variant)) {
switch (namespace_.keyword) { switch (namespace_.keyword) {
case NamespaceSpecification::NO_MANGLING: case NamespaceSpecification::NO_MANGLING:
case NamespaceSpecification::CAPITALIZED: case NamespaceSpecification::CAPITALIZED:
......
...@@ -83,6 +83,9 @@ struct NamespaceSpecification ...@@ -83,6 +83,9 @@ struct NamespaceSpecification
char * prefix; // for NAMESPACE char * prefix; // for NAMESPACE
char * target; // for TEXT char * target; // for TEXT
}; };
/** Indicates whether the namespace was set by a global variant attribute
* (i.e. group or module level attribute) */
bool global_variant;
}; };
inline void free_name_or_kw(char *s) inline void free_name_or_kw(char *s)
......
Issue545
Issue545.exe
Issue545*.cc
Issue545*.hh
Issue545*.d
compile
Issue545*.log
/******************************************************************************
* Copyright (c) 2000-2021 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
*
******************************************************************************/
module Issue545a {
type record T1 {
universal charstring s
}
}
with {
encode "XML";
variant "namespace as 'http://www.somewhere.com/A' prefix 'nsA'";
variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'";
variant "elementFormQualified";
}
/******************************************************************************
* Copyright (c) 2000-2021 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
*
******************************************************************************/
module Issue545b {
// global namespace variants should no longer overwrite inherited namespace variants (issue #545)
import from Issue545a all;
type record T2 {
T1 t1
}
external function f_enc(in T2 x) return octetstring
with { extension "prototype(convert) encode(XER:XER_EXTENDED)" }
external function f_dec(in octetstring x) return T2
with { extension "prototype(convert) decode(XER:XER_EXTENDED)" }
type component CT {}
testcase tc_Issue545() runs on CT {
var T2 val := { t1 := { s := "abc" } };
var octetstring enc := f_enc(val);
var octetstring enc_exp := char2oct("<nsB:T2 xmlns:nsB='http://www.somewhere.com/B' xmlns:nsA='http://www.somewhere.com/A'>\n\t<nsA:t1>\n\t\t<nsA:s>abc</nsA:s>\n\t</nsA:t1>\n</nsB:T2>\n\n");
if (enc != enc_exp) {
setverdict(fail, "Encoding failed. Expected: ", enc_exp, ", got: ", enc);
}
else {
var T2 dec := f_dec(enc_exp);
if (dec != val) {
setverdict(fail, "Decoding failed. Expected: ", val, ", got: ", dec);
}
else {
setverdict(pass);
}
}
}
control {
execute(tc_Issue545());
}
}
with {
encode "XML";
variant "namespace as 'http://www.somewhere.com/B' prefix 'nsB'";
variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'";
variant "elementFormQualified";
}
##############################################################################
# Copyright (c) 2000-2021 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
#
##############################################################################
TOPDIR = ../..
include $(TOPDIR)/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 the C++ preprocessor (and makedepend as well):
#CPPFLAGS +=
# Flags for dependency generation
CXXDEPFLAGS = -MM
# Flags for the C++ compiler:
CXXFLAGS += -Wall
# Flags for the linker:
#LDFLAGS +=
# 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 = Issue545a.ttcn Issue545b.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)
# Other files of the project (Makefile, configuration files, etc.)
# that will be added to the archived source files:
OTHER_FILES = Makefile
# The name of the executable test suite:
TARGET = Issue545$(EXESUFFIX)
#
# Rules for building the executable...
#
all: $(TARGET) ;
objects: $(OBJECTS) compile;
$(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 distclean:
-$(RM) $(TARGET) $(OBJECTS) $(GENERATED_HEADERS) \
$(GENERATED_SOURCES) compile $(DEPFILES) \
tags *.log
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)
./$^
...@@ -38,7 +38,7 @@ const universal charstring bstr_NewC1 := ...@@ -38,7 +38,7 @@ const universal charstring bstr_NewC1 :=
"</NewC1>\n\n"; "</NewC1>\n\n";
const universal charstring estr_NewC1 := const universal charstring estr_NewC1 :=
"<NA:newC1 xmlns:NA='nsA' A1='1' A2='2'>-1000</NA:newC1>\n\n"; "<A:newC1 xmlns:A='urn:nsA' A1='1' A2='2'>-1000</A:newC1>\n\n";
DECLARE_XER_ENCODERS(NewC1, newc1); DECLARE_XER_ENCODERS(NewC1, newc1);
DECLARE_EXER_ENCODERS(NewC1, newc1); DECLARE_EXER_ENCODERS(NewC1, newc1);
......
...@@ -1775,7 +1775,7 @@ group ComplexType { ...@@ -1775,7 +1775,7 @@ group ComplexType {
} }
} }
} }
var charstring pl_expectedEncodedPdu:="<imp:purchaseReportImport xmlns:imp='www.XmlTest.org/complex_import' xmlns:r='www.XmlTest.org/complex_include' period='P3M' periodEnding='1999-12-31'>\n\t<imp:regions>\n\t\t<r:zip code='95819'>\n\t\t\t<r:part number='872-AA' quantity='1'/>\n\t\t\t<r:part number='926-AA' quantity='2'/>\n\t\t</r:zip>\n\t</imp:regions>\n\t<imp:parts>\n\t\t<r:part number='872-AA'>Lawnmower</r:part>\n\t\t<r:part number='926-AA'>Baby Monitor</r:part>\n\t</imp:parts>\n</imp:purchaseReportImport>\n\n"; var charstring pl_expectedEncodedPdu:="<imp:purchaseReportImport xmlns:imp='www.XmlTest.org/complex_import' xmlns:r='www.XmlTest.org/complex_include' period='P3M' periodEnding='1999-12-31'>\n\t<r:regions>\n\t\t<r:zip code='95819'>\n\t\t\t<r:part number='872-AA' quantity='1'/>\n\t\t\t<r:part number='926-AA' quantity='2'/>\n\t\t</r:zip>\n\t</r:regions>\n\t<r:parts>\n\t\t<r:part number='872-AA'>Lawnmower</r:part>\n\t\t<r:part number='926-AA'>Baby Monitor</r:part>\n\t</r:parts>\n</imp:purchaseReportImport>\n\n";
//see http://www.w3.org/TR/xmlschema-0/#quartelyReport ! //see http://www.w3.org/TR/xmlschema-0/#quartelyReport !
f_encDecTest_PurchaseReportImport(pl_pdu,pl_expectedEncodedPdu,pl_pdu); f_encDecTest_PurchaseReportImport(pl_pdu,pl_expectedEncodedPdu,pl_pdu);
}//tc_ }//tc_
......
...@@ -152,8 +152,8 @@ const IntegratedSite c_mgw_integratedsite_pdu := { ...@@ -152,8 +152,8 @@ const IntegratedSite c_mgw_integratedsite_pdu := {
}; };
const charstring c_mgw_integratedsite_encodedPdu:= template charstring t_mgw_integratedsite_encodedPdu:= pattern
"<IntegratedSite:IntegratedSite xmlns:IntegratedSite='http://www.ericsson.com/is/isco/IntegratedSite/R4L06/R4AB_1.02'>\n" & "<IntegratedSite:IntegratedSite xmlns:IntegratedSite='http://www.ericsson.com/is/isco/IntegratedSite/R4L06/R4AB_1.02' xmlns:tq????='http://tail-f.com/ns/confd/1.0'>\n" &
"\t<IntegratedSite:AdministrativeData>\n" & "\t<IntegratedSite:AdministrativeData>\n" &
"\t\t<IntegratedSite:SystemRestart/>\n" & "\t\t<IntegratedSite:SystemRestart/>\n" &
"\t</IntegratedSite:AdministrativeData>\n" & "\t</IntegratedSite:AdministrativeData>\n" &
...@@ -161,7 +161,7 @@ const charstring c_mgw_integratedsite_encodedPdu:= ...@@ -161,7 +161,7 @@ const charstring c_mgw_integratedsite_encodedPdu:=
"\t\t<IntegratedSite:BladeSystem>\n" & "\t\t<IntegratedSite:BladeSystem>\n" &
"\t\t\t<IntegratedSite:name>blade-1</IntegratedSite:name>\n" & "\t\t\t<IntegratedSite:name>blade-1</IntegratedSite:name>\n" &
"\t\t\t<IntegratedSite:alias>Blade of the immortal</IntegratedSite:alias>\n" & "\t\t\t<IntegratedSite:alias>Blade of the immortal</IntegratedSite:alias>\n" &
"\t\t\t<IntegratedSite:swgRef>swg17</IntegratedSite:swgRef>\n" & "\t\t\t<tq????:swgRef>swg17</tq????:swgRef>\n" &
"\t\t\t<IntegratedSite:BsNetworkConfiguration/>\n" & "\t\t\t<IntegratedSite:BsNetworkConfiguration/>\n" &
"\t\t</IntegratedSite:BladeSystem>\n\t</IntegratedSite:BladeSystems>\n" & "\t\t</IntegratedSite:BladeSystem>\n\t</IntegratedSite:BladeSystems>\n" &
"\t<IntegratedSite:Hardware/>\n" & "\t<IntegratedSite:Hardware/>\n" &
...@@ -338,15 +338,15 @@ with { extension "prototype(backtrack) decode(XER:XER_EXTENDED) errorbehavior(AL ...@@ -338,15 +338,15 @@ with { extension "prototype(backtrack) decode(XER:XER_EXTENDED) errorbehavior(AL
//========================================================================= //=========================================================================
// f_encDecTest_MGW_IntegratedSite // f_encDecTest_MGW_IntegratedSite
//========================================================================= //=========================================================================
function f_encDecTest_MGW_IntegratedSite(in IntegratedSite pl_pdu, in charstring pl_expectedEncodedPdu, in IntegratedSite pl_expectedDecodedPdu ) { function f_encDecTest_MGW_IntegratedSite(in IntegratedSite pl_pdu, in template charstring pl_expectedEncodedPdu, in IntegratedSite pl_expectedDecodedPdu ) {
var octetstring vl_encodedPdu:=''O; var octetstring vl_encodedPdu:=''O;
f_enc_MGW_IntegratedSite(pl_pdu,vl_encodedPdu); f_enc_MGW_IntegratedSite(pl_pdu,vl_encodedPdu);
if(match(vl_encodedPdu,char2oct(pl_expectedEncodedPdu))) { if(match(oct2char(vl_encodedPdu),pl_expectedEncodedPdu)) {
setverdict(pass) setverdict(pass)
} else { } else {
log("The encoded message: ",vl_encodedPdu); log("The encoded message: ",vl_encodedPdu);
setverdict(fail, match(vl_encodedPdu,char2oct(pl_expectedEncodedPdu))); setverdict(fail, match(oct2char(vl_encodedPdu),pl_expectedEncodedPdu));
} }
//log("===Checking value decoded from the encoded value vs expected value==="); //log("===Checking value decoded from the encoded value vs expected value===");
var IntegratedSite vl_decodedPdu; var IntegratedSite vl_decodedPdu;
...@@ -476,7 +476,7 @@ testcase tc_XmlTest_MGW_HK84933_converter() runs on xmlTest_CT ...@@ -476,7 +476,7 @@ testcase tc_XmlTest_MGW_HK84933_converter() runs on xmlTest_CT
testcase tc_XmlTest_MGW_encDec() runs on xmlTest_CT testcase tc_XmlTest_MGW_encDec() runs on xmlTest_CT
{ {
f_encDecTest_MGW_IntegratedSite(c_mgw_integratedsite_pdu,c_mgw_integratedsite_encodedPdu,c_mgw_integratedsite_pdu); f_encDecTest_MGW_IntegratedSite(c_mgw_integratedsite_pdu,t_mgw_integratedsite_encodedPdu,c_mgw_integratedsite_pdu);
} }
testcase tc_XmlTest_PAP_converter() runs on xmlTest_CT testcase tc_XmlTest_PAP_converter() runs on xmlTest_CT
......
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