2016-05-05 03:14:32 +03:00
|
|
|
using System;
|
2017-02-01 19:05:08 +03:00
|
|
|
using System.Collections.Generic;
|
2017-03-02 16:57:49 +03:00
|
|
|
using System.Runtime.InteropServices;
|
2018-01-16 21:15:59 +03:00
|
|
|
#if XAMCORE_2_0 || __UNIFIED__
|
2016-05-05 03:14:32 +03:00
|
|
|
using AppKit;
|
|
|
|
using Foundation;
|
|
|
|
#else
|
|
|
|
using MonoMac.AppKit;
|
|
|
|
using MonoMac.Foundation;
|
|
|
|
#endif
|
|
|
|
using GuiUnit;
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
2017-02-01 19:05:08 +03:00
|
|
|
// This is a bit of a hack. A number of BCL types have using statements with this namespace but no uses that we care about
|
|
|
|
namespace NUnit.Framework.SyntaxHelpers
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-05 03:14:32 +03:00
|
|
|
namespace Xamarin.Mac.Tests
|
2017-02-01 19:05:08 +03:00
|
|
|
{
|
2016-05-05 03:14:32 +03:00
|
|
|
static class MainClass
|
|
|
|
{
|
2017-02-01 19:05:08 +03:00
|
|
|
static void Main (string[] args)
|
2016-05-05 03:14:32 +03:00
|
|
|
{
|
2017-02-01 19:05:08 +03:00
|
|
|
#if !NO_GUI_TESTING
|
2016-05-05 03:14:32 +03:00
|
|
|
NSApplication.Init();
|
2017-02-01 19:05:08 +03:00
|
|
|
#endif
|
2017-11-23 21:16:02 +03:00
|
|
|
RunTests (args);
|
2016-05-05 03:14:32 +03:00
|
|
|
}
|
|
|
|
|
2017-11-23 21:16:02 +03:00
|
|
|
static void RunTests (string [] original_args)
|
2016-05-05 03:14:32 +03:00
|
|
|
{
|
2017-02-01 19:05:08 +03:00
|
|
|
TestRunner.MainLoop = new NSRunLoopIntegration ();
|
|
|
|
List<string> args = new List<string> () { typeof (MainClass).Assembly.Location, "-labels", "-noheader" };
|
|
|
|
|
2016-10-13 18:42:05 +03:00
|
|
|
string testName = System.Environment.GetEnvironmentVariable ("XM_TEST_NAME");
|
2017-02-01 19:05:08 +03:00
|
|
|
if (testName != null)
|
|
|
|
args.Add ($"-test={testName}");
|
|
|
|
|
|
|
|
#if ADD_BCL_EXCLUSIONS
|
|
|
|
args.Add ("-exclude=MacNotWorking,MobileNotWorking,NotOnMac,NotWorking,ValueAdd,CAS,InetAccess,NotWorkingInterpreter");
|
|
|
|
#endif
|
2016-10-13 18:42:05 +03:00
|
|
|
|
2017-11-23 21:16:02 +03:00
|
|
|
// Skip arguments added by VSfM/macOS when running from the IDE
|
|
|
|
foreach (var arg in original_args)
|
|
|
|
if (!arg.StartsWith ("-psn_", StringComparison.Ordinal))
|
|
|
|
args.Add (arg);
|
|
|
|
|
2017-02-01 19:05:08 +03:00
|
|
|
TestRunner.Main (args.ToArray ());
|
|
|
|
|
|
|
|
#if NO_GUI_TESTING
|
|
|
|
// HACK - TestRunner.Main assumes you have a message pump spinning, but when I hack it out via NO_GUI_TESTING it returns right away
|
|
|
|
// We will exit via Environment.Exit in NSRunLoopIntegration
|
|
|
|
while (true) {
|
|
|
|
System.Threading.Thread.Sleep (1000);
|
|
|
|
}
|
|
|
|
#endif
|
2016-05-05 03:14:32 +03:00
|
|
|
}
|
|
|
|
|
2017-03-02 16:57:49 +03:00
|
|
|
[DllImport ("/usr/lib/libSystem.dylib")]
|
|
|
|
static extern void _exit (int exit_code);
|
|
|
|
|
2017-02-01 19:05:08 +03:00
|
|
|
#if !NO_GUI_TESTING
|
2016-05-05 03:14:32 +03:00
|
|
|
class NSRunLoopIntegration : NSObject, IMainLoopIntegration
|
|
|
|
{
|
2017-02-01 19:05:08 +03:00
|
|
|
public void InitializeToolkit ()
|
2016-05-05 03:14:32 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-02-01 19:05:08 +03:00
|
|
|
public void RunMainLoop ()
|
2016-05-05 03:14:32 +03:00
|
|
|
{
|
2017-02-01 19:05:08 +03:00
|
|
|
NSApplication.SharedApplication.Run ();
|
2016-05-05 03:14:32 +03:00
|
|
|
}
|
2016-05-26 16:06:52 +03:00
|
|
|
|
2017-02-01 19:05:08 +03:00
|
|
|
public void InvokeOnMainLoop (InvokerHelper helper)
|
2016-05-05 03:14:32 +03:00
|
|
|
{
|
2016-05-26 16:06:52 +03:00
|
|
|
NSApplication.SharedApplication.InvokeOnMainThread(helper.Invoke);
|
2016-05-05 03:14:32 +03:00
|
|
|
}
|
|
|
|
|
2017-02-01 19:05:08 +03:00
|
|
|
public void Shutdown ()
|
|
|
|
{
|
2017-03-02 16:57:49 +03:00
|
|
|
_exit (TestRunner.ExitCode);
|
2017-02-01 19:05:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
class NSRunLoopIntegration : IMainLoopIntegration
|
|
|
|
{
|
|
|
|
public void InitializeToolkit ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RunMainLoop ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void InvokeOnMainLoop (InvokerHelper helper)
|
|
|
|
{
|
|
|
|
helper.Invoke ();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Shutdown ()
|
2016-05-05 03:14:32 +03:00
|
|
|
{
|
2017-03-02 16:57:49 +03:00
|
|
|
_exit (TestRunner.ExitCode);
|
2016-05-05 03:14:32 +03:00
|
|
|
}
|
|
|
|
}
|
2017-02-01 19:05:08 +03:00
|
|
|
#endif
|
2016-05-05 03:14:32 +03:00
|
|
|
}
|
|
|
|
}
|
2017-01-12 21:13:56 +03:00
|
|
|
|
|
|
|
#if XAMCORE_2_0
|
|
|
|
partial class TestRuntime {
|
|
|
|
public static bool RunAsync (DateTime timeout, Action action, Func<bool> check_completed)
|
|
|
|
{
|
|
|
|
NSTimer.CreateScheduledTimer (0.01, (v) => action ());
|
|
|
|
do {
|
|
|
|
if (timeout < DateTime.Now)
|
|
|
|
return false;
|
|
|
|
NSRunLoop.Main.RunUntil (NSDate.Now.AddSeconds (0.1));
|
|
|
|
} while (!check_completed ());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|