Commit 0797da7c authored by BenceJanosSzabo's avatar BenceJanosSzabo
Browse files

xsd2ttcn: fixed generation of special float values in enumerations (Bug 510734)



Change-Id: Icc4dc4db28716d439b1ba8eb1ead00b03b249cc1
Signed-off-by: default avatarBenceJanosSzabo <bence.janos.szabo@ericsson.com>
parent 2a3c1e2f
/*******************************************************************************
* Copyright (c) 2000-2017 Ericsson Telecom AB
*
* XSD to TTCN-3 Translator
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Szabo, Bence Janos
*
*******************************************************************************/
//
// File: www_example_org_ranges_float.ttcn
// Description:
// References:
// Rev:
// Prodnr:
// Updated: Fri Jan 20 10:28:48 2017
// Contact: http://ttcn.ericsson.se
//
////////////////////////////////////////////////////////////////////////////////
// Generated from file(s):
// - ranges_float.xsd
// /* xml version = "1.0" encoding = "UTF-8" */
// /* targetnamespace = "www.example.org/ranges/float" */
////////////////////////////////////////////////////////////////////////////////
// Modification header(s):
//-----------------------------------------------------------------------------
// Modified by:
// Modification date:
// Description:
// Modification contact:
//------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
module www_example_org_ranges_float {
import from XSD all;
/* minInclusive, maxInclusive, minExclusive, maxExclusive */
type XSD.Float E9b (-5.0 .. infinity)
with {
variant "name as uncapitalized";
};
type XSD.Float E9c
with {
variant "name as uncapitalized";
};
type XSD.Float E9d ( not_a_number )
with {
variant "name as uncapitalized";
};
/* mixed */
type XSD.Float E19b (-5.0 .. !-1.0)
with {
variant "name as uncapitalized";
};
type XSD.Float E19c (-infinity .. -1.0)
with {
variant "name as uncapitalized";
};
type XSD.Float E19d ( not_a_number )
with {
variant "name as uncapitalized";
};
type XSD.Float Enum (-infinity, infinity, not_a_number)
with {
variant "name as uncapitalized";
};
}
with {
encode "XML";
variant "namespace as 'www.example.org/ranges/float'";
variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'";
}
/*******************************************************************************
* Copyright (c) 2000-2017 Ericsson Telecom AB
*
* XSD to TTCN-3 Translator
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Szabo, Bence Janos
*
*******************************************************************************/
//
// File: www_example_org_ranges_integer.ttcn
// Description:
// References:
// Rev:
// Prodnr:
// Updated: Fri Jan 20 10:32:38 2017
// Contact: http://ttcn.ericsson.se
//
////////////////////////////////////////////////////////////////////////////////
// Generated from file(s):
// - ranges_integer.xsd
// /* xml version = "1.0" encoding = "UTF-8" */
// /* targetnamespace = "www.example.org/ranges/integer" */
////////////////////////////////////////////////////////////////////////////////
// Modification header(s):
//-----------------------------------------------------------------------------
// Modified by:
// Modification date:
// Description:
// Modification contact:
//------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
module www_example_org_ranges_integer {
import from XSD all;
/* minInclusive, maxInclusive, minExclusive, maxExclusive */
type XSD.Integer E9a (-5 .. infinity)
with {
variant "name as uncapitalized";
};
type XSD.PositiveInteger E10a (1 .. 100)
with {
variant "name as uncapitalized";
};
type XSD.Integer E11a (!-5 .. infinity)
with {
variant "name as uncapitalized";
};
type XSD.PositiveInteger E12a (1 .. !100)
with {
variant "name as uncapitalized";
};
/* mixed */
type XSD.Integer E19a (-5 .. -1)
with {
variant "name as uncapitalized";
};
type XSD.PositiveInteger E110a (1 .. 100)
with {
variant "name as uncapitalized";
};
type XSD.Integer E111a (!-5 .. !100)
with {
variant "name as uncapitalized";
};
}
with {
encode "XML";
variant "namespace as 'www.example.org/ranges/integer'";
variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'";
}
......@@ -415,6 +415,8 @@
<File path="../XmlTest_expectedTtcns/www_example_org_simpletype_aliases_e.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_complextype_aliases_e.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_attribute_rename_e.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_ranges_integer_e.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_ranges_float_e.ttcn" />
</File_Group>
<File_Group name="XmlTest_src" >
<File path="xmlTest_Shell.ttcn" />
......
......@@ -898,9 +898,28 @@ group IntegerTest {
}
}//tc_
testcase tc_ranges_integer() runs on xmlTest_CT {
f_shellCommandWithVerdict(xsd2ttcn_command & " ranges_integer.xsd","",c_shell_successWithoutWarningAndError)
if(getverdict==pass) {
f_compareFiles(
"www_example_org_ranges_integer_e.ttcn",
"www_example_org_ranges_integer.ttcn", c_numOfDiff);
}
}//tc_
}//IntegerTest
testcase tc_ranges_float() runs on xmlTest_CT {
f_shellCommandWithVerdict(xsd2ttcn_command & " ranges_float.xsd","",c_shell_successWithoutWarningAndError)
if(getverdict==pass) {
f_compareFiles(
"www_example_org_ranges_float_e.ttcn",
"www_example_org_ranges_float.ttcn", c_numOfDiff);
}
}//tc_
testcase tc_float_not_a_number() runs on xmlTest_CT {
f_shellCommandWithVerdict(xsd2ttcn_command & " not_a_number_minex_inf_maxex_-inf.xsd","",c_shell_successWithoutWarningAndError)
......@@ -2631,6 +2650,7 @@ control {
execute(tc_integer_withMaxIncl());//Passed
execute(tc_integer_withMinExcl());//Passed
execute(tc_integer_withMaxExcl());//Passed
execute(tc_ranges_integer());//Passed
//===Time===
execute(tc_time());//passed
execute(tc_time_withEnum());//Passed TR HL22058
......@@ -2642,6 +2662,7 @@ control {
execute(tc_list_complextype());
execute(tc_list_minmaxoccurs());
//===Float===
execute(tc_ranges_float());
execute(tc_float_not_a_number());
//===simpleType enum====
......
......@@ -9,6 +9,7 @@
Contributors:
Balasko, Jeno
Raduly, Csaba
Szabo, Bence Janos
-->
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
......@@ -69,4 +70,13 @@ targetNamespace="www.example.org/ranges/float">
</restriction>
</simpleType>
<simpleType name="enum">
<restriction base="float">
<enumeration value="INF"/>
<enumeration value="-INF"/>
<enumeration value="NaN"/>
</restriction>
</simpleType>
</schema>
......@@ -28,6 +28,18 @@
extern bool g_flag_used;
extern bool h_flag_used;
#ifndef INFINITY
#define INFINITY (DBL_MAX*DBL_MAX)
#endif
const double PLUS_INFINITY(INFINITY);
const double MINUS_INFINITY(-INFINITY);
#ifdef NAN
const double NOT_A_NUMBER(NAN);
#else
const double NOT_A_NUMBER((double)PLUS_INFINITY+(double)MINUS_INFINITY);
#endif
SimpleType::SimpleType(XMLParser * a_parser, TTCN3Module * a_module, ConstructType a_construct)
: RootType(a_parser, a_module, a_construct)
, builtInBase()
......@@ -1242,7 +1254,11 @@ void EnumerationType::applyFacets() // string types, integer types, float types,
for (List<Mstring>::iterator facet = facets.begin(); facet; facet = facet->Next) {
double float_value = atof(facet->Data.c_str());
const ValueType & value = parent->getValue();
if (value.lower <= float_value && float_value <= value.upper) {
// Value uses DBL_MAX as infinity or -DBL_MAX as -infinity
if ((value.lower <= float_value && float_value <= value.upper)
|| (facet->Data == "-INF" && value.lower == -DBL_MAX)
|| (facet->Data == "INF" && value.upper == DBL_MAX)
|| facet->Data == "NaN") {
bool found = false;
for (List<double>::iterator itemFloat = items_float.begin(); itemFloat; itemFloat = itemFloat->Next) {
if (float_value == itemFloat->Data) {
......@@ -1307,13 +1323,21 @@ void EnumerationType::printToFile(FILE * file, unsigned int indent_level) const
for (List<double>::iterator itemFloat = items_float.begin(); itemFloat; itemFloat = itemFloat->Next) {
if (itemFloat != items_float.begin()) fputs(", ", file);
double intpart = 0;
double fracpart = 0;
fracpart = modf(itemFloat->Data, &intpart);
if (fracpart == 0) {
fprintf(file, "%lld.0", (long long int) (itemFloat->Data));
if (itemFloat->Data == PLUS_INFINITY) {
fprintf(file, "infinity");
} else if (itemFloat->Data == MINUS_INFINITY) {
fprintf(file, "-infinity");
} else if (isnan(itemFloat->Data)) {
fprintf(file, "not_a_number");
} else {
fprintf(file, "%g", itemFloat->Data);
double intpart = 0;
double fracpart = 0;
fracpart = modf(itemFloat->Data, &intpart);
if (fracpart == 0) {
fprintf(file, "%lld.0", (long long int) (itemFloat->Data));
} else {
fprintf(file, "%g", itemFloat->Data);
}
}
}
} else if (isTimeType(base)) {
......
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