From 2a3c1e2fa524c7ebba50868b8c3a0a241c07a95c Mon Sep 17 00:00:00 2001
From: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
Date: Wed, 18 Jan 2017 15:43:09 +0100
Subject: [PATCH] xsd2ttcn: Added .0 if needed after the value of a fixed float
 value (Bug 510589)

Change-Id: Ib13ae3d240c39aa04fd4f3e01be48a056ac3fa3a
Signed-off-by: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
---
 .../www_example_org_fixed_value_e.ttcn        | 42 +++++++++++++++++++
 .../XML/XmlWorkflow/xsd/fixed_value.xsd       |  6 +++
 xsdconvert/Mstring.cc                         |  8 ++--
 xsdconvert/Mstring.hh                         |  8 ++--
 xsdconvert/SimpleType.cc                      |  4 ++
 5 files changed, 60 insertions(+), 8 deletions(-)

diff --git a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_fixed_value_e.ttcn b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_fixed_value_e.ttcn
index d3478eb1f..fef4c8964 100644
--- a/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_fixed_value_e.ttcn
+++ b/regression_test/XML/XmlWorkflow/XmlTest_expectedTtcns/www_example_org_fixed_value_e.ttcn
@@ -86,6 +86,48 @@ with {
 };
 
 
+type XSD.Float FloatType5 (3.0)
+with {
+  variant "defaultForEmpty as '3'";
+  variant "element";
+};
+
+
+type XSD.Float FloatType6 (-3.0)
+with {
+  variant "defaultForEmpty as '-3'";
+  variant "element";
+};
+
+
+type XSD.Float FloatType7 (-1E4)
+with {
+  variant "defaultForEmpty as '-1E4'";
+  variant "element";
+};
+
+
+type XSD.Float FloatType8 (12.78e-2)
+with {
+  variant "defaultForEmpty as '12.78e-2'";
+  variant "element";
+};
+
+
+type XSD.Float FloatType9 (0.0)
+with {
+  variant "defaultForEmpty as '0'";
+  variant "element";
+};
+
+
+type XSD.Float FloatType10 (-0.0)
+with {
+  variant "defaultForEmpty as '-0'";
+  variant "element";
+};
+
+
 type XSD.Double DoubleType (7.0)
 with {
   variant "defaultForEmpty as '7.0'";
diff --git a/regression_test/XML/XmlWorkflow/xsd/fixed_value.xsd b/regression_test/XML/XmlWorkflow/xsd/fixed_value.xsd
index b7e4d7900..8841ea4e6 100644
--- a/regression_test/XML/XmlWorkflow/xsd/fixed_value.xsd
+++ b/regression_test/XML/XmlWorkflow/xsd/fixed_value.xsd
@@ -9,6 +9,12 @@
 <xsd:element name="FloatType2" type="xsd:float" fixed="INF"/> 
 <xsd:element name="FloatType3" type="xsd:float" fixed="-INF"/> 
 <xsd:element name="FloatType4" type="xsd:float" fixed="NaN"/> 
+<xsd:element name="FloatType5" type="xsd:float" fixed="3"/> 
+<xsd:element name="FloatType6" type="xsd:float" fixed="-3"/> 
+<xsd:element name="FloatType7" type="xsd:float" fixed="-1E4"/> 
+<xsd:element name="FloatType8" type="xsd:float" fixed="12.78e-2"/> 
+<xsd:element name="FloatType9" type="xsd:float" fixed="0"/> 
+<xsd:element name="FloatType10" type="xsd:float" fixed="-0"/> 
 <xsd:element name="DoubleType" type="xsd:double" fixed="7.0"/>
 <xsd:element name="BooleanType" type="xsd:boolean" fixed="true"/>
 <xsd:element name="BooleanType2" type="xsd:boolean" fixed="0"/>
diff --git a/xsdconvert/Mstring.cc b/xsdconvert/Mstring.cc
index 4c020d8ba..e3b8ab8df 100644
--- a/xsdconvert/Mstring.cc
+++ b/xsdconvert/Mstring.cc
@@ -86,19 +86,19 @@ void Mstring::insertChar(size_t pos, char c) {
   text = mcopystr(temp.text);
 }
 
-bool Mstring::isFound(const Mstring & s) {
+bool Mstring::isFound(const Mstring & s) const {
   return strstr(text, s.text);
 }
 
-bool Mstring::isFound(const char * s) {
+bool Mstring::isFound(const char * s) const {
   return strstr(text, s);
 }
 
-bool Mstring::isFound(char c) {
+bool Mstring::isFound(char c) const {
   return strchr(text, c);
 }
 
-char * Mstring::foundAt(const char * s) {
+char * Mstring::foundAt(const char * s) const {
   return strstr(text, s);
 }
 
diff --git a/xsdconvert/Mstring.hh b/xsdconvert/Mstring.hh
index 244b277e1..5e8af1621 100644
--- a/xsdconvert/Mstring.hh
+++ b/xsdconvert/Mstring.hh
@@ -98,21 +98,21 @@ public:
    * true if s is found
    * false otherwise
    */
-  bool isFound(const Mstring & s);
+  bool isFound(const Mstring & s) const;
 
   /**
    * Look for s c-string content
    * true if s is found
    * false otherwise
    */
-  bool isFound(const char * s);
+  bool isFound(const char * s) const;
 
   /**
    * Look for c character content
    * true if s is found
    * false otherwise
    */
-  bool isFound(char c);
+  bool isFound(char c) const;
 
   /**
    * Look for c-string content
@@ -120,7 +120,7 @@ public:
    * character where the matching found,
    * returns null otherwise
    */
-  char * foundAt(const char * c);
+  char * foundAt(const char * c) const;
 
   /**
    * The first character of the Mstring is set to uppercase
diff --git a/xsdconvert/SimpleType.cc b/xsdconvert/SimpleType.cc
index b186c6b0f..2f7c43a13 100644
--- a/xsdconvert/SimpleType.cc
+++ b/xsdconvert/SimpleType.cc
@@ -1559,6 +1559,10 @@ void ValueType::printToFile(FILE * file) const {
         val = "-infinity";
       } else if (fixed_value == "NaN") {
         val = "not_a_number";
+      } else if (!fixed_value.isFound('.') && !fixed_value.isFound('e') &&
+               !fixed_value.isFound('E')) {
+        // Float types need the .0 if it is a single integer.
+        val = fixed_value + Mstring(".0");
       } else {
         val = fixed_value;
       }
-- 
GitLab