Imported Upstream version 4.3.2.467

Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
Xamarin Public Jenkins
2016-02-22 11:00:01 -05:00
parent f302175246
commit f3e3aab35a
4097 changed files with 122406 additions and 82300 deletions

View File

@@ -22,7 +22,6 @@
//
//
#if NET_4_0
using System;
using System.Linq;
@@ -141,4 +140,3 @@ namespace MonoTests.System
}
}
}
#endif

View File

@@ -26,6 +26,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if MONO_FEATURE_MULTIPLE_APPDOMAINS
using NUnit.Framework;
using System;
@@ -404,3 +406,5 @@ namespace MonoCasTests.System {
}
}
}
#endif // MONO_FEATURE_MULTIPLE_APPDOMAINS

View File

@@ -26,6 +26,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if MONO_FEATURE_MULTIPLE_APPDOMAINS
using System;
using System.Security;
@@ -56,3 +57,4 @@ namespace MonoTests.System {
}
}
#endif // MONO_FEATURE_MULTIPLE_APPDOMAINS

View File

@@ -169,6 +169,7 @@ namespace MonoTests.System
}
}
#if MONO_FEATURE_MULTIPLE_APPDOMAINS
[Test]
#if MOBILE
[Category ("NotWorking")]
@@ -184,6 +185,7 @@ namespace MonoTests.System
Assert.IsNotNull (data);
Assert.IsTrue ((bool) data);
}
#endif // MONO_FEATURE_MULTIPLE_APPDOMAINS
static void AppDomainInitialized1 (string [] args)
{
@@ -199,6 +201,7 @@ namespace MonoTests.System
{
}
#if MONO_FEATURE_MULTIPLE_APPDOMAINS
[Test]
#if MOBILE
[Category ("NotWorking")]
@@ -211,5 +214,6 @@ namespace MonoTests.System
s.AppDomainInitializer = InstanceInitializer;
AppDomain.CreateDomain ("MyDomain", null, s);
}
#endif // MONO_FEATURE_MULTIPLE_APPDOMAINS
}
}

View File

@@ -2548,6 +2548,33 @@ public class ArrayTest
Assert.AreEqual (4, indices [0]);
}
[Test]
public void TestSortComparable()
{
int[] source = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int[] expected = { 6, 5, 4, 3, 2, 1, 7, 8, 9 };
Comp[] c = { new Comp (100), new Comp (16), new Comp (11), new Comp (9), new Comp (0), new Comp (-100) };
IComparer<Comp> comp = null;
Array.Sort<Comp, int> (c, source, comp);
Assert.AreEqual (expected, source);
}
class Comp : IComparable
{
readonly int val;
public Comp (int a)
{
val = a;
}
int IComparable.CompareTo (object obj)
{
return val.CompareTo ((obj as Comp).val);
}
}
[Test]
public void TestInitializeEmpty()
{
@@ -3449,7 +3476,6 @@ public class ArrayTest
Assert.AreEqual (input, expected);
}
#if NET_4_0
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CompareToWithJaggedArray () {
@@ -3616,7 +3642,6 @@ public class ArrayTest
Assert.AreEqual (3, c.Counter);
}
#endif
[Test]
public void JaggedArrayCtor ()

View File

@@ -836,6 +836,8 @@ namespace MonoTests.System
}
[Test]
// The linker removes the serializable attribute
[Category ("MobileNotWorking")]
public void OrderIsImportant ()
{
var custom = typeof (ClassForOrderIsImportant).GetCustomAttributes (false);

View File

@@ -278,5 +278,18 @@ namespace MonoTests.System {
Buffer.SetByte (byteArray, 3, (byte) 10);
Assert.AreEqual ((Byte)10, Buffer.GetByte (byteArray, 3), "TestSetByte");
}
[Test]
public void MemoryCopy_Simple ()
{
int a = 0xBC614E;
int b = 1;
unsafe {
Buffer.MemoryCopy (&a, &b, 4, 2);
}
Assert.AreEqual (0xBC614E, a, "#1");
Assert.AreEqual (0x614E, b, "#2");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -569,6 +569,12 @@ public class CharTest
Assert.AreEqual(b6, Char.ToUpper(a6), "char uppered");
}
[Test]
public void TestToUpperInvariant ()
{
Assert.AreEqual ('\u01c5', char.ToUpperInvariant ('\u01c5'));
}
[Test]
public void TestToString()
{

View File

@@ -0,0 +1,143 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Globalization;
using NUnit.Framework;
namespace MonoTests.System {
[TestFixture]
public static class DateTimeOffsetUnixTimeConversionTests
{
private class TestTime
{
private TestTime(DateTimeOffset dateTimeOffset, long unixTimeMilliseconds, long unixTimeSeconds)
{
DateTimeOffset = dateTimeOffset;
UnixTimeMilliseconds = unixTimeMilliseconds;
UnixTimeSeconds = unixTimeSeconds;
}
public static TestTime FromMilliseconds(DateTimeOffset dateTimeOffset, long unixTimeMilliseconds)
{
long unixTimeSeconds = unixTimeMilliseconds / 1000;
// Always round UnixTimeSeconds down toward 1/1/0001 00:00:00
// (this happens automatically for unixTimeMilliseconds > 0)
bool hasSubSecondPrecision = unixTimeMilliseconds % 1000 != 0;
if (unixTimeMilliseconds < 0 && hasSubSecondPrecision)
{
--unixTimeSeconds;
}
return new TestTime(dateTimeOffset, unixTimeMilliseconds, unixTimeSeconds);
}
public static TestTime FromSeconds(DateTimeOffset dateTimeOffset, long unixTimeSeconds)
{
return new TestTime(dateTimeOffset, unixTimeSeconds * 1000, unixTimeSeconds);
}
public DateTimeOffset DateTimeOffset { get; private set; }
public long UnixTimeMilliseconds { get; private set; }
public long UnixTimeSeconds { get; private set; }
}
private static readonly TestTime[] s_testTimes = {
TestTime.FromMilliseconds(DateTimeOffset.MinValue, -62135596800000),
TestTime.FromMilliseconds(DateTimeOffset.MaxValue, 253402300799999),
TestTime.FromMilliseconds(new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero), 0),
TestTime.FromMilliseconds(new DateTimeOffset(2014, 6, 13, 17, 21, 50, TimeSpan.Zero), 1402680110000),
TestTime.FromMilliseconds(new DateTimeOffset(2830, 12, 15, 1, 23, 45, TimeSpan.Zero), 27169089825000),
TestTime.FromMilliseconds(new DateTimeOffset(2830, 12, 15, 1, 23, 45, 399, TimeSpan.Zero), 27169089825399),
TestTime.FromMilliseconds(new DateTimeOffset(9999, 12, 30, 23, 24, 25, TimeSpan.Zero), 253402212265000),
TestTime.FromMilliseconds(new DateTimeOffset(1907, 7, 7, 7, 7, 7, TimeSpan.Zero), -1971967973000),
TestTime.FromMilliseconds(new DateTimeOffset(1907, 7, 7, 7, 7, 7, 1, TimeSpan.Zero), -1971967972999),
TestTime.FromMilliseconds(new DateTimeOffset(1907, 7, 7, 7, 7, 7, 777, TimeSpan.Zero), -1971967972223),
TestTime.FromMilliseconds(new DateTimeOffset(601636288270011234, TimeSpan.Zero), -1971967972999)
};
[Test]
public static void TestToUnixTime()
{
foreach (var test in s_testTimes)
{
TestToUnixTimeMilliseconds(test);
TestToUnixTimeSeconds(test);
}
}
private static void TestToUnixTimeMilliseconds(TestTime test)
{
long expectedMilliseconds = test.UnixTimeMilliseconds;
long actualMilliseconds = test.DateTimeOffset.ToUnixTimeMilliseconds();
Assert.AreEqual(expectedMilliseconds, actualMilliseconds);
}
private static void TestToUnixTimeSeconds(TestTime test)
{
long expectedSeconds = test.UnixTimeSeconds;
long actualSeconds = test.DateTimeOffset.ToUnixTimeSeconds();
Assert.AreEqual(expectedSeconds, actualSeconds);
}
[Test]
public static void TestFromUnixTime()
{
foreach (var test in s_testTimes)
{
TestFromUnixTimeMilliseconds(test);
TestFromUnixTimeSeconds(test);
}
}
private static void TestFromUnixTimeMilliseconds(TestTime test)
{
// Only assert that expected == actual up to millisecond precision for conversion from milliseconds
long expectedTicks = (test.DateTimeOffset.UtcTicks / TimeSpan.TicksPerMillisecond) * TimeSpan.TicksPerMillisecond;
long actualTicks = DateTimeOffset.FromUnixTimeMilliseconds(test.UnixTimeMilliseconds).UtcTicks;
Assert.AreEqual(expectedTicks, actualTicks);
}
private static void TestFromUnixTimeSeconds(TestTime test)
{
// Only assert that expected == actual up to second precision for conversion from seconds
long expectedTicks = (test.DateTimeOffset.UtcTicks / TimeSpan.TicksPerSecond) * TimeSpan.TicksPerSecond;
long actualTicks = DateTimeOffset.FromUnixTimeSeconds(test.UnixTimeSeconds).UtcTicks;
Assert.AreEqual(expectedTicks, actualTicks);
}
[Test]
public static void TestRoundtripDateTimes()
{
foreach (var test in s_testTimes)
{
// Roundtrip through Unix time in milliseconds
long unixTimeMilliseconds = test.DateTimeOffset.ToUnixTimeMilliseconds();
TestFromUnixTimeMilliseconds(TestTime.FromMilliseconds(test.DateTimeOffset, unixTimeMilliseconds));
// Roundtrip through Unix time in seconds
long unixTimeSeconds = test.DateTimeOffset.ToUnixTimeSeconds();
TestFromUnixTimeSeconds(TestTime.FromSeconds(test.DateTimeOffset, unixTimeSeconds));
}
}
[Test]
public static void TestRoundtripUnixTimes()
{
foreach (var test in s_testTimes)
{
// Roundtrip Unix time in milliseconds
DateTimeOffset dateTime = DateTimeOffset.FromUnixTimeMilliseconds(test.UnixTimeMilliseconds);
TestToUnixTimeMilliseconds(TestTime.FromMilliseconds(dateTime, test.UnixTimeMilliseconds));
// Roundtrip Unix time in seconds
dateTime = DateTimeOffset.FromUnixTimeSeconds(test.UnixTimeSeconds);
TestToUnixTimeSeconds(TestTime.FromSeconds(dateTime, test.UnixTimeSeconds));
}
}
}
}

View File

@@ -1296,6 +1296,21 @@ namespace MonoTests.System
}
}
[Test]
public void Parse_SameTimeAndDateSeparator ()
{
var fiFI = (CultureInfo) CultureInfo.GetCultureInfo("fi-FI").Clone();
fiFI.DateTimeFormat.TimeSeparator = fiFI.DateTimeFormat.DateSeparator;
var dt = DateTime.Parse("4.3.2010", fiFI);
Assert.AreEqual (2010, dt.Year, "#1");
Assert.AreEqual (3, dt.Month, "#2");
Assert.AreEqual (4, dt.Day, "#3");
}
[Test]
[ExpectedException (typeof (FormatException))]
public void Parse_RequireSpaceSeparator ()
@@ -2530,9 +2545,7 @@ namespace MonoTests.System
DateTime expected2 = new DateTime (2011, 03, 22, 08, 32, 00, DateTimeKind.Utc);
string [] cultures = new string [] {"es-ES", "en-US", "en-GB", "de-DE", "fr-FR"
#if NET_4_0
,"es", "en", "de", "fr"
#endif
};
foreach (string culture in cultures) {
@@ -2631,5 +2644,28 @@ namespace MonoTests.System
Assert.AreEqual (2, res.Year, "#1");
Assert.AreEqual (12, res.Month, "#2");
}
[Test]
[Culture ("en-us")]
public void ToUniversalTime_TimeZoneOffsetShouldNotOverflow ()
{
var m = DateTime.MaxValue;
var res = m.ToUniversalTime ();
// It does not matter which time zone but we should never overflow or have DateTime.MinValue
Assert.AreEqual (9999, res.Year, "#1");
Assert.AreEqual (12, res.Month, "#2");
Assert.AreEqual (31, res.Day, "#3");
Assert.AreEqual (DateTimeKind.Utc, res.Kind, "#4");
m = DateTime.MinValue;
res = m.ToUniversalTime ();
// It does not matter which time zone but we should never overflow or have DateTime.MinValue
Assert.AreEqual (0, res.Year, "#10");
Assert.AreEqual (1, res.Month, "#11");
Assert.AreEqual (1, res.Day, "#12");
Assert.AreEqual (DateTimeKind.Utc, res.Kind, "#13");
}
}
}

View File

@@ -673,7 +673,6 @@ namespace MonoTests.System
Assert.AreEqual (TestingEnum3.Test, Enum.Parse (t1.GetType (), "18446744073709551615", false));
}
#if NET_4_0
[Test]
public void TryParseErrors ()
{
@@ -736,7 +735,6 @@ namespace MonoTests.System
Assert.AreEqual (true, success, "#E1");
Assert.AreEqual (TestingEnum.Is, result, "#E2");
}
#endif
[Test]
public void ToObject_EnumType_Int32 ()
@@ -947,28 +945,28 @@ namespace MonoTests.System
[Test]
public void GetHashCode_ShouldBeEqualToUnderlyingType ()
{
Assert.AreEqual (EnInt8.A.GetHashCode(), SByte.MinValue, "i8#0");
Assert.AreEqual (EnInt8.B.GetHashCode(), 44, "i8#1");
Assert.AreEqual (EnInt8.C.GetHashCode(), SByte.MaxValue, "i8#2");
Assert.AreEqual (EnInt8.A.GetHashCode(), SByte.MinValue.GetHashCode (), "i8#0");
Assert.AreEqual (EnInt8.B.GetHashCode(), ((sbyte)44).GetHashCode (), "i8#1");
Assert.AreEqual (EnInt8.C.GetHashCode(), SByte.MaxValue.GetHashCode (), "i8#2");
Assert.AreEqual (EnUInt8.A.GetHashCode(), Byte.MinValue, "u8#0");
Assert.AreEqual (EnUInt8.B.GetHashCode(), 55, "u8#1");
Assert.AreEqual (EnUInt8.C.GetHashCode(), Byte.MaxValue, "u8#2");
Assert.AreEqual (EnUInt8.A.GetHashCode(), Byte.MinValue.GetHashCode (), "u8#0");
Assert.AreEqual (EnUInt8.B.GetHashCode(), ((byte)55).GetHashCode (), "u8#1");
Assert.AreEqual (EnUInt8.C.GetHashCode(), Byte.MaxValue.GetHashCode (), "u8#2");
Assert.AreEqual (EnInt16.A.GetHashCode(), Int16.MinValue, "i16#0");
Assert.AreEqual (EnInt16.B.GetHashCode(), 66, "i16#1");
Assert.AreEqual (EnInt16.C.GetHashCode(), Int16.MaxValue, "i16#2");
Assert.AreEqual (EnInt16.A.GetHashCode(), Int16.MinValue.GetHashCode (), "i16#0");
Assert.AreEqual (EnInt16.B.GetHashCode(), ((short)66).GetHashCode (), "i16#1");
Assert.AreEqual (EnInt16.C.GetHashCode(), Int16.MaxValue.GetHashCode (), "i16#2");
Assert.AreEqual (EnUInt16.A.GetHashCode(), UInt16.MinValue, "u16#0");
Assert.AreEqual (EnUInt16.B.GetHashCode(), 77, "u16#1");
Assert.AreEqual (EnUInt16.C.GetHashCode(), UInt16.MaxValue, "u16#2");
Assert.AreEqual (EnUInt16.A.GetHashCode(), UInt16.MinValue.GetHashCode (), "u16#0");
Assert.AreEqual (EnUInt16.B.GetHashCode(), ((ushort)77).GetHashCode (), "u16#1");
Assert.AreEqual (EnUInt16.C.GetHashCode(), UInt16.MaxValue.GetHashCode (), "u16#2");
Assert.AreEqual (EnInt32.A.GetHashCode(), Int32.MinValue, "i32#0");
Assert.AreEqual (EnInt32.B.GetHashCode(), 88, "i32#1");
Assert.AreEqual (EnInt32.C.GetHashCode(), Int32.MaxValue, "i32#2");
Assert.AreEqual (EnInt32.A.GetHashCode(), Int32.MinValue.GetHashCode (), "i32#0");
Assert.AreEqual (EnInt32.B.GetHashCode(), ((int)88).GetHashCode (), "i32#1");
Assert.AreEqual (EnInt32.C.GetHashCode(), Int32.MaxValue.GetHashCode (), "i32#2");
Assert.AreEqual (EnUInt32.A.GetHashCode(), UInt32.MinValue, "u32#0");
Assert.AreEqual (EnUInt32.B.GetHashCode(), 99, "u32#1");
Assert.AreEqual (EnUInt32.A.GetHashCode(), UInt32.MinValue.GetHashCode (), "u32#0");
Assert.AreEqual (EnUInt32.B.GetHashCode(), ((uint)99).GetHashCode (), "u32#1");
Assert.AreEqual (EnUInt32.C.GetHashCode(), UInt32.MaxValue.GetHashCode (), "u32#2");
Assert.AreEqual (EnInt64.A.GetHashCode(), Int64.MinValue.GetHashCode (), "i64#0");
@@ -976,7 +974,7 @@ namespace MonoTests.System
Assert.AreEqual (EnInt64.C.GetHashCode(), Int64.MaxValue.GetHashCode (), "i64#2");
Assert.AreEqual (EnUInt64.A.GetHashCode(), UInt64.MinValue.GetHashCode (), "u64#0");
Assert.AreEqual (EnUInt64.B.GetHashCode(), 3488924689489L.GetHashCode (), "u64#1");
Assert.AreEqual (EnUInt64.B.GetHashCode(), ((ulong)3488924689489L).GetHashCode (), "u64#1");
Assert.AreEqual (EnUInt64.C.GetHashCode(), UInt64.MaxValue.GetHashCode (), "u64#2");
}
@@ -1139,7 +1137,6 @@ namespace MonoTests.System
negative = -1
}
#if NET_4_0
// Our first implementation used to crash
[Test]
public void HasFlagTest ()
@@ -1147,7 +1144,6 @@ namespace MonoTests.System
Foo f = Foo.negative;
bool has = f.HasFlag (Foo.negative);
}
#endif
[Test]
[ExpectedException (typeof (ArgumentNullException))]

View File

@@ -110,7 +110,6 @@ namespace MonoCasTests.System {
Environment.CurrentDirectory = cd;
}
#if !RUN_ONDOTNET || NET_4_0 // Disabled because .net 2 fails to load dll with "Failure decoding embedded permission set object" due to "/" path
[Test]
[FileIOPermission (SecurityAction.Deny, PathDiscovery = "/")]
@@ -129,7 +128,6 @@ namespace MonoCasTests.System {
// now that the stack is set, call the method
string s = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
}
#endif
[Test]
public void CurrentDirectory_Set_FileIOPermission ()
@@ -513,4 +511,4 @@ namespace MonoCasTests.System {
}
}
#endif
#endif

View File

@@ -127,7 +127,6 @@ namespace MonoCasTests.System {
}
}
#if !RUN_ONDOTNET || NET_4_0 // Disabled because .net 2 fails to load dll with "Failure decoding embedded permission set object" due to "/" path
[Test]
[FileIOPermission (SecurityAction.Deny, PathDiscovery = "/")]
@@ -157,6 +156,5 @@ namespace MonoCasTests.System {
}
}
#endif
}
}

View File

@@ -294,20 +294,10 @@ namespace MonoTests.System {
Assert.AreEqual ("00010203-0405-0607-0809-0a0b0c0d0e0f", g.ToString (""), "A6");
Assert.AreEqual ("00010203-0405-0607-0809-0a0b0c0d0e0f", g.ToString ((string)null), "A7");
Assert.AreEqual ("{00010203-0405-0607-0809-0a0b0c0d0e0f}", g.ToString ("B", null), "A10");
#if NET_4_0
Assert.AreEqual ("{0x00010203,0x0405,0x0607,{0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f}}", g.ToString ("x"), "A11");
Assert.AreEqual ("{0x00010203,0x0405,0x0607,{0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f}}", g.ToString ("X"), "A11");
#endif
}
#if !NET_4_0
[Test]
[ExpectedException (typeof (FormatException))]
public void ToString_UnsupportedFormat ()
{
new Guid (0x00010203, 0x0405, 0x0607, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f).ToString ("X");
}
#endif
[Test]
[ExpectedException (typeof (FormatException))]
@@ -351,7 +341,6 @@ namespace MonoTests.System {
new Guid ("{0x00010203,0x0405,0x0607,{0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f}}aaaa");
}
#if NET_4_0
/*
N = new Guid ("000102030405060708090a0b0c0d0e0f");
@@ -445,6 +434,5 @@ namespace MonoTests.System {
Assert.IsFalse (Guid.TryParseExact("foobar", null, out guid), "A5");
Assert.AreEqual (Guid.Empty, guid, "A6");
}
#endif
}
}

View File

@@ -16,8 +16,7 @@ namespace MonoTests.System
[TestFixture]
public class MathTest
{
private static double double_epsilon =
double.Epsilon;
private static double double_epsilon = 2.2204460492503131e-16; /* DBL_EPSILON = 2^-52 */
static double x = 0.1234;
static double y = 12.345;
@@ -405,7 +404,7 @@ namespace MonoTests.System
public void TestIEEERemainder ()
{
double a = Math.IEEERemainder (y, x);
double b = 0.0050000000000007816;
double b = 0.0050000000000010592;
Assert.IsTrue ((Math.Abs (a - b) <= double_epsilon), a.ToString ("G99")
+ " != " + b.ToString ("G99"));
@@ -456,7 +455,8 @@ namespace MonoTests.System
// MS docs say this should be PositiveInfinity
Assert.IsTrue (Math.Log (0, y) == double.NegativeInfinity);
Assert.IsTrue (Math.Log (double.PositiveInfinity, y) == double.PositiveInfinity);
Assert.IsTrue (Math.Log (x, double.PositiveInfinity) == 0);
Assert.IsTrue (Double.IsNaN (Math.Log (x, double.PositiveInfinity)));
}
[Test]
@@ -480,7 +480,6 @@ namespace MonoTests.System
public void TestPow ()
{
double precision;
int iTest = 1;
#if MONODROID
// It fails on Nexus 9 with
//
@@ -488,82 +487,109 @@ namespace MonoTests.System
//
// when using double_epsilon. Precision differs between different ARM CPUs, so we
// will just use a more conservative value
precision = 0.000001;
precision = double_epsilon * 10;
#else
precision = double_epsilon;
#endif
try {
double a = Math.Pow (y, x);
double b = 1.363609446060212;
Assert.IsTrue ((Math.Abs (a - b) <= precision), a.ToString ("G99") + " != " + b.ToString ("G99"));
iTest++;
Assert.IsTrue (double.IsNaN (Math.Pow (y, double.NaN)));
iTest++;
Assert.IsTrue (double.IsNaN (Math.Pow (double.NaN, x)));
iTest++;
Assert.IsTrue (double.IsNegativeInfinity (Math.Pow (double.NegativeInfinity, 1)),
"Math.Pow(double.NegativeInfinity, 1) should be NegativeInfinity");
iTest++;
Assert.IsTrue (double.IsPositiveInfinity (Math.Pow (double.NegativeInfinity, 2)),
"Math.Pow(double.NegativeInfinity, 2) should be PositiveInfinity");
/* documentation cases : https://msdn.microsoft.com/en-us/library/system.math.pow%28v=vs.110%29.aspx */
// MS docs say this should be 0
iTest++;
Assert.IsTrue (double.IsNaN (Math.Pow (1, double.NegativeInfinity)));
iTest++;
Assert.AreEqual ((double) 0, Math.Pow (double.PositiveInfinity, double.NegativeInfinity),
"Math.Pow(double.PositiveInfinity, double.NegativeInfinity)");
iTest++;
Assert.IsTrue (double.IsPositiveInfinity (Math.Pow (double.PositiveInfinity, 1)),
"Math.Pow(double.PositiveInfinity, 1) should be PositiveInfinity");
/* x or y = NaN -> NaN */
Assert.IsTrue (double.IsNaN (Math.Pow ( double.NaN, double.NaN)), "#1");
Assert.IsTrue (double.IsNaN (Math.Pow ( double.NaN, double.NegativeInfinity)), "#2");
Assert.IsTrue (double.IsNaN (Math.Pow ( double.NaN, -2)), "#2");
Assert.IsTrue (double.IsNaN (Math.Pow ( double.NaN, -1)), "#3");
Assert.IsTrue (double.IsNaN (Math.Pow ( double.NaN, 0)), "#4");
Assert.IsTrue (double.IsNaN (Math.Pow ( double.NaN, 1)), "#5");
Assert.IsTrue (double.IsNaN (Math.Pow ( double.NaN, 2)), "#6");
Assert.IsTrue (double.IsNaN (Math.Pow ( double.NaN, double.PositiveInfinity)), "#7");
Assert.IsTrue (double.IsNaN (Math.Pow (double.NegativeInfinity, double.NaN)), "#8");
Assert.IsTrue (double.IsNaN (Math.Pow ( -2, double.NaN)), "#9");
Assert.IsTrue (double.IsNaN (Math.Pow ( -1, double.NaN)), "#10");
Assert.IsTrue (double.IsNaN (Math.Pow ( 0, double.NaN)), "#11");
Assert.IsTrue (double.IsNaN (Math.Pow ( 1, double.NaN)), "#12");
Assert.IsTrue (double.IsNaN (Math.Pow ( 2, double.NaN)), "#13");
Assert.IsTrue (double.IsNaN (Math.Pow (double.PositiveInfinity, double.NaN)), "#14");
// MS docs say this should be PositiveInfinity
iTest++;
Assert.IsTrue (double.IsNaN (Math.Pow (1, double.PositiveInfinity)),
"Math.Pow(1, double.PositiveInfinity) should be NaN");
/* x = Any value except NaN; y = 0 -> 1 */
Assert.AreEqual ((double) 1, Math.Pow (2, 0), "#15");
iTest++;
Assert.IsTrue (Double.IsNaN (Math.Pow (1, Double.NaN)),
"Math.Pow(1, NaN) should be NaN");
iTest++;
Assert.IsTrue (Double.IsNaN (Math.Pow (Double.NaN, 0)),
"Math.Pow(NaN, 0) should be NaN");
iTest++;
Assert.IsTrue (1.0 == Math.Pow (-1, Double.MaxValue),
"Math.Pow(-1, MaxValue) should be 1.0");
/* x = NegativeInfinity; y < 0 -> 0 */
Assert.AreEqual ((double) 0, Math.Pow (double.NegativeInfinity, -2), "#16");
iTest++;
Assert.IsTrue (1.0 == Math.Pow (-1, Double.MinValue),
"Math.Pow(-1, MinValue) should be 1.0");
/* x = NegativeInfinity; y is a positive odd integer -> NegativeInfinity */
Assert.AreEqual (double.NegativeInfinity, Math.Pow (double.NegativeInfinity, 3), "#17");
iTest++;
Assert.IsTrue (Double.IsPositiveInfinity (Math.Pow (Double.MinValue,
Double.MaxValue)), "Math.Pow(MinValue, MaxValue) should be +Infinity");
/* x = NegativeInfinity; y is positive but not an odd integer -> PositiveInfinity */
Assert.AreEqual (double.PositiveInfinity, Math.Pow (double.NegativeInfinity, 2), "#18");
iTest++;
Assert.IsTrue (0.0 == Math.Pow (Double.MinValue, Double.MinValue),
"Math.Pow(MinValue, MinValue) should be 0.0");
/* x < 0 but not NegativeInfinity; y is not an integer, NegativeInfinity, or PositiveInfinity -> NaN */
Assert.IsTrue (double.IsNaN (Math.Pow (-1, 2.5)), "#19");
//
// The following bugs were present because we tried to outsmart the C Pow:
//
double infinity = Double.PositiveInfinity;
Assert.IsTrue (Math.Pow (0.5, infinity) == 0.0,
"Math.Pow(0.5, Infinity) == 0.0");
Assert.IsTrue (Math.Pow (0.5, -infinity) == infinity,
"Math.Pow(0.5, -Infinity) == Infinity");
Assert.IsTrue (Math.Pow (2, infinity) == infinity,
"Math.Pow(2, Infinity) == Infinity");
Assert.IsTrue (Math.Pow (2, -infinity) == 0.0,
"Math.Pow(2, -Infinity) == 0");
Assert.IsTrue (Math.Pow (infinity, 0) == 1.0,
"Math.Pow(Infinity, 0) == 1.0");
Assert.IsTrue (Math.Pow (-infinity, 0) == 1.0,
"Math.Pow(-Infinity, 0) == 1.0");
} catch (Exception e) {
Assert.Fail ("Unexpected exception at iTest=" + iTest + ". e=" + e);
}
/* x = -1; y = NegativeInfinity or PositiveInfinity -> NaN */
Assert.IsTrue (double.IsNaN (Math.Pow (-1, double.PositiveInfinity)), "#20");
Assert.IsTrue (double.IsNaN (Math.Pow (-1, double.NegativeInfinity)), "#21");
/* -1 < x < 1; y = NegativeInfinity -> PositiveInfinity */
Assert.AreEqual (double.PositiveInfinity, Math.Pow (-0.5, double.NegativeInfinity), "#22");
Assert.AreEqual (double.PositiveInfinity, Math.Pow (+0.5, double.NegativeInfinity), "#23");
/* -1 < x < 1; y = PositiveInfinity -> 0 */
Assert.AreEqual ((double) 0, Math.Pow (-0.5, double.PositiveInfinity), "#24");
Assert.AreEqual ((double) 0, Math.Pow (+0.5, double.PositiveInfinity), "#25");
/* x < -1 or x > 1; y = NegativeInfinity -> 0 */
Assert.AreEqual ((double) 0, Math.Pow (-2, double.NegativeInfinity), "#26");
Assert.AreEqual ((double) 0, Math.Pow (+2, double.NegativeInfinity), "#27");
/* x < -1 or x > 1; y = PositiveInfinity -> PositiveInfinity */
Assert.AreEqual (double.PositiveInfinity, Math.Pow (-2, double.PositiveInfinity), "#28");
Assert.AreEqual (double.PositiveInfinity, Math.Pow (+2, double.PositiveInfinity), "#29");
/* x = 0; y < 0 -> PositiveInfinity */
Assert.AreEqual (double.PositiveInfinity, Math.Pow (0, -2), "#30");
/* x = 0; y > 0 -> PositiveInfinity */
Assert.AreEqual ((double) 0, Math.Pow (0, +2), "#31");
/* x = 1; y is any value except NaN -> 1 */
Assert.AreEqual ((double) 1, Math.Pow (1, double.NegativeInfinity), "#32");
Assert.AreEqual ((double) 1, Math.Pow (1, -2), "#33");
Assert.AreEqual ((double) 1, Math.Pow (1, 0), "#34");
Assert.AreEqual ((double) 1, Math.Pow (1, +2), "#35");
Assert.AreEqual ((double) 1, Math.Pow (1, double.PositiveInfinity), "#36");
/* x = PositiveInfinity; y < 0 -> 0 */
Assert.AreEqual ((double) 0, Math.Pow (double.PositiveInfinity, -1), "#37");
Assert.AreEqual ((double) 0, Math.Pow (double.PositiveInfinity, -2), "#38");
/* x = PositiveInfinity; y > 0 -> PositiveInfinity */
Assert.AreEqual (double.PositiveInfinity, Math.Pow (double.PositiveInfinity, 1), "#39");
Assert.AreEqual (double.PositiveInfinity, Math.Pow (double.PositiveInfinity, 2), "#40");
/* other cases */
double a = Math.Pow (y, x);
double b = 1.363609446060212;
Assert.IsTrue (Math.Abs (a - b) <= precision, "#41 " + a.ToString ("G99") + " != " + b.ToString ("G99") + " +/- " + precision.ToString ("G99"));
Assert.AreEqual (double.NegativeInfinity, Math.Pow (double.NegativeInfinity, 1), "#42");
Assert.AreEqual (double.PositiveInfinity, Math.Pow (double.NegativeInfinity, 2), "#43");
Assert.AreEqual (Math.Pow (double.PositiveInfinity, double.NegativeInfinity), (double) 0, "#44");
Assert.AreEqual ((double) 1, Math.Pow (-1, Double.MaxValue), "#45");
Assert.AreEqual ((double) 1, Math.Pow (-1, Double.MinValue), "#46");
Assert.AreEqual ((double) 0, Math.Pow (Double.MinValue, Double.MinValue), "#47");
Assert.AreEqual (double.PositiveInfinity, Math.Pow (Double.MinValue, Double.MaxValue), "#48");
double infinity = double.PositiveInfinity;
Assert.AreEqual ((double) 0, Math.Pow ( 0.5, infinity), "#49");
Assert.AreEqual ( infinity, Math.Pow ( 0.5, -infinity), "#50");
Assert.AreEqual ( infinity, Math.Pow ( 2, infinity), "#51");
Assert.AreEqual ((double) 0, Math.Pow ( 2, -infinity), "#52");
Assert.AreEqual ((double) 1, Math.Pow ( infinity, 0), "#53");
Assert.AreEqual ((double) 1, Math.Pow (-infinity, 0), "#54");
}
[Test]

View File

@@ -215,6 +215,20 @@ namespace MonoTests.System
StringComparer.Ordinal.GetHashCode (null);
}
[Test]
[SetCulture("en-us")]
public void OrdinarCultureSwitch ()
{
var cmp1 = StringComparer.OrdinalIgnoreCase;
var h1 = cmp1.GetHashCode ("w");
global::System.Threading.Thread.CurrentThread.CurrentCulture = new global::System.Globalization.CultureInfo ("fi");
var cmp2 = StringComparer.OrdinalIgnoreCase;
var h2 = cmp2.GetHashCode ("w");
Assert.AreEqual (h1, h2);
}
private static readonly byte [] _serializedCurrentCulture = new byte [] {
0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00,

View File

@@ -1 +1 @@
74570292985d0e3c02e90e5d03a21dd4521dbb03
a45c7ec198cb62b2fb068a2a13b743b86f535288

View File

@@ -638,14 +638,10 @@ public class TimeSpanTest {
ParseHelper (" 13:45:15 ",false, false, "13:45:15");
ParseHelper (" -1:2:3 ", false, false, "-01:02:03");
#if NET_4_0
// In 4.0 when the first part is out of range, it parses it as day.
ParseHelper (" 25:11:12 ", false, false, "25.11:12:00");
ParseHelper (" 24:11:12 ", false, false, "24.11:12:00");
ParseHelper (" 23:11:12 ", false, false, "23:11:12");
#else
ParseHelper (" 25:0:0 ",false, true, "dontcare");
#endif
ParseHelper ("-21.23:59:59.9999999", false, false, "-21.23:59:59.9999999");
ParseHelper ("10:12 ", false, false, "10:12:00");
@@ -655,14 +651,9 @@ public class TimeSpanTest {
ParseHelper ("24:60:60", false, true, "dontcare");
ParseHelper ("0001:0002:0003.12 ", false, false, "01:02:03.1200000");
#if NET_4_0
// In 4.0 when a section has more than 7 digits an OverflowException is thrown.
ParseHelper (" 1:2:3:12345678 ", false, true, "dontcare");
#else
ParseHelper (" 1:2:3:12345678 ", true, false, "dontcare");
#endif
#if NET_4_0
ParseHelper ("10:11:12:13", false, false, "10.11:12:13"); // Days using : instead of . as separator
ParseHelper ("10.11", true, false, "dontcare"); // days+hours is invalid
@@ -679,7 +670,6 @@ public class TimeSpanTest {
// restore culture
Thread.CurrentThread.CurrentCulture = prev_culture;
}
#endif
ParseHelper ("00:00:00", false, false, "00:00:00");
ParseHelper ("00:10:00", false, false, "00:10:00");
@@ -740,19 +730,11 @@ public class TimeSpanTest {
{
// hours should be between 0 and 23 but format is also invalid (too many dots)
// In 2.0 overflow as precedence over format, but not in 4.0
#if NET_4_0
try {
TimeSpan.Parse ("0.99.99.0");
Assert.Fail ("#A1");
} catch (FormatException) {
}
#else
try {
TimeSpan.Parse ("0.99.99.0");
Assert.Fail ("#A1");
} catch (OverflowException) {
}
#endif
try {
TimeSpan.Parse ("0.999999999999.99.0");
Assert.Fail ("#A2");
@@ -820,12 +802,7 @@ public class TimeSpanTest {
Assert.AreEqual (false, TimeSpan.TryParse ("100000000000000.1:1:1", out result), "#E1");
Assert.AreEqual (false, TimeSpan.TryParse ("24:60:60", out result), "#E2");
#if NET_4_0
Assert.AreEqual (true, TimeSpan.TryParse ("0001:0002:0003.12 ", out result), "#F1");
#else
Assert.AreEqual (true, TimeSpan.TryParse ("0001:0002:0003.12 ", out result), "#F1");
Assert.AreEqual ("01:02:03.1200000", result.ToString (), "#F2");
#endif
Assert.AreEqual (false, TimeSpan.TryParse (" 1:2:3:12345678 ", out result), "#G1");
@@ -835,7 +812,6 @@ public class TimeSpanTest {
Assert.AreEqual (true, TimeSpan.TryParse ("-10675199.02:48:05.4775808", out result), "MinValue#1");
Assert.AreEqual (TimeSpan.MinValue, result, "MinValue#2");
#if NET_4_0
// Force the use of french culture -which is using a non common NumberDecimalSeparator-
// as current culture, to show that the Parse method is *actually* being culture sensitive
CultureInfo french_culture = CultureInfo.GetCultureInfo ("fr-FR");
@@ -849,7 +825,6 @@ public class TimeSpanTest {
// restore culture
Thread.CurrentThread.CurrentCulture = prev_culture;
}
#endif
}
[Test]
@@ -862,7 +837,6 @@ public class TimeSpanTest {
Assert.AreEqual (false, TimeSpan.TryParse ("-10675199.02:48:05.4775809", out result), "UnderMinValue");
}
#if NET_4_0
[Test]
public void TryParseOverloads ()
{
@@ -1341,7 +1315,6 @@ public class TimeSpanTest {
{
}
}
#endif
}
}

View File

@@ -28,6 +28,7 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Collections;
using System.Reflection;
@@ -38,6 +39,31 @@ namespace MonoTests.System
{
public class TimeZoneInfoTest
{
static FieldInfo localField;
static FieldInfo cachedDataField;
static object localFieldObj;
public static void SetLocal (TimeZoneInfo val)
{
if (localField == null) {
if (Type.GetType ("Mono.Runtime") != null) {
localField = typeof (TimeZoneInfo).GetField ("local",
BindingFlags.Static | BindingFlags.GetField | BindingFlags.NonPublic);
} else {
cachedDataField = typeof (TimeZoneInfo).GetField ("s_cachedData",
BindingFlags.Static | BindingFlags.GetField | BindingFlags.NonPublic);
localField = cachedDataField.FieldType.GetField ("m_localTimeZone",
BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic);
}
}
if (cachedDataField != null)
localFieldObj = cachedDataField.GetValue (null);
localField.SetValue (localFieldObj, val);
}
[TestFixture]
public class PropertiesTests
{
@@ -50,6 +76,28 @@ namespace MonoTests.System
Assert.IsNotNull (local);
Assert.IsTrue (true);
}
[DllImport ("libc")]
private static extern int readlink (string path, byte[] buffer, int buflen);
[Test] // Covers #24958
public void LocalId ()
{
byte[] buf = new byte [512];
var path = "/etc/localtime";
try {
var ret = readlink (path, buf, buf.Length);
if (ret == -1)
return; // path is not a symbolic link, nothing to test
} catch (DllNotFoundException e) {
return;
}
#if !MONOTOUCH && !XAMMAC
// this assumption is incorrect for iOS, tvO, watchOS and OSX
Assert.IsTrue (TimeZoneInfo.Local.Id != "Local", "Local timezone id should not be \"Local\"");
#endif
}
}
[TestFixture]
@@ -313,6 +361,27 @@ namespace MonoTests.System
}
}
[TestFixture]
public class ConvertTimeTests_LocalUtc : ConvertTimeTests
{
static TimeZoneInfo oldLocal;
[SetUp]
public void SetLocal ()
{
base.CreateTimeZones ();
oldLocal = TimeZoneInfo.Local;
TimeZoneInfoTest.SetLocal (TimeZoneInfo.Utc);
}
[TearDown]
public void RestoreLocal ()
{
TimeZoneInfoTest.SetLocal (oldLocal);
}
}
[TestFixture]
public class ConvertTimeTests
{
@@ -445,20 +514,29 @@ namespace MonoTests.System
Assert.AreEqual (res.Kind, DateTimeKind.Utc, "#2");
}
[Test]
public void ConvertFromToUtc_Utc ()
{
DateTime utc = DateTime.UtcNow;
Assert.AreEqual (utc.Kind, DateTimeKind.Utc);
DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, TimeZoneInfo.Utc);
Assert.AreEqual (DateTimeKind.Utc, converted.Kind);
DateTime back = TimeZoneInfo.ConvertTimeToUtc (converted, TimeZoneInfo.Utc);
Assert.AreEqual (back.Kind, DateTimeKind.Utc);
Assert.AreEqual (utc, back);
}
[Test]
public void ConvertFromToLocal ()
{
DateTime utc = DateTime.UtcNow;
Assert.AreEqual(utc.Kind, DateTimeKind.Utc);
DateTime converted = TimeZoneInfo.ConvertTimeFromUtc(utc, TimeZoneInfo.Local);
#if NET_4_0
Assert.AreEqual(DateTimeKind.Local, converted.Kind);
#else
Assert.AreEqual(DateTimeKind.Unspecified, converted.Kind);
#endif
DateTime back = TimeZoneInfo.ConvertTimeToUtc(converted, TimeZoneInfo.Local);
Assert.AreEqual(back.Kind, DateTimeKind.Utc);
Assert.AreEqual(utc, back);
Assert.AreEqual (utc.Kind, DateTimeKind.Utc);
DateTime converted = TimeZoneInfo.ConvertTimeFromUtc (utc, TimeZoneInfo.Local);
var expectedKind = (TimeZoneInfo.Local == TimeZoneInfo.Utc)? DateTimeKind.Utc : DateTimeKind.Local;
Assert.AreEqual (expectedKind, converted.Kind);
DateTime back = TimeZoneInfo.ConvertTimeToUtc (converted, TimeZoneInfo.Local);
Assert.AreEqual (back.Kind, DateTimeKind.Utc);
Assert.AreEqual (utc, back);
}
[Test]
@@ -492,8 +570,9 @@ namespace MonoTests.System
sdt = new DateTime (2014, 1, 9, 23, 0, 0);
ddt = TimeZoneInfo.ConvertTime (sdt, TimeZoneInfo.Local);
Assert.AreEqual (ddt.Kind, sdt.Kind, "#3.1");
Assert.AreEqual (ddt.Kind, DateTimeKind.Unspecified, "#3.2");
var expectedKind = (TimeZoneInfo.Local == TimeZoneInfo.Utc)? DateTimeKind.Utc : sdt.Kind;
Assert.AreEqual (expectedKind, ddt.Kind, "#3.1");
Assert.AreEqual (DateTimeKind.Unspecified, sdt.Kind, "#3.2");
}
[Test]
@@ -694,6 +773,15 @@ namespace MonoTests.System
}
Assert.Fail ("Europe/Brussels not found in SystemTZ");
}
[Test]
public void ReflectionReturnsTheCorrectMethod ()
{
var method = (MethodInfo) typeof (TimeZoneInfo).GetMember ("GetSystemTimeZones", MemberTypes.Method, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)[0];
var timeZones = (global::System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo>) method.Invoke (null, null);
Assert.IsTrue (timeZones.Count > 0, "GetSystemTimeZones should not return an empty collection.");
}
}
[TestFixture]
@@ -1068,7 +1156,7 @@ namespace MonoTests.System
{
foreach (var tz in TimeZoneInfo.GetSystemTimeZones ()) {
try {
for (var year = 1950; year <= DateTime.Now.Year; year++)
for (var year = 1950; year <= 2051; year++)
getChanges.Invoke (tz, new object [] {year} );
} catch (Exception e) {
Assert.Fail ("TimeZone " + tz.Id + " exception: " + e.ToString ());

Some files were not shown because too many files have changed in this diff Show More