Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 63c1dca

Browse files
committed
Add System.Runtime.InteropServices tests
ComAwareEventInfo does not yet have tests, not sure if we want/need any
1 parent 6ce862b commit 63c1dca

File tree

6 files changed

+771
-0
lines changed

6 files changed

+771
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.31101.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.InteropServices.CoreCLR", "src\System.Runtime.InteropServices.CoreCLR.csproj", "{EC6AA4D9-B3E8-4CCA-8AB1-8BBFD89266AE}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.InteropServices.Tests", "tests\System.Runtime.InteropServices.Tests.csproj", "{A824F4CD-935B-4496-A1B2-C3664936DA7B}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Linux_Debug|Any CPU = Linux_Debug|Any CPU
14+
Linux_Release|Any CPU = Linux_Release|Any CPU
15+
OSX_Debug|Any CPU = OSX_Debug|Any CPU
16+
OSX_Release|Any CPU = OSX_Release|Any CPU
17+
Release|Any CPU = Release|Any CPU
18+
Windows_Debug|Any CPU = Windows_Debug|Any CPU
19+
Windows_Release|Any CPU = Windows_Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
22+
{EC6AA4D9-B3E8-4CCA-8AB1-8BBFD89266AE}.Debug|Any CPU.ActiveCfg = Windows_Debug|Any CPU
23+
{EC6AA4D9-B3E8-4CCA-8AB1-8BBFD89266AE}.Debug|Any CPU.Build.0 = Windows_Debug|Any CPU
24+
{EC6AA4D9-B3E8-4CCA-8AB1-8BBFD89266AE}.Linux_Debug|Any CPU.ActiveCfg = Linux_Debug|Any CPU
25+
{EC6AA4D9-B3E8-4CCA-8AB1-8BBFD89266AE}.Linux_Debug|Any CPU.Build.0 = Linux_Debug|Any CPU
26+
{EC6AA4D9-B3E8-4CCA-8AB1-8BBFD89266AE}.Linux_Release|Any CPU.ActiveCfg = Linux_Release|Any CPU
27+
{EC6AA4D9-B3E8-4CCA-8AB1-8BBFD89266AE}.Linux_Release|Any CPU.Build.0 = Linux_Release|Any CPU
28+
{EC6AA4D9-B3E8-4CCA-8AB1-8BBFD89266AE}.OSX_Debug|Any CPU.ActiveCfg = OSX_Debug|Any CPU
29+
{EC6AA4D9-B3E8-4CCA-8AB1-8BBFD89266AE}.OSX_Debug|Any CPU.Build.0 = OSX_Debug|Any CPU
30+
{EC6AA4D9-B3E8-4CCA-8AB1-8BBFD89266AE}.OSX_Release|Any CPU.ActiveCfg = OSX_Release|Any CPU
31+
{EC6AA4D9-B3E8-4CCA-8AB1-8BBFD89266AE}.OSX_Release|Any CPU.Build.0 = OSX_Release|Any CPU
32+
{EC6AA4D9-B3E8-4CCA-8AB1-8BBFD89266AE}.Release|Any CPU.ActiveCfg = Windows_Release|Any CPU
33+
{EC6AA4D9-B3E8-4CCA-8AB1-8BBFD89266AE}.Release|Any CPU.Build.0 = Windows_Release|Any CPU
34+
{EC6AA4D9-B3E8-4CCA-8AB1-8BBFD89266AE}.Windows_Debug|Any CPU.ActiveCfg = Windows_Debug|Any CPU
35+
{EC6AA4D9-B3E8-4CCA-8AB1-8BBFD89266AE}.Windows_Debug|Any CPU.Build.0 = Windows_Debug|Any CPU
36+
{EC6AA4D9-B3E8-4CCA-8AB1-8BBFD89266AE}.Windows_Release|Any CPU.ActiveCfg = Windows_Release|Any CPU
37+
{EC6AA4D9-B3E8-4CCA-8AB1-8BBFD89266AE}.Windows_Release|Any CPU.Build.0 = Windows_Release|Any CPU
38+
{A824F4CD-935B-4496-A1B2-C3664936DA7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{A824F4CD-935B-4496-A1B2-C3664936DA7B}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{A824F4CD-935B-4496-A1B2-C3664936DA7B}.Linux_Debug|Any CPU.ActiveCfg = Debug|Any CPU
41+
{A824F4CD-935B-4496-A1B2-C3664936DA7B}.Linux_Debug|Any CPU.Build.0 = Debug|Any CPU
42+
{A824F4CD-935B-4496-A1B2-C3664936DA7B}.Linux_Release|Any CPU.ActiveCfg = Release|Any CPU
43+
{A824F4CD-935B-4496-A1B2-C3664936DA7B}.Linux_Release|Any CPU.Build.0 = Release|Any CPU
44+
{A824F4CD-935B-4496-A1B2-C3664936DA7B}.OSX_Debug|Any CPU.ActiveCfg = Debug|Any CPU
45+
{A824F4CD-935B-4496-A1B2-C3664936DA7B}.OSX_Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{A824F4CD-935B-4496-A1B2-C3664936DA7B}.OSX_Release|Any CPU.ActiveCfg = Release|Any CPU
47+
{A824F4CD-935B-4496-A1B2-C3664936DA7B}.OSX_Release|Any CPU.Build.0 = Release|Any CPU
48+
{A824F4CD-935B-4496-A1B2-C3664936DA7B}.Release|Any CPU.ActiveCfg = Release|Any CPU
49+
{A824F4CD-935B-4496-A1B2-C3664936DA7B}.Release|Any CPU.Build.0 = Release|Any CPU
50+
{A824F4CD-935B-4496-A1B2-C3664936DA7B}.Windows_Debug|Any CPU.ActiveCfg = Debug|Any CPU
51+
{A824F4CD-935B-4496-A1B2-C3664936DA7B}.Windows_Debug|Any CPU.Build.0 = Debug|Any CPU
52+
{A824F4CD-935B-4496-A1B2-C3664936DA7B}.Windows_Release|Any CPU.ActiveCfg = Release|Any CPU
53+
{A824F4CD-935B-4496-A1B2-C3664936DA7B}.Windows_Release|Any CPU.Build.0 = Release|Any CPU
54+
EndGlobalSection
55+
GlobalSection(SolutionProperties) = preSolution
56+
HideSolutionNode = FALSE
57+
EndGlobalSection
58+
EndGlobal
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<OutputType>Library</OutputType>
8+
<RootNamespace>System.Runtime.InteropServices</RootNamespace>
9+
<AssemblyName>System.Runtime.InteropServices.Tests</AssemblyName>
10+
<RestorePackages>true</RestorePackages>
11+
<ProjectGuid>{A824F4CD-935B-4496-A1B2-C3664936DA7B}</ProjectGuid>
12+
</PropertyGroup>
13+
<!-- Default configurations to help VS understand the configurations -->
14+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " />
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />
16+
<ItemGroup>
17+
<Compile Include="System\Runtime\InteropServices\DefaultParameterValueAttributeTests.cs" />
18+
<Compile Include="System\Runtime\InteropServices\HandleCollector.cs" />
19+
</ItemGroup>
20+
<ItemGroup>
21+
<None Include="project.json" />
22+
</ItemGroup>
23+
<ItemGroup>
24+
<!-- Compile tests against the contract, but copy our local-built implementation for testing -->
25+
<ProjectReference Include="..\src\System.Runtime.InteropServices.CoreCLR.csproj">
26+
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
27+
<OutputItemType>Content</OutputItemType>
28+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
29+
<Targets>Build;DebugSymbolsProjectOutputGroup</Targets>
30+
</ProjectReference>
31+
</ItemGroup>
32+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
33+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Xunit;
5+
6+
namespace System.Runtime.InteropServices
7+
{
8+
public class DefaultParameterValueAttributeTests
9+
{
10+
[Theory]
11+
[InlineData(0)]
12+
[InlineData((byte)255)]
13+
[InlineData(5.0)]
14+
[InlineData(5.0f)]
15+
[InlineData("ExpectedValue")]
16+
[InlineData(null)]
17+
public static void Constructor(object expected)
18+
{
19+
DefaultParameterValueAttribute attribute = new DefaultParameterValueAttribute(expected);
20+
Assert.Equal(expected, attribute.Value);
21+
}
22+
}
23+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Xunit;
5+
6+
namespace System.Runtime.InteropServices
7+
{
8+
public static class HandleCollectorTests
9+
{
10+
private const int LowLimitSize = 20;
11+
private const int HighLimitSize = 100000;
12+
13+
[Fact]
14+
public static void NegativeInitialThresholdCtor()
15+
{
16+
Assert.Throws<ArgumentOutOfRangeException>(() => new HandleCollector("NegativeInitial", -1));
17+
}
18+
19+
[Fact]
20+
public static void NegateMaximumThresholdCtor()
21+
{
22+
Assert.Throws<ArgumentOutOfRangeException>(() => new HandleCollector("NegativeMax", 0, -1));
23+
}
24+
25+
[Fact]
26+
public static void InitialGreaterThanMaxThresholdCtor()
27+
{
28+
Assert.Throws<ArgumentException>(() => new HandleCollector("InitialGreaterThanMax", 100, 1));
29+
}
30+
31+
[Fact]
32+
public static void SimplePropertyValidation()
33+
{
34+
string name = "ExampleName";
35+
int initial = 10;
36+
int max = 20;
37+
38+
HandleCollector collector = new HandleCollector(name, initial, max);
39+
40+
Assert.Equal(0, collector.Count);
41+
Assert.Equal(name, collector.Name);
42+
Assert.Equal(initial, collector.InitialThreshold);
43+
Assert.Equal(max, collector.MaximumThreshold);
44+
}
45+
46+
[Fact]
47+
public static void NullNameCtor()
48+
{
49+
HandleCollector collector = new HandleCollector(null, 0, 0);
50+
Assert.Equal(string.Empty, collector.Name);
51+
}
52+
53+
[Fact]
54+
public static void EmptyRemoval()
55+
{
56+
HandleCollector collector = new HandleCollector("EmptyRemoval", 10);
57+
Assert.Throws<InvalidOperationException>(() => collector.Remove());
58+
}
59+
60+
[Fact]
61+
[OuterLoop]
62+
public static void CountOverflow()
63+
{
64+
HandleCollector collector = new HandleCollector("CountOverflow", int.MaxValue);
65+
for (int i = 0; i < Int32.MaxValue; i++)
66+
{
67+
collector.Add();
68+
}
69+
70+
Assert.Throws<InvalidOperationException>(() => collector.Add());
71+
}
72+
73+
[Fact]
74+
public static void TestHandleCollector()
75+
{
76+
Tuple<int, int, int> intialGcState = new Tuple<int, int, int>(
77+
GC.CollectionCount(0),
78+
GC.CollectionCount(1),
79+
GC.CollectionCount(2));
80+
81+
HandleCollector lowLimitCollector = new HandleCollector("LowLimit.Collector", LowLimitSize);
82+
for (int i = 0; i < LowLimitSize + 1; ++i)
83+
{
84+
HandleLimitTester hlt = new HandleLimitTester(lowLimitCollector);
85+
}
86+
87+
Tuple<int, int, int> postLowLimitState = new Tuple<int, int, int>(
88+
GC.CollectionCount(0),
89+
GC.CollectionCount(1),
90+
GC.CollectionCount(2));
91+
92+
Assert.True(intialGcState.Item1 + intialGcState.Item2 + intialGcState.Item3 < postLowLimitState.Item1 + postLowLimitState.Item2 + postLowLimitState.Item3, "Low limit handle did not trigger a GC");
93+
94+
HandleCollector highLimitCollector = new HandleCollector("HighLimit.Collector", HighLimitSize);
95+
for (int i = 0; i < HighLimitSize + 10; ++i)
96+
{
97+
HandleLimitTester hlt = new HandleLimitTester(highLimitCollector);
98+
}
99+
100+
Tuple<int, int, int> postHighLimitState = new Tuple<int, int, int>(
101+
GC.CollectionCount(0),
102+
GC.CollectionCount(1),
103+
GC.CollectionCount(2));
104+
105+
Assert.True(postLowLimitState.Item1 + postLowLimitState.Item2 + postLowLimitState.Item3 < postHighLimitState.Item1 + postHighLimitState.Item2 + postHighLimitState.Item3, "High limit handle did not trigger a GC");
106+
}
107+
108+
private sealed class HandleLimitTester
109+
{
110+
private HandleCollector _collector;
111+
112+
internal HandleLimitTester(HandleCollector collector)
113+
{
114+
_collector = collector;
115+
_collector.Add();
116+
GC.KeepAlive(this);
117+
}
118+
119+
~HandleLimitTester()
120+
{
121+
_collector.Remove();
122+
}
123+
}
124+
}
125+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"dependencies": {
3+
"System.Runtime.InteropServices": "4.0.20-beta-23008",
4+
"xunit": "2.0.0-beta5-build2785",
5+
"xunit.abstractions.netcore": "1.0.0-prerelease",
6+
"xunit.assert": "2.0.0-beta5-build2785",
7+
"xunit.core.netcore": "1.0.1-prerelease",
8+
"xunit.netcore.extensions": "1.0.0-prerelease-*"
9+
},
10+
"frameworks": {
11+
"dnxcore50": {}
12+
}
13+
}

0 commit comments

Comments
 (0)