diff options
Diffstat (limited to 'mcs/class/corlib/Test')
38 files changed, 1336 insertions, 165 deletions
diff --git a/mcs/class/corlib/Test/Microsoft.Win32/RegistryKeyTest.cs b/mcs/class/corlib/Test/Microsoft.Win32/RegistryKeyTest.cs index a2c030c0c9..3bffaf3b83 100644..100755 --- a/mcs/class/corlib/Test/Microsoft.Win32/RegistryKeyTest.cs +++ b/mcs/class/corlib/Test/Microsoft.Win32/RegistryKeyTest.cs @@ -2201,6 +2201,8 @@ namespace MonoTests.Microsoft.Win32 } [Test] + // This hangs on windows + [Category ("NotWorking")] public void OpenRemoteBaseKey_MachineName_DoesNotExist () { // access to registry of remote machines is not implemented on unix diff --git a/mcs/class/corlib/Test/System.Collections.Generic/ListTest.cs b/mcs/class/corlib/Test/System.Collections.Generic/ListTest.cs index cb5b9f7cf1..9ac58e0fdd 100644 --- a/mcs/class/corlib/Test/System.Collections.Generic/ListTest.cs +++ b/mcs/class/corlib/Test/System.Collections.Generic/ListTest.cs @@ -30,8 +30,6 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -#if NET_2_0 - using System; using System.Collections; using System.Collections.Generic; @@ -286,6 +284,10 @@ namespace MonoTests.System.Collections.Generic { Assert.AreEqual (l1.Count, l1.Capacity); for (int i = 0; i < l1.Count; i++) Assert.AreEqual (_list1 [i], l1 [i]); + + var input = new [] { "a", "b", "c" }; + var l2 = new List<string>(input); + Assert.AreEqual (3, l2.Capacity); } [Test, ExpectedException (typeof (ArgumentNullException))] @@ -555,12 +557,55 @@ namespace MonoTests.System.Collections.Generic { i = _list1.FindIndex (FindMultipleOfTwelve); Assert.AreEqual (-1, i); + + var a = new List<int> () { 2, 2, 2, 3, 2 }; + Assert.AreEqual (2, a.FindIndex (2, 2, l => true)); } - [Test, ExpectedException (typeof (ArgumentNullException))] - public void FindIndexNullTest () + [Test] + public void FindIndex_Invalid () { - int i = _list1.FindIndex (null); + try { + _list1.FindIndex (null); + Assert.Fail ("#1"); + } catch (ArgumentNullException) { + } + + try { + _list1.FindIndex (-1, l => true); + Assert.Fail ("#2"); + } catch (ArgumentOutOfRangeException) { + } + + try { + _list1.FindIndex (-1, 0, l => true); + Assert.Fail ("#2b"); + } catch (ArgumentOutOfRangeException) { + } + + try { + _list1.FindIndex (0, -1, l => true); + Assert.Fail ("#3"); + } catch (ArgumentOutOfRangeException) { + } + + try { + _list1.FindIndex (100, l => true); + Assert.Fail ("#4"); + } catch (ArgumentOutOfRangeException) { + } + + try { + _list1.FindIndex (100, 0, l => true); + Assert.Fail ("#4b"); + } catch (ArgumentOutOfRangeException) { + } + + try { + _list1.FindIndex (7, 2, l => true); + Assert.Fail ("#5"); + } catch (ArgumentOutOfRangeException) { + } } [Test] @@ -579,8 +624,6 @@ namespace MonoTests.System.Collections.Generic { int i = _list1.FindLast (null); } - // FIXME currently generates Invalid IL Code error - /* [Test] public void ForEachTest () { @@ -589,7 +632,7 @@ namespace MonoTests.System.Collections.Generic { Assert.AreEqual (418, i); } - */ + [Test] public void FindLastIndexTest () { @@ -601,12 +644,56 @@ namespace MonoTests.System.Collections.Generic { i = _list1.FindIndex (FindMultipleOfTwelve); Assert.AreEqual (-1, i); + + Assert.AreEqual (2, _list1.FindLastIndex (2, 3, l => true)); + Assert.AreEqual (2, _list1.FindLastIndex (2, 2, l => true)); + Assert.AreEqual (1, _list1.FindLastIndex (1, 2, l => true)); } - [Test, ExpectedException (typeof (ArgumentNullException))] - public void FindLastIndexNullTest () + [Test] + public void FindLastIndex_Invalid () { - int i = _list1.FindLastIndex (null); + try { + _list1.FindLastIndex (null); + Assert.Fail ("#1"); + } catch (ArgumentNullException) { + } + + try { + _list1.FindLastIndex (-1, l => true); + Assert.Fail ("#2"); + } catch (ArgumentOutOfRangeException) { + } + + try { + _list1.FindLastIndex (-1, 0, l => true); + Assert.Fail ("#2b"); + } catch (ArgumentOutOfRangeException) { + } + + try { + _list1.FindLastIndex (0, -1, l => true); + Assert.Fail ("#3"); + } catch (ArgumentOutOfRangeException) { + } + + try { + _list1.FindLastIndex (100, l => true); + Assert.Fail ("#4"); + } catch (ArgumentOutOfRangeException) { + } + + try { + _list1.FindLastIndex (100, 0, l => true); + Assert.Fail ("#4b"); + } catch (ArgumentOutOfRangeException) { + } + + try { + _list1.FindLastIndex (2, 4, l => true); + Assert.Fail ("#5"); + } catch (ArgumentOutOfRangeException) { + } } [Test] @@ -1464,5 +1551,4 @@ namespace MonoTests.System.Collections.Generic { } } -#endif diff --git a/mcs/class/corlib/Test/System.Diagnostics/DebuggerDisplayAttributeTest.cs b/mcs/class/corlib/Test/System.Diagnostics/DebuggerDisplayAttributeTest.cs index 3dbcccdf29..5564e47a36 100644 --- a/mcs/class/corlib/Test/System.Diagnostics/DebuggerDisplayAttributeTest.cs +++ b/mcs/class/corlib/Test/System.Diagnostics/DebuggerDisplayAttributeTest.cs @@ -1,5 +1,5 @@ // -// MonoTests.System.Diagnostics.DebuggerDisplayAttributeTest.cs +// DebuggerDisplayAttributeTest.cs // // Author: // Rolf Bjarne Kvinge (RKvinge@novell.com) @@ -7,8 +7,6 @@ // (C) 2007 // -#if NET_2_0 - using System; using System.Diagnostics; using NUnit.Framework; @@ -172,5 +170,3 @@ namespace MonoTests.System.Diagnostics } } } - -#endif
\ No newline at end of file diff --git a/mcs/class/corlib/Test/System.Diagnostics/DebuggerTypeProxyAttribute.cs b/mcs/class/corlib/Test/System.Diagnostics/DebuggerTypeProxyAttribute.cs new file mode 100644 index 0000000000..bd3297d3cb --- /dev/null +++ b/mcs/class/corlib/Test/System.Diagnostics/DebuggerTypeProxyAttribute.cs @@ -0,0 +1,56 @@ +// +// DecoupledTask.cs +// +// Authors: +// Marek Safar <marek.safar@gmail.com> +// +// Copyright 2013 Xamarin Inc (http://www.xamarin.com). +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// + +using System; +using System.Diagnostics; +using NUnit.Framework; + +namespace MonoTests.System.Diagnostics +{ + [TestFixture] + public class DebuggerTypeProxyAttributeTest + { + [Test] + public void Constructor_Type () + { + var dtp = new DebuggerTypeProxyAttribute (typeof (string)); + Assert.IsNull (dtp.Target, "#1"); + Assert.AreEqual (typeof (string).AssemblyQualifiedName, dtp.ProxyTypeName, "#2"); + } + + [Test] + public void Constructor_Type_Invalid () + { + try { + new DebuggerTypeProxyAttribute (null as Type); + Assert.Fail (); + } catch (ArgumentNullException) { + } + } + } +} diff --git a/mcs/class/corlib/Test/System.Diagnostics/StackFrameTest.cs b/mcs/class/corlib/Test/System.Diagnostics/StackFrameTest.cs index 033cc08539..0f7646b036 100644 --- a/mcs/class/corlib/Test/System.Diagnostics/StackFrameTest.cs +++ b/mcs/class/corlib/Test/System.Diagnostics/StackFrameTest.cs @@ -42,6 +42,7 @@ namespace MonoTests.System.Diagnostics /// Tests whether getting file name works. /// </summary> [Test] + [Category("LLVMNotWorking")] public void TestGetFileName () { Assert.AreEqual ("dir/someFile", @@ -57,6 +58,7 @@ namespace MonoTests.System.Diagnostics /// Tests whether getting file line number works. /// </summary> [Test] + [Category("LLVMNotWorking")] public void TestGetFileLineNumber () { Assert.AreEqual (13, @@ -152,6 +154,7 @@ namespace MonoTests.System.Diagnostics } [Test] + [Category ("LLVMNotWorking")] public void TestGetFileName2 () { Assert.IsNotNull (frame2.GetFileName (), "File name not null"); @@ -164,13 +167,14 @@ namespace MonoTests.System.Diagnostics /// Tests whether getting file line number works. /// </summary> [Test] + [Category ("LLVMNotWorking")] public void TestGetFileLineNumber () { Assert.AreEqual (0, frame1.GetFileLineNumber (), "Line number (1)"); - Assert.AreEqual (132, + Assert.AreEqual (134, frame2.GetFileLineNumber (), "Line number (2)"); @@ -280,6 +284,7 @@ namespace MonoTests.System.Diagnostics /// Tests whether getting file name works. /// </summary> [Test] + [Category ("LLVMNotWorking")] public void TestGetFileName () { Assert.IsNull (frame1.GetFileName (), @@ -299,13 +304,14 @@ namespace MonoTests.System.Diagnostics #if ONLY_1_1 [Category ("NotDotNet")] // .NET 1.1 is off by one #endif + [Category ("LLVMNotWorking")] public void TestGetFileLineNumber () { Assert.AreEqual (0, frame1.GetFileLineNumber (), "Line number (1)"); - Assert.AreEqual (260, + Assert.AreEqual (264, frame2.GetFileLineNumber (), "Line number (2)"); } diff --git a/mcs/class/corlib/Test/System.Globalization/CultureInfoTest.cs b/mcs/class/corlib/Test/System.Globalization/CultureInfoTest.cs index 7714f53ab3..45fd5d0e99 100644 --- a/mcs/class/corlib/Test/System.Globalization/CultureInfoTest.cs +++ b/mcs/class/corlib/Test/System.Globalization/CultureInfoTest.cs @@ -599,5 +599,122 @@ namespace MonoTests.System.Globalization // https://bugzilla.xamarin.com/show_bug.cgi?id=3471 new CultureInfo ("en-HK"); } + +#if NET_4_5 + CountdownEvent barrier = new CountdownEvent (3); + AutoResetEvent[] evt = new AutoResetEvent [] { new AutoResetEvent (false), new AutoResetEvent (false), new AutoResetEvent (false)}; + + CultureInfo[] initial_culture = new CultureInfo[3]; + CultureInfo[] changed_culture = new CultureInfo[3]; + CultureInfo[] changed_culture2 = new CultureInfo[3]; + CultureInfo alternative_culture = new CultureInfo("pt-BR"); + + void StepAllPhases (int index) + { + initial_culture [index] = CultureInfo.CurrentCulture; + /*Phase 1 - we witness the original value */ + barrier.Signal (); + + /*Phase 2 - main thread changes culture */ + evt [index].WaitOne (); + + /*Phase 3 - we witness the new value */ + changed_culture [index] = CultureInfo.CurrentCulture; + barrier.Signal (); + + /* Phase 4 - main thread changes culture back */ + evt [index].WaitOne (); + + /*Phase 5 - we witness the new value */ + changed_culture2 [index] = CultureInfo.CurrentCulture; + barrier.Signal (); + } + + void ThreadWithoutChange () { + StepAllPhases (0); + } + + void ThreadWithChange () { + Thread.CurrentThread.CurrentCulture = alternative_culture; + StepAllPhases (1); + } + + void ThreadPoolWithoutChange () { + StepAllPhases (2); + } + + [Test] + public void DefaultThreadCurrentCulture () { + var orig_culture = CultureInfo.CurrentCulture; + var new_culture = new CultureInfo("fr-FR"); + + // The test doesn't work if the current culture is already set + if (orig_culture != CultureInfo.InvariantCulture) + return; + + /* Phase 0 - warm up */ + new Thread (ThreadWithoutChange).Start (); + new Thread (ThreadWithChange).Start (); + Action x = ThreadPoolWithoutChange; + x.BeginInvoke (null, null); + + /* Phase 1 - let everyone witness initial values */ + initial_culture [0] = CultureInfo.CurrentCulture; + barrier.Wait (); + barrier.Reset (); + + /* Phase 2 - change the default culture*/ + CultureInfo.DefaultThreadCurrentCulture = new_culture; + evt [0].Set (); + evt [1].Set (); + evt [2].Set (); + /* Phase 3 - let everyone witness the new value */ + changed_culture [0] = CultureInfo.CurrentCulture; + barrier.Wait (); + barrier.Reset (); + + /* Phase 4 - revert the default culture back to null */ + CultureInfo.DefaultThreadCurrentCulture = null; + evt [0].Set (); + evt [1].Set (); + evt [2].Set (); + + /* Phase 5 - let everyone witness the new value */ + changed_culture2 [0] = CultureInfo.CurrentCulture; + barrier.Wait (); + barrier.Reset (); + + CultureInfo.DefaultThreadCurrentCulture = null; + + Assert.AreEqual (orig_culture, initial_culture [0], "#2"); + Assert.AreEqual (alternative_culture, initial_culture [1], "#3"); + Assert.AreEqual (orig_culture, initial_culture [2], "#4"); + + Assert.AreEqual (new_culture, changed_culture [0], "#6"); + Assert.AreEqual (alternative_culture, changed_culture [1], "#7"); + Assert.AreEqual (new_culture, changed_culture [2], "#8"); + + Assert.AreEqual (orig_culture, changed_culture2 [0], "#10"); + Assert.AreEqual (alternative_culture, changed_culture2 [1], "#11"); + Assert.AreEqual (orig_culture, changed_culture2 [2], "#12"); + } + + [Test] + public void DefaultThreadCurrentCultureAndNumberFormaters () { + string us_str = null; + string br_str = null; + var thread = new Thread (() => { + CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US"); + us_str = 100000.ToString ("C"); + CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("pt-BR"); + br_str = 100000.ToString ("C"); + }); + thread.Start (); + thread.Join (); + CultureInfo.DefaultThreadCurrentCulture = null; + Assert.AreEqual ("$100,000.00", us_str, "#1"); + Assert.AreEqual ("R$ 100.000,00", br_str, "#2"); + } +#endif } } diff --git a/mcs/class/corlib/Test/System.Globalization/DateTimeFormatInfoTest.cs b/mcs/class/corlib/Test/System.Globalization/DateTimeFormatInfoTest.cs index d3d388f670..e0230b788a 100644 --- a/mcs/class/corlib/Test/System.Globalization/DateTimeFormatInfoTest.cs +++ b/mcs/class/corlib/Test/System.Globalization/DateTimeFormatInfoTest.cs @@ -94,11 +94,11 @@ namespace MonoTests.System.Globalization { CultureInfo ci = new CultureInfo ("es-ES"); DateTimeFormatInfo di = ci.DateTimeFormat; - Assert.AreEqual ("dddd, dd' de 'MMMM' de 'yyyy", di.LongDatePattern, "#1"); + Assert.AreEqual ("dddd, d' de 'MMMM' de 'yyyy", di.LongDatePattern, "#1"); Assert.AreEqual ("H:mm:ss", di.LongTimePattern, "#2"); - Assert.AreEqual ("dddd, dd' de 'MMMM' de 'yyyy H:mm:ss", di.FullDateTimePattern, "#3"); + Assert.AreEqual ("dddd, d' de 'MMMM' de 'yyyy H:mm:ss", di.FullDateTimePattern, "#3"); Assert.AreEqual ("MMMM' de 'yyyy", di.YearMonthPattern, "#4"); - Assert.AreEqual ("dd MMMM", di.MonthDayPattern, "#5"); + Assert.AreEqual ("d' de 'MMMM", di.MonthDayPattern, "#5"); } [Test] diff --git a/mcs/class/corlib/Test/System.Globalization/NumberFormatInfoTest.cs b/mcs/class/corlib/Test/System.Globalization/NumberFormatInfoTest.cs new file mode 100644 index 0000000000..a195c28f72 --- /dev/null +++ b/mcs/class/corlib/Test/System.Globalization/NumberFormatInfoTest.cs @@ -0,0 +1,57 @@ +// +// NumberFormatInfoTest.cs +// +// Authors: +// Marek Safar (marek.safar@gmail.com) +// +// Copyright (C) 2013 Xamarin Inc (http://www.xamarin.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + + +using NUnit.Framework; +using System; +using System.Globalization; + +namespace MonoTests.System.Globalization +{ + [TestFixture] + public class NumberFormatInfoTest + { + [Test] + public void CurrencyDecimalDigits () + { + CultureInfo c; + + c = CultureInfo.GetCultureInfo ("id-ID"); + Assert.AreEqual (0, c.NumberFormat.CurrencyDecimalDigits, "#1"); + + c = CultureInfo.GetCultureInfo ("is-IS"); + Assert.AreEqual (0, c.NumberFormat.CurrencyDecimalDigits, "#2"); + + c = CultureInfo.InvariantCulture; + Assert.AreEqual (2, c.NumberFormat.CurrencyDecimalDigits, "#3"); + + } + } +} + + diff --git a/mcs/class/corlib/Test/System.Globalization/TextInfoTest.cs b/mcs/class/corlib/Test/System.Globalization/TextInfoTest.cs index 5113cc5e98..9629dacf4b 100644 --- a/mcs/class/corlib/Test/System.Globalization/TextInfoTest.cs +++ b/mcs/class/corlib/Test/System.Globalization/TextInfoTest.cs @@ -24,10 +24,11 @@ public class TextInfoTest { { TextInfo ti = new CultureInfo ("en-US", false).TextInfo; - Assert.AreEqual (" The Dog", ti.ToTitleCase (" the dog")); - Assert.AreEqual (" The Dude", ti.ToTitleCase (" The Dude")); - Assert.AreEqual ("La Guerra Yla Paz", ti.ToTitleCase ("la Guerra yLa pAz")); - Assert.AreEqual ("\tTab\tAnd\tPeace", ti.ToTitleCase ("\ttab\taNd\tpeaCE")); + Assert.AreEqual (" The Dog", ti.ToTitleCase (" the dog"), "#1"); + Assert.AreEqual (" The Dude", ti.ToTitleCase (" The Dude"), "#2"); + Assert.AreEqual ("La Guerra Yla Paz", ti.ToTitleCase ("la Guerra yLa pAz"), "#3"); + Assert.AreEqual ("\tTab\tAnd\tPeace", ti.ToTitleCase ("\ttab\taNd\tpeaCE"), "#4"); + Assert.AreEqual ("This_Is\uFE58A\u0095String\u06D4With\uFE33Separators", ti.ToTitleCase ("this_is\uFE58a\u0095string\u06D4with\uFE33separators"), "#5"); } [Test] diff --git a/mcs/class/corlib/Test/System.IO/FileTest.cs b/mcs/class/corlib/Test/System.IO/FileTest.cs index 6267439aed..112978ae8b 100644 --- a/mcs/class/corlib/Test/System.IO/FileTest.cs +++ b/mcs/class/corlib/Test/System.IO/FileTest.cs @@ -2760,5 +2760,53 @@ namespace MonoTests.System.IO } } #endif + + void MoveTest (FileAccess acc, FileShare share, bool works) + { + var file = "kk597rfdnllh89"; + + File.Delete (file + ".old"); + using (var v = File.Create (file)) { } + + using (var stream = new FileStream(file, FileMode.Open, acc, share, 4096, FileOptions.SequentialScan)) { + try { + File.Move(file, file + ".old"); + if (!works) + Assert.Fail ("Move with ({0}) and ({1}) did not fail", acc, share); + } catch (IOException) { + if (works) + Assert.Fail ("Move with ({0}) and ({1}) did fail", acc, share); + } + } + } + + [Test] + public void MoveTest () + { + MoveTest (FileAccess.Read, FileShare.None, false); + MoveTest (FileAccess.Read, FileShare.Read, false); + MoveTest (FileAccess.Read, FileShare.Write, false); + MoveTest (FileAccess.Read, FileShare.ReadWrite, false); + MoveTest (FileAccess.Read, FileShare.Delete, true); + MoveTest (FileAccess.Read, FileShare.Read | FileShare.Delete, true); + MoveTest (FileAccess.Read, FileShare.Write | FileShare.Delete, true); + MoveTest (FileAccess.Read, FileShare.ReadWrite | FileShare.Delete, true); + MoveTest (FileAccess.Write, FileShare.None, false); + MoveTest (FileAccess.Write, FileShare.Read, false); + MoveTest (FileAccess.Write, FileShare.Write, false); + MoveTest (FileAccess.Write, FileShare.ReadWrite, false); + MoveTest (FileAccess.Write, FileShare.Delete, true); + MoveTest (FileAccess.Write, FileShare.Read | FileShare.Delete, true); + MoveTest (FileAccess.Write, FileShare.Write | FileShare.Delete, true); + MoveTest (FileAccess.Write, FileShare.ReadWrite | FileShare.Delete, true); + MoveTest (FileAccess.ReadWrite, FileShare.None, false); + MoveTest (FileAccess.ReadWrite, FileShare.Read, false); + MoveTest (FileAccess.ReadWrite, FileShare.Write, false); + MoveTest (FileAccess.ReadWrite, FileShare.ReadWrite, false); + MoveTest (FileAccess.ReadWrite, FileShare.Delete, true); + MoveTest (FileAccess.ReadWrite, FileShare.Read | FileShare.Delete, true); + MoveTest (FileAccess.ReadWrite, FileShare.Write | FileShare.Delete, true); + MoveTest (FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete, true); + } } } diff --git a/mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs b/mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs index 692a735950..7953d46250 100644 --- a/mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs +++ b/mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs @@ -11074,5 +11074,53 @@ namespace MonoTests.System.Reflection.Emit Activator.CreateInstance (t, new object[] { "string"}); } + public interface IFace16096 { + object Bar (); + } + + [Test] + public void MemberRef_Caching_16096 () { + var outer_class = module.DefineType( + "container", + TypeAttributes.Class | TypeAttributes.Public, + typeof(object)); + + var builder = outer_class.DefineNestedType( + "bind@32-1", + TypeAttributes.Class | TypeAttributes.Public, + typeof(object)); + + builder.AddInterfaceImplementation (typeof (IFace16096)); + + var ctor = builder.DefineDefaultConstructor (MethodAttributes.Public); + var field = builder.DefineField ("Field", typeof (object), FieldAttributes.Public); + var g_args = builder.DefineGenericParameters("b","a"); + var method = builder.DefineMethod ("Bar", MethodAttributes.Public | MethodAttributes.Virtual, typeof (object), new Type [0]); + + var il = method.GetILGenerator(); + il.Emit (OpCodes.Ldarg_0); + il.Emit (OpCodes.Ldfld, TypeBuilder.GetField (builder.MakeGenericType (g_args), field)); + il.Emit (OpCodes.Pop); + il.Emit (OpCodes.Newobj, TypeBuilder.GetConstructor (builder.MakeGenericType (g_args), ctor)); + il.Emit (OpCodes.Ret); + + var type = builder.CreateType (); + + /*Build a gshared instance. */ + var ginst = type.MakeGenericType (typeof (List<char>), typeof (object)); + var ins = (IFace16096)Activator.CreateInstance (ginst); + + /* This will trigger the runtime to cache the MEMBER_REF to the .ctor as it won't have a context. */ + var ins2 = ins.Bar (); + Assert.IsNotNull (ins2); + + /* Build an unsharable version. */ + var ginst2 = type.MakeGenericType (typeof (List<char>), typeof (char)); + var ins3 = (IFace16096)Activator.CreateInstance (ginst2); + + /* This will trigger the runtime to use the cached version, which is wrong as it's an open type. */ + var ins4 = ins3.Bar (); + Assert.IsNotNull (ins4); + } } } diff --git a/mcs/class/corlib/Test/System.Reflection/AssemblyNameTest.cs b/mcs/class/corlib/Test/System.Reflection/AssemblyNameTest.cs index fc36438b45..0e26ea1770 100644 --- a/mcs/class/corlib/Test/System.Reflection/AssemblyNameTest.cs +++ b/mcs/class/corlib/Test/System.Reflection/AssemblyNameTest.cs @@ -1177,9 +1177,7 @@ public class AssemblyNameTest { Assert.AreEqual (an.HashAlgorithm, clone.HashAlgorithm, "HashAlgorithm"); Assert.AreEqual (an.KeyPair, clone.KeyPair, "KeyPair"); Assert.AreEqual (an.Name, clone.Name, "Name"); -#if NET_2_0 - Assert.AreEqual (an.ProcessorArchitecture, clone.ProcessorArchitecture, "PA"); -#endif + //Assert.AreEqual (an.ProcessorArchitecture, clone.ProcessorArchitecture, "PA"); Assert.AreEqual (an.Version, clone.Version, "Version"); Assert.AreEqual (an.VersionCompatibility, clone.VersionCompatibility, "VersionCompatibility"); Assert.AreEqual (an.GetPublicKey (), clone.GetPublicKey (), "GetPublicKey"); diff --git a/mcs/class/corlib/Test/System.Reflection/ParameterInfoTest.cs b/mcs/class/corlib/Test/System.Reflection/ParameterInfoTest.cs index ff1d915632..b22f46f365 100644 --- a/mcs/class/corlib/Test/System.Reflection/ParameterInfoTest.cs +++ b/mcs/class/corlib/Test/System.Reflection/ParameterInfoTest.cs @@ -98,6 +98,15 @@ namespace MonoTests.System.Reflection Assert.AreEqual (ParamEnum.Foo, info [5].DefaultValue, "#2"); } +#if NET_4_5 + [Test] + public void HasDefaultValueEnum () { + ParameterInfo[] info = typeof (ParameterInfoTest).GetMethod ("paramMethod").GetParameters (); + + Assert.IsTrue (info [5].HasDefaultValue); + } +#endif + public static void Sample2 ([DecimalConstantAttribute(2,2,2,2,2)] decimal a, [DateTimeConstantAttribute(123456)] DateTime b) {} [Test] @@ -117,7 +126,19 @@ namespace MonoTests.System.Reflection Assert.AreEqual (pi [1].DefaultValue.GetType (), typeof (Missing), "#2"); } - public void Sample (int a, [Optional] int b) +#if NET_4_5 + [Test] + public void TestHasDefaultValues () + { + ParameterInfo [] pi = typeof (ParameterInfoTest).GetMethod ("Sample").GetParameters (); + + Assert.IsFalse (pi [0].HasDefaultValue, "#1"); + Assert.IsFalse (pi [1].HasDefaultValue, "#2"); + Assert.IsTrue (pi [2].HasDefaultValue, "#3"); + } +#endif + + public void Sample (int a, [Optional] int b, object c = null) { } @@ -235,6 +256,14 @@ namespace MonoTests.System.Reflection Assert.AreEqual (decimal.MaxValue, info [0].DefaultValue); } +#if NET_4_5 + [Test] + public void HasDefaultValueDecimal () { + var info = typeof (ParameterInfoTest).GetMethod ("TestC").GetParameters (); + Assert.IsTrue (info [0].HasDefaultValue); + } +#endif + class MyParameterInfo2 : ParameterInfo { public ParameterAttributes MyAttrsImpl; diff --git a/mcs/class/corlib/Test/System.Runtime.CompilerServices/TaskAwaiterTest.cs b/mcs/class/corlib/Test/System.Runtime.CompilerServices/TaskAwaiterTest.cs index 48f629adfa..18b2099b8d 100644 --- a/mcs/class/corlib/Test/System.Runtime.CompilerServices/TaskAwaiterTest.cs +++ b/mcs/class/corlib/Test/System.Runtime.CompilerServices/TaskAwaiterTest.cs @@ -33,12 +33,45 @@ using System.Threading; using System.Threading.Tasks; using NUnit.Framework; using System.Runtime.CompilerServices; +using System.Collections.Generic; namespace MonoTests.System.Runtime.CompilerServices { [TestFixture] public class TaskAwaiterTest { + class Scheduler : TaskScheduler + { + string name; + + public Scheduler (string name) + { + this.name = name; + } + + public int InlineCalls { get; set; } + public int QueueCalls { get; set; } + + protected override IEnumerable<Task> GetScheduledTasks () + { + throw new NotImplementedException (); + } + + protected override void QueueTask (Task task) + { + ++QueueCalls; + ThreadPool.QueueUserWorkItem (o => { + TryExecuteTask (task); + }); + } + + protected override bool TryExecuteTaskInline (Task task, bool taskWasPreviouslyQueued) + { + ++InlineCalls; + return false; + } + } + [Test] public void GetResultFaulted () { @@ -85,6 +118,72 @@ namespace MonoTests.System.Runtime.CompilerServices awaiter.GetResult (); Assert.AreEqual (TaskStatus.RanToCompletion, task.Status); } + + [Test] + public void CustomScheduler () + { + // some test runners (e.g. Touch.Unit) will execute this on the main thread and that would lock them + if (!Thread.CurrentThread.IsBackground) + return; + + var a = new Scheduler ("a"); + var b = new Scheduler ("b"); + + var t = TestCS (a, b); + Assert.IsTrue (t.Wait (3000), "#0"); + Assert.AreEqual (0, t.Result, "#1"); + Assert.AreEqual (1, a.InlineCalls, "#2a"); + Assert.AreEqual (0, b.InlineCalls, "#2b"); + Assert.AreEqual (2, a.QueueCalls, "#3a"); + Assert.AreEqual (1, b.QueueCalls, "#3b"); + } + + static async Task<int> TestCS (TaskScheduler schedulerA, TaskScheduler schedulerB) + { + var res = await Task.Factory.StartNew (async () => { + if (TaskScheduler.Current != schedulerA) + return 1; + + await Task.Factory.StartNew ( + () => { + if (TaskScheduler.Current != schedulerB) + return 2; + + return 0; + }, CancellationToken.None, TaskCreationOptions.None, schedulerB); + + if (TaskScheduler.Current != schedulerA) + return 3; + + return 0; + }, CancellationToken.None, TaskCreationOptions.None, schedulerA); + + return res.Result; + } + + [Test] + public void FinishedTaskOnCompleted () + { + var mres = new ManualResetEvent (false); + var mres2 = new ManualResetEvent (false); + + var tcs = new TaskCompletionSource<object> (); + tcs.SetResult (null); + var task = tcs.Task; + + var awaiter = task.GetAwaiter (); + Assert.IsTrue (awaiter.IsCompleted, "#1"); + + awaiter.OnCompleted(() => { + if (mres.WaitOne (1000)) + mres2.Set (); + }); + + mres.Set (); + // this will only terminate correctly if the test was not executed from the main thread + // e.g. Touch.Unit defaults to run tests on the main thread and this will return false + Assert.AreEqual (Thread.CurrentThread.IsBackground, mres2.WaitOne (2000), "#2");; + } } } diff --git a/mcs/class/corlib/Test/System.Security.Principal/WindowsIdentityTest.cs b/mcs/class/corlib/Test/System.Security.Principal/WindowsIdentityTest.cs index d3a1e2de3c..4c84824c91 100644 --- a/mcs/class/corlib/Test/System.Security.Principal/WindowsIdentityTest.cs +++ b/mcs/class/corlib/Test/System.Security.Principal/WindowsIdentityTest.cs @@ -213,9 +213,6 @@ namespace MonoTests.System.Security.Principal { } [Test] -#if __IOS__ - [Ignore ("https://bugzilla.xamarin.com/show_bug.cgi?id=12789")] -#endif public void SerializeRoundTrip () { WindowsIdentity wi = WindowsIdentity.GetCurrent (); diff --git a/mcs/class/corlib/Test/System.Text/UTF8EncodingTest.cs b/mcs/class/corlib/Test/System.Text/UTF8EncodingTest.cs index 1f53af7e3e..91a465c13d 100644 --- a/mcs/class/corlib/Test/System.Text/UTF8EncodingTest.cs +++ b/mcs/class/corlib/Test/System.Text/UTF8EncodingTest.cs @@ -125,34 +125,36 @@ namespace MonoTests.System.Text } [Test] -#if NET_2_0 - [Category ("NotWorking")] -#endif public void TestMaxCharCount() { UTF8Encoding UTF8enc = new UTF8Encoding (); -#if NET_2_0 - // hmm, where is this extra 1 coming from? + Encoding UTF8encWithBOM = new UTF8Encoding(true); Assert.AreEqual (51, UTF8enc.GetMaxCharCount(50), "UTF #1"); -#else - Assert.AreEqual (50, UTF8enc.GetMaxCharCount(50), "UTF #1"); -#endif + Assert.AreEqual (UTF8enc.GetMaxByteCount(50), UTF8encWithBOM.GetMaxByteCount(50), "UTF #2"); + } + + [Test] + public void TestMaxCharCountWithCustomFallback() + { + Encoding encoding = Encoding.GetEncoding("utf-8", new EncoderReplacementFallback("\u2047\u2047"), new DecoderReplacementFallback("\u2047\u2047")); + Assert.AreEqual (102, encoding.GetMaxCharCount(50), "UTF #1"); } [Test] -#if NET_2_0 - [Category ("NotWorking")] -#endif public void TestMaxByteCount() { UTF8Encoding UTF8enc = new UTF8Encoding (); -#if NET_2_0 - // maybe under .NET 2.0 insufficient surrogate pair is - // just not handled, and 3 is Preamble size. + Encoding UTF8encWithBOM = new UTF8Encoding(true); + Assert.AreEqual (153, UTF8enc.GetMaxByteCount(50), "UTF #1"); -#else - Assert.AreEqual (200, UTF8enc.GetMaxByteCount(50), "UTF #1"); -#endif + Assert.AreEqual (UTF8enc.GetMaxByteCount(50), UTF8encWithBOM.GetMaxByteCount(50), "UTF #2"); + } + + [Test] + public void TestMaxByteCountWithCustomFallback() + { + Encoding encoding = Encoding.GetEncoding("utf-8", new EncoderReplacementFallback("\u2047\u2047"), new DecoderReplacementFallback("?")); + Assert.AreEqual (306, encoding.GetMaxByteCount(50), "UTF #1"); } // regression for bug #59648 diff --git a/mcs/class/corlib/Test/System.Threading.Tasks/TaskFactoryTest.cs b/mcs/class/corlib/Test/System.Threading.Tasks/TaskFactoryTest.cs index 16db84cb41..857841e326 100644 --- a/mcs/class/corlib/Test/System.Threading.Tasks/TaskFactoryTest.cs +++ b/mcs/class/corlib/Test/System.Threading.Tasks/TaskFactoryTest.cs @@ -282,6 +282,16 @@ namespace MonoTests.System.Threading.Tasks } [Test] + public void ContinueWhenAny_WithResult () + { + var tcs = new TaskCompletionSource<int>(); + tcs.SetResult(1); + Task[] tasks = new[] { tcs.Task }; + var res = Task.Factory.ContinueWhenAny (tasks, l => 4); + Assert.AreEqual (4, res.Result); + } + + [Test] public void ContinueWhenAny_InvalidArguments () { try { @@ -594,16 +604,24 @@ namespace MonoTests.System.Threading.Tasks [Test] public void StartNewCancelled () { - var cts = new CancellationTokenSource (); - cts.Cancel (); + var ct = new CancellationToken (true); - var task = factory.StartNew (() => Assert.Fail ("Should never be called"), cts.Token); + var task = factory.StartNew (() => Assert.Fail ("Should never be called"), ct); try { task.Start (); + Assert.Fail ("#1"); } catch (InvalidOperationException) { } Assert.IsTrue (task.IsCanceled, "#2"); + + task = factory.StartNew (() => { }, ct); + try { + task.Wait (); + } catch (AggregateException e) { + Assert.IsTrue (task.IsCanceled, "#3"); + Assert.That (e.InnerException, Is.TypeOf (typeof (TaskCanceledException)), "#4"); + } } } } diff --git a/mcs/class/corlib/Test/System.Threading.Tasks/TaskFactoryTest_T.cs b/mcs/class/corlib/Test/System.Threading.Tasks/TaskFactoryTest_T.cs index 0c30a093b0..ff964bb9cf 100644 --- a/mcs/class/corlib/Test/System.Threading.Tasks/TaskFactoryTest_T.cs +++ b/mcs/class/corlib/Test/System.Threading.Tasks/TaskFactoryTest_T.cs @@ -33,6 +33,9 @@ using System.Threading; using System.Threading.Tasks; using NUnit.Framework; +#if !MOBILE +using NUnit.Framework.SyntaxHelpers; +#endif namespace MonoTests.System.Threading.Tasks { @@ -249,6 +252,29 @@ namespace MonoTests.System.Threading.Tasks Assert.AreEqual ("1", task.Result, "#2"); } + [Test] + public void StartNewCancelled () + { + var ct = new CancellationToken (true); + var factory = new TaskFactory<int> (); + + var task = factory.StartNew (() => { Assert.Fail ("Should never be called"); return 1; }, ct); + try { + task.Start (); + Assert.Fail ("#1"); + } catch (InvalidOperationException) { + } + + Assert.IsTrue (task.IsCanceled, "#2"); + + task = factory.StartNew (() => 1, ct); + try { + task.Wait (); + } catch (AggregateException e) { + Assert.IsTrue (task.IsCanceled, "#3"); + Assert.That (e.InnerException, Is.TypeOf (typeof (TaskCanceledException)), "#4"); + } + } } } diff --git a/mcs/class/corlib/Test/System.Threading.Tasks/TaskTest.cs b/mcs/class/corlib/Test/System.Threading.Tasks/TaskTest.cs index d9811306fb..1f3c156d77 100644 --- a/mcs/class/corlib/Test/System.Threading.Tasks/TaskTest.cs +++ b/mcs/class/corlib/Test/System.Threading.Tasks/TaskTest.cs @@ -838,6 +838,23 @@ namespace MonoTests.System.Threading.Tasks } [Test] + public void RunSynchronously_SchedulerException () + { + var scheduler = new MockScheduler (); + scheduler.TryExecuteTaskInlineHandler += (task, b) => { + throw new ApplicationException (); + }; + + Task t = new Task (() => { }); + try { + t.RunSynchronously (scheduler); + Assert.Fail (); + } catch (Exception e) { + Assert.AreEqual (t.Exception.InnerException, e); + } + } + + [Test] public void RunSynchronouslyWithAttachedChildren () { var result = false; @@ -1126,6 +1143,15 @@ namespace MonoTests.System.Threading.Tasks } [Test] + public void Delay_TimeManagement () + { + var delay1 = Task.Delay(50); + var delay2 = Task.Delay(25); + Assert.IsTrue (Task.WhenAny(new[] { delay1, delay2 }).Wait (1000)); + Assert.AreEqual (TaskStatus.RanToCompletion, delay2.Status); + } + + [Test] public void WaitAny_WithNull () { var tasks = new [] { @@ -1141,6 +1167,16 @@ namespace MonoTests.System.Threading.Tasks } [Test] + public void WhenAll_Empty () + { + var tasks = new Task[0]; + + Task t = Task.WhenAll(tasks); + + Assert.IsTrue(t.Wait(1000), "#1"); + } + + [Test] public void WhenAll_WithNull () { var tasks = new[] { @@ -1266,6 +1302,18 @@ namespace MonoTests.System.Threading.Tasks } [Test] + public void WhenAllResult_Empty () + { + var tasks = new Task<int>[0]; + + Task<int[]> t = Task.WhenAll(tasks); + + Assert.IsTrue(t.Wait(1000), "#1"); + Assert.IsNotNull(t.Result, "#2"); + Assert.AreEqual(t.Result.Length, 0, "#3"); + } + + [Test] public void WhenAllResult_WithNull () { var tasks = new[] { diff --git a/mcs/class/corlib/Test/System.Threading/AutoResetEventTest.cs b/mcs/class/corlib/Test/System.Threading/AutoResetEventTest.cs index 6f9c23fc5f..df0a77631c 100644 --- a/mcs/class/corlib/Test/System.Threading/AutoResetEventTest.cs +++ b/mcs/class/corlib/Test/System.Threading/AutoResetEventTest.cs @@ -66,6 +66,8 @@ namespace MonoTests.System.Threading } [Test] // bug #81529 + // Causes a Attempting to unref unused handle 0x2 warning + [Category ("NotWorking")] public void Handle_Valid () { AutoResetEvent are1 = new AutoResetEvent (false); diff --git a/mcs/class/corlib/Test/System.Threading/CancellationTokenSourceTest.cs b/mcs/class/corlib/Test/System.Threading/CancellationTokenSourceTest.cs index 644d0c5049..24534c3fd8 100644 --- a/mcs/class/corlib/Test/System.Threading/CancellationTokenSourceTest.cs +++ b/mcs/class/corlib/Test/System.Threading/CancellationTokenSourceTest.cs @@ -132,6 +132,20 @@ namespace MonoTests.System.Threading [Test] + public void Cancel_Order () + { + var cts = new CancellationTokenSource (); + var current = 0; + Action<object> a = x => { Assert.AreEqual(current, x); current++; }; + + cts.Token.Register (a, 2); + cts.Token.Register (a, 1); + cts.Token.Register (a, 0); + cts.Cancel (); + } + + + [Test] public void CancelWithDispose () { CancellationTokenSource cts = new CancellationTokenSource (); @@ -193,6 +207,25 @@ namespace MonoTests.System.Threading } [Test] + public void Cancel_ExceptionOrder () + { + var cts = new CancellationTokenSource (); + + cts.Token.Register (() => { throw new ApplicationException ("1"); }); + cts.Token.Register (() => { throw new ApplicationException ("2"); }); + cts.Token.Register (() => { throw new ApplicationException ("3"); }); + + try { + cts.Cancel (); + } catch (AggregateException e) { + Assert.AreEqual (3, e.InnerExceptions.Count, "#2"); + Assert.AreEqual ("3", e.InnerExceptions[0].Message, "#3"); + Assert.AreEqual ("2", e.InnerExceptions[1].Message, "#4"); + Assert.AreEqual ("1", e.InnerExceptions[2].Message, "#5"); + } + } + + [Test] public void Cancel_MultipleException_Recursive () { CancellationTokenSource cts = new CancellationTokenSource (); @@ -375,10 +408,9 @@ namespace MonoTests.System.Threading var source = new CancellationTokenSource (); var token = source.Token; - var reg = new CancellationTokenRegistration (); Console.WriteLine ("Test1"); + var reg = token.Register (() => unregister = true); token.Register (() => reg.Dispose ()); - reg = token.Register (() => unregister = true); token.Register (() => { Console.WriteLine ("Gnyah"); token.Register (() => register = true); }); source.Cancel (); diff --git a/mcs/class/corlib/Test/System.Threading/ExecutionContextTest.cs b/mcs/class/corlib/Test/System.Threading/ExecutionContextTest.cs index 9e79512002..2fa3d91a04 100644 --- a/mcs/class/corlib/Test/System.Threading/ExecutionContextTest.cs +++ b/mcs/class/corlib/Test/System.Threading/ExecutionContextTest.cs @@ -67,6 +67,66 @@ namespace MonoTests.System.Threading { { if (ExecutionContext.IsFlowSuppressed ()) ExecutionContext.RestoreFlow (); + + CallContext.FreeNamedDataSlot ("testlc"); + } + + [Test] + [Category("MobileNotWorking")] + public void LogicalGetData_SetData() + { + var value = "a"; + + CallContext.SetData ("testlc", value); + var capturedValue = CallContext.LogicalGetData ("testlc"); + + Assert.IsNull (capturedValue); + } + + [Test] + [Category("MobileNotWorking")] + public void LogicalGetData_SetDataLogicalThreadAffinative() + { + var value = new CallContextValue ("a"); + + CallContext.SetData ("testlc", value); + var capturedValue = CallContext.LogicalGetData ("testlc"); + + Assert.AreEqual (value, capturedValue); + } + + [Test] + [Category("MobileNotWorking")] + public void GetData_SetLogicalData() + { + var value = "a"; + + CallContext.LogicalSetData ("testlc", value); + var capturedValue = CallContext.GetData ("testlc"); + + Assert.AreEqual (value, capturedValue); + } + + [Test] + [Category("MobileNotWorking")] + public void CaptureLogicalCallContext() + { + var value = "Tester"; + object capturedValue = null; + + CallContext.LogicalSetData ("testlc", value); + + ExecutionContext ec = ExecutionContext.Capture (); + Assert.IsNotNull (ec, "Capture"); + Assert.AreEqual (value, CallContext.LogicalGetData ("testlc")); + CallContext.LogicalSetData ("testlc", null); + + ExecutionContext.Run (ec, new ContextCallback (new Action<object> ((data) => { + capturedValue = CallContext.LogicalGetData ("testlc"); + })), null); + + Assert.AreEqual (value, capturedValue); + Assert.AreNotEqual (value, CallContext.LogicalGetData ("testlc")); } [Test] @@ -92,6 +152,7 @@ namespace MonoTests.System.Threading { } [Test] + [Category("MobileNotWorking")] public void Capture () { ExecutionContext ec = ExecutionContext.Capture (); @@ -109,6 +170,7 @@ namespace MonoTests.System.Threading { } [Test] + [Category("MobileNotWorking")] public void Copy () { ExecutionContext ec = ExecutionContext.Capture (); @@ -138,6 +200,7 @@ namespace MonoTests.System.Threading { } [Test] + [Category("MobileNotWorking")] public void IsFlowSuppressed () { Assert.IsFalse (ExecutionContext.IsFlowSuppressed (), "IsFlowSuppressed-1"); @@ -151,12 +214,14 @@ namespace MonoTests.System.Threading { [Test] [ExpectedException (typeof (InvalidOperationException))] + [Category("MobileNotWorking")] public void RestoreFlow_None () { ExecutionContext.RestoreFlow (); } [Test] + [Category("MobileNotWorking")] public void RestoreFlow_SuppressFlow () { Assert.IsFalse (ExecutionContext.IsFlowSuppressed (), "IsFlowSuppressed-1"); @@ -177,6 +242,7 @@ namespace MonoTests.System.Threading { [Test] [ExpectedException (typeof (InvalidOperationException))] + [Category("MobileNotWorking")] public void Run_SuppressFlow () { Assert.IsFalse (ExecutionContext.IsFlowSuppressed ()); @@ -191,6 +257,7 @@ namespace MonoTests.System.Threading { } [Test] + [Category("MobileNotWorking")] public void SuppressFlow () { Assert.IsFalse (ExecutionContext.IsFlowSuppressed (), "IsFlowSuppressed-1"); @@ -204,6 +271,7 @@ namespace MonoTests.System.Threading { [Test] [ExpectedException (typeof (InvalidOperationException))] + [Category("MobileNotWorking")] public void SuppressFlow_Two_Undo () { Assert.IsFalse (ExecutionContext.IsFlowSuppressed (), "IsFlowSuppressed-1"); diff --git a/mcs/class/corlib/Test/System.Threading/ThreadPoolTest.cs b/mcs/class/corlib/Test/System.Threading/ThreadPoolTest.cs index 951e41ee1a..88803e5c2d 100644 --- a/mcs/class/corlib/Test/System.Threading/ThreadPoolTest.cs +++ b/mcs/class/corlib/Test/System.Threading/ThreadPoolTest.cs @@ -49,6 +49,37 @@ namespace MonoTests.System.Threading Assert.Fail ("#2"); } catch (ArgumentNullException) { } - } + } + + [Test] + public void UnsafeQueueUserWorkItem_InvalidArguments () + { + try { + ThreadPool.UnsafeQueueUserWorkItem (null, 1); + Assert.Fail ("#1"); + } catch (ArgumentNullException) { + } + } + +#if NET_4_0 + event WaitCallback e; + + [Test] + public void UnsafeQueueUserWorkItem_MulticastDelegate () + { + CountdownEvent ev = new CountdownEvent (2); + + e += delegate { + ev.Signal (); + }; + + e += delegate { + ev.Signal (); + }; + + ThreadPool.UnsafeQueueUserWorkItem (e, null); + Assert.IsTrue (ev.Wait (3000)); + } +#endif } }
\ No newline at end of file diff --git a/mcs/class/corlib/Test/System.Threading/ThreadTest.cs b/mcs/class/corlib/Test/System.Threading/ThreadTest.cs index 7d483e6703..ca5489ef0d 100644 --- a/mcs/class/corlib/Test/System.Threading/ThreadTest.cs +++ b/mcs/class/corlib/Test/System.Threading/ThreadTest.cs @@ -837,6 +837,13 @@ namespace MonoTests.System.Threading } } + [Test] + public void GetNamedDataSlotTest () + { + Assert.IsNotNull (Thread.GetNamedDataSlot ("te#st"), "#1"); + Assert.AreSame (Thread.GetNamedDataSlot ("te#st"), Thread.GetNamedDataSlot ("te#st"), "#2"); + } + void CheckIsRunning (string s, Thread t) { int c = counter; diff --git a/mcs/class/corlib/Test/System.Threading/TimerTest.cs b/mcs/class/corlib/Test/System.Threading/TimerTest.cs index 2c05538c72..ee60eb53aa 100644 --- a/mcs/class/corlib/Test/System.Threading/TimerTest.cs +++ b/mcs/class/corlib/Test/System.Threading/TimerTest.cs @@ -60,11 +60,11 @@ namespace MonoTests.System.Threading { Timer t = new Timer (new TimerCallback (Callback), bucket, 10, 10); Thread.Sleep (500); int c = bucket.count; - Assert.IsTrue(c > 20, "#1"); + Assert.IsTrue (c > 20, "#1 " + c.ToString ()); t.Change (100, 100); c = bucket.count; Thread.Sleep (500); - Assert.IsTrue(bucket.count <= c + 20, "#2"); + Assert.IsTrue (bucket.count <= c + 20, "#2 " + c.ToString ()); t.Dispose (); } @@ -193,8 +193,7 @@ namespace MonoTests.System.Threading { Thread.Sleep(100); t.Change (int.MaxValue, Timeout.Infinite); // since period is 0 the callback should happen once (bug #340212) - Assert.IsTrue(b.count == 1); - + Assert.AreEqual (1, b.count, "only once"); } [Test] diff --git a/mcs/class/corlib/Test/System/AggregateExceptionTests.cs b/mcs/class/corlib/Test/System/AggregateExceptionTests.cs index bc91e12686..d133a82cd8 100644 --- a/mcs/class/corlib/Test/System/AggregateExceptionTests.cs +++ b/mcs/class/corlib/Test/System/AggregateExceptionTests.cs @@ -108,6 +108,17 @@ namespace MonoTests.System } } + [Test] + public void GetBaseWithInner () + { + var ae = new AggregateException ("x", new [] { new ArgumentException (), new ArgumentNullException () }); + Assert.AreEqual (ae, ae.GetBaseException (), "#1"); + + var expected = new ArgumentException (); + var ae2 = new AggregateException ("x", new AggregateException (expected, new Exception ())); + Assert.AreEqual (expected, ae2.GetBaseException ().InnerException, "#2"); + } + static void Throws (Type t, Action action) { Exception e = null; diff --git a/mcs/class/corlib/Test/System/AppDomainTest.cs b/mcs/class/corlib/Test/System/AppDomainTest.cs index 1d88666538..8772d7afde 100644 --- a/mcs/class/corlib/Test/System/AppDomainTest.cs +++ b/mcs/class/corlib/Test/System/AppDomainTest.cs @@ -2073,7 +2073,6 @@ namespace MonoTests.System AppDomain.CurrentDomain.ExecuteAssembly ( assembly.Location); Assert.Fail ("#1"); -#if NET_2_0 } catch (MissingMethodException ex) { // Entry point not found in assembly '...' Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2"); @@ -2081,15 +2080,6 @@ namespace MonoTests.System Assert.IsNotNull (ex.Message, "#4"); Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5"); } -#else - } catch (COMException ex) { - // Unspecified error - Assert.AreEqual (typeof (COMException), ex.GetType (), "#2"); - Assert.AreEqual (-2147467259, ex.ErrorCode, "#3"); - Assert.IsNull (ex.InnerException, "#4"); - Assert.IsNotNull (ex.Message, "#5"); - } -#endif } [Test] // ExecuteAssembly (String, Evidence) @@ -2102,7 +2092,6 @@ namespace MonoTests.System assembly.Location, (Evidence) null); Assert.Fail ("#1"); -#if NET_2_0 } catch (MissingMethodException ex) { // Entry point not found in assembly '...' Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2"); @@ -2110,15 +2099,6 @@ namespace MonoTests.System Assert.IsNotNull (ex.Message, "#4"); Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5"); } -#else - } catch (COMException ex) { - // Unspecified error - Assert.AreEqual (typeof (COMException), ex.GetType (), "#2"); - Assert.AreEqual (-2147467259, ex.ErrorCode, "#3"); - Assert.IsNull (ex.InnerException, "#4"); - Assert.IsNotNull (ex.Message, "#5"); - } -#endif } [Test] // ExecuteAssembly (String, Evidence, String []) @@ -2132,7 +2112,6 @@ namespace MonoTests.System (Evidence) null, new string [0]); Assert.Fail ("#1"); -#if NET_2_0 } catch (MissingMethodException ex) { // Entry point not found in assembly '...' Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2"); @@ -2140,15 +2119,6 @@ namespace MonoTests.System Assert.IsNotNull (ex.Message, "#4"); Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5"); } -#else - } catch (COMException ex) { - // Unspecified error - Assert.AreEqual (typeof (COMException), ex.GetType (), "#2"); - Assert.AreEqual (-2147467259, ex.ErrorCode, "#3"); - Assert.IsNull (ex.InnerException, "#4"); - Assert.IsNotNull (ex.Message, "#5"); - } -#endif } [Test] // ExecuteAssembly (String, Evidence, String [], Byte [], AssemblyHashAlgorithm) @@ -2165,7 +2135,6 @@ namespace MonoTests.System (byte []) null, AssemblyHashAlgorithm.SHA1); Assert.Fail ("#1"); -#if NET_2_0 } catch (MissingMethodException ex) { // Entry point not found in assembly '...' Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2"); @@ -2173,15 +2142,6 @@ namespace MonoTests.System Assert.IsNotNull (ex.Message, "#4"); Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5"); } -#else - } catch (COMException ex) { - // Unspecified error - Assert.AreEqual (typeof (COMException), ex.GetType (), "#2"); - Assert.AreEqual (-2147467259, ex.ErrorCode, "#3"); - Assert.IsNull (ex.InnerException, "#4"); - Assert.IsNotNull (ex.Message, "#5"); - } -#endif } [Test] // bug #79720 @@ -3044,14 +3004,9 @@ namespace MonoTests.System try { AppDomain.CurrentDomain.Load (aname); Assert.Fail ("#C9"); -#if NET_2_0 } catch (SecurityException) { // Invalid assembly public key } -#else - } catch (FileLoadException) { - } -#endif aname = new AssemblyName (); aname.Name = "bug79522C"; @@ -3212,6 +3167,30 @@ namespace MonoTests.System // we have no public way to get the default appdomain } + static bool resolve_called; + + [Test] + public void AssemblyResolveParseError () + { + AppDomain currentDomain = AppDomain.CurrentDomain; + ResolveEventHandler d = ParseErrorResolve; + currentDomain.AssemblyResolve += d; + try { + resolve_called = false; + var a = Assembly.Load ("MyDynamicType, 1.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"); + Assert.Fail (); + } catch (FileNotFoundException) { + Assert.IsTrue (resolve_called); + } + currentDomain.AssemblyResolve -= d; + } + + static Assembly ParseErrorResolve (object sender, ResolveEventArgs args) + { + resolve_called = true; + return null; + } + [Test] public void ReflectionOnlyGetAssemblies () { @@ -3329,6 +3308,14 @@ namespace MonoTests.System TestSerialization (tester, typeof (StuffToPick<int>).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int))); } + [Test] + public void ShadowCopyTypeGetTypeMissingAssemblyTest () + { + ad = CreateShadowCopyAppDomain (tempDir, true); + CrossDomainTester tester = CreateCrossDomainTester (ad); + tester.AssertLoadMissingAssemblyType (); + } + private static AppDomain CreateTestDomain (string baseDirectory, bool assemblyResolver) { AppDomainSetup setup = new AppDomainSetup (); @@ -3337,6 +3324,15 @@ namespace MonoTests.System return CreateTestDomain (setup, assemblyResolver); } + private static AppDomain CreateShadowCopyAppDomain (string baseDirectory, bool assemblyResolver) + { + AppDomainSetup setup = new AppDomainSetup (); + setup.ApplicationBase = baseDirectory; + setup.ApplicationName = "testdomain"; + setup.ShadowCopyFiles = "true"; + return CreateTestDomain (setup, assemblyResolver); + } + private static AppDomain CreateTestDomain (AppDomainSetup setup, bool assemblyResolver) { AppDomain ad = AppDomain.CreateDomain ("testdomain", @@ -3444,22 +3440,17 @@ namespace MonoTests.System } } - public bool AssertFileLoadException (AssemblyName assemblyRef) + public void AssertLoadMissingAssemblyType () { - try { - AppDomain.CurrentDomain.Load (assemblyRef); - return false; - } catch (FileLoadException) { - return true; - } + Assert.IsNull (Type.GetType ("A.B.C, MissingAssembly")); } - public bool AssertFileNotFoundException (AssemblyName assemblyRef) + public bool AssertFileLoadException (AssemblyName assemblyRef) { try { AppDomain.CurrentDomain.Load (assemblyRef); return false; - } catch (FileNotFoundException) { + } catch (FileLoadException) { return true; } } @@ -3629,4 +3620,4 @@ namespace MonoTests.System } } -#endif
\ No newline at end of file +#endif diff --git a/mcs/class/corlib/Test/System/ArraySegmentTest.cs b/mcs/class/corlib/Test/System/ArraySegmentTest.cs index 6a4d8ae78f..28588f8e00 100644 --- a/mcs/class/corlib/Test/System/ArraySegmentTest.cs +++ b/mcs/class/corlib/Test/System/ArraySegmentTest.cs @@ -260,6 +260,24 @@ namespace MonoTests.System s[1] = -3; Assert.AreEqual (-3, s[1], "#2a"); } + + [Test] + [ExpectedException (typeof (ArgumentOutOfRangeException))] + public void IList_IndexerErrorTest1 () + { + byte[] arr = new byte[4]; + IList<byte> seg = new ArraySegment<byte> (arr, 1, 2); + seg[-1] = 3; + } + + [Test] + [ExpectedException (typeof (ArgumentOutOfRangeException))] + public void IList_IndexerErrorTest2 () + { + byte[] arr = new byte[4]; + IList<byte> seg = new ArraySegment<byte> (arr); + seg[4] = 3; + } #endif } } diff --git a/mcs/class/corlib/Test/System/ArrayTest.cs b/mcs/class/corlib/Test/System/ArrayTest.cs index 4c74ee9d3d..ef41ce1794 100644 --- a/mcs/class/corlib/Test/System/ArrayTest.cs +++ b/mcs/class/corlib/Test/System/ArrayTest.cs @@ -1618,6 +1618,126 @@ public class ArrayTest } } + + [Test] + public void FindIndexTest () + { + var a = new int[] { 2, 2, 2, 3, 2 }; + Assert.AreEqual (2, Array.FindIndex (a, 2, 2, l => true)); + } + + [Test] + public void FindIndex_Invalid () + { + var array = new int [] { 1, 2, 3, 4, 5 }; + + try { + Array.FindIndex (array, null); + Assert.Fail ("#1"); + } catch (ArgumentNullException) { + } + + try { + Array.FindIndex (array, -1, l => true); + Assert.Fail ("#2"); + } catch (ArgumentOutOfRangeException) { + } + + try { + Array.FindIndex (array, -1, 0, l => true); + Assert.Fail ("#2b"); + } catch (ArgumentOutOfRangeException) { + } + + try { + Array.FindIndex (array, 0, -1, l => true); + Assert.Fail ("#3"); + } catch (ArgumentOutOfRangeException) { + } + + try { + Array.FindIndex (array, 100, l => true); + Assert.Fail ("#4"); + } catch (ArgumentOutOfRangeException) { + } + + try { + Array.FindIndex (array, 100, 0, l => true); + Assert.Fail ("#4b"); + } catch (ArgumentOutOfRangeException) { + } + + try { + Array.FindIndex (array, 7, 2, l => true); + Assert.Fail ("#5"); + } catch (ArgumentOutOfRangeException) { + } + } + + [Test, ExpectedException (typeof (ArgumentNullException))] + public void FindLastNullTest () + { + var array = new int [] { 1, 2, 3, 4, 5 }; + Array.FindLast (array, null); + } + + [Test] + public void FindLastIndexTest () + { + var array = new int [] { 1, 2, 3, 4, 5 }; + + Assert.AreEqual (2, Array.FindLastIndex (array, 2, 3, l => true)); + Assert.AreEqual (2, Array.FindLastIndex (array, 2, 2, l => true)); + Assert.AreEqual (1, Array.FindLastIndex (array, 1, 2, l => true)); + } + + [Test] + public void FindLastIndex_Invalid () + { + var array = new int [] { 1, 2, 3, 4, 5 }; + try { + Array.FindLastIndex (array, null); + Assert.Fail ("#1"); + } catch (ArgumentNullException) { + } + + try { + Array.FindLastIndex (array, -1, l => true); + Assert.Fail ("#2"); + } catch (ArgumentOutOfRangeException) { + } + + try { + Array.FindLastIndex (array, -1, 0, l => true); + Assert.Fail ("#2b"); + } catch (ArgumentOutOfRangeException) { + } + + try { + Array.FindLastIndex (array, 0, -1, l => true); + Assert.Fail ("#3"); + } catch (ArgumentOutOfRangeException) { + } + + try { + Array.FindLastIndex (array, 100, l => true); + Assert.Fail ("#4"); + } catch (ArgumentOutOfRangeException) { + } + + try { + Array.FindLastIndex (array, 100, 0, l => true); + Assert.Fail ("#4b"); + } catch (ArgumentOutOfRangeException) { + } + + try { + Array.FindLastIndex (array, 2, 4, l => true); + Assert.Fail ("#5"); + } catch (ArgumentOutOfRangeException) { + } + } + [Test] public void TestReverse() { { diff --git a/mcs/class/corlib/Test/System/AttributeTest.cs b/mcs/class/corlib/Test/System/AttributeTest.cs index f8fe8cd7a0..10fb4fcbce 100644 --- a/mcs/class/corlib/Test/System/AttributeTest.cs +++ b/mcs/class/corlib/Test/System/AttributeTest.cs @@ -88,6 +88,13 @@ namespace MonoTests.System class MyDerivedClassNoAttribute : MyClass { } + + internal class AttributeWithTypeId : Attribute + { + public override object TypeId { + get { return this; } + } + } } [TestFixture] @@ -998,6 +1005,14 @@ namespace MonoTests.System MyOwnCustomAttribute b1 = new MyOwnCustomAttribute (null); Assert.AreNotEqual (a1.GetHashCode (), b1.GetHashCode (), "non-identical-types"); } + + [Test] + public void GetHashCodeWithOverriddenTypeId () + { + //check for not throwing stack overflow exception + AttributeWithTypeId a = new AttributeWithTypeId (); + a.GetHashCode (); + } } namespace ParamNamespace { diff --git a/mcs/class/corlib/Test/System/DateTimeOffsetTest.cs b/mcs/class/corlib/Test/System/DateTimeOffsetTest.cs index df685fc0dd..3bc65a8204 100644 --- a/mcs/class/corlib/Test/System/DateTimeOffsetTest.cs +++ b/mcs/class/corlib/Test/System/DateTimeOffsetTest.cs @@ -163,7 +163,7 @@ namespace MonoTests.System { Assert.AreEqual (dto.ToString ("r", new CultureInfo ("en-us")), dto.ToString ("R", new CultureInfo ("en-us"))); Assert.AreEqual ("2007-10-31T21:00:00", dto.ToString ("s", new CultureInfo ("en-us"))); Assert.AreEqual ("2007-11-01 05:00:00Z", dto.ToString ("u", new CultureInfo ("en-us"))); - Assert.AreEqual ("October, 2007", dto.ToString ("Y", new CultureInfo ("en-us"))); + Assert.AreEqual ("October 2007", dto.ToString ("Y", new CultureInfo ("en-us"))); Assert.AreEqual (dto.ToString ("y", new CultureInfo ("en-us")), dto.ToString ("Y", new CultureInfo ("en-us"))); } diff --git a/mcs/class/corlib/Test/System/DateTimeTest.cs b/mcs/class/corlib/Test/System/DateTimeTest.cs index 72da88876a..30de11b489 100644 --- a/mcs/class/corlib/Test/System/DateTimeTest.cs +++ b/mcs/class/corlib/Test/System/DateTimeTest.cs @@ -2476,11 +2476,11 @@ namespace MonoTests.System } [Test] - public void Foo () + public void GenitiveMonth () { var ci = new CultureInfo ("ru-RU"); var dt = new DateTime (2012, 9, 15); - Assert.AreEqual ("сентября 15", dt.ToString ("m", ci)); + Assert.AreEqual ("15 сентября", dt.ToString ("m", ci)); } } } diff --git a/mcs/class/corlib/Test/System/EnumTest.cs b/mcs/class/corlib/Test/System/EnumTest.cs index f6c0dca2a5..973b068e82 100644 --- a/mcs/class/corlib/Test/System/EnumTest.cs +++ b/mcs/class/corlib/Test/System/EnumTest.cs @@ -849,9 +849,12 @@ namespace MonoTests.System } [Test] - public void ConvertToStringType () + public void IConvertible_Valid () { - Assert.AreEqual ("This", ((IConvertible) TestingEnum.This).ToType (typeof (string), null)); + IConvertible ic = TestingEnum.This; + Assert.AreEqual ("This", ic.ToType (typeof (string), null), "#1"); + Assert.AreEqual (TestingEnum.This, ic.ToType (typeof (TestingEnum), null), "#2"); + Assert.AreEqual (TestingEnum.This, ic.ToType (typeof (Enum), null), "#3"); } [Test] diff --git a/mcs/class/corlib/Test/System/IntegerFormatterTest.cs b/mcs/class/corlib/Test/System/IntegerFormatterTest.cs index 8873f308cd..a09e98a1b4 100644 --- a/mcs/class/corlib/Test/System/IntegerFormatterTest.cs +++ b/mcs/class/corlib/Test/System/IntegerFormatterTest.cs @@ -123,7 +123,10 @@ public class IntegerFormatterTest } - private static string tutti = "Int32\n" + + private static string tutti = tutti_1 + tutti_2; + + const string tutti_1 = + "Int32\n" + "(-2147483648) (C) (($2,147,483,648.00))\n" + "(-2147483648) (C0) (($2,147,483,648))\n" + "(-2147483648) (C1) (($2,147,483,648.0))\n" + @@ -852,7 +855,9 @@ public class IntegerFormatterTest "(9223372036854775807) (X8) (7FFFFFFFFFFFFFFF)\n" + "(9223372036854775807) (X9) (7FFFFFFFFFFFFFFF)\n" + "(9223372036854775807) (X10) (7FFFFFFFFFFFFFFF)\n" + -"(9223372036854775807) (X99) (000000000000000000000000000000000000000000000000000000000000000000000000000000000007FFFFFFFFFFFFFFF)\n" + +"(9223372036854775807) (X99) (000000000000000000000000000000000000000000000000000000000000000000000000000000000007FFFFFFFFFFFFFFF)\n"; + +const string tutti_2 = "(0) (C) ($0.00)\n" + "(0) (C0) ($0)\n" + "(0) (C1) ($0.0)\n" + @@ -2000,6 +2005,5 @@ public class IntegerFormatterTest "(100) (X10) (0000000064)\n" + "(100) (X99) (000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064)\n"; } - } diff --git a/mcs/class/corlib/Test/System/RandomTest.cs b/mcs/class/corlib/Test/System/RandomTest.cs index a18524968f..5e49ac3866 100644 --- a/mcs/class/corlib/Test/System/RandomTest.cs +++ b/mcs/class/corlib/Test/System/RandomTest.cs @@ -3,9 +3,10 @@ // // Authors: // Bob Smith <bob@thestuff.net> -// Sebastien Pouliot <sebastien@ximian.com> +// Sebastien Pouliot <sebastien@xamarin.com> // // Copyright (C) 2004 Novell, Inc (http://www.novell.com) +// Copyright 2013 Xamarin Inc. (http://www.xamarin.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -29,44 +30,21 @@ using NUnit.Framework; using System; +using System.Reflection; namespace MonoTests.System { [TestFixture] public class RandomTest { -#if false - // - // This test will fail, given enough runs. - // - // It is an ad-hoc test for distribution, and does not work - // 100% of the time. - // - [Test] - public void NextDouble () - { - Random r = new Random (); - int i; - double c=0; - for (i=0; i<20; i++) - c += r.NextDouble (); - c/=i; - Assert.IsTrue (c.ToString () + " is out of range.", c < .7 && c > .3); - } - -#endif - [Test] public void CompareStreamWithSameSeed () { Random r = new Random (42); Random r2 = new Random (42); - double c=0, c2=0; for (int i=0; i<20; i++) { - c += r.NextDouble (); - c2 += r2.NextDouble (); + Assert.AreEqual (r.NextDouble (), r2.NextDouble (), i.ToString ()); } - Assert.AreEqual (c, c2, "Compare"); } [Test] @@ -80,6 +58,13 @@ namespace MonoTests.System { } [Test] + public void NextZero () + { + Random r = new Random (); + Assert.AreEqual (0, r.Next (0),"Next(0) failed"); + } + + [Test] public void NextMax() { Random r = new Random(); @@ -109,23 +94,124 @@ namespace MonoTests.System { } } -/* Mono implementation is now compatible with Knuth (not MS) implementation (choice of constants) + class RandomSampleOverride : Random { + + protected override double Sample () + { + throw new NotImplementedException (); + } + } + [Test] - public void CompareWithMS () + public void Base_Int () { - string[] r = new string [4]; - byte[] buffer = new byte [8]; - int x = 4; - while (x-- > 0) { - int seed = (x << x); - Random random = new Random (seed); - random.NextBytes (buffer); - r [x] = BitConverter.ToString (buffer); + var random = new RandomSampleOverride (); + // from 2.0+ Next(), Next(int,int) and NextBytes(byte[]) do not call Sample + // see MSDN's Notes to Inheritors + random.Next (); + random.Next (Int32.MinValue, Int32.MaxValue); + random.NextBytes (new byte[1]); + } + + [Test] + [ExpectedException (typeof (NotImplementedException))] + public void Base_Double () + { + var random = new RandomSampleOverride (); + random.NextDouble (); + } + + // generate values (one for each 1024 returned values) from the original C implementation + static uint[] jkiss_values = { + 560241513, /* 0 */ + 1281708802, /* 1024 */ + 1571324528, /* 2048 */ + 1565809406, /* 3072 */ + 1010890569, /* 4096 */ + 1778803435, /* 5120 */ + 903613637, /* 6144 */ + 3496059008, /* 7168 */ + 108603163, /* 8192 */ + 1854081276, /* 9216 */ + 3703232459, /* 10240 */ + 2191562138, /* 11264 */ + 337995793, /* 12288 */ + 1340840062, /* 13312 */ + 2364148985, /* 14336 */ + 2549812361, /* 15360 */ + 563432369, /* 16384 */ + 229365487, /* 17408 */ + 1821397325, /* 18432 */ + 3246092454, /* 19456 */ + 691032417, /* 20480 */ + 86951316, /* 21504 */ + 3029975455, /* 22528 */ + 1261370163, /* 23552 */ + 2539815382, /* 24576 */ + 3017891647, /* 25600 */ + 3877215120, /* 26624 */ + 3142958765, /* 27648 */ + 1080903191, /* 28672 */ + 2837464745, /* 29696 */ + 614275602, /* 30720 */ + 2250626199, /* 31744 */ + 729001311, /* 32768 */ + 3313769017, /* 33792 */ + 2408398670, /* 34816 */ + 3123583383, /* 35840 */ + 3346590423, /* 36864 */ + 1629546563, /* 37888 */ + 251343753, /* 38912 */ + 2695793631, /* 39936 */ + 2768993787, /* 40960 */ + 3688573224, /* 41984 */ + 2897218561, /* 43008 */ + 2725058810, /* 44032 */ + 2142061914, /* 45056 */ + 3983217096, /* 46080 */ + 3609758190, /* 47104 */ + 842060935, /* 48128 */ + 2893482035, /* 49152 */ + 2290461665, /* 50176 */ + 1709481476, /* 51200 */ + 3633857838, /* 52224 */ + 332645044, /* 53248 */ + 3522654497, /* 54272 */ + 2501348469, /* 55296 */ + 1644344287, /* 56320 */ + 3081428084, /* 57344 */ + 3114560766, /* 58368 */ + 489030597, /* 59392 */ + 367291591, /* 60416 */ + 106358682, /* 61440 */ + 3020781303, /* 62464 */ + 1209590375, /* 63488 */ + 1833282169, /* 64512 */ + 61543407, /* 65536 */ + }; + + [Test] + public void JKISS () + { + // Random.Next() returns a non-negative *signed* integer value - so it can't be used for testing + var next = typeof(Random).GetMethod ("JKiss", BindingFlags.Instance | BindingFlags.NonPublic); + + // if the method is not present, e.g. on MS.NET, skip this test + if (next == null) + return; + + // ensure we match the original JKISS random stream + // first 64KB but without checking every value (one each KB) + Random r = new Random (123456789); + int n = 0; + int j = 0; + while (j < 64 * 1024) { + uint random = (uint) next.Invoke (r, null); + if (j++ % 1024 == 0) { + Assert.AreEqual (random, jkiss_values [n], n.ToString ()); + n++; + } } - Assert.AreEqual ("43-DB-8B-AE-0A-88-A8-7B", r [3], "Seed(24)"); - Assert.AreEqual ("E7-2A-5C-44-D1-8C-7D-74", r [2], "Seed(8)"); - Assert.AreEqual ("C5-67-2A-FC-1B-4E-CD-72", r [1], "Seed(2)"); - Assert.AreEqual ("B9-D1-C4-8E-34-8F-E7-71", r [0], "Seed(0)"); - }*/ + } } -} +}
\ No newline at end of file diff --git a/mcs/class/corlib/Test/System/TimeZoneTest.cs b/mcs/class/corlib/Test/System/TimeZoneTest.cs index 4d675d51e6..4403fd6346 100644 --- a/mcs/class/corlib/Test/System/TimeZoneTest.cs +++ b/mcs/class/corlib/Test/System/TimeZoneTest.cs @@ -122,6 +122,32 @@ public class TimeZoneTest { Assert.AreEqual(0L, t1.GetUtcOffset (d5).Ticks, "D14"); } + private void NZST(TimeZone t1) { + Assert.AreEqual("NZST", t1.StandardName, "E01"); + Assert.AreEqual("NZDT", t1.DaylightName, "E02"); + + DaylightTime d1 = t1.GetDaylightChanges (2013); + Assert.AreEqual("09/29/2013 02:00:00", d1.Start.ToString ("G"), "E03"); + Assert.AreEqual("04/07/2013 03:00:00", d1.End.ToString ("G"), "E04"); + Assert.AreEqual(36000000000L, d1.Delta.Ticks, "E05"); + + DaylightTime d2 = t1.GetDaylightChanges (2001); + Assert.AreEqual("10/07/2001 02:00:00", d2.Start.ToString ("G"), "E06"); + Assert.AreEqual("03/18/2001 03:00:00", d2.End.ToString ("G"), "E07"); + Assert.AreEqual(36000000000L, d2.Delta.Ticks, "E08"); + + DateTime d3 = new DateTime(2013,02,15); + Assert.AreEqual(true, t1.IsDaylightSavingTime (d3), "E09"); + DateTime d4 = new DateTime(2013,04,30); + Assert.AreEqual(false, t1.IsDaylightSavingTime (d4), "E10"); + DateTime d5 = new DateTime(2013,11,03); + Assert.AreEqual(true, t1.IsDaylightSavingTime (d5), "E11"); + + Assert.AreEqual(36000000000L /*hour*/ * 13L, t1.GetUtcOffset (d3).Ticks, "E12"); + Assert.AreEqual(36000000000L /*hour*/ * 12L, t1.GetUtcOffset (d4).Ticks, "E13"); + Assert.AreEqual(36000000000L /*hour*/ * 13L, t1.GetUtcOffset (d5).Ticks, "E14"); + } + [Test] [Culture ("")] public void TestCtors () @@ -141,6 +167,9 @@ public class TimeZoneTest { case "GMT": GMT (t1); break; + case "NZST": + NZST (t1); + break; default: NUnit.Framework.Assert.Ignore ("Your time zone (" + t1.StandardName + ") isn't defined in the test case"); break; @@ -252,6 +281,45 @@ public class TimeZoneTest { } [Test] + public void GetUtcOffsetAtDSTBoundary () + { + /* + * Getting a definitive list of timezones which do or don't observe Daylight + * Savings is difficult (can't say America's or USA definitively) and lengthy see + * + * http://en.wikipedia.org/wiki/Daylight_saving_time_by_country + * + * as a good starting point for a list. + * + * The following are SOME of the timezones/regions which do support daylight savings. + * + * Pacific/Auckland + * Pacific/Sydney + * USA (EST, CST, MST, PST, AKST) note this does not cover all states or regions + * Europe/London (GMT) + * CET (member states of the European Union) + * + * This test should work in all the above timezones + */ + + + TimeZone tz = TimeZone.CurrentTimeZone; + DaylightTime daylightChanges = tz.GetDaylightChanges(2007); + DateTime dst_end = daylightChanges.End; + + if (dst_end == DateTime.MinValue) + Assert.Ignore (tz.StandardName + " did not observe daylight saving time during 2007."); + + var standardOffset = tz.GetUtcOffset(daylightChanges.Start.AddMinutes(-1)); + + Assert.AreEqual(standardOffset, tz.GetUtcOffset (dst_end)); + Assert.AreEqual(standardOffset, tz.GetUtcOffset (dst_end.Add (daylightChanges.Delta.Negate ().Add (TimeSpan.FromSeconds(1))))); + Assert.AreEqual(standardOffset, tz.GetUtcOffset (dst_end.Add(daylightChanges.Delta.Negate ()))); + Assert.AreNotEqual(standardOffset, tz.GetUtcOffset (dst_end.Add(daylightChanges.Delta.Negate ().Add (TimeSpan.FromSeconds(-1))))); + } + + + [Test] public void StaticProperties () { Assert.IsNotNull (TimeZoneInfo.Local, "Local"); diff --git a/mcs/class/corlib/Test/System/TupleTest.cs b/mcs/class/corlib/Test/System/TupleTest.cs new file mode 100644 index 0000000000..cf410e7855 --- /dev/null +++ b/mcs/class/corlib/Test/System/TupleTest.cs @@ -0,0 +1,63 @@ +// +// TupleTest.cs +// +// Authors: +// Marek Safar <marek.safar@gmail.com> +// +// Copyright (C) 2014 Xamarin Inc (http://www.xamarin.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +#if NET_4_0 + +using System; +using NUnit.Framework; + +namespace MonoTests.System +{ + [TestFixture] + public class TupleTest + { + [Test] + [ExpectedException (typeof (ArgumentException))] + public void TupleWithRest_Invalid () + { + new Tuple<int, int, int, int, int, int, int, int> (1, 2, 3, 4, 5, 6, 7, 8); + } + + [Test] + [ExpectedException (typeof (ArgumentException))] + public void TupleWithRest_InvalidDueToNull () + { + new Tuple<int, object, int, int, int, int, int, Tuple<string, string>> (1, null, 3, 4, 5, 6, 7, null); + } + + [Test] + public void ToStringTest () + { + var t1 = new Tuple<int, object, int, int, int, int, int, Tuple<string, string>> (1, null, 3, 4, 5, 6, 7, new Tuple<string, string> (null, null)); + + Assert.AreEqual ("(1, , 3, 4, 5, 6, 7, , )", t1.ToString (), "#1"); + } + } +} + +#endif
\ No newline at end of file diff --git a/mcs/class/corlib/Test/System/TypeTest.cs b/mcs/class/corlib/Test/System/TypeTest.cs index bc726ce38f..8972880062 100644 --- a/mcs/class/corlib/Test/System/TypeTest.cs +++ b/mcs/class/corlib/Test/System/TypeTest.cs @@ -4024,6 +4024,25 @@ PublicKeyToken=b77a5c561934e089")); } #endif + [Test] + public void GetTypeParseGenericCorrectly () { //Bug #15124 + Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1"), typeof (Foo<>), "#1"); + Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[System.Int32]"), typeof (Foo<int>), "#2"); + Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[[System.Int32]]"), typeof (Foo<int>), "#3"); + Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[System.Int32][]"), typeof (Foo<int>[]), "#4"); + Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[][System.Int32]"), null, "#5"); + Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[System.Int32][,]"), typeof (Foo<int>[,]), "#6"); + Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[]"), typeof (Foo<>).MakeArrayType(), "#7"); + Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[,]"), typeof (Foo<>).MakeArrayType (2), "#8"); + Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[][]"), typeof (Foo<>).MakeArrayType ().MakeArrayType (), "#9"); + Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1["), null, "#10"); + Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[["), null, "#11"); + Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[[]"), null, "#12"); + Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[,"), null, "#13"); + Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[*"), null, "#14"); + Assert.AreEqual (Type.GetType ("MonoTests.System.Foo`1[System.Int32"), null, "#15"); + } + public abstract class Stream : IDisposable { public void Dispose () |