forked from dotnet/corefx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test a couple of fixes for apartment state issues
Partial port of dotnet#31682 to 2.2 Tests for dotnet/coreclr#19384 Related to https://github.com/dotnet/coreclr/issues/17822 Related to https://github.com/dotnet/coreclr/issues/17787 Related to https://github.com/dotnet/coreclr/issues/19225
- Loading branch information
Showing
9 changed files
with
193 additions
and
70 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/System.Threading.Thread/tests/DefaultApartmentStateMain/Configurations.props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<BuildConfigurations> | ||
netstandard; | ||
</BuildConfigurations> | ||
</PropertyGroup> | ||
</Project> |
61 changes: 61 additions & 0 deletions
61
src/System.Threading.Thread/tests/DefaultApartmentStateMain/DefaultApartmentStateMain.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// 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; | ||
using System.Threading; | ||
|
||
namespace DefaultApartmentStateMain | ||
{ | ||
internal static class DefaultApartmentStateMain | ||
{ | ||
private const int Success = 0; | ||
private const int SuccessOnUnix = 2; | ||
private const int Failure = 1; | ||
|
||
private static Thread s_mainThread; | ||
|
||
static int Main(string[] args) | ||
{ | ||
string testName = args[0]; | ||
s_mainThread = Thread.CurrentThread; | ||
|
||
switch (testName) | ||
{ | ||
case "GetApartmentStateTest": | ||
return GetApartmentStateTest(); | ||
case "SetApartmentStateTest": | ||
return SetApartmentStateTest(); | ||
default: | ||
return Failure; | ||
} | ||
} | ||
|
||
private static int GetApartmentStateTest() | ||
{ | ||
if (s_mainThread.GetApartmentState() == ApartmentState.MTA) | ||
{ | ||
s_mainThread.SetApartmentState(ApartmentState.MTA); | ||
return Success; | ||
} | ||
return SuccessOnUnix; | ||
} | ||
|
||
private static int SetApartmentStateTest() | ||
{ | ||
try | ||
{ | ||
s_mainThread.SetApartmentState(ApartmentState.STA); | ||
} | ||
catch (InvalidOperationException) | ||
{ | ||
return Success; | ||
} | ||
catch (PlatformNotSupportedException) | ||
{ | ||
return SuccessOnUnix; | ||
} | ||
return Failure; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/System.Threading.Thread/tests/DefaultApartmentStateMain/DefaultApartmentStateMain.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<ProjectGuid>{32432E07-5CA4-41F3-9855-22AB1F1E69B3}</ProjectGuid> | ||
<Configurations>netstandard-Debug;netstandard-Release</Configurations> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="DefaultApartmentStateMain.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="DefaultApartmentStateMain.runtimeconfig.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
<Content Include="DefaultApartmentStateMain.exe.config"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
</Project> |
6 changes: 6 additions & 0 deletions
6
...tem.Threading.Thread/tests/DefaultApartmentStateMain/DefaultApartmentStateMain.exe.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<runtime> | ||
<developmentMode developerInstallation="true" /> | ||
</runtime> | ||
</configuration> |
8 changes: 8 additions & 0 deletions
8
...ading.Thread/tests/DefaultApartmentStateMain/DefaultApartmentStateMain.runtimeconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"runtimeOptions": { | ||
"framework": { | ||
"name": "Microsoft.NETCore.App", | ||
"version": "9.9.9" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters