Commit c29c7f58 authored by Botond Baranyi's avatar Botond Baranyi
Browse files

xsd2ttcn: fixed order of fields generated for XSD groups (bug 537922)



Change-Id: I51d7f6e90f292917b0cadb5702b646553c1bcdbe
Signed-off-by: Botond Baranyi's avatarBotond Baranyi <botond.baranyi@ericsson.com>
parent d9bd5dc1
/*******************************************************************************
* Copyright (c) 2000-2019 Ericsson Telecom AB
*
* XSD to TTCN-3 Translator version: CRL 113 200/6 R5B
*
* 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
*******************************************************************************/
//
// File: www_example_org_bug537922.ttcn
// Description:
// References:
// Rev:
// Prodnr:
// Updated: Tue Feb 12 13:25:48 2019
// Contact: http://ttcn.ericsson.se
//
////////////////////////////////////////////////////////////////////////////////
// Generated from file(s):
// - Bug537922.xsd
// /* xml version = "1.0" encoding = "UTF-8" */
// /* targetnamespace = "www.example.org/bug537922" */
////////////////////////////////////////////////////////////////////////////////
// Modification header(s):
//-----------------------------------------------------------------------------
// Modified by:
// Modification date:
// Description:
// Modification contact:
//------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
module www_example_org_bug537922 {
import from XSD all;
type record Mapping
{
XSD.AnySimpleType expires,
XSD.Integer xsinteger optional,
XSD.DateTime lastUpdated,
XSD.Token message_ optional,
AppUniqueString source,
XSD.Token sourceId,
record of DisplayName displayName_list,
Service service optional,
union {
ServiceBoundary_1 serviceBoundary,
ServiceBoundaryReference serviceBoundaryReference
} choice optional,
record of Uri uri_list,
ServiceNumber serviceNumber optional,
record of NotLost notLost_list
}
with {
variant "name as uncapitalized";
variant "element";
variant (expires) "attribute";
variant (xsinteger) "name as 'xs:integer'";
variant (xsinteger) "attribute";
variant (lastUpdated) "attribute";
variant (message_) "name as 'message'";
variant (message_) "attribute";
variant (source) "attribute";
variant (sourceId) "attribute";
variant (displayName_list) "untagged";
variant (displayName_list[-]) "name as 'displayName'";
variant (choice) "untagged";
variant (uri_list) "untagged";
variant (uri_list[-]) "name as 'uri'";
variant (notLost_list) "untagged";
};
type record DisplayName
{
XSD.Integer xsinteger,
XSD.String base
}
with {
variant "name as uncapitalized";
variant "element";
variant (xsinteger) "name as 'xs:integer'";
variant (xsinteger) "attribute";
variant (base) "untagged";
};
type record ServiceGroup
{
Service service optional
}
with {
variant "untagged";
};
type XSD.AnyURI Service
with {
variant "name as uncapitalized";
variant "element";
};
type record ServiceBoundary_1
{
record length(1 .. infinity) of ServiceBoundary serviceBoundary_list
}
with {
variant "untagged";
variant (serviceBoundary_list) "untagged";
variant (serviceBoundary_list[-]) "name as 'serviceBoundary'";
};
type LocationInformation ServiceBoundary
with {
variant "name as uncapitalized";
variant "element";
};
type record LocationInformation
{
XSD.NMTOKEN profile optional,
record length(1 .. infinity) of ExtensionPoint extensionPoint_list
}
with {
variant "name as uncapitalized";
variant (profile) "attribute";
variant (extensionPoint_list) "untagged";
};
/* A point where future extensions
(elements from other namespaces)
can be added. */
type record ExtensionPoint
{
record of NotLost notLost_list
}
with {
variant "untagged";
variant (notLost_list) "untagged";
};
/* Any element not in the LoST namespace. */
type union NotLost
{
XSD.String elem
}
with {
variant "untagged";
variant (elem) "anyElement from unqualified";
};
type record ServiceBoundaryReference
{
XSD.Token key,
AppUniqueString source,
record of NotLost notLost_list
}
with {
variant "name as uncapitalized";
variant "element";
variant (key) "attribute";
variant (source) "attribute";
variant (notLost_list) "untagged";
};
type XSD.Token AppUniqueString (pattern "([a-zA-Z0-9\-]+.)+[a-zA-Z0-9]+")
with {
variant "name as uncapitalized";
};
type XSD.AnyURI Uri
with {
variant "name as uncapitalized";
variant "element";
};
type XSD.Token ServiceNumber (pattern "[0-9*#]+")
with {
variant "name as uncapitalized";
variant "element";
};
}
with {
encode "XML";
variant "namespace as 'www.example.org/bug537922' prefix 'ns1'";
variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'";
variant "elementFormQualified";
}
......@@ -150,6 +150,7 @@
<File path="../xsd/name_clashes_and_references_A.xsd" />
<File path="../xsd/name_clashes_and_references_B.xsd" />
<File path="../xsd/name_clashes_and_references_C.xsd" />
<File path="../xsd/Bug537922.xsd" />
<File path="../xsd/simpletype_base.xsd" />
<File path="../xsd/type_substitution.xsd" />
<File path="../xsd/type_substitution_chain.xsd" />
......@@ -397,6 +398,7 @@
<File path="../XmlTest_expectedTtcns/www_example_org_substitutiongroup_main_e.ttcn" />
<File path="../XmlTest_expectedTtcns/XSD_Definitions_e.ttcn" />
<File path="../XmlTest_expectedTtcns/XSD_Definitions_e2.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_bug537922_e.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_simpletype_base_e.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_type_substitution_e.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_type_substitution_chain_e.ttcn" />
......
......@@ -2636,6 +2636,16 @@ group Elements{
"XSD_Definitions.ttcn", c_numOfDiff);
}
}
testcase tc_group_ref_order() runs on xmlTest_CT { // bug 537922
f_shellCommandWithVerdict(xsd2ttcn_command & " Bug537922.xsd", "", c_shell_successWithoutWarningAndError);
if(getverdict == pass) {
f_compareFiles(
"www_example_org_bug537922_e.ttcn",
"www_example_org_bug537922.ttcn", c_numOfDiff);
}
}
}//Element
......@@ -2913,6 +2923,8 @@ control {
execute(tc_substitution_group_merged());
execute(tc_name_clashes_and_references_merged());
execute(tc_group_ref_order());
}
} with {
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2000-2018 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
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="www.example.org/bug537922" xmlns:ns1="www.example.org/bug537922">
<xs:element name="mapping">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="ns1:displayName"/>
<xs:group ref="ns1:serviceGroup"/>
<xs:choice minOccurs="0">
<xs:group ref="ns1:serviceBoundary"/>
<xs:element ref="ns1:serviceBoundaryReference"/>
</xs:choice>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="ns1:uri"/>
<xs:element minOccurs="0" ref="ns1:serviceNumber"/>
<xs:group ref="ns1:extensionPoint"/>
</xs:sequence>
<xs:attributeGroup ref="ns1:expires"/>
<xs:attribute name="lastUpdated" use="required" type="xs:dateTime"/>
<xs:attributeGroup ref="ns1:source"/>
<xs:attribute name="sourceId" use="required" type="xs:token"/>
<xs:attributeGroup ref="ns1:message"/>
</xs:complexType>
</xs:element>
<xs:element name="displayName">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute ref="xs:integer" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:group name="serviceGroup">
<xs:sequence>
<xs:element minOccurs="0" ref="ns1:service"/>
</xs:sequence>
</xs:group>
<xs:element name="service" type="xs:anyURI"/>
<xs:group name="serviceBoundary">
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="ns1:serviceBoundary"/>
</xs:sequence>
</xs:group>
<xs:element name="serviceBoundary" type="ns1:locationInformation"/>
<xs:complexType name="locationInformation">
<xs:group maxOccurs="unbounded" ref="ns1:extensionPoint"/>
<xs:attribute name="profile" type="xs:NMTOKEN"/>
</xs:complexType>
<xs:group name="extensionPoint">
<xs:annotation>
<xs:documentation>
A point where future extensions
(elements from other namespaces)
can be added.
</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:group minOccurs="0" maxOccurs="unbounded" ref="ns1:notLost"/>
</xs:sequence>
</xs:group>
<xs:group name="notLost">
<xs:annotation>
<xs:documentation>
Any element not in the LoST namespace.
</xs:documentation>
</xs:annotation>
<xs:choice>
<xs:any namespace="##local" processContents="skip"/>
</xs:choice>
</xs:group>
<xs:element name="serviceBoundaryReference">
<xs:complexType>
<xs:group ref="ns1:extensionPoint"/>
<xs:attributeGroup ref="ns1:source"/>
<xs:attributeGroup ref="ns1:serviceBoundaryKey"/>
</xs:complexType>
</xs:element>
<xs:attributeGroup name="source">
<xs:attribute name="source" use="required" type="ns1:appUniqueString"/>
</xs:attributeGroup>
<xs:simpleType name="appUniqueString">
<xs:restriction base="xs:token">
<xs:pattern value="([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]+"/>
</xs:restriction>
</xs:simpleType>
<xs:attributeGroup name="serviceBoundaryKey">
<xs:attribute name="key" use="required" type="xs:token"/>
</xs:attributeGroup>
<xs:element name="uri" type="xs:anyURI"/>
<xs:element name="serviceNumber">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:pattern value="[0-9*#]+"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:attributeGroup name="expires">
<xs:attribute name="expires" use="required">
</xs:attribute>
</xs:attributeGroup>
<xs:attributeGroup name="message">
<xs:attribute name="message" type="xs:token"/>
<xs:attribute ref="xs:integer"/>
</xs:attributeGroup>
</xs:schema>
......@@ -1826,23 +1826,27 @@ void ComplexType::resolveGroup() {
addNameSpaceas = true;
}
if (ct->getXsdtype() == n_sequence && getMinOccurs() == 1 && getMaxOccurs() == 1 && (parent->getXsdtype() == n_complexType || parent->getXsdtype() == n_sequence)) {
ComplexType* insertion_point = this;
for (List<ComplexType*>::iterator c = ct->complexfields.begin(); c; c = c->Next) {
ComplexType * newField = new ComplexType(*c->Data);
parent->complexfields.push_back(newField);
parent->complexfields.insert_after(newField, insertion_point);
insertion_point = newField;
setParent(parent, newField);
parent->complexfields.back()->setModule(getModule());
newField->setModule(getModule());
if (addNameSpaceas) {
parent->complexfields.back()->addVariant(V_namespaceAs, ct->getModule()->getTargetNamespace());
newField->addVariant(V_namespaceAs, ct->getModule()->getTargetNamespace());
}
}
} else if (ct->getXsdtype() == n_all) {
//If the parent optional, then every field is optional
ComplexType* insertion_point = this;
for (List<ComplexType*>::iterator c = ct->complexfields.begin(); c; c = c->Next) {
ComplexType* f = new ComplexType(*c->Data);
if (getMinOccurs() == 0 && !f->enumerated) {
f->isOptional = true;
}
((ComplexType*) parent)->complexfields.push_back(f);
((ComplexType*) parent)->complexfields.insert_after(f, insertion_point);
insertion_point = f;
setParent(parent, f);
f->setModule(getModule());
if (addNameSpaceas) {
......
......@@ -151,6 +151,8 @@ public:
* Pushes element at the front of the list
*/
void push_front(const T & element);
void insert_after(const T & new_element, const T & ref_element);
/**
* Removes the final element in the list
......@@ -375,6 +377,29 @@ void List<T>::push_front(const T & element) {
++Size;
}
template <class T>
void List<T>::insert_after(const T & new_element, const T & ref_element) {
for (Item<T>* ref_node = First; ref_node; ref_node = ref_node->Next) {
if (ref_node->Data == ref_element) {
Item<T> * new_node = new Item<T>;
new_node->Data = new_element;
new_node->Prev = ref_node;
Item<T>* next_node = ref_node->Next;
ref_node->Next = new_node;
new_node->Next = next_node;
if (next_node != NULL) {
next_node->Prev = new_node;
}
if (Last == ref_node) {
Last = new_node;
}
++Size;
return;
}
}
}
template <class T>
void List<T>::pop_back() {
Item<T> * LastNode = Last;
......
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