[tests] Add introspection tests for Constants.*.cs.in. Fixes #5047 (#5159)

* Fix mac classic build
* Fix mac 32 bits (can't load 64bits only libraries)
* Check paths too leading to fixes to old (now incorrect) paths and typo
* apitest (Mac) has a similar test - but assumed that a file that did not exists was fine (missing typos and changes);
* tvOS simulator does not (unlike iOS) support loading the MetalPerformanceShaders.framework

reference: https://github.com/xamarin/xamarin-macios/issues/5047
This commit is contained in:
Sebastien Pouliot 2018-11-22 13:24:55 -05:00 коммит произвёл GitHub
Родитель b059252473
Коммит 4f1c39a00f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 114 добавлений и 23 удалений

Просмотреть файл

@ -17,13 +17,13 @@ namespace Compression
public IntPtr State; // void * __nullable state;
[DllImport (Constants.libcompression)]
[DllImport (Constants.libcompressionLibrary)]
public static extern CompressionStatus compression_stream_init (ref CompressionStreamStruct stream, StreamOperation operation, CompressionAlgorithm algorithm);
[DllImport (Constants.libcompression)]
[DllImport (Constants.libcompressionLibrary)]
public static extern CompressionStatus compression_stream_process (ref CompressionStreamStruct stream, StreamFlag flags);
[DllImport (Constants.libcompression)]
[DllImport (Constants.libcompressionLibrary)]
public static extern CompressionStatus compression_stream_destroy (ref CompressionStreamStruct stream);
}
}

Просмотреть файл

@ -12,7 +12,9 @@ namespace MonoTouch {
public const string libSystemLibrary = "/usr/lib/libSystem.dylib";
public const string libcLibrary = "/usr/lib/libc.dylib";
#if !XAMCORE_4_0
public const string libdispatchLibrary = "/usr/lib/system/libdispatch.dylib";
#endif
public const string AddressBookLibrary = "/System/Library/Frameworks/AddressBook.framework/AddressBook";
public const string AddressBookUILibrary = "/System/Library/Frameworks/AddressBookUI.framework/AddressBookUI";
public const string AudioToolboxLibrary = "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox";
@ -98,14 +100,16 @@ namespace MonoTouch {
public const string MetalKitLibrary = "/System/Library/Frameworks/MetalKit.framework/MetalKit";
public const string ModelIOLibrary = "/System/Library/Frameworks/ModelIO.framework/ModelIO";
public const string GameplayKitLibrary = "/System/Library/Frameworks/GameplayKit.framework/GameplayKit";
public const string libcompressionLibrary = "/usr/lib/libcompression.dylib";
#if !XAMCORE_4_0
public const string libcompression = "/usr/lib/libcompression.dylib";
#endif
// iOS 9.3
public const string HealthKitUILibrary = "/System/Library/Frameworks/HealthKitUI.framework/HealthKit";
public const string HealthKitUILibrary = "/System/Library/Frameworks/HealthKitUI.framework/HealthKitUI";
// iOS 10.0
public const string CallKitLibrary = "/System/Library/Frameworks/CallKit.framework/CallKit";
public const string MessagesLibrary = "/System/Library/Frameworks/Messages.framework/Messages";
public const string SpeechLibrary = "/System/Library/Frameworks/Speech.framework/";
public const string SpeechLibrary = "/System/Library/Frameworks/Speech.framework/Speech";
public const string VideoSubscriberAccountLibrary = "/System/Library/Frameworks/VideoSubscriberAccount.framework/VideoSubscriberAccount";
public const string UserNotificationsLibrary = "/System/Library/Frameworks/UserNotifications.framework/UserNotifications";
public const string UserNotificationsUILibrary = "/System/Library/Frameworks/UserNotificationsUI.framework/UserNotificationsUI";
@ -130,6 +134,6 @@ namespace MonoTouch {
public const string AuthenticationServicesLibrary = "/System/Library/Frameworks/AuthenticationServices.framework/AuthenticationServices";
public const string CarPlayLibrary = "/System/Library/Frameworks/CarPlay.framework/CarPlay";
public const string IdentityLookupUILibrary = "/System/Library/Frameworks/IdentityLookupUI.framework/IdentityLookupUI";
public const string NaturalLanguageLibrary = "/System/Library/Frameworks/Frameworks/NaturalLanguage.framework/NaturalLanguage";
public const string NaturalLanguageLibrary = "/System/Library/Frameworks/NaturalLanguage.framework/NaturalLanguage";
}
}

Просмотреть файл

@ -59,17 +59,17 @@ namespace MonoMac {
public const string ImageKitLibrary = "/System/Library/Frameworks/Quartz.framework/Frameworks/ImageKit.framework/ImageKit";
public const string OpenGLLibrary = "/System/Library/Frameworks/OpenGL.framework/OpenGL";
public const string OpenALLibrary = "/System/Library/Frameworks/OpenAL.framework/OpenAL";
public const string CoreMediaLibrary = "/System/Library/PrivateFrameworks/CoreMedia.framework/Versions/A/CoreMedia";
public const string CoreMediaLibrary = "/System/Library/Frameworks/CoreMedia.framework/CoreMedia";
public const string ScriptingBridgeLibrary = "/System/Library/Frameworks/ScriptingBridge.framework/ScriptingBridge";
public const string CoreDataLibrary = "/System/Library/Frameworks/CoreData.framework/CoreData";
public const string CoreImageLibrary = "/System/Library/Frameworks/QuartzCore.framework/Versions/A/Frameworks/CoreImage.framework/CoreImage";
public const string CFNetworkLibrary = "/System/Library/Frameworks/CoreServices.framework/Frameworks/CFNetwork.framework/CFNetwork";
public const string CoreImageLibrary = "/System/Library/Frameworks/CoreImage.framework/Versions/Current/CoreImage";
public const string CFNetworkLibrary = "/System/Library/Frameworks//CFNetwork.framework/CFNetwork";
public const string CoreMidiLibrary = "/System/Library/Frameworks/CoreMIDI.framework/CoreMIDI";
public const string QuickLookLibrary = "/System/Library/Frameworks/QuickLook.framework/QuickLook";
public const string AVFoundationLibrary = "/System/Library/Frameworks/AVFoundation.framework/AVFoundation";
public const string AccelerateImageLibrary = "/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/vImage";
public const string CoreBluetoothLibrary = "/System/Library/Frameworks/IOBluetooth.framework/Versions/A/Frameworks/CoreBluetooth.framework/CoreBluetooth";
public const string CoreBluetoothLibrary = "/System/Library/Frameworks//CoreBluetooth.framework/CoreBluetooth";
public const string GameKitLibrary = "/System/Library/Frameworks/GameKit.framework/GameKit";
public const string SceneKitLibrary = "/System/Library/Frameworks/SceneKit.framework/SceneKit";
public const string StoreKitLibrary = "/System/Library/Frameworks/StoreKit.framework/StoreKit";
@ -107,7 +107,9 @@ namespace MonoMac {
public const string SearchKitLibrary = "/System/Library/Frameworks/CoreServices.framework/Frameworks/SearchKit.framework/SearchKit";
public const string libSystemLibrary = "/usr/lib/libSystem.dylib";
public const string libcLibrary = "/usr/lib/libc.dylib";
#if !XAMCORE_4_0
public const string libdispatchLibrary = "/usr/lib/system/libdispatch.dylib";
#endif
public const string ContactsLibrary = "/System/Library/Frameworks/Contacts.framework/Contacts";
public const string ContactsUILibrary = "/System/Library/Frameworks/ContactsUI.framework/ContactsUI";
@ -123,8 +125,10 @@ namespace MonoMac {
public const string SafariServicesLibrary = "/System/Library/Frameworks/SafariServices.framework/SafariServices";
public const string PrintCoreLibrary = "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/PrintCore";
public const string libcompressionLibrary = "/usr/lib/libcompression.dylib";
#if !XAMCORE_4_0
public const string libcompression = "/usr/lib/libcompression.dylib";
#endif
// macOS 10.12
public const string PhotosLibrary = "/System/Library/Frameworks/Photos.framework/Photos";
@ -144,7 +148,7 @@ namespace MonoMac {
// macOS 10.14
public const string AdSupportLibrary = "/System/Library/Frameworks/AdSupport.framework/AdSupport";
public const string NaturalLanguageLibrary = "/System/Library/Frameworks/Frameworks/NaturalLanguage.framework/NaturalLanguage";
public const string NaturalLanguageLibrary = "/System/Library/Frameworks/NaturalLanguage.framework/NaturalLanguage";
public const string VideoSubscriberAccountLibrary = "/System/Library/Frameworks/VideoSubscriberAccount.framework/VideoSubscriberAccount";
public const string UserNotificationsLibrary = "/System/Library/Frameworks/UserNotifications.framework/UserNotifications";
public const string iTunesLibraryLibrary = "/System/Library/Frameworks/iTunesLibrary.framework/iTunesLibrary";

Просмотреть файл

@ -7,7 +7,9 @@ namespace ObjCRuntime {
public const string libSystemLibrary = "/usr/lib/libSystem.dylib";
public const string libcLibrary = "/usr/lib/libc.dylib";
public const string ObjectiveCLibrary = "/usr/lib/libobjc.dylib";
#if !XAMCORE_4_0
public const string libdispatchLibrary = "/usr/lib/system/libdispatch.dylib";
#endif
// TVOS 9.0
internal const string CoreServicesLibrary = "/System/Library/Frameworks/MobileCoreServices.framework/MobileCoreServices";
@ -47,7 +49,9 @@ namespace ObjCRuntime {
public const string ModelIOLibrary = "/System/Library/Frameworks/ModelIO.framework/ModelIO";
public const string NetworkLibrary = "/System/Library/Frameworks/Network.framework/Network";
public const string OpenGLESLibrary = "/System/Library/Frameworks/OpenGLES.framework/OpenGLES";
#if !XAMCORE_4_0
public const string PassKitLibrary = "/System/Library/Frameworks/PassKit.framework/PassKit";
#endif
public const string QuartzLibrary = "/System/Library/Frameworks/QuartzCore.framework/QuartzCore";
public const string SceneKitLibrary = "/System/Library/Frameworks/SceneKit.framework/SceneKit";
public const string SecurityLibrary = "/System/Library/Frameworks/Security.framework/Security";
@ -57,8 +61,10 @@ namespace ObjCRuntime {
public const string TVMLKitLibrary = "/System/Library/Frameworks/TVMLKit.framework/TVMLKit";
public const string TVServicesLibrary = "/System/Library/Frameworks/TVServices.framework/TVServices";
public const string UIKitLibrary = "/System/Library/Frameworks/UIKit.framework/UIKit";
public const string libcompressionLibrary = "/usr/lib/libcompression.dylib";
#if !XAMCORE_4_0
public const string libcompression = "/usr/lib/libcompression.dylib";
#endif
// TVOS 9.2
public const string MapKitLibrary = "/System/Library/Frameworks/MapKit.framework/MapKit";
@ -80,6 +86,6 @@ namespace ObjCRuntime {
public const string IOSurfaceLibrary = "/System/Library/Frameworks/IOSurface.framework/IOSurface";
// tvOS 12.0
public const string NaturalLanguageLibrary = "/System/Library/Frameworks/Frameworks/NaturalLanguage.framework/NaturalLanguage";
public const string NaturalLanguageLibrary = "/System/Library/Frameworks/NaturalLanguage.framework/NaturalLanguage";
}
}

Просмотреть файл

@ -7,7 +7,9 @@ namespace ObjCRuntime {
public const string libSystemLibrary = "/usr/lib/libSystem.dylib";
public const string libcLibrary = "/usr/lib/libc.dylib";
public const string ObjectiveCLibrary = "/usr/lib/libobjc.dylib";
#if !XAMCORE_4_0
public const string libdispatchLibrary = "/usr/lib/system/libdispatch.dylib";
#endif
// WatchOS 2.0
public const string CFNetworkLibrary = "/System/Library/Frameworks/CFNetwork.framework/CFNetwork";
@ -32,8 +34,10 @@ namespace ObjCRuntime {
public const string UIKitLibrary = "/System/Library/Frameworks/UIKit.framework/UIKit";
public const string WatchConnectivityLibrary = "/System/Library/Frameworks/WatchConnectivity.framework/WatchConnectivity";
public const string WatchKitLibrary = "/System/Library/Frameworks/WatchKit.framework/WatchKit";
public const string libcompressionLibrary = "/usr/lib/libcompression.dylib";
#if !XAMCORE_4_0
public const string libcompression = "/usr/lib/libcompression.dylib";
#endif
// WatchOS 3.0
public const string AVFoundationLibrary = "/System/Library/Frameworks/AVFoundation.framework/AVFoundation";
@ -54,7 +58,7 @@ namespace ObjCRuntime {
public const string VisionLibrary = "/System/Library/Frameworks/Vision.framework/Vision";
// WatchOS 5
public const string NaturalLanguageLibrary = "/System/Library/Frameworks/Frameworks/NaturalLanguage.framework/NaturalLanguage";
public const string NaturalLanguageLibrary = "/System/Library/Frameworks/NaturalLanguage.framework/NaturalLanguage";
public const string MediaPlayerLibrary = "/System/Library/Frameworks/MediaPlayer.framework/MediaPlayer";
}
}

Просмотреть файл

@ -79,6 +79,7 @@ namespace Xamarin.Mac.Tests
// macOS 10.14
case "AdSupportLibrary":
case "iTunesLibraryLibrary":
case "NaturalLanguageLibrary":
case "NetworkLibrary":
case "UserNotificationsLibrary":
case "VideoSubscriberAccountLibrary":

Просмотреть файл

@ -21,6 +21,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
@ -36,6 +37,7 @@ using UIKit;
using Foundation;
#else
#if MONOMAC
using MonoMac;
using MonoMac.AppKit;
using MonoMac.ObjCRuntime;
using MonoMac.Foundation;
@ -847,7 +849,7 @@ namespace Introspection
}
[Test]
public void TypoTest ()
public virtual void TypoTest ()
{
var types = Assembly.GetTypes ();
int totalErrors = 0;
@ -1034,5 +1036,70 @@ namespace Introspection
}
return clean.ToString ();
}
bool CheckLibrary (string lib)
{
#if MONOMAC
// on macOS the file should exist on the specified path
// for iOS the simulator paths do not match the strings
if (!File.Exists (lib))
return false;
#endif
var h = IntPtr.Zero;
try {
h = Dlfcn.dlopen (lib, 0);
if (h != IntPtr.Zero)
return true;
#if MONOMAC
// on macOS it might be wrong architecture
// i.e. 64 bits only (thin) libraries running on 32 bits process
if (IntPtr.Size == 4)
return true;
#endif
} finally {
Dlfcn.dlclose (h);
}
return false;
}
[Test]
public void ConstantsCheck ()
{
var c = typeof (Constants);
foreach (var fi in c.GetFields ()) {
if (!fi.IsPublic)
continue;
var s = fi.GetValue (null) as string;
switch (fi.Name) {
case "Version":
case "SdkVersion":
Assert.True (Version.TryParse (s, out _), fi.Name);
break;
#if !XAMCORE_4_0
#if __TVOS__
case "PassKitLibrary": // not part of tvOS
break;
#endif
case "libcompression": // bad (missing) suffix
Assert.True (CheckLibrary (s), fi.Name);
break;
#endif
#if __TVOS__
case "MetalPerformanceShadersLibrary":
// not supported in tvOS (12.1) simulator so load fails
if (Runtime.Arch == Arch.SIMULATOR)
break;
goto default;
#endif
default:
if (fi.Name.EndsWith ("Library", StringComparison.Ordinal)) {
Assert.True (CheckLibrary (s), fi.Name);
} else {
Assert.Fail ($"Unknown '{fi.Name}' field cannot be verified - please fix me!");
}
break;
}
}
}
}
}

Просмотреть файл

@ -26,11 +26,6 @@ namespace Introspection {
#if __WATCHOS__
Assert.Ignore ("Need to find alternative for UITextChecker on WatchOS.");
#else
// that's slow and there's no value to run it on devices as the API names
// being verified won't change from the simulator
if (Runtime.Arch == Arch.DEVICE)
Assert.Ignore ("Typos only detected on simulator");
// the dictionary used by iOS varies with versions and
// we don't want to maintain special cases for each version
var sdk = new Version (Constants.SdkVersion);
@ -51,5 +46,15 @@ namespace Introspection {
return txt.Substring ((int) typoRange.Location, (int) typoRange.Length);
#endif
}
public override void TypoTest ()
{
// that's slow and there's no value to run it on devices as the API names
// being verified won't change from the simulator
if (Runtime.Arch == Arch.DEVICE)
Assert.Ignore ("Typos only detected on simulator");
base.TypoTest ();
}
}
}