From b3b358afbcd0a3dda6b3b120a19fd990ff1252bc Mon Sep 17 00:00:00 2001
From: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
Date: Tue, 12 Sep 2017 11:51:57 +0200
Subject: [PATCH] xsd2ttcn: support enumeration restriction on sequence types
 (Bug 522177)

Change-Id: Icf0604f94e1ffc00ef818cc6acbeb4e8752ea9de
Signed-off-by: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
---
 .../www_example_org_defaultforempty_e.ttcn    | 26 +++++++++++++++-
 ...xample_org_enumeration_restriction3_e.ttcn | 30 +++++++++++++++++++
 ...example_org_enumeration_restriction_e.ttcn | 20 +++++++++++--
 .../XmlWorkflow/src/xmlTest_Testcases.ttcn    |  4 +--
 .../XML/XmlWorkflow/xsd/defaultforempty.xsd   | 10 ++++++-
 .../xsd/enumeration_restriction3.xsd          | 28 +++++++++++++++++
 xsdconvert/SimpleType.cc                      |  8 ++---
 7 files changed, 116 insertions(+), 10 deletions(-)

diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_defaultforempty_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_defaultforempty_e.ttcn
index 1fd513111..fd22228c3 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_defaultforempty_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_defaultforempty_e.ttcn
@@ -322,7 +322,7 @@ with {
 };
 
 
-/* Unsupported anytype and QName */
+/* Unsupported anytype and QName and IDREFS and ENTITIES and NMTOKENS */
 
 
 type XSD.AnyType AnyTypeDefault
@@ -361,6 +361,30 @@ with {
 };
 
 
+type XSD.IDREFS IDREFSDefault
+with {
+  variant "element";
+};
+
+
+type XSD.IDREFS IDREFSFixed
+with {
+  variant "element";
+};
+
+
+type XSD.NMTOKENS NMTOKENSDefault
+with {
+  variant "element";
+};
+
+
+type XSD.NMTOKENS NMTOKENSFixed
+with {
+  variant "element";
+};
+
+
 /* Check if the name conversion follows to the constants too */
 
 
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_enumeration_restriction3_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_enumeration_restriction3_e.ttcn
index 734ae7166..883703f9f 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_enumeration_restriction3_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_enumeration_restriction3_e.ttcn
@@ -116,6 +116,36 @@ with {
 };
 
 
+type enumerated NMTokens
+{
+	vxmlcurrency,
+	vxmldate,
+	vxmldigits,
+	vxmlnumber,
+	vxmltime
+}
+with {
+  variant "text 'vxmlcurrency' as 'vxml:currency'";
+  variant "text 'vxmldate' as 'vxml:date'";
+  variant "text 'vxmldigits' as 'vxml:digits'";
+  variant "text 'vxmlnumber' as 'vxml:number'";
+  variant "text 'vxmltime' as 'vxml:time'";
+};
+
+
+type enumerated IDRefs
+{
+	nmtokens_ref,
+	qname_ref
+};
+
+
+/* Still unsupported QName */
+
+
+type XSD.QName QName;
+
+
 }
 with {
   encode "XML";
diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_enumeration_restriction_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_enumeration_restriction_e.ttcn
index 2f47ea778..ef57f20dc 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_enumeration_restriction_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_enumeration_restriction_e.ttcn
@@ -195,10 +195,26 @@ with {
 };
 
 
-type XSD.NMTOKENS NMTOKENSEnumeration;
+type enumerated NMTOKENSEnumeration
+{
+	false_,
+	true_
+}
+with {
+  variant "text 'false_' as 'false'";
+  variant "text 'true_' as 'true'";
+};
 
 
-type XSD.IDREFS IDREFSEnumeration;
+type enumerated IDREFSEnumeration
+{
+	false_,
+	true_
+}
+with {
+  variant "text 'false_' as 'false'";
+  variant "text 'true_' as 'true'";
+};
 
 
 type record Element
diff --git a/regression_test/XML/XmlWorkflow/src/xmlTest_Testcases.ttcn b/regression_test/XML/XmlWorkflow/src/xmlTest_Testcases.ttcn
index 446509d8b..59f8c9b10 100644
--- a/regression_test/XML/XmlWorkflow/src/xmlTest_Testcases.ttcn
+++ b/regression_test/XML/XmlWorkflow/src/xmlTest_Testcases.ttcn
@@ -1113,7 +1113,7 @@ group UnionTest {
 
  testcase tc_enumeration_union_restriction() runs on xmlTest_CT {
 
-    f_shellCommandWithVerdict(xsd2ttcn_command & "  enumeration_restriction.xsd","",c_shell_successWithWarning)
+    f_shellCommandWithVerdict(xsd2ttcn_command & "  enumeration_restriction.xsd","",c_shell_successWithoutWarningAndError)
 
     if(getverdict==pass) {
       f_compareFiles(
@@ -1135,7 +1135,7 @@ group UnionTest {
 
  testcase tc_enumeration_restriction3() runs on xmlTest_CT {
 
-    f_shellCommandWithVerdict(xsd2ttcn_command & "  enumeration_restriction3.xsd","",c_shell_successWithoutWarningAndError)
+    f_shellCommandWithVerdict(xsd2ttcn_command & "  enumeration_restriction3.xsd","",c_shell_successWithWarning)
 
     if(getverdict==pass) {
       f_compareFiles(
diff --git a/regression_test/XML/XmlWorkflow/xsd/defaultforempty.xsd b/regression_test/XML/XmlWorkflow/xsd/defaultforempty.xsd
index 3c7e07226..2e37831c6 100644
--- a/regression_test/XML/XmlWorkflow/xsd/defaultforempty.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/defaultforempty.xsd
@@ -53,7 +53,7 @@
 
 <xs:element name='AnySimpleTypeFixed' type="xs:anySimpleType" fixed='1.0.0'/>
 
-<!-- Unsupported anytype and QName -->
+<!-- Unsupported anytype and QName and IDREFS and ENTITIES and NMTOKENS -->
 <xs:element name='AnyTypeDefault' default='1.0.0'/>
 
 <xs:element name='AnyTypeFixed' fixed='1.0.0'/>
@@ -66,6 +66,14 @@
 
 <xs:element name='QNameFixed' type="xs:QName" fixed='Name'/>
 
+<xs:element name='IDREFSDefault' type="xs:IDREFS" id="my_id" default='my_id'/>
+
+<xs:element name='IDREFSFixed' type="xs:IDREFS" fixed='my_id'/>
+
+<xs:element name='NMTOKENSDefault' type="xs:NMTOKENS" default='abc'/>
+
+<xs:element name='NMTOKENSFixed' type="xs:NMTOKENS" fixed='abc'/>
+
 <!-- Check if the name conversion follows to the constants too -->
 <xs:element name="AttrfixedMyString3_"/>
 <xs:element name="MyString_"/>
diff --git a/regression_test/XML/XmlWorkflow/xsd/enumeration_restriction3.xsd b/regression_test/XML/XmlWorkflow/xsd/enumeration_restriction3.xsd
index b2f1d2150..c245f0219 100644
--- a/regression_test/XML/XmlWorkflow/xsd/enumeration_restriction3.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/enumeration_restriction3.xsd
@@ -52,5 +52,33 @@
 	</simpleContent>
 </complexType>
 
+<simpleType name="NMTokens" id="nmtokens_ref">
+   <restriction base="NMTOKENS">
+      <enumeration value="vxml:digits"/>
+      <enumeration value="vxml:number"/>
+      <enumeration value="vxml:time"/>
+      <enumeration value="vxml:date"/>
+      <enumeration value="vxml:currency"/>
+   </restriction>
+</simpleType>
+
+<simpleType name="IDRefs">
+   <restriction base="IDREFS">
+      <enumeration value="nmtokens_ref"/>
+      <enumeration value="qname_ref"/>
+   </restriction>
+</simpleType>
+
+
+<!-- Still unsupported QName -->
+<simpleType name="QName" id="qname_ref">
+   <restriction base="QName">
+      <enumeration value="digits"/>
+      <enumeration value="number"/>
+      <enumeration value="time"/>
+      <enumeration value="date"/>
+      <enumeration value="currency"/>
+   </restriction>
+</simpleType>
 
 </schema>
diff --git a/xsdconvert/SimpleType.cc b/xsdconvert/SimpleType.cc
index 6d605410f..d1ef38bbb 100644
--- a/xsdconvert/SimpleType.cc
+++ b/xsdconvert/SimpleType.cc
@@ -1267,7 +1267,7 @@ void EnumerationType::applyFacets() // string types, integer types, float types,
 
   const Mstring & base = parent->getBuiltInBase();
 
-  if (isStringType(base)) // here length restriction is applicable
+  if (isStringType(base) || (isSequenceType(base) && base != "QName")) // here length restriction is applicable
   {
     List<Mstring> text_variants;
     for (List<Mstring>::iterator facet = facets.begin(); facet; facet = facet->Next) {
@@ -1370,7 +1370,7 @@ void EnumerationType::printToFile(FILE * file, unsigned int indent_level) const
   if (!modified) return;
 
   const Mstring & base = parent->getBuiltInBase();
-  if (isStringType(base)) {
+  if (isStringType(base) || (isSequenceType(base) && base != "QName")) {
     for (QualifiedNames::iterator itemString = items_string.begin(); itemString; itemString = itemString->Next) {
       if (itemString != items_string.begin()) fputs(",\n", file);
       for (unsigned int l = 0; l != indent_level; ++l) fputs("\t", file);
@@ -1634,8 +1634,8 @@ void ValueType::printToFile(FILE * file) const {
       if(!isBuiltInType(type)){
         type = findBuiltInType(parent, type);
       }
+      const Mstring& name = type.getValueWithoutPrefix(':');
       if (isStringType(type) || isTimeType(type) || isQNameType(type) || isAnyType(type)) {
-        const Mstring& name = type.getValueWithoutPrefix(':');
         if (name != "hexBinary" && name != "base64Binary") {
           fprintf(file, " (\"%s\")", fixed_value.c_str());
         }
@@ -1652,7 +1652,7 @@ void ValueType::printToFile(FILE * file) const {
       } else if (isFloatType(type)) {
         Mstring val = xmlFloat2TTCN3FloatStr(fixed_value);
         fprintf(file, " (%s)", val.c_str());
-      } else {
+      } else if (name != "NMTOKENS" && name != "IDREFS" && name != "ENTITIES"){
         fprintf(file, " (%s)", fixed_value.c_str());
       }
     }
-- 
GitLab