Imported Upstream version 4.2.0.179

Former-commit-id: 4610231f55806d2a05ed69e5ff3faa7336cc1479
This commit is contained in:
Xamarin Public Jenkins
2015-08-26 07:17:56 -04:00
committed by Jo Shields
parent aa7da660d6
commit c042cd0c52
7507 changed files with 90259 additions and 657307 deletions

View File

@ -1083,7 +1083,7 @@ namespace MonoTests.System.Runtime.Serialization.Json
[Test]
[ExpectedException (typeof (SerializationException))]
[Category ("NotDotNet")] // 0.0 is an invalid Colors value.
[Ignore ("NotDotNet")] // 0.0 is an invalid Colors value.
public void DeserializeEnumInvalid3 ()
{
//"0.0" instead of "0"
@ -1104,7 +1104,7 @@ namespace MonoTests.System.Runtime.Serialization.Json
[Test]
[ExpectedException (typeof (SerializationException))]
[Category ("NotDotNet")] // 4 is an invalid Colors value.
[Ignore ("NotDotNet")] // 4 is an invalid Colors value.
[Category ("NotWorking")]
public void DeserializeEnumWithDCInvalid ()
{
@ -1360,8 +1360,8 @@ namespace MonoTests.System.Runtime.Serialization.Json
var ms = new MemoryStream ();
DataContractJsonSerializer serializer = new DataContractJsonSerializer (typeof (Query));
Query query = new Query () {
StartDate = new DateTime (2010, 3, 4, 5, 6, 7),
EndDate = new DateTime (2010, 4, 5, 6, 7, 8)
StartDate = DateTime.SpecifyKind (new DateTime (2010, 3, 4, 5, 6, 7), DateTimeKind.Utc),
EndDate = DateTime.SpecifyKind (new DateTime (2010, 4, 5, 6, 7, 8), DateTimeKind.Utc)
};
serializer.WriteObject (ms, query);
Assert.AreEqual ("{\"StartDate\":\"\\/Date(1267679167000)\\/\",\"EndDate\":\"\\/Date(1270447628000)\\/\"}", Encoding.UTF8.GetString (ms.ToArray ()), "#1");
@ -1386,14 +1386,14 @@ namespace MonoTests.System.Runtime.Serialization.Json
[Test]
public void BugXamarin163 ()
{
string json = @"{""should_have_value"":""\/Date(1277355600000-0500)\/""}";
string json = @"{""should_have_value"":""\/Date(1277355600000)\/""}";
byte[] bytes = global::System.Text.Encoding.UTF8.GetBytes(json);
Stream inputStream = new MemoryStream(bytes);
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(DateTest));
DateTest t = serializer.ReadObject(inputStream) as DateTest;
Assert.AreEqual (634129344000000000, t.ShouldHaveValue.Value.Ticks, "#1");
Assert.AreEqual (634129524000000000, t.ShouldHaveValue.Value.Ticks, "#1");
}
[Test]
@ -1550,7 +1550,7 @@ namespace MonoTests.System.Runtime.Serialization.Json
public void TestHashtableSerialization ()
{
var collection = new HashtableContainer ();
var expectedOutput = "{\"Items\":[{\"Key\":\"key2\",\"Value\":\"apple\"},{\"Key\":\"key1\",\"Value\":\"banana\"}]}";
var expectedOutput = "{\"Items\":[{\"Key\":\"key1\",\"Value\":\"banana\"},{\"Key\":\"key2\",\"Value\":\"apple\"}]}";
var serializer = new DataContractJsonSerializer (collection.GetType ());
var stream = new MemoryStream ();
@ -1871,8 +1871,55 @@ namespace MonoTests.System.Runtime.Serialization.Json
string serializedObj = @"{""PolymorphicProperty"":{""__type"":""UnknownDerivedType:#MonoTests.System.Runtime.Serialization.Json"",""BaseTypeProperty"":""Base"",""DerivedProperty"":""Derived 1""},""Name"":""Parent2""}";
ParentType deserializedObj = Deserialize<ParentType> (serializedObj);
}
[Test]
public void SubclassTest ()
{
var knownTypes = new List<Type> { typeof(IntList) };
var serializer = new DataContractJsonSerializer(typeof(ListOfNumbers), knownTypes);
string json = "{\"Numbers\": [85]}";
using (var stream = new MemoryStream(UTF8Encoding.Default.GetBytes(json)))
{
var nums = (ListOfNumbers)serializer.ReadObject(stream);
Assert.AreEqual (1, nums.Numbers.Count);
}
}
[DataContract]
public class ListOfNumbers
{
[DataMember]
public IntList Numbers;
}
public class IntList : List<int>{}
#endregion
[Test]
public void DefaultValueDeserialization ()
{
// value type
var person = new Person { name = "John" };
using (var ms = new MemoryStream()) {
var serializer = new DataContractJsonSerializer (typeof (Person), new DataContractJsonSerializerSettings {
SerializeReadOnlyTypes = true,
UseSimpleDictionaryFormat = true
});
serializer.WriteObject (ms, person);
}
// reference type
var person2 = new PersonWithContact {
name = "Jane",
contact = new Contact { url = "localhost", email = "jane@localhost" } };
using (var ms = new MemoryStream ()) {
var serializer = new DataContractJsonSerializer (typeof (PersonWithContact), new DataContractJsonSerializerSettings {
SerializeReadOnlyTypes = true,
UseSimpleDictionaryFormat = true
});
serializer.WriteObject (ms, person2);
}
}
}
public class CharTest
@ -2069,6 +2116,7 @@ namespace MonoTests.System.Runtime.Serialization.Json
void Init ()
{
C = true;
ServerTimeUTC = DateTime.SpecifyKind (DateTime.MinValue, DateTimeKind.Utc);
}
[OnDeserializing]
@ -2663,4 +2711,33 @@ public class Bug13485Type
}
}
#endregion
#endregion
#region DefaultValueDeserialization
[DataContract]
public class Person
{
[DataMember(EmitDefaultValue = false)]
public string name { get; set; }
}
[DataContract]
public class PersonWithContact
{
[DataMember(EmitDefaultValue = false)]
public string name { get; set; }
[DataMember(EmitDefaultValue = false)]
public Contact contact { get; set; }
}
[DataContract]
public class Contact
{
[DataMember(EmitDefaultValue = false)]
public string url { get; set; }
[DataMember(EmitDefaultValue = false)]
public string email{ get; set; }
}
#endregion

View File

@ -509,7 +509,7 @@ namespace MonoTests.System.Runtime.Serialization.Json
// Read() valid and invalid contents
[Test]
[ExpectedException (typeof (XmlException))]
[Ignore ("It should throw XmlException for parser error, but .NET fails to report that")]
public void ReadTwoTopLevelContents ()
{
ReadToEnd (CreateReader ("{}{}"));
@ -537,7 +537,7 @@ namespace MonoTests.System.Runtime.Serialization.Json
}
[Test]
[ExpectedException (typeof (XmlException))]
[Ignore ("It should throw XmlException for parser error, but .NET fails to report that")]
public void ReadExtraCloseCurly2 ()
{
ReadToEnd (CreateReader ("{}}"));
@ -566,7 +566,7 @@ namespace MonoTests.System.Runtime.Serialization.Json
[Test]
[ExpectedException (typeof (XmlException))]
[Category ("NotDotNet")] // hmm, why does it pass?
[Ignore ("NotDotNet")] // hmm, why does it pass?
public void ReadExtraCloseBrace2 ()
{
ReadToEnd (CreateReader ("[]]"));
@ -655,7 +655,7 @@ namespace MonoTests.System.Runtime.Serialization.Json
[Test]
[ExpectedException (typeof (XmlException))]
[Category ("NotDotNet")] // likely .NET bug
[Ignore ("NotDotNet")] // likely .NET bug
public void ReadInvalidNumber3 ()
{
ReadToEnd (CreateReader ("01"));
@ -670,7 +670,7 @@ namespace MonoTests.System.Runtime.Serialization.Json
[Test]
[ExpectedException (typeof (XmlException))]
[Category ("NotDotNet")] // likely .NET bug
[Ignore ("NotDotNet")] // likely .NET bug
public void ReadInvalidNumber5 ()
{
ReadToEnd (CreateReader ("10."));
@ -685,7 +685,7 @@ namespace MonoTests.System.Runtime.Serialization.Json
[Test]
[ExpectedException (typeof (XmlException))]
[Category ("NotDotNet")] // likely .NET bug
[Ignore ("NotDotNet")] // likely .NET bug
public void ReadInvalidNumber8 ()
{
ReadToEnd (CreateReader ("-e5"));
@ -693,7 +693,7 @@ namespace MonoTests.System.Runtime.Serialization.Json
[Test]
[ExpectedException (typeof (XmlException))]
[Category ("NotDotNet")] // likely .NET bug
[Ignore ("NotDotNet")] // likely .NET bug
public void ReadInvalidNumber9 ()
{
ReadToEnd (CreateReader ("-e5.5"));
@ -714,7 +714,7 @@ namespace MonoTests.System.Runtime.Serialization.Json
[Test]
[ExpectedException (typeof (XmlException))]
[Category ("NotDotNet")] // likely .NET bug
[Ignore ("NotDotNet")] // likely .NET bug
public void ReadInvalidObjectContent2 ()
{
ReadToEnd (CreateReader ("{\"A\": 123 456}"));
@ -729,7 +729,7 @@ namespace MonoTests.System.Runtime.Serialization.Json
[Test]
[ExpectedException (typeof (XmlException))]
[Category ("NotDotNet")] // likely .NET bug
[Ignore ("NotDotNet")] // likely .NET bug
public void ReadInvalidObjectContent4 ()
{
ReadToEnd (CreateReader ("{\"A\":123, \"B\":456,}"));
@ -744,7 +744,7 @@ namespace MonoTests.System.Runtime.Serialization.Json
[Test]
[ExpectedException (typeof (XmlException))]
[Category ("NotDotNet")] // likely .NET bug
[Ignore ("NotDotNet")] // likely .NET bug
public void ReadInvalidArrayContent2 ()
{
ReadToEnd (CreateReader ("[123 456]"));
@ -759,7 +759,7 @@ namespace MonoTests.System.Runtime.Serialization.Json
[Test]
[ExpectedException (typeof (XmlException))]
[Category ("NotDotNet")] // likely .NET bug
[Ignore ("NotDotNet")] // likely .NET bug
public void ReadInvalidArrayContent4 ()
{
ReadToEnd (CreateReader ("[123,456,]"));
@ -876,7 +876,7 @@ namespace MonoTests.System.Runtime.Serialization.Json
DataContractJsonSerializer jsonSerializer = new
DataContractJsonSerializer(typeof(IEnumerable<string>));
var result = jsonSerializer.ReadObject(stream);
Assert.AreEqual (typeof (List<string>), result.GetType ());
Assert.AreEqual (typeof (string []), result.GetType ());
}
}
}

View File

@ -28,6 +28,7 @@
using System;
using System.IO;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Xml;
using NUnit.Framework;
@ -51,6 +52,39 @@ namespace MonoTests.System.Runtime.Serialization.Json
w = JsonReaderWriterFactory.CreateJsonWriter (ms);
}
/*
[Test]
public void Dummy_BitFlagsGenerator ()
{
var b = new BitFlagsGenerator (2);
Assert.IsFalse (b.Load (0), "#a1");
b.Store (0, false);
Assert.IsFalse (b.Load (0), "#a2");
b.Store (0, true);
Assert.IsTrue (b.Load (0), "#a3");
Assert.IsFalse (b.Load (1), "#a4");
b.Store (0, false);
Assert.IsFalse (b.Load (0), "#a5");
Assert.IsFalse (b.Load (1), "#a6");
Assert.IsFalse (b.Load (1), "#b1");
b.Store (1, false);
Assert.IsFalse (b.Load (1), "#b2");
b.Store (1, true);
Assert.IsTrue (b.Load (1), "#b3");
b.Store (1, false);
Assert.IsFalse (b.Load (1), "#b4");
var bytes = new byte [2];
Assert.IsFalse (BitFlagsGenerator.IsBitSet (bytes, 0), "#c1");
BitFlagsGenerator.SetBit (bytes, 0);
Assert.IsTrue (BitFlagsGenerator.IsBitSet (bytes, 0), "#c2");
Assert.IsFalse (BitFlagsGenerator.IsBitSet (bytes, 1), "#c3");
BitFlagsGenerator.SetBit (bytes, 0);
Assert.IsTrue (BitFlagsGenerator.IsBitSet (bytes, 0), "#c4");
}
*/
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConstructorNullStream ()