Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugh Bellamy <hughbellars@gmail.com>2017-06-17 09:02:40 +0300
committerDan Moseley <danmose@microsoft.com>2017-06-17 09:02:40 +0300
commit5ed78fa35cb842b9bc67f720a1178f762a86d9f8 (patch)
tree8f90278dfea81ca962a2be0ca8a7e9a5a18b5a93 /src/System.Runtime.InteropServices
parentba5a33a58548f8bff03f792487bee0a89b3b3125 (diff)
Add some System.Runtime.InteropServices tests (#21140)
* Cleanup some product code * Cleanup and bolster existing tests
Diffstat (limited to 'src/System.Runtime.InteropServices')
-rw-r--r--src/System.Runtime.InteropServices/src/System/Runtime/CompilerServices/Attributes.cs11
-rw-r--r--src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/Attributes.cs46
-rw-r--r--src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComAwareEventInfo.cs64
-rw-r--r--src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComEventInterfaceAttribute.cs13
-rw-r--r--src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs11
-rw-r--r--src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/HandleCollector.cs30
-rw-r--r--src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs34
-rw-r--r--src/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.Tests.csproj5
-rw-r--r--src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/AllowReversePInvokeCallsAttributeTests.cs13
-rw-r--r--src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/CallingConventionTests.cs17
-rw-r--r--src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComAliasNameAttributeTests.cs18
-rw-r--r--src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComCompatibleVersionAttributeTests.cs29
-rw-r--r--src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComConversionLossAttributeTests.cs8
-rw-r--r--src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComRegisterFunctionAttributeTests.cs13
-rw-r--r--src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComUnregisterFunctionAttributeTests.cs13
-rw-r--r--src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComVisibleAttributeTests.cs18
-rw-r--r--src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/DefaultParameterValueAttributeTests.cs6
-rw-r--r--src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/HandleCollectorTests.cs100
-rw-r--r--src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/HandleRefTests.cs28
-rw-r--r--src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/LCIDConversionAttributeTests.cs24
-rw-r--r--src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/MarshalTests.cs1
-rw-r--r--src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/PrimaryInteropAssemblyAttributeTests.cs23
-rw-r--r--src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ProgIdAttributeTests.cs18
-rw-r--r--src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/RuntimeEnvironmentTest.cs43
-rw-r--r--src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/RuntimeEnvironmentTests.cs54
25 files changed, 322 insertions, 318 deletions
diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/CompilerServices/Attributes.cs b/src/System.Runtime.InteropServices/src/System/Runtime/CompilerServices/Attributes.cs
index 6ccbc1c304..e98f40d317 100644
--- a/src/System.Runtime.InteropServices/src/System/Runtime/CompilerServices/Attributes.cs
+++ b/src/System.Runtime.InteropServices/src/System/Runtime/CompilerServices/Attributes.cs
@@ -7,15 +7,10 @@ using System.Runtime.InteropServices;
namespace System.Runtime.CompilerServices
{
[System.AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)]
- public sealed partial class IUnknownConstantAttribute : System.Runtime.CompilerServices.CustomConstantAttribute
+ public sealed partial class IUnknownConstantAttribute : CustomConstantAttribute
{
public IUnknownConstantAttribute() { }
- public override object Value
- {
- get
- {
- return new UnknownWrapper(null);
- }
- }
+
+ public override object Value => new UnknownWrapper(null);
}
}
diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/Attributes.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/Attributes.cs
index af989d0742..9ab87e0ca3 100644
--- a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/Attributes.cs
+++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/Attributes.cs
@@ -2,27 +2,21 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
-
namespace System.Runtime.InteropServices
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false)]
public sealed class AutomationProxyAttribute : Attribute
{
- public AutomationProxyAttribute(bool val)
- {
- Value = val;
- }
+ public AutomationProxyAttribute(bool val) => Value = val;
+
public bool Value { get; }
}
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
public sealed class ComAliasNameAttribute : Attribute
{
- public ComAliasNameAttribute(string alias)
- {
- Value = alias;
- }
+ public ComAliasNameAttribute(string alias) => Value = alias;
+
public string Value { get; }
}
@@ -62,14 +56,12 @@ namespace System.Runtime.InteropServices
[Obsolete("This attribute is deprecated and will be removed in a future version.", false)]
public sealed class IDispatchImplAttribute : Attribute
{
- public IDispatchImplAttribute(short implType)
- {
- Value = (IDispatchImplType)implType;
- }
- public IDispatchImplAttribute(IDispatchImplType implType)
+ public IDispatchImplAttribute(short implType) : this((IDispatchImplType)implType)
{
- Value = implType;
}
+
+ public IDispatchImplAttribute(IDispatchImplType implType) => Value = implType;
+
public IDispatchImplType Value { get; }
}
@@ -84,10 +76,8 @@ namespace System.Runtime.InteropServices
[AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
public sealed class ImportedFromTypeLibAttribute : Attribute
{
- public ImportedFromTypeLibAttribute(String tlbFile)
- {
- Value = tlbFile;
- }
+ public ImportedFromTypeLibAttribute(string tlbFile) => Value = tlbFile;
+
public string Value { get; }
}
@@ -129,10 +119,8 @@ namespace System.Runtime.InteropServices
[AttributeUsage(AttributeTargets.Interface, Inherited = false)]
public sealed class TypeLibImportClassAttribute : Attribute
{
- public TypeLibImportClassAttribute(Type importClass)
- {
- Value = importClass.ToString();
- }
+ public TypeLibImportClassAttribute(Type importClass) => Value = importClass.ToString();
+
public string Value { get; }
}
@@ -192,16 +180,18 @@ namespace System.Runtime.InteropServices
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Enum | AttributeTargets.Struct, Inherited = false)]
- public sealed class TypeLibTypeAttribute : Attribute
+ public sealed class TypeLibTypeAttribute : Attribute
{
public TypeLibTypeAttribute(TypeLibTypeFlags flags)
{
Value = flags;
}
+
public TypeLibTypeAttribute(short flags)
{
Value = (TypeLibTypeFlags)flags;
}
+
public TypeLibTypeFlags Value { get; }
}
@@ -212,10 +202,12 @@ namespace System.Runtime.InteropServices
{
Value = flags;
}
+
public TypeLibFuncAttribute(short flags)
{
Value = (TypeLibFuncFlags)flags;
}
+
public TypeLibFuncFlags Value { get; }
}
@@ -226,15 +218,17 @@ namespace System.Runtime.InteropServices
{
Value = flags;
}
+
public TypeLibVarAttribute(short flags)
{
Value = (TypeLibVarFlags)flags;
}
+
public TypeLibVarFlags Value { get; }
}
[AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
+ [ComVisible(true)]
public sealed class TypeLibVersionAttribute : Attribute
{
public TypeLibVersionAttribute(int major, int minor)
diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComAwareEventInfo.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComAwareEventInfo.cs
index f5fac0b579..6212d0b62f 100644
--- a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComAwareEventInfo.cs
+++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComAwareEventInfo.cs
@@ -2,28 +2,29 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Reflection;
+using System.Security;
+
namespace System.Runtime.InteropServices
{
- [System.Security.SecuritySafeCritical]
- public class ComAwareEventInfo : System.Reflection.EventInfo
+ [SecuritySafeCritical]
+ public class ComAwareEventInfo : EventInfo
{
- private System.Reflection.EventInfo _innerEventInfo;
+ private EventInfo _innerEventInfo;
public ComAwareEventInfo(Type type, string eventName)
{
_innerEventInfo = type.GetEvent(eventName);
}
- [System.Security.SecuritySafeCritical]
+ [SecuritySafeCritical]
public override void AddEventHandler(object target, Delegate handler)
{
if (Marshal.IsComObject(target))
{
// retrieve sourceIid and dispid
- Guid sourceIid;
- int dispid;
- GetDataForComInvocation(_innerEventInfo, out sourceIid, out dispid);
- System.Runtime.InteropServices.ComEventsHelper.Combine(target, sourceIid, dispid, handler);
+ GetDataForComInvocation(_innerEventInfo, out Guid sourceIid, out int dispid);
+ ComEventsHelper.Combine(target, sourceIid, dispid, handler);
}
else
{
@@ -32,17 +33,15 @@ namespace System.Runtime.InteropServices
}
}
- [System.Security.SecuritySafeCritical]
+ [SecuritySafeCritical]
public override void RemoveEventHandler(object target, Delegate handler)
{
if (Marshal.IsComObject(target))
{
// retrieve sourceIid and dispid
- Guid sourceIid;
- int dispid;
- GetDataForComInvocation(_innerEventInfo, out sourceIid, out dispid);
+ GetDataForComInvocation(_innerEventInfo, out Guid sourceIid, out int dispid);
- System.Runtime.InteropServices.ComEventsHelper.Remove(target, sourceIid, dispid, handler);
+ ComEventsHelper.Remove(target, sourceIid, dispid, handler);
}
else
{
@@ -51,30 +50,15 @@ namespace System.Runtime.InteropServices
}
}
- public override System.Reflection.EventAttributes Attributes
- {
- get { return _innerEventInfo.Attributes; }
- }
+ public override EventAttributes Attributes => _innerEventInfo.Attributes;
- public override System.Reflection.MethodInfo GetAddMethod(bool nonPublic)
- {
- return _innerEventInfo.GetAddMethod(nonPublic);
- }
+ public override MethodInfo GetAddMethod(bool nonPublic) => _innerEventInfo.GetAddMethod(nonPublic);
- public override System.Reflection.MethodInfo GetRaiseMethod(bool nonPublic)
- {
- return _innerEventInfo.GetRaiseMethod(nonPublic);
- }
+ public override MethodInfo GetRaiseMethod(bool nonPublic) => _innerEventInfo.GetRaiseMethod(nonPublic);
- public override System.Reflection.MethodInfo GetRemoveMethod(bool nonPublic)
- {
- return _innerEventInfo.GetRemoveMethod(nonPublic);
- }
+ public override MethodInfo GetRemoveMethod(bool nonPublic) => _innerEventInfo.GetRemoveMethod(nonPublic);
- public override Type DeclaringType
- {
- get { return _innerEventInfo.DeclaringType; }
- }
+ public override Type DeclaringType => _innerEventInfo.DeclaringType;
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
{
@@ -91,15 +75,9 @@ namespace System.Runtime.InteropServices
return _innerEventInfo.IsDefined(attributeType, inherit);
}
- public override string Name
- {
- get { return _innerEventInfo.Name; }
- }
+ public override string Name => _innerEventInfo.Name;
- public override Type ReflectedType
- {
- get { return _innerEventInfo.ReflectedType; }
- }
+ public override Type ReflectedType => _innerEventInfo.ReflectedType;
private static void GetDataForComInvocation(System.Reflection.EventInfo eventInfo, out Guid sourceIid, out int dispid)
{
@@ -114,13 +92,13 @@ namespace System.Runtime.InteropServices
if (comEventInterfaces.Length > 1)
{
// TODO: event strings need to be localizable
- throw new System.Reflection.AmbiguousMatchException("more than one ComSourceInterfaceGuidAttribute found");
+ throw new AmbiguousMatchException("more than one ComSourceInterfaceGuidAttribute found");
}
Type sourceItf = ((ComEventInterfaceAttribute)comEventInterfaces[0]).SourceInterface;
Guid guid = sourceItf.GUID;
- System.Reflection.MethodInfo methodInfo = sourceItf.GetMethod(eventInfo.Name);
+ MethodInfo methodInfo = sourceItf.GetMethod(eventInfo.Name);
Attribute dispIdAttribute = Attribute.GetCustomAttribute(methodInfo, typeof(DispIdAttribute));
if (dispIdAttribute == null)
{
diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComEventInterfaceAttribute.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComEventInterfaceAttribute.cs
index 7cb6fb951e..3a3cef7c4e 100644
--- a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComEventInterfaceAttribute.cs
+++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComEventInterfaceAttribute.cs
@@ -2,23 +2,18 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
-
namespace System.Runtime.InteropServices
{
[AttributeUsage(AttributeTargets.Interface, Inherited = false)]
public sealed class ComEventInterfaceAttribute : Attribute
{
- internal Type _SourceInterface;
- internal Type _EventProvider;
-
public ComEventInterfaceAttribute(Type SourceInterface, Type EventProvider)
{
- _SourceInterface = SourceInterface;
- _EventProvider = EventProvider;
+ this.SourceInterface = SourceInterface;
+ this.EventProvider = EventProvider;
}
- public Type SourceInterface { get { return _SourceInterface; } }
- public Type EventProvider { get { return _EventProvider; } }
+ public Type SourceInterface { get; }
+ public Type EventProvider { get; }
}
} \ No newline at end of file
diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs
index 6b50bd148d..160a961790 100644
--- a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs
+++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs
@@ -10,16 +10,11 @@ namespace System.Runtime.InteropServices
// from other languages. This is particularly useful for
// methods defined in COM interop interfaces.
//
- [AttributeUsageAttribute(AttributeTargets.Parameter)]
+ [AttributeUsage(AttributeTargets.Parameter)]
public sealed class DefaultParameterValueAttribute : Attribute
{
- public DefaultParameterValueAttribute(object value)
- {
- _value = value;
- }
+ public DefaultParameterValueAttribute(object value) => Value = value;
- public object Value { get { return _value; } }
-
- private object _value;
+ public object Value { get; }
}
}
diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/HandleCollector.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/HandleCollector.cs
index 2dea85f3af..49eba3b952 100644
--- a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/HandleCollector.cs
+++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/HandleCollector.cs
@@ -8,10 +8,8 @@ namespace System.Runtime.InteropServices
{
public sealed class HandleCollector
{
- private const int deltaPercent = 10; // this is used for increasing the threshold.
- private string _name;
+ private const int DeltaPercent = 10; // this is used for increasing the threshold.
private int _initialThreshold;
- private int _maximumThreshold;
private int _threshold;
private int _handleCount;
@@ -40,28 +38,20 @@ namespace System.Runtime.InteropServices
throw new ArgumentException(SR.Arg_InvalidThreshold);
}
- if (name != null)
- {
- _name = name;
- }
- else
- {
- _name = String.Empty;
- }
-
+ Name = name ?? string.Empty;
_initialThreshold = initialThreshold;
- _maximumThreshold = maximumThreshold;
+ MaximumThreshold = maximumThreshold;
_threshold = initialThreshold;
_handleCount = 0;
}
- public int Count { get { return _handleCount; } }
+ public int Count => _handleCount;
- public int InitialThreshold { get { return _initialThreshold; } }
+ public int InitialThreshold => _initialThreshold;
- public int MaximumThreshold { get { return _maximumThreshold; } }
+ public int MaximumThreshold { get; }
- public string Name { get { return _name; } }
+ public string Name { get; }
public void Add()
{
@@ -76,7 +66,7 @@ namespace System.Runtime.InteropServices
{
lock (this)
{
- _threshold = _handleCount + (_handleCount / deltaPercent);
+ _threshold = _handleCount + (_handleCount / DeltaPercent);
gen_collect = _gc_gen;
if (_gc_gen < 2)
{
@@ -108,8 +98,8 @@ namespace System.Runtime.InteropServices
throw new InvalidOperationException(SR.InvalidOperation_HCCountOverflow);
}
- int newThreshold = _handleCount + _handleCount / deltaPercent;
- if (newThreshold < (_threshold - _threshold / deltaPercent))
+ int newThreshold = _handleCount + _handleCount / DeltaPercent;
+ if (newThreshold < (_threshold - _threshold / DeltaPercent))
{
lock (this)
{
diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs
index 57f0837ee3..b68f90baf5 100644
--- a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs
+++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
using System.IO;
using System.Reflection;
@@ -10,17 +9,10 @@ namespace System.Runtime.InteropServices
{
public static class RuntimeEnvironment
{
- public static string SystemConfigurationFile
- {
- get
- {
- throw new PlatformNotSupportedException();
- }
- }
- public static bool FromGlobalAccessCache(System.Reflection.Assembly a)
- {
- return false;
- }
+ public static string SystemConfigurationFile => throw new PlatformNotSupportedException();
+
+ public static bool FromGlobalAccessCache(Assembly a) => false;
+
public static string GetRuntimeDirectory()
{
string runtimeDirectory = typeof(object).Assembly.Location;
@@ -30,17 +22,11 @@ namespace System.Runtime.InteropServices
}
return Path.GetDirectoryName(runtimeDirectory) + Path.DirectorySeparatorChar;
}
- public static System.IntPtr GetRuntimeInterfaceAsIntPtr(Guid clsid, Guid riid)
- {
- throw new PlatformNotSupportedException();
- }
- public static object GetRuntimeInterfaceAsObject(Guid clsid, Guid riid)
- {
- throw new PlatformNotSupportedException();
- }
- public static string GetSystemVersion()
- {
- return typeof(object).Assembly.ImageRuntimeVersion;
- }
+
+ public static IntPtr GetRuntimeInterfaceAsIntPtr(Guid clsid, Guid riid) => throw new PlatformNotSupportedException();
+
+ public static object GetRuntimeInterfaceAsObject(Guid clsid, Guid riid) => throw new PlatformNotSupportedException();
+
+ public static string GetSystemVersion() => typeof(object).Assembly.ImageRuntimeVersion;
}
}
diff --git a/src/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.Tests.csproj b/src/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.Tests.csproj
index 5d13a5b16a..a43afc32dc 100644
--- a/src/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.Tests.csproj
+++ b/src/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.Tests.csproj
@@ -18,7 +18,6 @@
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
<Link>Common\System\PlatformDetection.cs</Link>
</Compile>
- <Compile Include="System\Runtime\InteropServices\RuntimeEnvironmentTest.cs" />
<Compile Include="System\Runtime\InteropServices\AllowReversePInvokeCallsAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\CallingConventionTests.cs" />
<Compile Include="System\Runtime\InteropServices\ComAliasNameAttributeTests.cs" />
@@ -31,6 +30,10 @@
<Compile Include="System\Runtime\InteropServices\LCIDConversionAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\PrimaryInteropAssemblyAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\ProgIdAttributeTests.cs" />
+ <Compile Include="System\Runtime\InteropServices\RuntimeEnvironmentTests.cs" />
+ <Compile Include="$(CommonTestPath)\System\AssertExtensions.cs">
+ <Link>Common\System\AssertExtensions.cs</Link>
+ </Compile>
<Compile Include="$(CommonTestPath)\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs">
<Link>System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs</Link>
</Compile>
diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/AllowReversePInvokeCallsAttributeTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/AllowReversePInvokeCallsAttributeTests.cs
index 1d71e986e5..08a65e7a13 100644
--- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/AllowReversePInvokeCallsAttributeTests.cs
+++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/AllowReversePInvokeCallsAttributeTests.cs
@@ -11,18 +11,15 @@ namespace System.Runtime.InteropServices.Tests
public class AllowReversePInvokeCallsAttributeTests
{
[AllowReversePInvokeCalls]
- private int Func(int a, int b)
- {
- return a + b;
- }
+ private int Func(int a, int b) => a + b;
[Fact]
public void Exists()
{
- var type = typeof(AllowReversePInvokeCallsAttributeTests);
- var method = type.GetTypeInfo().DeclaredMethods.Single(m => m.Name == "Func");
- var attr = method.GetCustomAttributes(typeof(AllowReversePInvokeCallsAttribute), false).OfType<AllowReversePInvokeCallsAttribute>().SingleOrDefault();
- Assert.NotNull(attr);
+ Type type = typeof(AllowReversePInvokeCallsAttributeTests);
+ MethodInfo method = type.GetTypeInfo().DeclaredMethods.Single(m => m.Name == "Func");
+ AllowReversePInvokeCallsAttribute attribute = Assert.Single(method.GetCustomAttributes< AllowReversePInvokeCallsAttribute>(false));
+ Assert.NotNull(attribute);
}
}
}
diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/CallingConventionTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/CallingConventionTests.cs
index 7ea53a1e2b..63df4f90dc 100644
--- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/CallingConventionTests.cs
+++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/CallingConventionTests.cs
@@ -2,22 +2,21 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Linq;
-using System.Reflection;
using Xunit;
namespace System.Runtime.InteropServices.Tests
{
public class CallingConventionTests
{
- [Fact]
- public void Values()
+ [Theory]
+ [InlineData(CallingConvention.Winapi, 1)]
+ [InlineData(CallingConvention.Cdecl, 2)]
+ [InlineData(CallingConvention.StdCall, 3)]
+ [InlineData(CallingConvention.ThisCall, 4)]
+ [InlineData(CallingConvention.FastCall, 5)]
+ public void CallingConvention_Get_ReturnsExpected(CallingConvention convention, int expected)
{
- Assert.Equal(1, (int)CallingConvention.Winapi);
- Assert.Equal(2, (int)CallingConvention.Cdecl);
- Assert.Equal(3, (int)CallingConvention.StdCall);
- Assert.Equal(4, (int)CallingConvention.ThisCall);
- Assert.Equal(5, (int)CallingConvention.FastCall);
+ Assert.Equal(expected, (int)convention);
}
}
}
diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComAliasNameAttributeTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComAliasNameAttributeTests.cs
index 88ad06210a..4fef851968 100644
--- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComAliasNameAttributeTests.cs
+++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComAliasNameAttributeTests.cs
@@ -18,11 +18,19 @@ namespace System.Runtime.InteropServices.Tests
[Fact]
public void Exists()
{
- var type = typeof(ComAliasNameAttributeTests);
- var field = type.GetTypeInfo().DeclaredFields.Single(f => f.Name == "_foo");
- var attr = field.GetCustomAttributes(typeof(ComAliasNameAttribute), false).OfType<ComAliasNameAttribute>().SingleOrDefault();
- Assert.NotNull(attr);
- Assert.Equal("foo", attr.Value);
+ FieldInfo field = typeof(ComAliasNameAttributeTests).GetTypeInfo().DeclaredFields.Single(f => f.Name == "_foo");
+ ComAliasNameAttribute attribute = Assert.Single(field.GetCustomAttributes<ComAliasNameAttribute>(false));
+ Assert.Equal("foo", attribute.Value);
+ }
+
+ [Theory]
+ [InlineData(null)]
+ [InlineData("")]
+ [InlineData("value")]
+ public void Ctor_Alias(string alias)
+ {
+ var attribute = new ComAliasNameAttribute(alias);
+ Assert.Equal(alias, attribute.Value);
}
}
}
diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComCompatibleVersionAttributeTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComCompatibleVersionAttributeTests.cs
index 6545abba7b..695f80ad1b 100644
--- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComCompatibleVersionAttributeTests.cs
+++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComCompatibleVersionAttributeTests.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using Xunit;
@@ -16,14 +15,26 @@ namespace System.Runtime.InteropServices.Tests
[Fact]
public void Exists()
{
- var type = typeof(ComCompatibleVersionAttributeTests);
- var assembly = type.GetTypeInfo().Assembly;
- var attr = assembly.GetCustomAttributes(typeof(ComCompatibleVersionAttribute), false).OfType<ComCompatibleVersionAttribute>().SingleOrDefault();
- Assert.NotNull(attr);
- Assert.Equal(1, attr.MajorVersion);
- Assert.Equal(2, attr.MinorVersion);
- Assert.Equal(3, attr.BuildNumber);
- Assert.Equal(4, attr.RevisionNumber);
+ Type type = typeof(ComCompatibleVersionAttributeTests);
+ Assembly assembly = type.GetTypeInfo().Assembly;
+ ComCompatibleVersionAttribute attribute = Assert.Single(assembly.GetCustomAttributes<ComCompatibleVersionAttribute>());
+ Assert.Equal(1, attribute.MajorVersion);
+ Assert.Equal(2, attribute.MinorVersion);
+ Assert.Equal(3, attribute.BuildNumber);
+ Assert.Equal(4, attribute.RevisionNumber);
+ }
+
+ [Theory]
+ [InlineData(-1, -2, -3, -4)]
+ [InlineData(0, 0, 0, 0)]
+ [InlineData(1, 2, 3, 4)]
+ public void Ctor_Major_Minor_Build_Revision(int major, int minor, int build, int revision)
+ {
+ var attribute = new ComCompatibleVersionAttribute(major, minor, build, revision);
+ Assert.Equal(major, attribute.MajorVersion);
+ Assert.Equal(minor, attribute.MinorVersion);
+ Assert.Equal(build, attribute.BuildNumber);
+ Assert.Equal(revision, attribute.RevisionNumber);
}
}
}
diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComConversionLossAttributeTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComConversionLossAttributeTests.cs
index a723f49257..07871ad859 100644
--- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComConversionLossAttributeTests.cs
+++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComConversionLossAttributeTests.cs
@@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Linq;
-using System.Reflection;
using Xunit;
namespace System.Runtime.InteropServices.Tests
@@ -14,9 +12,9 @@ namespace System.Runtime.InteropServices.Tests
[Fact]
public void Exists()
{
- var type = typeof(ComConversionLossAttributeTests);
- var attr = type.GetCustomAttributes(typeof(ComConversionLossAttribute), false).OfType<ComConversionLossAttribute>().SingleOrDefault();
- Assert.NotNull(attr);
+ Type type = typeof(ComConversionLossAttributeTests);
+ ComConversionLossAttribute attribute = Assert.IsType<ComConversionLossAttribute>(Assert.Single(type.GetCustomAttributes(typeof(ComConversionLossAttribute), false)));
+ Assert.NotNull(attribute);
}
}
}
diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComRegisterFunctionAttributeTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComRegisterFunctionAttributeTests.cs
index fbc4332026..0d4c40ba65 100644
--- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComRegisterFunctionAttributeTests.cs
+++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComRegisterFunctionAttributeTests.cs
@@ -11,18 +11,15 @@ namespace System.Runtime.InteropServices.Tests
public class ComRegisterFunctionAttributeTests
{
[ComRegisterFunction]
- private int Func(int a, int b)
- {
- return a + b;
- }
+ private int Func(int a, int b) => a + b;
[Fact]
public void Exists()
{
- var type = typeof(ComRegisterFunctionAttributeTests);
- var method = type.GetTypeInfo().DeclaredMethods.Single(m => m.Name == "Func");
- var attr = method.GetCustomAttributes(typeof(ComRegisterFunctionAttribute), false).OfType<ComRegisterFunctionAttribute>().SingleOrDefault();
- Assert.NotNull(attr);
+ Type type = typeof(ComRegisterFunctionAttributeTests);
+ MethodInfo method = type.GetTypeInfo().DeclaredMethods.Single(m => m.Name == "Func");
+ ComRegisterFunctionAttribute attribute = Assert.Single(method.GetCustomAttributes<ComRegisterFunctionAttribute>(false));
+ Assert.NotNull(attribute);
}
}
}
diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComUnregisterFunctionAttributeTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComUnregisterFunctionAttributeTests.cs
index 3189d93e69..80d37d15f8 100644
--- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComUnregisterFunctionAttributeTests.cs
+++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComUnregisterFunctionAttributeTests.cs
@@ -11,18 +11,15 @@ namespace System.Runtime.InteropServices.Tests
public class ComUnregisterFunctionAttributeTests
{
[ComUnregisterFunction]
- private int Func(int a, int b)
- {
- return a + b;
- }
+ private int Func(int a, int b) => a + b;
[Fact]
public void Exists()
{
- var type = typeof(ComUnregisterFunctionAttributeTests);
- var method = type.GetTypeInfo().DeclaredMethods.Single(m => m.Name == "Func");
- var attr = method.GetCustomAttributes(typeof(ComUnregisterFunctionAttribute), false).OfType<ComUnregisterFunctionAttribute>().SingleOrDefault();
- Assert.NotNull(attr);
+ Type type = typeof(ComUnregisterFunctionAttributeTests);
+ MethodInfo method = type.GetTypeInfo().DeclaredMethods.Single(m => m.Name == "Func");
+ ComUnregisterFunctionAttribute attribute = Assert.Single(method.GetCustomAttributes<ComUnregisterFunctionAttribute>(false));
+ Assert.NotNull(attribute);
}
}
}
diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComVisibleAttributeTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComVisibleAttributeTests.cs
index 6c0124ad00..b7c0814672 100644
--- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComVisibleAttributeTests.cs
+++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComVisibleAttributeTests.cs
@@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Linq;
-using System.Reflection;
using Xunit;
namespace System.Runtime.InteropServices.Tests
@@ -14,10 +12,18 @@ namespace System.Runtime.InteropServices.Tests
[Fact]
public void Exists()
{
- var type = typeof(ComVisibleAttributeTests);
- var attr = type.GetCustomAttributes(typeof(ComVisibleAttribute), false).OfType<ComVisibleAttribute>().SingleOrDefault();
- Assert.NotNull(attr);
- Assert.Equal(true, attr.Value);
+ Type type = typeof(ComVisibleAttributeTests);
+ ComVisibleAttribute attribute = Assert.IsType<ComVisibleAttribute>(Assert.Single(type.GetCustomAttributes(typeof(ComVisibleAttribute), false)));
+ Assert.True(attribute.Value);
+ }
+
+ [Theory]
+ [InlineData(true)]
+ [InlineData(false)]
+ public void Ctor_Visible(bool visibility)
+ {
+ var attribute = new ComVisibleAttribute(visibility);
+ Assert.Equal(visibility, attribute.Value);
}
}
}
diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/DefaultParameterValueAttributeTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/DefaultParameterValueAttributeTests.cs
index 97f568deb5..fa2ac4bdf6 100644
--- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/DefaultParameterValueAttributeTests.cs
+++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/DefaultParameterValueAttributeTests.cs
@@ -15,10 +15,10 @@ namespace System.Runtime.InteropServices
[InlineData(5.0f)]
[InlineData("ExpectedValue")]
[InlineData(null)]
- public static void Constructor(object expected)
+ public static void Ctor_Value(object value)
{
- DefaultParameterValueAttribute attribute = new DefaultParameterValueAttribute(expected);
- Assert.Equal(expected, attribute.Value);
+ var attribute = new DefaultParameterValueAttribute(value);
+ Assert.Equal(value, attribute.Value);
}
}
}
diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/HandleCollectorTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/HandleCollectorTests.cs
index 4c73dd4244..d67005548d 100644
--- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/HandleCollectorTests.cs
+++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/HandleCollectorTests.cs
@@ -7,53 +7,81 @@ using Xunit;
namespace System.Runtime.InteropServices
{
- public static class HandleCollectorTests
+ public class HandleCollectorTests
{
private const int LowLimitSize = 20;
private const int HighLimitSize = 100000;
- [Fact]
- public static void NegativeInitialThresholdCtor()
+ [Theory]
+ [InlineData(null, 0)]
+ [InlineData("", 10)]
+ [InlineData("InitialThreshold", int.MaxValue)]
+ public void Ctor_Name_InitialThreshold(string name, int initialThreshold)
{
- Assert.Throws<ArgumentOutOfRangeException>(() => new HandleCollector("NegativeInitial", -1));
+ var handleCollector = new HandleCollector(name, initialThreshold);
+ Assert.Equal(0, handleCollector.Count);
+ Assert.Equal(name ?? string.Empty, handleCollector.Name);
+ Assert.Equal(initialThreshold, handleCollector.InitialThreshold);
+ Assert.Equal(int.MaxValue, handleCollector.MaximumThreshold);
}
- [Fact]
- public static void NegateMaximumThresholdCtor()
+ [Theory]
+ [InlineData(null, 0, 0)]
+ [InlineData("", 10, 15)]
+ [InlineData("InitialThreshold", 1, 2)]
+ public void Ctor_Name_InitialThreshold_MaximumThreshold(string name, int initialThreshold, int maximumThreshold)
{
- Assert.Throws<ArgumentOutOfRangeException>(() => new HandleCollector("NegativeMax", 0, -1));
+ var handleCollector = new HandleCollector(name, initialThreshold, maximumThreshold);
+ Assert.Equal(0, handleCollector.Count);
+ Assert.Equal(name ?? string.Empty, handleCollector.Name);
+ Assert.Equal(initialThreshold, handleCollector.InitialThreshold);
+ Assert.Equal(maximumThreshold, handleCollector.MaximumThreshold);
}
[Fact]
- public static void InitialGreaterThanMaxThresholdCtor()
+ public void Ctor_NegativeInitialThreshold_ThrowsArgumentOufORangeException()
{
- Assert.Throws<ArgumentException>(() => new HandleCollector("InitialGreaterThanMax", 100, 1));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("initialThreshold", () => new HandleCollector("NegativeInitial", -1));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("initialThreshold", () => new HandleCollector("NegativeInitial", -1, 0));
}
[Fact]
- public static void SimplePropertyValidation()
+ public static void Ctor_NegativeMaximumThreshold_ThrowsArgumentOutOfRangeException()
{
- string name = "ExampleName";
- int initial = 10;
- int max = 20;
-
- HandleCollector collector = new HandleCollector(name, initial, max);
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("maximumThreshold", () => new HandleCollector("NegativeMax", 0, -1));
+ }
- Assert.Equal(0, collector.Count);
- Assert.Equal(name, collector.Name);
- Assert.Equal(initial, collector.InitialThreshold);
- Assert.Equal(max, collector.MaximumThreshold);
+ [Fact]
+ public static void Ctor_InitialThresholdGreaterThanMaximumThreshold_ThrowsArgumentException()
+ {
+ AssertExtensions.Throws<ArgumentException>(null, () => new HandleCollector("InitialGreaterThanMax", 100, 1));
}
[Fact]
- public static void NullNameCtor()
+ public void AddRemove_AcrossMultipleGenerations_Success()
{
- HandleCollector collector = new HandleCollector(null, 0, 0);
- Assert.Equal(string.Empty, collector.Name);
+ var collector = new HandleCollector("name", 0);
+ collector.Add();
+ Assert.Equal(1, collector.Count);
+
+ collector.Add();
+ Assert.Equal(2, collector.Count);
+
+ collector.Add();
+ Assert.Equal(3, collector.Count);
+
+ collector.Remove();
+ Assert.Equal(2, collector.Count);
+
+ collector.Remove();
+ Assert.Equal(1, collector.Count);
+
+ collector.Remove();
+ Assert.Equal(0, collector.Count);
}
[Fact]
- public static void EmptyRemoval()
+ public static void Remove_EmptyCollection_ThrowsInvalidOperationException()
{
HandleCollector collector = new HandleCollector("EmptyRemoval", 10);
Assert.Throws<InvalidOperationException>(() => collector.Remove());
@@ -61,7 +89,7 @@ namespace System.Runtime.InteropServices
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.UapAot,"Reflects on private member handleCount")]
- public static void CountOverflow()
+ public static void Add_Overflows_ThrowsInvalidOperationException()
{
HandleCollector collector = new HandleCollector("CountOverflow", int.MaxValue);
@@ -95,10 +123,7 @@ namespace System.Runtime.InteropServices
[Fact]
public static void TestHandleCollector()
{
- Tuple<int, int, int> initialGcState = new Tuple<int, int, int>(
- GC.CollectionCount(0),
- GC.CollectionCount(1),
- GC.CollectionCount(2));
+ (int gen0, int gen1, int gen2) initialGcState = (GC.CollectionCount(0), GC.CollectionCount(1), GC.CollectionCount(2));
HandleCollector lowLimitCollector = new HandleCollector("LowLimit.Collector", LowLimitSize);
for (int i = 0; i < LowLimitSize + 1; ++i)
@@ -106,12 +131,9 @@ namespace System.Runtime.InteropServices
HandleLimitTester hlt = new HandleLimitTester(lowLimitCollector);
}
- Tuple<int, int, int> postLowLimitState = new Tuple<int, int, int>(
- GC.CollectionCount(0),
- GC.CollectionCount(1),
- GC.CollectionCount(2));
+ (int gen0, int gen1, int gen2) postLowLimitState = (GC.CollectionCount(0),GC.CollectionCount(1), GC.CollectionCount(2));
- Assert.True(initialGcState.Item1 + initialGcState.Item2 + initialGcState.Item3 < postLowLimitState.Item1 + postLowLimitState.Item2 + postLowLimitState.Item3, "Low limit handle did not trigger a GC");
+ Assert.True(initialGcState.gen0 + initialGcState.gen1 + initialGcState.gen2 < postLowLimitState.gen0 + postLowLimitState.gen1 + postLowLimitState.gen2, "Low limit handle did not trigger a GC");
HandleCollector highLimitCollector = new HandleCollector("HighLimit.Collector", HighLimitSize);
for (int i = 0; i < HighLimitSize + 10; ++i)
@@ -119,12 +141,9 @@ namespace System.Runtime.InteropServices
HandleLimitTester hlt = new HandleLimitTester(highLimitCollector);
}
- Tuple<int, int, int> postHighLimitState = new Tuple<int, int, int>(
- GC.CollectionCount(0),
- GC.CollectionCount(1),
- GC.CollectionCount(2));
+ (int gen0, int gen1, int gen2) postHighLimitState = (GC.CollectionCount(0), GC.CollectionCount(1), GC.CollectionCount(2));
- Assert.True(postLowLimitState.Item1 + postLowLimitState.Item2 + postLowLimitState.Item3 < postHighLimitState.Item1 + postHighLimitState.Item2 + postHighLimitState.Item3, "High limit handle did not trigger a GC");
+ Assert.True(postLowLimitState.gen0 + postLowLimitState.gen1 + postLowLimitState.gen2 < postHighLimitState.gen0 + postHighLimitState.gen1 + postHighLimitState.gen2, "High limit handle did not trigger a GC");
}
private sealed class HandleLimitTester
@@ -138,10 +157,7 @@ namespace System.Runtime.InteropServices
GC.KeepAlive(this);
}
- ~HandleLimitTester()
- {
- _collector.Remove();
- }
+ ~HandleLimitTester() => _collector.Remove();
}
}
}
diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/HandleRefTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/HandleRefTests.cs
index 8f1979e262..9183dcd010 100644
--- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/HandleRefTests.cs
+++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/HandleRefTests.cs
@@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Linq;
-using System.Reflection;
using Xunit;
namespace System.Runtime.InteropServices.Tests
@@ -11,15 +9,25 @@ namespace System.Runtime.InteropServices.Tests
public class HandleRefTests
{
[Fact]
- public void Properties()
+ public void Ctor_Default()
{
- var obj = new object();
- var ptr = new IntPtr(1337);
- var handleRef = new HandleRef(obj, ptr);
- Assert.Equal(ptr, (IntPtr)handleRef);
- Assert.Equal(ptr, HandleRef.ToIntPtr(handleRef));
- Assert.Equal(ptr, handleRef.Handle);
- Assert.Same(obj, handleRef.Wrapper);
+ var handleRef = new HandleRef();
+ Assert.Null(handleRef.Wrapper);
+ Assert.Equal(IntPtr.Zero, handleRef.Handle);
+ Assert.Equal(IntPtr.Zero, (IntPtr)handleRef);
+ Assert.Equal(IntPtr.Zero, HandleRef.ToIntPtr(handleRef));
+ }
+
+ [Theory]
+ [InlineData(null, 0)]
+ [InlineData("Wrapper", 1337)]
+ public void Ctor_Wrapper_Handle(object wrapper, int handle)
+ {
+ var handleRef = new HandleRef(wrapper, (IntPtr)handle);
+ Assert.Same(wrapper, handleRef.Wrapper);
+ Assert.Equal((IntPtr)handle, handleRef.Handle);
+ Assert.Equal((IntPtr)handle, (IntPtr)handleRef);
+ Assert.Equal((IntPtr)handle, HandleRef.ToIntPtr(handleRef));
}
}
}
diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/LCIDConversionAttributeTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/LCIDConversionAttributeTests.cs
index 48198b04e8..cc5dd2c080 100644
--- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/LCIDConversionAttributeTests.cs
+++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/LCIDConversionAttributeTests.cs
@@ -11,19 +11,25 @@ namespace System.Runtime.InteropServices.Tests
public class LCIDConversionAttributeTests
{
[LCIDConversion(1337)]
- private int Func(int a, int b)
- {
- return a + b;
- }
+ private int Func(int a, int b) => a + b;
[Fact]
public void Exists()
{
- var type = typeof(LCIDConversionAttributeTests);
- var method = type.GetTypeInfo().DeclaredMethods.Single(m => m.Name == "Func");
- var attr = method.GetCustomAttributes(typeof(LCIDConversionAttribute), false).OfType<LCIDConversionAttribute>().SingleOrDefault();
- Assert.NotNull(attr);
- Assert.Equal(1337, attr.Value);
+ Type type = typeof(LCIDConversionAttributeTests);
+ MethodInfo method = type.GetTypeInfo().DeclaredMethods.Single(m => m.Name == "Func");
+ LCIDConversionAttribute attribute = Assert.Single(method.GetCustomAttributes<LCIDConversionAttribute>(false));
+ Assert.Equal(1337, attribute.Value);
+ }
+
+ [Theory]
+ [InlineData(-1)]
+ [InlineData(0)]
+ [InlineData(1)]
+ public void Ctor_Lcid(int lcid)
+ {
+ var attribute = new LCIDConversionAttribute(lcid);
+ Assert.Equal(lcid, attribute.Value);
}
}
}
diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/MarshalTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/MarshalTests.cs
index a7ccb59f8c..a4c97eb480 100644
--- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/MarshalTests.cs
+++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/MarshalTests.cs
@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using Xunit;
-using System.Collections.Generic;
using System.Security;
namespace System.Runtime.InteropServices
diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/PrimaryInteropAssemblyAttributeTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/PrimaryInteropAssemblyAttributeTests.cs
index 2135e9ccaa..68f85ff0c2 100644
--- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/PrimaryInteropAssemblyAttributeTests.cs
+++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/PrimaryInteropAssemblyAttributeTests.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using Xunit;
@@ -16,12 +15,22 @@ namespace System.Runtime.InteropServices.Tests
[Fact]
public void Exists()
{
- var type = typeof(PrimaryInteropAssemblyAttributeTests);
- var assembly = type.GetTypeInfo().Assembly;
- var attr = assembly.GetCustomAttributes(typeof(PrimaryInteropAssemblyAttribute), false).OfType<PrimaryInteropAssemblyAttribute>().SingleOrDefault();
- Assert.NotNull(attr);
- Assert.Equal(1, attr.MajorVersion);
- Assert.Equal(2, attr.MinorVersion);
+ Type type = typeof(PrimaryInteropAssemblyAttributeTests);
+ Assembly assembly = type.GetTypeInfo().Assembly;
+ PrimaryInteropAssemblyAttribute attribute = Assert.Single(assembly.GetCustomAttributes<PrimaryInteropAssemblyAttribute>());
+ Assert.Equal(1, attribute.MajorVersion);
+ Assert.Equal(2, attribute.MinorVersion);
+ }
+
+ [Theory]
+ [InlineData(-1, -2)]
+ [InlineData(0, 0)]
+ [InlineData(1, 2)]
+ public void Ctor_MajorVersion_MinorVersion(int major, int minor)
+ {
+ var attribute = new PrimaryInteropAssemblyAttribute(major, minor);
+ Assert.Equal(major, attribute.MajorVersion);
+ Assert.Equal(minor, attribute.MinorVersion);
}
}
}
diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ProgIdAttributeTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ProgIdAttributeTests.cs
index a0e00935cd..402fb5569f 100644
--- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ProgIdAttributeTests.cs
+++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ProgIdAttributeTests.cs
@@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Linq;
-using System.Reflection;
using Xunit;
namespace System.Runtime.InteropServices.Tests
@@ -14,10 +12,18 @@ namespace System.Runtime.InteropServices.Tests
[Fact]
public void Exists()
{
- var type = typeof(ProgIdAttributeTests);
- var attr = type.GetCustomAttributes(typeof(ProgIdAttribute), false).OfType<ProgIdAttribute>().SingleOrDefault();
- Assert.NotNull(attr);
- Assert.Equal("pizza", attr.Value);
+ Type type = typeof(ProgIdAttributeTests);
+ ProgIdAttribute attribute = Assert.IsType<ProgIdAttribute>(Assert.Single(type.GetCustomAttributes(typeof(ProgIdAttribute), false)));
+ Assert.Equal("pizza", attribute.Value);
+ }
+
+ [Theory]
+ [InlineData(null)]
+ [InlineData("ProgId")]
+ public void Ctor_ProgId(string progId)
+ {
+ var attribute = new ProgIdAttribute(progId);
+ Assert.Equal(progId, attribute.Value);
}
}
}
diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/RuntimeEnvironmentTest.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/RuntimeEnvironmentTest.cs
deleted file mode 100644
index b758813c4b..0000000000
--- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/RuntimeEnvironmentTest.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Reflection;
-using System.Runtime;
-using System.Runtime.InteropServices;
-using System.IO;
-using Xunit;
-
-namespace System.Runtime.InteropServices
-{
- public static class RuntimeEnvironmentTest
- {
- [Fact]
- public static void RuntimeEnvironmentRuntimeDirectory()
- {
- Assert.True(Directory.Exists(RuntimeEnvironment.GetRuntimeDirectory()));
- }
-
- [Fact]
- [ActiveIssue(20600, TargetFrameworkMonikers.UapAot)]
- public static void RuntimeEnvironmentSysVersion()
- {
- Assert.True(!String.IsNullOrEmpty(RuntimeEnvironment.GetSystemVersion()));
- }
-
- [Fact]
- [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
- public static void RuntimeEnvironmentNegTest()
- {
- Type clsType = typeof(RuntimeEnvironmentTest);
- Assembly assem = clsType.Assembly;
- Assert.True(!RuntimeEnvironment.FromGlobalAccessCache(assem));
-
- Assert.Throws<PlatformNotSupportedException>(() => RuntimeEnvironment.SystemConfigurationFile);
-
- Guid guid;
- Assert.Throws<PlatformNotSupportedException>(() => RuntimeEnvironment.GetRuntimeInterfaceAsObject(guid, guid));
- Assert.Throws<PlatformNotSupportedException>(() => RuntimeEnvironment.GetRuntimeInterfaceAsIntPtr(guid, guid));
- }
- }
-}
diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/RuntimeEnvironmentTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/RuntimeEnvironmentTests.cs
new file mode 100644
index 0000000000..956399207d
--- /dev/null
+++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/RuntimeEnvironmentTests.cs
@@ -0,0 +1,54 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.IO;
+using Xunit;
+
+namespace System.Runtime.InteropServices
+{
+ public class RuntimeEnvironmentTests
+ {
+ [Fact]
+ public void RuntimeEnvironmentRuntimeDirectory()
+ {
+ Assert.True(Directory.Exists(RuntimeEnvironment.GetRuntimeDirectory()));
+ }
+
+ [Fact]
+ [ActiveIssue(20600, TargetFrameworkMonikers.UapAot)]
+ public void RuntimeEnvironmentSysVersion()
+ {
+ Assert.NotEmpty(RuntimeEnvironment.GetSystemVersion());
+ }
+
+ [Fact]
+ [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "SystemConfigurationFile is not supported on .NET Core.")]
+ public void SystemConfigurationFile_Get_ThrowsPlatformNotSupportedException()
+ {
+ Assert.Throws<PlatformNotSupportedException>(() => RuntimeEnvironment.SystemConfigurationFile);
+ }
+
+ [Fact]
+ [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "GetRuntimeInterfaceAsObject is not supported on .NET Core.")]
+ public void GetRuntimeInterfaceAsObject_Invoke_ThrowsPlatformNotSupportedException()
+ {
+ Assert.Throws<PlatformNotSupportedException>(() => RuntimeEnvironment.GetRuntimeInterfaceAsObject(Guid.Empty, Guid.Empty));
+ }
+
+ [Fact]
+ [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "GetRuntimeInterfaceAsIntPtr is not supported on .NET Core.")]
+ public void GetRuntimeInterfaceAsIntPtr_Invoke_ThrowsPlatformNotSupportedException()
+ {
+ Assert.Throws<PlatformNotSupportedException>(() => RuntimeEnvironment.GetRuntimeInterfaceAsIntPtr(Guid.Empty, Guid.Empty));
+ }
+
+ [Fact]
+ [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "FromGlobalAccessCache always returns true on .NET Core.")]
+ public void FromGlobalAccessCache_INvoke_ReturnsFalse()
+ {
+ Assert.False(RuntimeEnvironment.FromGlobalAccessCache(typeof(RuntimeEnvironmentTests).Assembly));
+ Assert.False(RuntimeEnvironment.FromGlobalAccessCache(null));
+ }
+ }
+}