-Added ReadAsInt32 to JsonReader

-Improved performance by using an enum rather than a type check to test contract type
This commit is contained in:
JamesNK
2012-01-22 01:51:01 +00:00
parent cd424a7bc5
commit 58d51cda5c
24 changed files with 398 additions and 238 deletions
@@ -1075,6 +1075,36 @@ bye", reader.Value);
Assert.IsFalse(jsonReader.Read());
}
[Test]
public void ReadOctalNumberAsInt32()
{
StringReader s = new StringReader(@"[0372, 0xFA, 0XFA]");
JsonTextReader jsonReader = new JsonTextReader(s);
Assert.IsTrue(jsonReader.Read());
Assert.AreEqual(JsonToken.StartArray, jsonReader.TokenType);
jsonReader.ReadAsInt32();
Assert.AreEqual(JsonToken.Integer, jsonReader.TokenType);
Assert.AreEqual(typeof(int), jsonReader.ValueType);
Assert.AreEqual(250, jsonReader.Value);
jsonReader.ReadAsInt32();
Assert.AreEqual(JsonToken.Integer, jsonReader.TokenType);
Assert.AreEqual(typeof(int), jsonReader.ValueType);
Assert.AreEqual(250, jsonReader.Value);
jsonReader.ReadAsInt32();
Assert.AreEqual(JsonToken.Integer, jsonReader.TokenType);
Assert.AreEqual(typeof(int), jsonReader.ValueType);
Assert.AreEqual(250, jsonReader.Value);
Assert.IsTrue(jsonReader.Read());
Assert.AreEqual(JsonToken.EndArray, jsonReader.TokenType);
Assert.IsFalse(jsonReader.Read());
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unexpected character encountered while parsing value: }. Line 1, position 1.")]
public void ReadBadCharInArray()
@@ -36,8 +36,8 @@ namespace Newtonsoft.Json.Tests
public class PerformanceTests : TestFixtureBase
{
private const int Iterations = 100;
//private const int Iterations = 5000;
//private const int Iterations = 100;
private const int Iterations = 5000;
private static SimpleObject CreateSimpleObject()
{
@@ -101,12 +101,12 @@ namespace Newtonsoft.Json.Tests
private void SerializeTests(object value)
{
//BenchmarkSerializeMethod(SerializeMethod.DataContractSerializer, value);
////BenchmarkSerializeMethod(SerializeMethod.BinaryFormatter, value);
//BenchmarkSerializeMethod(SerializeMethod.JavaScriptSerializer, value);
//BenchmarkSerializeMethod(SerializeMethod.DataContractJsonSerializer, value);
BenchmarkSerializeMethod(SerializeMethod.DataContractSerializer, value);
BenchmarkSerializeMethod(SerializeMethod.BinaryFormatter, value);
BenchmarkSerializeMethod(SerializeMethod.JavaScriptSerializer, value);
BenchmarkSerializeMethod(SerializeMethod.DataContractJsonSerializer, value);
BenchmarkSerializeMethod(SerializeMethod.JsonNet, value);
//BenchmarkSerializeMethod(SerializeMethod.JsonNetBinary, value);
BenchmarkSerializeMethod(SerializeMethod.JsonNetBinary, value);
}
[Test]
@@ -763,6 +763,7 @@ namespace Newtonsoft.Json.Tests
}
[DataContract]
[Serializable]
public class SimpleObject
{
[DataMember]
@@ -1931,7 +1931,7 @@ keyword such as type of business.""
}
[Test]
[ExpectedException(typeof(JsonSerializationException), ExpectedMessage = @"Error converting value """" to type 'System.Int32'. Line 1, position 15.")]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = @"Could not convert string to integer: . Line 1, position 15.")]
public void DeserializeEnsureTypeEmptyStringToIntError()
{
JsonConvert.DeserializeObject<MemoryStream>("{ReadTimeout:''}");