2016-06-09 20:17:06 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
#if XAMCORE_2_0
|
|
|
|
using Foundation;
|
2016-06-10 11:52:03 +03:00
|
|
|
#if MONOMAC
|
|
|
|
using AppKit;
|
|
|
|
#else
|
2016-06-09 20:17:06 +03:00
|
|
|
using UIKit;
|
2016-06-10 11:52:03 +03:00
|
|
|
#endif
|
2016-06-09 20:17:06 +03:00
|
|
|
using ObjCRuntime;
|
|
|
|
#else
|
2016-06-10 11:52:03 +03:00
|
|
|
#if MONOMAC
|
|
|
|
using MonoMac.ObjCRuntime;
|
|
|
|
using MonoMac.Foundation;
|
|
|
|
using MonoMac.AppKit;
|
|
|
|
#else
|
2016-06-09 20:17:06 +03:00
|
|
|
using MonoTouch.ObjCRuntime;
|
|
|
|
using MonoTouch.Foundation;
|
|
|
|
using MonoTouch.UIKit;
|
|
|
|
#endif
|
2016-06-10 11:52:03 +03:00
|
|
|
#endif
|
2016-06-09 20:17:06 +03:00
|
|
|
|
|
|
|
partial class TestRuntime
|
|
|
|
{
|
|
|
|
[DllImport ("/usr/lib/system/libdyld.dylib")]
|
|
|
|
static extern int dyld_get_program_sdk_version ();
|
|
|
|
|
2016-06-10 13:26:20 +03:00
|
|
|
[DllImport ("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
|
|
|
|
static extern IntPtr IntPtr_objc_msgSend (IntPtr receiver, IntPtr selector);
|
|
|
|
|
2016-06-09 20:17:06 +03:00
|
|
|
public const string BuildVersion_iOS9_GM = "13A340";
|
|
|
|
|
|
|
|
public static string GetiOSBuildVersion ()
|
|
|
|
{
|
|
|
|
#if __WATCHOS__
|
|
|
|
throw new Exception ("Can't get iOS Build version on watchOS.");
|
2016-06-10 11:52:03 +03:00
|
|
|
#elif MONOMAC
|
|
|
|
throw new Exception ("Can't get iOS Build version on OSX.");
|
2016-06-09 20:17:06 +03:00
|
|
|
#else
|
2016-06-10 13:26:20 +03:00
|
|
|
return NSString.FromHandle (IntPtr_objc_msgSend (UIDevice.CurrentDevice.Handle, Selector.GetHandle ("buildVersion")));
|
2016-06-09 20:17:06 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-06-10 11:52:03 +03:00
|
|
|
#if MONOMAC
|
|
|
|
const int sys1 = 1937339185;
|
|
|
|
const int sys2 = 1937339186;
|
|
|
|
const int sys3 = 1937339187;
|
|
|
|
|
|
|
|
// Deprecated in OSX 10.8 - but no good alternative is (yet) available
|
|
|
|
[System.Runtime.InteropServices.DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
|
|
|
|
static extern int Gestalt (int selector, out int result);
|
|
|
|
|
|
|
|
static Version version;
|
|
|
|
|
|
|
|
public static Version OSXVersion {
|
|
|
|
get {
|
|
|
|
if (version == null) {
|
|
|
|
int major, minor, build;
|
|
|
|
Gestalt (sys1, out major);
|
|
|
|
Gestalt (sys2, out minor);
|
|
|
|
Gestalt (sys3, out build);
|
|
|
|
version = new Version (major, minor, build);
|
|
|
|
}
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-06-09 20:17:06 +03:00
|
|
|
public static Version GetSDKVersion ()
|
|
|
|
{
|
|
|
|
var v = dyld_get_program_sdk_version ();
|
|
|
|
var major = v >> 16;
|
|
|
|
var minor = (v >> 8) & 0xFF;
|
|
|
|
var build = v & 0xFF;
|
|
|
|
return new Version (major, minor, build);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void AssertXcodeVersion (int major, int minor)
|
|
|
|
{
|
|
|
|
if (CheckXcodeVersion (major, minor))
|
|
|
|
return;
|
|
|
|
|
|
|
|
NUnit.Framework.Assert.Ignore ("Requires the platform version shipped with Xcode {0}.{1}", major, minor);
|
|
|
|
}
|
|
|
|
|
2016-06-10 19:10:03 +03:00
|
|
|
public static bool CheckXcodeVersion (int major, int minor, int build = 0)
|
2016-06-09 20:17:06 +03:00
|
|
|
{
|
|
|
|
switch (major) {
|
2016-06-28 17:19:42 +03:00
|
|
|
case 8:
|
|
|
|
switch (minor) {
|
|
|
|
case 0:
|
|
|
|
#if __WATCHOS__
|
|
|
|
return CheckWatchOSSystemVersion (3, 0);
|
|
|
|
#elif __TVOS__
|
|
|
|
return ChecktvOSSystemVersion (10, 0);
|
|
|
|
#elif __IOS__
|
|
|
|
return CheckiOSSystemVersion (10, 0);
|
|
|
|
#elif MONOMAC
|
|
|
|
return CheckMacSystemVersion (10, 12, 0);
|
|
|
|
#else
|
|
|
|
throw new NotImplementedException ();
|
2016-10-12 12:30:11 +03:00
|
|
|
#endif
|
|
|
|
case 1:
|
|
|
|
#if __WATCHOS__
|
|
|
|
return CheckWatchOSSystemVersion (3, 1);
|
|
|
|
#elif __TVOS__
|
|
|
|
return ChecktvOSSystemVersion (10, 0);
|
|
|
|
#elif __IOS__
|
|
|
|
return CheckiOSSystemVersion (10, 1);
|
|
|
|
#elif MONOMAC
|
|
|
|
return CheckMacSystemVersion (10, 12, 1);
|
|
|
|
#else
|
|
|
|
throw new NotImplementedException ();
|
2016-06-28 17:19:42 +03:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
}
|
2016-06-09 20:17:06 +03:00
|
|
|
case 7:
|
|
|
|
switch (minor) {
|
|
|
|
case 0:
|
|
|
|
#if __WATCHOS__
|
|
|
|
return CheckWatchOSSystemVersion (2, 0);
|
|
|
|
#elif __TVOS__
|
|
|
|
return ChecktvOSSystemVersion (9, 0);
|
|
|
|
#elif __IOS__
|
|
|
|
return CheckiOSSystemVersion (9, 0);
|
2016-06-10 19:10:03 +03:00
|
|
|
#elif MONOMAC
|
|
|
|
return CheckMacSystemVersion (10, 11, 0);
|
2016-06-09 20:17:06 +03:00
|
|
|
#else
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
#endif
|
|
|
|
case 1:
|
|
|
|
#if __WATCHOS__
|
|
|
|
return CheckWatchOSSystemVersion (2, 0);
|
|
|
|
#elif __TVOS__
|
|
|
|
return ChecktvOSSystemVersion (9, 0);
|
|
|
|
#elif __IOS__
|
|
|
|
return CheckiOSSystemVersion (9, 1);
|
2016-06-10 19:10:03 +03:00
|
|
|
#elif MONOMAC
|
|
|
|
return CheckMacSystemVersion (10, 11, 0 /* yep */);
|
2016-06-09 20:17:06 +03:00
|
|
|
#else
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
#endif
|
|
|
|
case 2:
|
|
|
|
#if __WATCHOS__
|
|
|
|
return CheckWatchOSSystemVersion (2, 1);
|
|
|
|
#elif __TVOS__
|
|
|
|
return ChecktvOSSystemVersion (9, 1);
|
|
|
|
#elif __IOS__
|
|
|
|
return CheckiOSSystemVersion (9, 2);
|
2016-06-10 19:10:03 +03:00
|
|
|
#elif MONOMAC
|
|
|
|
return CheckMacSystemVersion (10, 11, 2);
|
2016-06-09 20:17:06 +03:00
|
|
|
#else
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
#endif
|
|
|
|
case 3:
|
|
|
|
#if __WATCHOS__
|
|
|
|
return CheckWatchOSSystemVersion (2, 2);
|
|
|
|
#elif __TVOS__
|
|
|
|
return ChecktvOSSystemVersion (9, 2);
|
|
|
|
#elif __IOS__
|
|
|
|
return CheckiOSSystemVersion (9, 3);
|
2016-06-10 19:10:03 +03:00
|
|
|
#elif MONOMAC
|
|
|
|
return CheckMacSystemVersion (10, 11, 4);
|
2016-06-09 20:17:06 +03:00
|
|
|
#else
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
#if __IOS__
|
|
|
|
switch (minor) {
|
|
|
|
case 0:
|
|
|
|
return CheckiOSSystemVersion (8, 0);
|
|
|
|
case 1:
|
|
|
|
return CheckiOSSystemVersion (8, 1);
|
|
|
|
case 2:
|
|
|
|
return CheckiOSSystemVersion (8, 2);
|
|
|
|
case 3:
|
|
|
|
return CheckiOSSystemVersion (8, 3);
|
|
|
|
default:
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
}
|
|
|
|
#elif __TVOS__ || __WATCHOS__
|
|
|
|
return true;
|
2016-06-10 19:10:03 +03:00
|
|
|
#elif MONOMAC
|
|
|
|
switch (minor) {
|
|
|
|
case 0:
|
|
|
|
return CheckMacSystemVersion (10, 9, 0);
|
|
|
|
case 1:
|
|
|
|
return CheckMacSystemVersion (10, 10, 0);
|
|
|
|
case 2:
|
|
|
|
return CheckMacSystemVersion (10, 10, 0);
|
|
|
|
case 3:
|
|
|
|
return CheckMacSystemVersion (10, 10, 0);
|
|
|
|
default:
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
}
|
2016-06-09 20:17:06 +03:00
|
|
|
#else
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
#endif
|
2016-06-10 11:52:48 +03:00
|
|
|
case 5:
|
|
|
|
#if __IOS__
|
2016-06-09 20:17:06 +03:00
|
|
|
switch (minor) {
|
|
|
|
case 0:
|
|
|
|
return CheckiOSSystemVersion (7, 0);
|
|
|
|
case 1:
|
|
|
|
return CheckiOSSystemVersion (7, 1);
|
|
|
|
default:
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
}
|
|
|
|
#elif __TVOS__ || __WATCHOS__
|
|
|
|
return true;
|
2016-06-10 19:10:03 +03:00
|
|
|
#elif MONOMAC
|
|
|
|
switch (minor) {
|
|
|
|
case 0:
|
|
|
|
// Xcode 5.0.1 ships OSX 10.9 SDK
|
|
|
|
return CheckMacSystemVersion (10, build > 0 ? 9 : 8, 0);
|
|
|
|
case 1:
|
|
|
|
return CheckMacSystemVersion (10, 9, 0);
|
|
|
|
default:
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
}
|
2016-06-09 20:17:06 +03:00
|
|
|
#else
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
#endif
|
2016-06-10 11:52:48 +03:00
|
|
|
case 4:
|
|
|
|
#if __IOS__
|
2016-06-09 20:17:06 +03:00
|
|
|
switch (minor) {
|
|
|
|
case 5:
|
|
|
|
return CheckiOSSystemVersion (6, 0);
|
2016-06-09 20:37:23 +03:00
|
|
|
case 6:
|
|
|
|
return CheckiOSSystemVersion (6, 1);
|
2016-06-09 20:17:06 +03:00
|
|
|
default:
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
}
|
2016-06-10 11:52:48 +03:00
|
|
|
#elif __TVOS__ || __WATCHOS__
|
|
|
|
return true;
|
2016-06-10 19:10:03 +03:00
|
|
|
#elif MONOMAC
|
|
|
|
switch (minor) {
|
|
|
|
case 5:
|
|
|
|
case 6:
|
|
|
|
return CheckMacSystemVersion (10, 8, 0);
|
|
|
|
default:
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
}
|
2016-06-10 11:52:48 +03:00
|
|
|
#else
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
#endif
|
2016-06-09 20:17:06 +03:00
|
|
|
default:
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This method returns true if:
|
|
|
|
// system version >= specified version
|
|
|
|
// AND
|
|
|
|
// sdk version >= specified version
|
|
|
|
public static bool CheckiOSSystemVersion (int major, int minor, bool throwIfOtherPlatform = true)
|
|
|
|
{
|
|
|
|
#if __IOS__
|
|
|
|
return UIDevice.CurrentDevice.CheckSystemVersion (major, minor);
|
|
|
|
#else
|
|
|
|
if (throwIfOtherPlatform)
|
|
|
|
throw new Exception ("Can't get iOS System version on other platforms.");
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// This method returns true if:
|
|
|
|
// system version >= specified version
|
|
|
|
// AND
|
|
|
|
// sdk version >= specified version
|
|
|
|
public static bool ChecktvOSSystemVersion (int major, int minor, bool throwIfOtherPlatform = true)
|
|
|
|
{
|
|
|
|
#if __TVOS__
|
|
|
|
return UIDevice.CurrentDevice.CheckSystemVersion (major, minor);
|
|
|
|
#else
|
|
|
|
if (throwIfOtherPlatform)
|
|
|
|
throw new Exception ("Can't get tvOS System version on other platforms.");
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// This method returns true if:
|
|
|
|
// system version >= specified version
|
|
|
|
// AND
|
|
|
|
// sdk version >= specified version
|
|
|
|
public static bool CheckWatchOSSystemVersion (int major, int minor, bool throwIfOtherPlatform = true)
|
|
|
|
{
|
|
|
|
#if __WATCHOS__
|
|
|
|
return WatchKit.WKInterfaceDevice.CurrentDevice.CheckSystemVersion (major, minor);
|
|
|
|
#else
|
|
|
|
if (throwIfOtherPlatform)
|
|
|
|
throw new Exception ("Can't get watchOS System version on iOS/tvOS.");
|
|
|
|
// This is both iOS and tvOS
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-06-10 19:10:03 +03:00
|
|
|
public static bool CheckMacSystemVersion (int major, int minor, int build = 0, bool throwIfOtherPlatform = true)
|
|
|
|
{
|
|
|
|
#if MONOMAC
|
|
|
|
return OSXVersion >= new Version (major, minor, build);
|
|
|
|
#else
|
|
|
|
if (throwIfOtherPlatform)
|
|
|
|
throw new Exception ("Can't get iOS System version on other platforms.");
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-06-09 20:17:06 +03:00
|
|
|
// This method returns true if:
|
|
|
|
// system version >= specified version
|
|
|
|
// AND
|
|
|
|
// sdk version >= specified version
|
|
|
|
public static bool CheckSystemAndSDKVersion (int major, int minor)
|
|
|
|
{
|
|
|
|
#if __WATCHOS__
|
|
|
|
throw new Exception ("Can't get iOS System/SDK version on WatchOS.");
|
2016-06-10 11:52:03 +03:00
|
|
|
#elif MONOMAC
|
|
|
|
if (OSXVersion < new Version (major, minor))
|
|
|
|
return false;
|
2016-06-09 20:17:06 +03:00
|
|
|
#else
|
|
|
|
if (!UIDevice.CurrentDevice.CheckSystemVersion (major, minor))
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Check if the SDK version we're built includes the version we're checking for
|
|
|
|
// We don't want to execute iOS7 tests on an iOS7 device when built with the iOS6 SDK.
|
|
|
|
return CheckSDKVersion (major, minor);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool CheckSDKVersion (int major, int minor)
|
|
|
|
{
|
|
|
|
#if __WATCHOS__
|
|
|
|
throw new Exception ("Can't get iOS SDK version on WatchOS.");
|
2016-06-10 11:52:03 +03:00
|
|
|
#elif !MONOMAC
|
2016-06-09 20:17:06 +03:00
|
|
|
if (Runtime.Arch == Arch.SIMULATOR || !UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) {
|
|
|
|
// dyld_get_program_sdk_version was introduced with iOS 6.0, so don't do the SDK check on older deviecs.
|
|
|
|
return true; // dyld_get_program_sdk_version doesn't return what we're looking for on the mac.
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
var sdk = GetSDKVersion ();
|
|
|
|
if (sdk.Major > major)
|
|
|
|
return true;
|
|
|
|
if (sdk.Major == major && sdk.Minor >= minor)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void IgnoreOnTVOS ()
|
|
|
|
{
|
|
|
|
#if __TVOS__
|
|
|
|
NUnit.Framework.Assert.Ignore ("This test is disabled on TVOS.");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsTVOS {
|
|
|
|
get {
|
|
|
|
#if __TVOS__
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|