Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
81 lines (69 loc) · 2.45 KB
/
Copy pathProgram.cs
File metadata and controls
81 lines (69 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) 2019-2026 ReactiveUI and Contributors. All rights reserved.
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
#if PLATFORM_WINDOWS
using System.Runtime.ExceptionServices;
using PlatformBindingsVerification.WinForms;
using PlatformBindingsVerification.Wpf;
#elif PLATFORM_MAUI
using PlatformBindingsVerification.Maui;
#endif
if (args.Length == 0 || args[0] != "--verify")
{
Console.WriteLine("Pass --verify to run this platform's headless self-check.");
return 1;
}
var failures = 0;
#if PLATFORM_WINDOWS
failures += Run("WPF: ToProperty helper fed by a background thread, delivered to a TextBlock through the dispatcher invoker", static () => OnStaThread(WpfVerification.Verify));
failures += Run("WPF: BindCommand on a plain view writes a command replaced on a background thread through the button's dispatcher", static () => OnStaThread(WpfCommandVerification.Verify));
failures += Run("WinForms: ToProperty helper fed by a background thread, delivered to a Label through the control invoker", static () => OnStaThread(WinFormsVerification.Verify));
#elif PLATFORM_MAUI
failures += Run("MAUI: ToProperty helper fed by a background thread, delivered to a Label inline (no application dispatcher)", MauiVerification.Verify);
#endif
Console.WriteLine();
Console.WriteLine(failures == 0 ? "ALL SCENARIOS PASSED" : $"{failures} SCENARIO(S) FAILED");
return failures == 0 ? 0 : 1;
#if PLATFORM_WINDOWS
// WPF and WinForms controls need a single-threaded apartment, which a top-level program's main thread is not.
static bool OnStaThread(Func<bool> scenario)
{
var passed = false;
ExceptionDispatchInfo? failure = null;
Thread thread = new(() =>
{
try
{
passed = scenario();
}
catch (Exception ex)
{
failure = ExceptionDispatchInfo.Capture(ex);
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
failure?.Throw();
return passed;
}
#endif
static int Run(string name, Func<bool> scenario)
{
try
{
if (scenario())
{
Console.WriteLine($"PASS: {name}");
return 0;
}
Console.WriteLine($"FAIL: {name}");
return 1;
}
catch (Exception ex)
{
Console.WriteLine($"FAIL: {name}");
Console.WriteLine($" {ex}");
return 1;
}
}