-Fixed null reference error when using JEnumerable created with default constructor
-Tests
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
using System.Numerics;
|
||||
@@ -1007,6 +1008,8 @@ namespace Newtonsoft.Json.Tests
|
||||
settings.DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
|
||||
var json = JsonConvert.SerializeObject(dict, settings);
|
||||
|
||||
Console.WriteLine(json);
|
||||
|
||||
var newDict = new Dictionary<string, object>();
|
||||
JsonConvert.PopulateObject(json, newDict, settings);
|
||||
|
||||
@@ -1014,8 +1017,57 @@ namespace Newtonsoft.Json.Tests
|
||||
|
||||
Assert.AreEqual(date, now);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MaximumDateTimeOffsetLength()
|
||||
{
|
||||
DateTimeOffset dt = new DateTimeOffset(2000, 12, 31, 20, 59, 59, new TimeSpan(0, 11, 33, 0, 0));
|
||||
dt = dt.AddTicks(9999999);
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
JsonTextWriter writer = new JsonTextWriter(sw);
|
||||
|
||||
writer.WriteValue(dt);
|
||||
writer.Flush();
|
||||
|
||||
Console.WriteLine(sw.ToString());
|
||||
Console.WriteLine(sw.ToString().Length);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void MaximumDateTimeLength()
|
||||
{
|
||||
DateTime dt = new DateTime(2000, 12, 31, 20, 59, 59, DateTimeKind.Local);
|
||||
dt = dt.AddTicks(9999999);
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
JsonTextWriter writer = new JsonTextWriter(sw);
|
||||
|
||||
writer.WriteValue(dt);
|
||||
writer.Flush();
|
||||
|
||||
Console.WriteLine(sw.ToString());
|
||||
Console.WriteLine(sw.ToString().Length);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MaximumDateTimeMicrosoftDateFormatLength()
|
||||
{
|
||||
DateTime dt = DateTime.MaxValue;
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
JsonTextWriter writer = new JsonTextWriter(sw);
|
||||
writer.DateFormatHandling = DateFormatHandling.MicrosoftDateFormat;
|
||||
|
||||
writer.WriteValue(dt);
|
||||
writer.Flush();
|
||||
|
||||
Console.WriteLine(sw.ToString());
|
||||
Console.WriteLine(sw.ToString().Length);
|
||||
}
|
||||
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
[Test]
|
||||
public void IntegerLengthOverflows()
|
||||
@@ -1031,6 +1083,17 @@ namespace Newtonsoft.Json.Tests
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void ParseIsoDate()
|
||||
{
|
||||
StringReader sr = new StringReader(@"""2014-02-14T14:25:02-13:00""");
|
||||
|
||||
JsonReader jsonReader = new JsonTextReader(sr);
|
||||
|
||||
Assert.IsTrue(jsonReader.Read());
|
||||
Assert.AreEqual(typeof(DateTime), jsonReader.ValueType);
|
||||
}
|
||||
|
||||
//[Test]
|
||||
public void StackOverflowTest()
|
||||
{
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
#if !NETFX_CORE
|
||||
@@ -49,6 +50,44 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
[TestFixture]
|
||||
public class LinqToJsonTest : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void EmptyJEnumerableCount()
|
||||
{
|
||||
JEnumerable<JToken> tokens = new JEnumerable<JToken>();
|
||||
|
||||
Assert.AreEqual(0, tokens.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmptyJEnumerableAsEnumerable()
|
||||
{
|
||||
IEnumerable tokens = new JEnumerable<JToken>();
|
||||
|
||||
Assert.AreEqual(0, tokens.Cast<JToken>().Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmptyJEnumerableEquals()
|
||||
{
|
||||
JEnumerable<JToken> tokens1 = new JEnumerable<JToken>();
|
||||
JEnumerable<JToken> tokens2 = new JEnumerable<JToken>();
|
||||
|
||||
Assert.IsTrue(tokens1.Equals(tokens2));
|
||||
|
||||
object o1 = new JEnumerable<JToken>();
|
||||
object o2 = new JEnumerable<JToken>();
|
||||
|
||||
Assert.IsTrue(o1.Equals(o2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmptyJEnumerableGetHashCode()
|
||||
{
|
||||
JEnumerable<JToken> tokens = new JEnumerable<JToken>();
|
||||
|
||||
Assert.AreEqual(0, tokens.GetHashCode());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CommentsAndReadFrom()
|
||||
{
|
||||
|
||||
@@ -298,6 +298,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{3259AA49-8AA1-44D3-9025-A0B520596A8C}" />
|
||||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Newtonsoft.Json\Newtonsoft.Json.Net20.csproj">
|
||||
@@ -338,6 +339,11 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="large.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
@@ -339,6 +339,9 @@
|
||||
<Compile Include="Utilities\StringUtilsTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="large.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="LinqToSql\LinqToSqlClasses.dbml">
|
||||
<Generator>MSLinqToSQLGenerator</Generator>
|
||||
<LastGenOutput>LinqToSqlClasses.designer.cs</LastGenOutput>
|
||||
|
||||
@@ -461,6 +461,9 @@
|
||||
<Compile Include="Utilities\StringUtilsTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="large.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="LinqToSql\LinqToSqlClasses.dbml">
|
||||
<Generator>MSLinqToSQLGenerator</Generator>
|
||||
<LastGenOutput>LinqToSqlClasses.designer.cs</LastGenOutput>
|
||||
|
||||
@@ -379,6 +379,11 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="large.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
@@ -386,6 +386,11 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="large.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
@@ -417,6 +417,9 @@
|
||||
<Compile Include="Utilities\StringUtilsTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="large.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="LinqToSql\LinqToSqlClasses.dbml">
|
||||
<Generator>MSLinqToSQLGenerator</Generator>
|
||||
<LastGenOutput>LinqToSqlClasses.designer.cs</LastGenOutput>
|
||||
|
||||
@@ -132,6 +132,67 @@ namespace Newtonsoft.Json.Tests
|
||||
SerializeTests(test);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadLargeJson()
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
using (var fs = System.IO.File.OpenText("large.json"))
|
||||
using (JsonTextReader jsonTextReader = new JsonTextReader(fs))
|
||||
{
|
||||
while (jsonTextReader.Read())
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Friend
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
|
||||
public class RootObject
|
||||
{
|
||||
public string _id { get; set; }
|
||||
public int index { get; set; }
|
||||
public Guid guid { get; set; }
|
||||
public bool isActive { get; set; }
|
||||
public string balance { get; set; }
|
||||
public string picture { get; set; }
|
||||
public int age { get; set; }
|
||||
public string eyeColor { get; set; }
|
||||
public string name { get; set; }
|
||||
public string gender { get; set; }
|
||||
public string company { get; set; }
|
||||
public string email { get; set; }
|
||||
public string phone { get; set; }
|
||||
public string address { get; set; }
|
||||
public string about { get; set; }
|
||||
public string registered { get; set; }
|
||||
public double latitude { get; set; }
|
||||
public decimal longitude { get; set; }
|
||||
public List<string> tags { get; set; }
|
||||
public List<Friend> friends { get; set; }
|
||||
public string greeting { get; set; }
|
||||
public string favoriteFruit { get; set; }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeLargeJson()
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
using (var fs = System.IO.File.OpenText("large.json"))
|
||||
using (JsonTextReader jsonTextReader = new JsonTextReader(fs))
|
||||
{
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
serializer.Deserialize<IList<RootObject>>(jsonTextReader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeKeyValuePair()
|
||||
{
|
||||
|
||||
@@ -42,7 +42,6 @@ using System.Security;
|
||||
#elif NET40
|
||||
[assembly: AssemblyTitle("Json.NET Tests .NET 4.0")]
|
||||
#else
|
||||
|
||||
[assembly: AssemblyTitle("Json.NET Tests")]
|
||||
#endif
|
||||
|
||||
@@ -75,4 +74,4 @@ using System.Security;
|
||||
// by using the '*' as shown below:
|
||||
|
||||
[assembly: AssemblyVersion("6.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("6.0.5.17712")]
|
||||
[assembly: AssemblyFileVersion("6.0.5.17725")]
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user