2018-06-08 20:00:48 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2019-09-10 16:02:27 +03:00
|
|
|
using System.IO;
|
2018-06-08 20:00:48 +03:00
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
using Foundation;
|
|
|
|
using ObjCRuntime;
|
|
|
|
|
|
|
|
|
|
|
|
public class Application {
|
|
|
|
public bool IsSimulatorBuild {
|
|
|
|
get {
|
2021-12-16 00:32:14 +03:00
|
|
|
return TestRuntime.IsSimulator;
|
2018-06-08 20:00:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Introspection {
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
[Preserve (AllMembers = true)]
|
|
|
|
public class ApiFrameworkTest : ApiBaseTest {
|
|
|
|
|
|
|
|
HashSet<string> namespaces = new HashSet<string> ();
|
|
|
|
Application app = new Application ();
|
|
|
|
|
|
|
|
public bool Skip (string @namespace)
|
|
|
|
{
|
|
|
|
if (@namespace == null)
|
|
|
|
return true;
|
|
|
|
if (namespaces.Contains (@namespace))
|
|
|
|
return true;
|
|
|
|
namespaces.Add (@namespace);
|
|
|
|
switch (@namespace) {
|
|
|
|
// we always link with the CoreFoundation framework
|
|
|
|
case "CoreFoundation":
|
|
|
|
return true;
|
|
|
|
// not a framework but a dynamic library /usr/lib/libcompression.dylib - tracked elsewhere (p/invoke only)
|
|
|
|
case "Compression":
|
|
|
|
return true;
|
|
|
|
// not a framework, largely p/invokes to /usr/lib/libobjc.dylib
|
|
|
|
case "ObjCRuntime":
|
|
|
|
return true;
|
|
|
|
// pinvokes into OpenGL[ES]
|
|
|
|
case "OpenTK":
|
|
|
|
return true;
|
|
|
|
// n[u]int, nfloat and friends
|
|
|
|
case "System":
|
|
|
|
case "System.Drawing":
|
|
|
|
return true;
|
|
|
|
#if __IOS__
|
2022-01-19 10:07:06 +03:00
|
|
|
#if !NET
|
2018-06-08 20:00:48 +03:00
|
|
|
// Some CF* types that requires CFNetwork which we always link with
|
|
|
|
// ref: tools/common/CompilerFlags.cs
|
|
|
|
case "CoreServices":
|
2022-01-19 10:07:06 +03:00
|
|
|
#endif
|
2021-11-08 18:17:26 +03:00
|
|
|
#if !NET
|
2019-08-14 18:46:55 +03:00
|
|
|
case "WatchKit": // Apple removed WatchKit from iOS
|
2021-11-08 18:17:26 +03:00
|
|
|
#endif
|
2018-06-08 20:00:48 +03:00
|
|
|
return true;
|
|
|
|
#elif __TVOS__ && !XAMCORE_4_0
|
|
|
|
// mistakes (can't be fixed without breaking binary compatibility)
|
|
|
|
case "CoreSpotlight":
|
|
|
|
case "WebKit":
|
|
|
|
return true;
|
|
|
|
#elif __WATCHOS__ && !XAMCORE_4_0
|
|
|
|
// helpers (largely enums) for AVFoundation API - no p/invokes or obj-C API that requires native linking
|
|
|
|
case "AudioToolbox":
|
|
|
|
return true;
|
|
|
|
// mistakes (can't be fixed without breaking binary compatibility)
|
|
|
|
case "WebKit":
|
|
|
|
return true;
|
|
|
|
#elif __MACOS__
|
|
|
|
// always included, ref: tools/common/CompilerFlags.cs
|
|
|
|
case "CFNetwork":
|
|
|
|
return true;
|
|
|
|
// not a framework, largely p/invokes to /usr/lib/libSystem.dylib
|
|
|
|
case "Darwin":
|
|
|
|
return true;
|
2019-05-23 17:51:42 +03:00
|
|
|
#endif
|
2018-06-08 20:00:48 +03:00
|
|
|
// not directly bindings
|
|
|
|
case "System.Net.Http":
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Frameworks GetFrameworks ()
|
|
|
|
{
|
2021-07-19 16:02:47 +03:00
|
|
|
#if __MACCATALYST__
|
|
|
|
return Frameworks.GetMacCatalystFrameworks ();
|
|
|
|
#elif __IOS__
|
2020-05-05 17:52:56 +03:00
|
|
|
return Frameworks.GetiOSFrameworks (app.IsSimulatorBuild);
|
2018-06-08 20:00:48 +03:00
|
|
|
#elif __TVOS__
|
|
|
|
return Frameworks.TVOSFrameworks;
|
|
|
|
#elif __WATCHOS__
|
2020-05-05 17:52:56 +03:00
|
|
|
return Frameworks.GetwatchOSFrameworks (app.IsSimulatorBuild);
|
2018-06-08 20:00:48 +03:00
|
|
|
#elif __MACOS__
|
|
|
|
return Frameworks.MacFrameworks;
|
|
|
|
#else
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void NativeFrameworks ()
|
|
|
|
{
|
|
|
|
ContinueOnFailure = true;
|
|
|
|
Errors = 0;
|
|
|
|
int n = 0;
|
|
|
|
var frameworks = GetFrameworks ();
|
|
|
|
|
|
|
|
foreach (Type t in Assembly.GetTypes ()) {
|
|
|
|
if (!t.IsPublic)
|
|
|
|
continue;
|
|
|
|
var ns = t.Namespace;
|
|
|
|
if (Skip (ns))
|
|
|
|
continue;
|
|
|
|
n++;
|
|
|
|
if (LogProgress)
|
|
|
|
Console.WriteLine ($"Namespace candidate '{ns}'");
|
|
|
|
if (frameworks.TryGetValue (ns, out var f))
|
|
|
|
continue;
|
2019-04-02 05:23:56 +03:00
|
|
|
// skip System.Net.Http handlers (since we moved them out of the BCL)
|
|
|
|
switch (ns) {
|
|
|
|
case "System.Net.Http":
|
|
|
|
switch (t.Name) {
|
|
|
|
case "CFNetworkHandler":
|
|
|
|
case "NSUrlSessionHandler":
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
2020-01-31 23:02:52 +03:00
|
|
|
case "Errors":
|
|
|
|
continue;
|
2019-04-02 05:23:56 +03:00
|
|
|
}
|
2018-06-08 20:00:48 +03:00
|
|
|
// Either Skip method or Frameworks.cs needs to be updated
|
|
|
|
ReportError ("Unknown framework '{0}'", ns);
|
|
|
|
}
|
|
|
|
AssertIfErrors ($"{Errors} unknown frameworks found:\n{ErrorData}");
|
|
|
|
}
|
2019-09-10 16:02:27 +03:00
|
|
|
|
2021-11-26 22:14:38 +03:00
|
|
|
#if __IOS__ && !__MACCATALYST__ && !NET
|
2019-09-10 16:02:27 +03:00
|
|
|
[Test]
|
|
|
|
public void Simlauncher ()
|
|
|
|
{
|
2021-12-16 00:32:14 +03:00
|
|
|
TestRuntime.AssertSimulator ("Only needed on simulator");
|
2019-09-10 16:02:27 +03:00
|
|
|
|
|
|
|
var all = GetFrameworks ();
|
|
|
|
|
|
|
|
var namespaces = new HashSet<string> (StringComparer.OrdinalIgnoreCase);
|
|
|
|
foreach (Type t in Assembly.GetTypes ()) {
|
|
|
|
if (!t.IsPublic)
|
|
|
|
continue;
|
|
|
|
namespaces.Add (t.Namespace);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var line in File.ReadAllLines ("simlauncher64-sgen.frameworks")) {
|
|
|
|
var c = line.IndexOf (" (compatibility");
|
|
|
|
if (c < 0)
|
|
|
|
continue;
|
|
|
|
var path = line.Substring (1, c - 1);
|
|
|
|
if (!path.StartsWith ("/System/Library/Frameworks/", StringComparison.Ordinal))
|
|
|
|
continue;
|
|
|
|
var fx = Path.GetFileNameWithoutExtension (path);
|
|
|
|
|
|
|
|
// match with mtouch framework list
|
|
|
|
if (!all.TryGetValue (fx, out var framework)) {
|
|
|
|
// special cases
|
|
|
|
switch (fx) {
|
|
|
|
case "CoreAudio": // AudioToolbox, AVFoundation...
|
|
|
|
case "CoreFoundation": // implied (always linked)
|
|
|
|
case "CFNetwork": // implied (StartWWAN) and included (mostly) in CoreServices
|
|
|
|
case "OpenAL": // part of OpenTK
|
|
|
|
break;
|
|
|
|
case "CoreMIDI":
|
|
|
|
// CoreMidi (case) in the fx list
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ReportError ($"{fx} is not part of mtouch's GetFrameworks");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// match with Xamarin.iOS.dll namespaces
|
|
|
|
if (!namespaces.Contains (fx)) {
|
|
|
|
// special cases
|
|
|
|
switch (fx) {
|
|
|
|
case "CoreAudio": // AudioToolbox, AVFoundation...
|
|
|
|
case "CFNetwork": // implied (StartWWAN) and included (mostly) in CoreServices
|
|
|
|
case "OpenAL": // part of OpenTK
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ReportError ($"{fx} is not part of mtouch's GetFrameworks");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-11-26 22:14:38 +03:00
|
|
|
|
|
|
|
AssertIfErrors ($"{Errors} unknown frameworks found:\n{ErrorData}");
|
2019-09-10 16:02:27 +03:00
|
|
|
}
|
|
|
|
#endif
|
2018-06-08 20:00:48 +03:00
|
|
|
}
|
|
|
|
}
|