diff options
author | Ungureanu Marius <marius.ungureanu@xamarin.com> | 2015-02-17 07:39:46 +0300 |
---|---|---|
committer | Ungureanu Marius <marius.ungureanu@xamarin.com> | 2015-02-17 07:41:12 +0300 |
commit | 818d229538e22b7bfbc068850fbcd6141e118bb5 (patch) | |
tree | a2360f094bc305f5bef89284b83fb8035da77e17 /mcs | |
parent | bc57fda921d7c35dd7f52f71bdbdff9e831f328e (diff) |
Bug 27010 - Difference in Assembly.GetExportedTypes with .NET
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/corlib/Test/System.Reflection/VisibilityTest.cs | 98 | ||||
-rw-r--r-- | mcs/class/corlib/corlib_test.dll.sources | 1 |
2 files changed, 99 insertions, 0 deletions
diff --git a/mcs/class/corlib/Test/System.Reflection/VisibilityTest.cs b/mcs/class/corlib/Test/System.Reflection/VisibilityTest.cs new file mode 100644 index 00000000000..3dcb3ae2480 --- /dev/null +++ b/mcs/class/corlib/Test/System.Reflection/VisibilityTest.cs @@ -0,0 +1,98 @@ +// VisibilityTest.cs +// +// +// Author: +// Marius Ungureanu <marius.ungureanu@xamarin.com> +// +// Copyright (c) 2015 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 !MONOTOUCH + +using System; +using System.Linq; +using System.Reflection; +using NUnit.Framework; + +namespace MonoTests.System.Reflection.VisibilityTypes +{ + [TestFixture] + public class VisibilityTests + { + [Test] + public void TestsExportedTypes () + { + var types = typeof (VisibilityTests).Assembly.GetExportedTypes (); + + // Test visibility means that the class is public by applying and on the 'public' visibility of the nested items. + CollectionAssert.DoesNotContain (types, typeof (InternalClass)); + CollectionAssert.Contains (types, typeof (PublicClass)); + + CollectionAssert.DoesNotContain (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+InternalNested", true)); + CollectionAssert.DoesNotContain (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+PrivateNested", true)); + CollectionAssert.DoesNotContain (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+ProtectedNested", true)); + CollectionAssert.DoesNotContain (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+PublicNested", true)); + + CollectionAssert.DoesNotContain (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+InternalNested", true)); + CollectionAssert.DoesNotContain (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+PrivateNested", true)); + CollectionAssert.DoesNotContain (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+ProtectedNested", true)); + CollectionAssert.Contains (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+PublicNested", true)); + } + + [Test] + public void TestsModuleTypes () + { + var types = typeof (VisibilityTests).Module.GetTypes (); + + // Test that all the types defined exist. + CollectionAssert.Contains (types, typeof (InternalClass)); + CollectionAssert.Contains (types, typeof (PublicClass)); + + CollectionAssert.Contains (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+InternalNested", true)); + CollectionAssert.Contains (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+PrivateNested", true)); + CollectionAssert.Contains (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+ProtectedNested", true)); + CollectionAssert.Contains (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+PublicNested", true)); + + CollectionAssert.Contains (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+InternalNested", true)); + CollectionAssert.Contains (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+PrivateNested", true)); + CollectionAssert.Contains (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+ProtectedNested", true)); + CollectionAssert.Contains (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+PublicNested", true)); + } + + class InternalClass + { + internal class InternalNested {} + private class PrivateNested {} + protected class ProtectedNested {} + public class PublicNested {} + } + + public class PublicClass + { + internal class InternalNested {} + private class PrivateNested {} + protected class ProtectedNested {} + public class PublicNested {} + } + } +} + +#endif + diff --git a/mcs/class/corlib/corlib_test.dll.sources b/mcs/class/corlib/corlib_test.dll.sources index e03f139adb9..33dabcf9c99 100644 --- a/mcs/class/corlib/corlib_test.dll.sources +++ b/mcs/class/corlib/corlib_test.dll.sources @@ -148,6 +148,7 @@ System.Reflection/ParameterInfoTest.cs System.Reflection/PropertyInfoTest.cs System.Reflection/ReflectedTypeTest.cs System.Reflection/TypeDelegatorTest.cs +System.Reflection/VisibilityTest.cs System.Reflection.Emit/AssemblyBuilderTest.cs System.Reflection.Emit/AssemblyBuilderAccessTest.cs System.Reflection.Emit/ConstructorBuilderTest.cs |