Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiayi Yu <14067510+yujayee@users.noreply.github.com>2018-03-27 02:40:25 +0300
committerGitHub <noreply@github.com>2018-03-27 02:40:25 +0300
commit56c0ffacb4056bc8e975f3236d3a5d1383335c5c (patch)
tree097b0b6a2f41a1e8ae758c004714073c33c42bf4 /src/System.Private.Xml
parent94079a75105c3ac2a9010fcb3e030eda6790ce86 (diff)
Support PositiveInfinity and NegativeInfinity as default value in sgen (#27734)
* PositiveAndNegativeInfinityTests * addspaces * addSerializeWithDefaultValueTest * addNaNtest * Add ActiveIssue attribute
Diffstat (limited to 'src/System.Private.Xml')
-rw-r--r--src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriter.cs29
-rw-r--r--src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs91
2 files changed, 118 insertions, 2 deletions
diff --git a/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriter.cs b/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriter.cs
index 766ee3628a..dda50dfb90 100644
--- a/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriter.cs
+++ b/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriter.cs
@@ -4153,6 +4153,15 @@ namespace System.Xml.Serialization
Writer.Write(source);
Writer.Write(".Length != 0)");
}
+ else if(value is Double || value is Single)
+ {
+ Writer.Write("!");
+ Writer.Write(source);
+ Writer.Write(".Equals(");
+ Type type= Type.GetType(mapping.TypeDesc.Type.FullName);
+ WriteValue(type != null ? Convert.ChangeType(value, type) : value);
+ Writer.Write(")");
+ }
else
{
Writer.Write(source);
@@ -4220,9 +4229,17 @@ namespace System.Xml.Serialization
Writer.Write(((Int32)value).ToString(null, NumberFormatInfo.InvariantInfo));
else if (type == typeof(Double))
{
- if (double.IsNaN((Double)value))
+ if (Double.IsNaN((Double)value))
+ {
+ Writer.Write("System.Double.NaN");
+ }
+ else if(Double.IsPositiveInfinity((Double)value))
{
- Writer.Write("double.NaN");
+ Writer.Write("System.Double.PositiveInfinity");
+ }
+ else if(Double.IsNegativeInfinity((Double)value))
+ {
+ Writer.Write("System.Double.NegativeInfinity");
}
else
{
@@ -4246,6 +4263,14 @@ namespace System.Xml.Serialization
{
Writer.Write("System.Single.NaN");
}
+ else if(Single.IsPositiveInfinity((Single)value))
+ {
+ Writer.Write("System.Single.PositiveInfinity");
+ }
+ else if (Single.IsNegativeInfinity((Single)value))
+ {
+ Writer.Write("System.Single.NegativeInfinity");
+ }
else
{
Writer.Write(((Single)value).ToString("R", NumberFormatInfo.InvariantInfo));
diff --git a/src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs b/src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs
index 846202defb..81c8f7bb1e 100644
--- a/src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs
+++ b/src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs
@@ -1614,6 +1614,97 @@ string.Format(@"<?xml version=""1.0"" encoding=""utf-8""?>
}
[Fact]
+ public static void Xml_DefaultValueAttributeSetToPositiveInfinityTest()
+ {
+ var value = new DefaultValuesSetToPositiveInfinity();
+ var actual = SerializeAndDeserialize(value,
+@"<?xml version=""1.0""?>
+<DefaultValuesSetToPositiveInfinity xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
+ <DoubleField>0</DoubleField>
+ <SingleField>0</SingleField>
+ <DoubleProp>0</DoubleProp>
+ <FloatProp>0</FloatProp>
+</DefaultValuesSetToPositiveInfinity>");
+ Assert.NotNull(actual);
+ Assert.Equal(value, actual);
+ }
+
+ [Fact]
+ public static void Xml_DefaultValueAttributeSetToNegativeInfinityTest()
+ {
+ var value = new DefaultValuesSetToNegativeInfinity();
+ var actual = SerializeAndDeserialize(value,
+@"<?xml version=""1.0""?>
+<DefaultValuesSetToNegativeInfinity xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
+ <DoubleField>0</DoubleField>
+ <SingleField>0</SingleField>
+ <DoubleProp>0</DoubleProp>
+ <FloatProp>0</FloatProp>
+</DefaultValuesSetToNegativeInfinity>");
+ Assert.NotNull(actual);
+ Assert.Equal(value, actual);
+ }
+
+ [ActiveIssue(28321)]
+ [Fact]
+ public static void SerializeWithDefaultValueSetToNaNTest()
+ {
+ var value = new DefaultValuesSetToNaN();
+ value.DoubleField = Double.NaN;
+ value.SingleField = Single.NaN;
+ value.FloatProp = Single.NaN;
+ value.DoubleProp = Double.NaN;
+
+ bool result=SerializeWithDefaultValue(value,
+@"<?xml version=""1.0""?>
+<DefaultValuesSetToNaN xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" />");
+ Assert.True(result);
+ }
+
+ [Fact]
+ public static void SerializeWithDefaultValueSetToPositiveInfinityTest()
+ {
+ var value = new DefaultValuesSetToPositiveInfinity();
+ value.DoubleField = Double.PositiveInfinity;
+ value.SingleField = Single.PositiveInfinity;
+ value.FloatProp = Single.PositiveInfinity;
+ value.DoubleProp = Double.PositiveInfinity;
+
+ bool result = SerializeWithDefaultValue(value,
+@"<?xml version=""1.0""?>
+<DefaultValuesSetToPositiveInfinity xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" />");
+ Assert.True(result);
+ }
+
+ [Fact]
+ public static void SerializeWithDefaultValueSetToNegativeInfinityTest()
+ {
+ var value = new DefaultValuesSetToNegativeInfinity();
+ value.DoubleField = Double.NegativeInfinity;
+ value.SingleField = Single.NegativeInfinity;
+ value.FloatProp = Single.NegativeInfinity;
+ value.DoubleProp = Double.NegativeInfinity;
+
+ bool result = SerializeWithDefaultValue(value,
+ @"<?xml version=""1.0""?>
+<DefaultValuesSetToNegativeInfinity xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" />");
+ Assert.True(result);
+ }
+
+ private static bool SerializeWithDefaultValue<T>(T value, string baseline)
+ {
+ XmlSerializer serializer = new XmlSerializer(typeof(T));
+ using (MemoryStream ms = new MemoryStream())
+ {
+ serializer.Serialize(ms, value);
+ ms.Position = 0;
+ string output = new StreamReader(ms).ReadToEnd();
+ Utils.CompareResult result = Utils.Compare(baseline, output);
+ return result.Equal;
+ }
+ }
+
+ [Fact]
public static void Xml_TypeWithMismatchBetweenAttributeAndPropertyType()
{
var value = new TypeWithMismatchBetweenAttributeAndPropertyType();