Commit c6fb7822 authored by BenceJanosSzabo's avatar BenceJanosSzabo
Browse files

XER: TITAN encodes +-INFINITY and not_a_number now encoded correctly (Bug 505684)



Change-Id: I846db1086a1c495219bfa5daff21d677cded868e
Signed-off-by: default avatarBenceJanosSzabo <bence.janos.szabo@ericsson.com>
parent 5e95fef9
......@@ -843,6 +843,10 @@ int FLOAT::RAW_decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& buff,
return decode_length + prepaddlength;
}
const char* XER_POS_INF_STR = "INF";
const char* XER_NEG_INF_STR = "-INF";
const char* XER_NAN_STR = "NaN";
int FLOAT::XER_encode(const XERdescriptor_t& p_td,
TTCN_Buffer& p_buf, unsigned int flavor, int indent, embed_values_enc_struct_t*) const
{
......@@ -859,11 +863,29 @@ int FLOAT::XER_encode(const XERdescriptor_t& p_td,
if (exer && (p_td.xer_bits & XER_DECIMAL)) {
char buf[312];
int n = snprintf(buf, sizeof(buf), "%f", (double)float_value);
int n = 0;
if (isnan((double)float_value)) {
n = snprintf(buf, sizeof(buf), "%s", XER_NAN_STR);
} else if ((double)float_value == (double)INFINITY) {
n = snprintf(buf, sizeof(buf), "%s", XER_POS_INF_STR);
} else if ((double)float_value == -(double)INFINITY) {
n = snprintf(buf, sizeof(buf), "%s", XER_NEG_INF_STR);
} else {
n = snprintf(buf, sizeof(buf), "%f", (double)float_value);
}
p_buf.put_s((size_t)n, (const unsigned char*)buf);
}
else {
CHARSTRING value = float2str(float_value);
CHARSTRING value;
if (isnan((double)float_value)) {
value = XER_NAN_STR;
} else if ((double)float_value == (double)INFINITY) {
value = XER_POS_INF_STR;
} else if ((double)float_value == -(double)INFINITY) {
value = XER_NEG_INF_STR;
} else {
value = float2str(float_value);
}
p_buf.put_string(value);
}
......@@ -942,12 +964,25 @@ int FLOAT::XER_decode(const XERdescriptor_t& p_td, XmlReaderWrap& reader,
verify_name(reader, p_td, exer);
tagless:
const char * value = (const char *)reader.Value();
if (value && is_float(value)) {
bound_flag = true;
sscanf(value, "%lf", &float_value);
if (value) {
if (is_float(value)) {
bound_flag = true;
sscanf(value, "%lf", &float_value);
} else if (strcmp(XER_NAN_STR, value) == 0 ) {
bound_flag = true;
#ifdef NAN
float_value = NAN;
#else
float_value = INFINITY + (-INFINITY);
#endif
} else if (strcmp(XER_POS_INF_STR, value) == 0) {
bound_flag = true;
float_value = (double)INFINITY;
} else if (strcmp(XER_NEG_INF_STR, value) == 0) {
bound_flag = true;
float_value = -(double)INFINITY;
}
}
// Let the caller do reader.AdvanceAttribute();
}
else {
......@@ -966,9 +1001,24 @@ tagless:
}
else if (XML_READER_TYPE_TEXT == type && depth != -1) {
const char * value = (const char*)reader.Value();
if (value && is_float(value)) {
bound_flag = true;
sscanf(value, "%lf", &float_value);
if (value) {
if (is_float(value)) {
bound_flag = true;
sscanf(value, "%lf", &float_value);
} else if (strcmp("NaN", value) == 0 ) {
bound_flag = true;
#ifdef NAN
float_value = NAN;
#else
float_value = INFINITY + (-INFINITY);
#endif
} else if (strcmp("INF", value) == 0) {
bound_flag = true;
float_value = (double)INFINITY;
} else if (strcmp("-INF", value) == 0) {
bound_flag = true;
float_value = -(double)INFINITY;
}
}
}
else if (XML_READER_TYPE_END_ELEMENT == type) {
......
......@@ -223,8 +223,8 @@ testcase tc_encode_decode() runs on CT {
testcase tc_decode() runs on CT {
const charstring result :=
"<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/'"&
"xmlns:ns2='http://schemas.ericsson.com/cai3g1.2/'"&
"<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/' "&
"xmlns:ns2='http://schemas.ericsson.com/cai3g1.2/' "&
"xmlns:mc='http://schemas.ericsson.com/mtas/mmtel/cai3g'>"&
"<S:Body>"&
"<ns2:GetResponse>"&
......@@ -253,10 +253,11 @@ testcase tc_decode() runs on CT {
"</ns2:GetResponse>"&
"</S:Body>"&
"</S:Envelope>";
log(result);
const charstring result_omit_attr :=
"<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/'"&
"xmlns:ns2='http://schemas.ericsson.com/cai3g1.2/'"&
"<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/' "&
"xmlns:ns2='http://schemas.ericsson.com/cai3g1.2/' "&
"xmlns:mc='http://schemas.ericsson.com/mtas/mmtel/cai3g'>"&
"<S:Body>"&
"<ns2:GetResponse>"&
......@@ -287,8 +288,8 @@ const charstring result_omit_attr :=
"</S:Envelope>";
const charstring result_omit_attr2 :=
"<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/'"&
"xmlns:ns2='http://schemas.ericsson.com/cai3g1.2/'"&
"<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/' "&
"xmlns:ns2='http://schemas.ericsson.com/cai3g1.2/' "&
"xmlns:mc='http://schemas.ericsson.com/mtas/mmtel/cai3g'>"&
"<S:Body>"&
"<ns2:GetResponse>"&
......@@ -318,8 +319,8 @@ const charstring result_omit_attr2 :=
"</S:Envelope>";
const charstring result_single :=
"<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/'"&
"xmlns:ns2='http://schemas.ericsson.com/cai3g1.2/'"&
"<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/' "&
"xmlns:ns2='http://schemas.ericsson.com/cai3g1.2/' "&
"xmlns:mc='http://schemas.ericsson.com/mtas/mmtel/cai3g'>"&
"<S:Body>"&
"<ns2:GetResponse>"&
......@@ -344,8 +345,8 @@ const charstring result_single :=
"</S:Envelope>";
const charstring result_single_omit_attr :=
"<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/'"&
"xmlns:ns2='http://schemas.ericsson.com/cai3g1.2/'"&
"<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/' "&
"xmlns:ns2='http://schemas.ericsson.com/cai3g1.2/' "&
"xmlns:mc='http://schemas.ericsson.com/mtas/mmtel/cai3g'>"&
"<S:Body>"&
"<ns2:GetResponse>"&
......
......@@ -8,6 +8,7 @@
* Contributors:
* Balasko, Jeno
* Raduly, Csaba
* Szabo, Bence Janos
*
******************************************************************************/
module Txerfloat {
......@@ -28,6 +29,8 @@ DECLARE_XER_ENCODERS(rfloat, rfloat);
DECLARE_EXER_ENCODERS(rfloat,rfloat)
DECLARE_XER_ENCODERS(ufloat, ufloat);
DECLARE_EXER_ENCODERS(ufloat,ufloat)
DECLARE_XER_ENCODERS(attrfloat, attrfloat);
DECLARE_EXER_ENCODERS(attrfloat, attrfloat)
type record rfloat {
float f optional
......@@ -37,6 +40,13 @@ type union ufloat {
float f
}
type record attrfloat {
float f optional
}
with {
variant (f) "attribute"
}
testcase encode_float() runs on TFLOAT
{
var float plain := 3.141592;
......@@ -62,6 +72,24 @@ testcase encode_float() runs on TFLOAT
CHECK_METHOD(cxer_enc_float, plain, expected);
CHECK_METHOD(bxer_enc_float, plain, expected & lf);
CHECK_METHOD(exer_enc_float, plain, expected & lf);
plain := infinity;
expected := "<REAL>INF</REAL>";
CHECK_METHOD(cxer_enc_float, plain, expected);
CHECK_METHOD(bxer_enc_float, plain, expected & lf);
CHECK_METHOD(exer_enc_float, plain, expected & lf);
plain := -infinity;
expected := "<REAL>-INF</REAL>";
CHECK_METHOD(cxer_enc_float, plain, expected);
CHECK_METHOD(bxer_enc_float, plain, expected & lf);
CHECK_METHOD(exer_enc_float, plain, expected & lf);
plain := not_a_number;
expected := "<REAL>NaN</REAL>";
CHECK_METHOD(cxer_enc_float, plain, expected);
CHECK_METHOD(bxer_enc_float, plain, expected & lf);
CHECK_METHOD(exer_enc_float, plain, expected & lf);
}
testcase decode_float() runs on TFLOAT
......@@ -72,10 +100,25 @@ testcase decode_float() runs on TFLOAT
CHECK_DECODE(bxer_dec_float, pie, float, expected);
// causes rounding errors : -2.718281828459045
const charstring ee := "<REAL>-2.7182818284590</REAL>";
var charstring ee := "<REAL>-2.7182818284590</REAL>";
expected := -2.7182818284590;
CHECK_DECODE(cxer_dec_float, ee, float, expected);
CHECK_DECODE(bxer_dec_float, ee, float, expected);
ee := "<REAL>INF</REAL>";
expected := infinity;
CHECK_DECODE(cxer_dec_float, ee, float, expected);
CHECK_DECODE(bxer_dec_float, ee, float, expected);
ee := "<REAL>-INF</REAL>";
expected := -infinity;
CHECK_DECODE(cxer_dec_float, ee, float, expected);
CHECK_DECODE(bxer_dec_float, ee, float, expected);
ee := "<REAL>NaN</REAL>";
expected := not_a_number;
CHECK_DECODE(cxer_dec_float, ee, float, expected);
CHECK_DECODE(bxer_dec_float, ee, float, expected);
}
testcase encode_float_omit() runs on TFLOAT
......@@ -136,6 +179,37 @@ testcase decode_float_choice() runs on TFLOAT
CHECK_DECODE(bxer_dec_ufloat, electron, ufloat, expected);
}
testcase encode_float_attribute() runs on TFLOAT
{
var attrfloat plain := { f := infinity };
var universal charstring expected := "<attrfloat f='INF'/>\n";
CHECK_METHOD(exer_enc_attrfloat, plain, expected & lf);
plain := { f := -infinity }
expected := "<attrfloat f='-INF'/>\n";
CHECK_METHOD(exer_enc_attrfloat, plain, expected & lf);
plain := { f := not_a_number }
expected := "<attrfloat f='NaN'/>\n";
CHECK_METHOD(exer_enc_attrfloat, plain, expected & lf);
}
testcase decode_float_attribute() runs on TFLOAT
{
var attrfloat expected := { f := infinity };
var universal charstring plain := "<attrfloat f='INF'/>\n";
CHECK_DECODE(exer_dec_attrfloat, plain, attrfloat, expected);
expected := { f := -infinity }
plain := "<attrfloat f='-INF'/>\n";
CHECK_DECODE(exer_dec_attrfloat, plain, attrfloat, expected);
expected := { f := not_a_number }
plain := "<attrfloat f='NaN'/>\n";
CHECK_DECODE(exer_dec_attrfloat, plain, attrfloat, expected);
}
control {
execute(encode_float());
......@@ -144,6 +218,8 @@ control {
execute(decode_float_omit())
execute(encode_float_choice());
execute(decode_float_choice());
execute(encode_float_attribute());
execute(decode_float_attribute());
}
}
......
......@@ -165,9 +165,9 @@
<File path="../xsd/list_complextype.xsd" />
<File path="../xsd/enumeration_restriction3.xsd" />
<File path="../xsd/MyXMLSchema.xsd" />
<File path="../xsd/www_example_org_pref1.xsd" />
<File path="../xsd/www_example_org_pref2.xsd" />
<File path="../xsd/www_example_org_pref3.xsd" />
<File path="../xsd/www_example_org_pref1.xsd" />
<File path="../xsd/www_example_org_pref2.xsd" />
<File path="../xsd/www_example_org_pref3.xsd" />
</File_Group>
<File_Group name="XmlTest_xsds" >
<File path="../XmlTest_xsds/XmlTest_boolean.xsd" />
......@@ -403,9 +403,9 @@
<File path="../XmlTest_expectedTtcns/www_example_org_list_complextype_e.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_enumeration_restriction3_e.ttcn" />
<File path="../XmlTest_expectedTtcns/http_www_example_org_2001_XMLSchema_e.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_pref1_e.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_pref2_e.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_pref3_e.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_pref1_e.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_pref2_e.ttcn" />
<File path="../XmlTest_expectedTtcns/www_example_org_pref3_e.ttcn" />
</File_Group>
<File_Group name="XmlTest_src" >
<File path="xmlTest_Shell.ttcn" />
......
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