Imported Upstream version 6.0.0.172

Former-commit-id: f3cc9b82f3e5bd8f0fd3ebc098f789556b44e9cd
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-04-12 14:10:50 +00:00
parent 8016999e4d
commit 64ac736ec5
32155 changed files with 3981439 additions and 75368 deletions

View File

@ -28,6 +28,7 @@
using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Collections;
@ -81,16 +82,16 @@ namespace MonoTests.System
public static void SetLocal (TimeZoneInfo val)
{
if (localField == null) {
if (Type.GetType ("Mono.Runtime") != null) {
#if MOBILE
localField = typeof (TimeZoneInfo).GetField ("local",
BindingFlags.Static | BindingFlags.GetField | BindingFlags.NonPublic);
} else {
#else
cachedDataField = typeof (TimeZoneInfo).GetField ("s_cachedData",
BindingFlags.Static | BindingFlags.GetField | BindingFlags.NonPublic);
localField = cachedDataField.FieldType.GetField ("m_localTimeZone",
localField = cachedDataField.FieldType.GetField ("_localTimeZone",
BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic);
}
#endif
}
if (cachedDataField != null)
@ -272,6 +273,7 @@ namespace MonoTests.System
}
[TestFixture]
[Category ("NotWasm")]
public class IsDaylightSavingTimeTests
{
TimeZoneInfo london;
@ -302,6 +304,7 @@ namespace MonoTests.System
}
[Test]
[Category ("MobileNotWorking")]
public void DSTTransitions ()
{
DateTime beforeDST = new DateTime (2007, 03, 25, 0, 59, 59, DateTimeKind.Unspecified);
@ -310,7 +313,7 @@ namespace MonoTests.System
DateTime afterDST = new DateTime (2007, 10, 28, 2, 0, 0, DateTimeKind.Unspecified);
Assert.IsFalse (london.IsDaylightSavingTime (beforeDST), "Just before DST");
Assert.IsTrue (london.IsDaylightSavingTime (startDST), "the first seconds of DST");
Assert.IsTrue (london.IsDaylightSavingTime (endDST), "The last seconds of DST");
Assert.IsFalse (london.IsDaylightSavingTime (endDST), "The last seconds of DST");
Assert.IsFalse (london.IsDaylightSavingTime (afterDST), "Just after DST");
}
@ -389,7 +392,7 @@ namespace MonoTests.System
{
// In .NET/.Net Core GetUtcOffset() returns the BaseUtcOffset for times within the hour
// lost when DST starts and IsDaylightSavingTime() returns false for datetime and true for datetimeoffset
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Athens"));
var date = new DateTime (2014, 3, 30 , 2, 0, 0);
@ -418,48 +421,6 @@ namespace MonoTests.System
Assert.IsTrue (tzi.IsDaylightSavingTime (new DateTimeOffset (date, tzi.GetUtcOffset (date))));
}
[Test]
public void TestAthensDST_InDSTDelta_NoTransitions ()
{
if (Environment.OSVersion.Platform != PlatformID.Unix)
Assert.Ignore ("TimeZoneInfo on Mono on Windows and .NET has no transitions");
// Repeat the previous test but this time force using AdjustmentRules by nulling out TimeZoneInfo.transitions
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById ("Europe/Athens");
var transitionsField = typeof (TimeZoneInfo).GetField ("transitions", BindingFlags.Instance | BindingFlags.NonPublic);
var transitions = transitionsField.GetValue (tzi);
Assert.IsNotNull (transitions, "Expected Athens TimeZoneInfo.transitions to be non-null");
transitionsField.SetValue (tzi, null);
try {
var date = new DateTime (2014, 3, 30 , 3, 0, 0);
Assert.IsFalse (tzi.IsDaylightSavingTime (date));
Assert.AreEqual (new TimeSpan (2, 0, 0), tzi.GetUtcOffset (date));
Assert.IsTrue (tzi.IsDaylightSavingTime (new DateTimeOffset (date, tzi.GetUtcOffset (date))));
date = new DateTime (2014, 3, 30 , 3, 1, 0);
Assert.IsFalse (tzi.IsDaylightSavingTime (date));
Assert.AreEqual (new TimeSpan (2, 0, 0), tzi.GetUtcOffset (date));
Assert.IsTrue (tzi.IsDaylightSavingTime (new DateTimeOffset (date, tzi.GetUtcOffset (date))));
date = new DateTime (2014, 3, 30 , 3, 59, 0);
Assert.IsFalse (tzi.IsDaylightSavingTime (date));
Assert.AreEqual (new TimeSpan (2, 0, 0), tzi.GetUtcOffset (date));
Assert.IsTrue (tzi.IsDaylightSavingTime (new DateTimeOffset (date, tzi.GetUtcOffset (date))));
date = new DateTime (2014, 3, 30 , 4, 0, 0);
Assert.IsTrue (tzi.IsDaylightSavingTime (date));
Assert.AreEqual (new TimeSpan (3, 0, 0), tzi.GetUtcOffset (date));
Assert.IsTrue (tzi.IsDaylightSavingTime (new DateTimeOffset (date, tzi.GetUtcOffset (date))));
} finally {
transitionsField.SetValue (tzi, transitions);
}
}
[Test] //Covers #41349
public void TestIsDST_DateTimeOffset ()
{
@ -500,8 +461,9 @@ namespace MonoTests.System
Assert.AreEqual (new TimeSpan (-5, 0, 0), tzi.GetUtcOffset (date));
}
}
[TestFixture]
[Category ("NotWasm")]
public class ConvertTimeTests_LocalUtc : ConvertTimeTests
{
static TimeZoneInfo oldLocal;
@ -512,7 +474,7 @@ namespace MonoTests.System
base.CreateTimeZones ();
oldLocal = TimeZoneInfo.Local;
TimeZoneInfoTest.SetLocal (TimeZoneInfo.Utc);
TimeZoneInfoTest.SetLocal (TimeZoneInfo.GetSystemTimeZones().First(t => t.BaseUtcOffset == TimeSpan.Zero));
}
[TearDown]
@ -523,6 +485,7 @@ namespace MonoTests.System
}
[TestFixture]
[Category ("NotWasm")]
public class ConvertTimeTests
{
TimeZoneInfo london;
@ -683,6 +646,7 @@ namespace MonoTests.System
}
[Test]
[Category ("MobileNotWorking")]
public void ConvertTime_DateTime_TimeZoneInfo_DateTimeKindMatch ()
{
var sdt = new DateTime (2014, 1, 9, 23, 0, 0, DateTimeKind.Utc);
@ -697,7 +661,7 @@ namespace MonoTests.System
sdt = new DateTime (2014, 1, 9, 23, 0, 0);
ddt = TimeZoneInfo.ConvertTime (sdt, TimeZoneInfo.Local);
var expectedKind = (TimeZoneInfo.Local == TimeZoneInfo.Utc)? DateTimeKind.Utc : sdt.Kind;
var expectedKind = (TimeZoneInfo.Local == TimeZoneInfo.Utc)? DateTimeKind.Utc : DateTimeKind.Local;
Assert.AreEqual (expectedKind, ddt.Kind, "#3.1");
Assert.AreEqual (DateTimeKind.Unspecified, sdt.Kind, "#3.2");
}
@ -782,6 +746,7 @@ namespace MonoTests.System
}
[TestFixture]
[Category ("NotWasm")]
public class IsInvalidTimeTests
{
TimeZoneInfo london;
@ -816,6 +781,7 @@ namespace MonoTests.System
}
[TestFixture]
[Category ("NotWasm")]
public class IsAmbiguousTimeTests
{
TimeZoneInfo london;
@ -830,21 +796,23 @@ namespace MonoTests.System
}
[Test]
[Category ("MobileNotWorking")]
public void AmbiguousDates ()
{
Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 0)));
Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 0)));
Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 1)));
Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 2, 0, 0)));
Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 2, 0, 0)));
Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 2, 0, 1)));
}
[Test]
[Category ("MobileNotWorking")]
public void AmbiguousUTCDates ()
{
Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 0, 0, DateTimeKind.Utc)));
Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 0, 0, DateTimeKind.Utc)));
Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 0, 1, DateTimeKind.Utc)));
Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 0, 59, 59, DateTimeKind.Utc)));
Assert.IsFalse (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 0, DateTimeKind.Utc)));
Assert.IsTrue (london.IsAmbiguousTime (new DateTime (2007, 10, 28, 1, 0, 0, DateTimeKind.Utc)));
}
#if SLOW_TESTS
@ -859,6 +827,7 @@ namespace MonoTests.System
}
[TestFixture]
[Category ("NotWasm")]
public class GetSystemTimeZonesTests
{
[Test]
@ -911,6 +880,7 @@ namespace MonoTests.System
}
[TestFixture]
[Category ("NotWasm")]
public class FindSystemTimeZoneByIdTests
{
[Test]
@ -949,10 +919,12 @@ namespace MonoTests.System
}
[Test]
public void NoDSTInKinshasa ()
[Category ("MobileNotWorking")]
[Category ("NotOnWindows")]
public void DSTInKinshasa ()
{
TimeZoneInfo kin = TimeZoneInfo.FindSystemTimeZoneById (MapTimeZoneId ("Africa/Kinshasa"));
Assert.IsFalse (kin.SupportsDaylightSavingTime);
Assert.IsTrue (kin.SupportsDaylightSavingTime);
}
[Test]
@ -1046,6 +1018,7 @@ namespace MonoTests.System
}
[TestFixture]
[Category ("NotWasm")]
public class GetAmbiguousTimeOffsetsTests
{
[Test]
@ -1214,6 +1187,7 @@ namespace MonoTests.System
}
[Test]
[Category ("MobileNotWorking")]
public void GetUtcOffset_FromUnspecified ()
{
var d = dst1Start.Add (dstOffset);
@ -1223,7 +1197,6 @@ namespace MonoTests.System
d = dst1End.Add (-dstOffset);
Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d));
Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,1,0, 1))));
d = dst2Start.Add (dstOffset);
@ -1233,11 +1206,11 @@ namespace MonoTests.System
d = dst2End.Add (-dstOffset);
Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0,-1))));
Assert.AreEqual(dstUtcOffset, cairo.GetUtcOffset (d));
Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,1,0, 1))));
}
[Test]
[Category ("MobileNotWorking")]
public void GetUtcOffset_FromDateTimeOffset ()
{
DateTimeOffset offset;
@ -1264,6 +1237,7 @@ namespace MonoTests.System
}
[Test]
[Category ("MobileNotWorking")]
public void DTS_WithMinimalDate ()
{
TimeZoneInfo.TransitionTime startTransition, endTransition;
@ -1276,44 +1250,65 @@ namespace MonoTests.System
TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue, DateTime.MaxValue.Date, TimeSpan.FromHours (-1), startTransition, endTransition) });
var offset = ctz.GetUtcOffset (DateTime.MinValue);
Assert.AreEqual (TimeSpan.FromHours (-5), offset); // TODO: Wrong it should be -6
Assert.AreEqual (TimeSpan.FromHours (-6), offset);
}
}
[TestFixture]
[Category ("NotWasm")]
public class GetDaylightChanges
{
MethodInfo getChanges;
[SetUp]
public void Setup ()
private static void GetDaylightTime (TimeZoneInfo tz, int year, out DateTime start, out DateTime end, out TimeSpan delta)
{
var flags = BindingFlags.Instance | BindingFlags.NonPublic;
getChanges = typeof (TimeZoneInfo).GetMethod ("GetDaylightChanges", flags);
#if !MOBILE
var rule = tz.GetAdjustmentRules ().FirstOrDefault (r => r.DateStart.Year <= year && r.DateEnd.Year >= year);
if (rule == null) {
start = DateTime.MinValue;
end = DateTime.MinValue;
delta = TimeSpan.Zero;
return;
}
var method = typeof (TimeZoneInfo).GetMethod ("GetDaylightTime", BindingFlags.Instance | BindingFlags.NonPublic);
var daylightTime = method.Invoke(tz, new object[] { year, rule, null });
var dts = daylightTime.GetType(); // internal readonly struct DaylightTimeStruct
start = (DateTime) dts.GetField ("Start").GetValue (daylightTime);
end = (DateTime) dts.GetField ("End").GetValue (daylightTime);
delta = (TimeSpan) dts.GetField ("Delta").GetValue (daylightTime);
#else
MethodInfo getChanges = typeof (TimeZoneInfo).GetMethod ("GetDaylightChanges", BindingFlags.Instance | BindingFlags.NonPublic);
var changes = (DaylightTime) getChanges.Invoke (tz, new object [] {year});
start = changes.Start;
end = changes.End;
delta = changes.Delta;
#endif
}
[Test]
[Category ("MobileNotWorking")]
[Category ("NotOnWindows")]
public void TestSydneyDaylightChanges ()
{
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById (MapTimeZoneId ("Australia/Sydney"));
var changes = (DaylightTime) getChanges.Invoke (tz, new object [] {2014});
GetDaylightTime (tz, 2014, out DateTime start, out DateTime end, out TimeSpan delta);
Assert.AreEqual (new TimeSpan (1, 0, 0), changes.Delta);
Assert.AreEqual (new DateTime (2014, 10, 5, 2, 0, 0), changes.Start);
Assert.AreEqual (new DateTime (2014, 4, 6, 3, 0, 0), changes.End);
Assert.AreEqual (new TimeSpan (1, 0, 0), delta);
Assert.AreEqual (new DateTime (2014, 10, 6, 2, 0, 0), start);
Assert.AreEqual (new DateTime (2014, 4, 6, 2, 59, 59), end);
}
[Test]
[Category ("MobileNotWorking")]
[Category ("NotOnWindows")]
public void TestAthensDaylightChanges ()
{
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Athens"));
var changes = (DaylightTime) getChanges.Invoke (tz, new object [] {2014});
GetDaylightTime (tz, 2014, out DateTime start, out DateTime end, out TimeSpan delta);
Assert.AreEqual (new TimeSpan (1, 0, 0), changes.Delta);
Assert.AreEqual (new DateTime (2014, 3, 30, 3, 0, 0), changes.Start);
Assert.AreEqual (new DateTime (2014, 10, 26, 4, 0, 0), changes.End);
Assert.AreEqual (new TimeSpan (0, 0, 0), delta);
Assert.AreEqual (new DateTime (2014, 10, 27, 3, 0, 0), start);
Assert.AreEqual (new DateTime (2014, 03, 30, 2, 59, 59), end);
}
[Test]
@ -1322,7 +1317,7 @@ namespace MonoTests.System
foreach (var tz in TimeZoneInfo.GetSystemTimeZones ()) {
try {
for (var year = 1950; year <= 2051; year++)
getChanges.Invoke (tz, new object [] {year} );
GetDaylightTime (tz, year, out DateTime start, out DateTime end, out TimeSpan delta);
} catch (Exception e) {
Assert.Fail ("TimeZone " + tz.Id + " exception: " + e.ToString ());
}
@ -1343,6 +1338,7 @@ namespace MonoTests.System
}
[Test]
[Category ("NotWorking")]
public void Bug31432 ()
{
// Europe/Moscow from failing device