From 70721ef67b075954b01a901c1102262fbd280e96 Mon Sep 17 00:00:00 2001 From: Kyle Date: Wed, 10 Jan 2024 00:19:09 +0800 Subject: [PATCH] Add _BenchmarkHost and _PerformanceTest --- .../{internal => }/LegacyApp.swift | 0 .../AppOrganization/TODO/AppDelegate.swift | 26 +++++---- .../Internal/Test/_Benchmark.swift | 3 - .../internal => Test}/TestApp.swift | 0 .../{Internal => }/Test/TestIDView.swift | 0 .../OpenSwiftUI/Test/TestingAppDelegate.swift | 13 +++++ Sources/OpenSwiftUI/Test/_Benchmark.swift | 10 ++++ .../{Internal => }/Test/_BenchmarkHost.swift | 0 .../OpenSwiftUI/Test/_PerformanceTest.swift | 58 +++++++++++++++++++ .../{Internal => }/Test/_Test.swift | 0 .../include/OpenSwiftUI_SPI.h | 22 +++++++ 11 files changed, 117 insertions(+), 15 deletions(-) rename Sources/OpenSwiftUI/AppStructure/AppOrganization/{internal => }/LegacyApp.swift (100%) delete mode 100644 Sources/OpenSwiftUI/Internal/Test/_Benchmark.swift rename Sources/OpenSwiftUI/{AppStructure/AppOrganization/internal => Test}/TestApp.swift (100%) rename Sources/OpenSwiftUI/{Internal => }/Test/TestIDView.swift (100%) create mode 100644 Sources/OpenSwiftUI/Test/TestingAppDelegate.swift create mode 100644 Sources/OpenSwiftUI/Test/_Benchmark.swift rename Sources/OpenSwiftUI/{Internal => }/Test/_BenchmarkHost.swift (100%) create mode 100644 Sources/OpenSwiftUI/Test/_PerformanceTest.swift rename Sources/OpenSwiftUI/{Internal => }/Test/_Test.swift (100%) create mode 100644 Sources/OpenSwiftUIShims/include/OpenSwiftUI_SPI.h diff --git a/Sources/OpenSwiftUI/AppStructure/AppOrganization/internal/LegacyApp.swift b/Sources/OpenSwiftUI/AppStructure/AppOrganization/LegacyApp.swift similarity index 100% rename from Sources/OpenSwiftUI/AppStructure/AppOrganization/internal/LegacyApp.swift rename to Sources/OpenSwiftUI/AppStructure/AppOrganization/LegacyApp.swift diff --git a/Sources/OpenSwiftUI/AppStructure/AppOrganization/TODO/AppDelegate.swift b/Sources/OpenSwiftUI/AppStructure/AppOrganization/TODO/AppDelegate.swift index 85b15867..8662c9e1 100644 --- a/Sources/OpenSwiftUI/AppStructure/AppOrganization/TODO/AppDelegate.swift +++ b/Sources/OpenSwiftUI/AppStructure/AppOrganization/TODO/AppDelegate.swift @@ -7,9 +7,20 @@ // Status: WIP // ID: 4475FD12FD59DEBA453321BD91F6EA04 -#if os(iOS) || os(tvOS) +#if os(iOS) import UIKit -class AppDelegate: UIResponder { +typealias DelegateBaseClass = UIResponder +#elseif os(macOS) +import AppKit +typealias DelegateBaseClass = NSResponder +#else +import Foundation +// FIXME: Temporarily use NSObject as a placeholder +typealias DelegateBaseClass = NSObject +#endif + +class AppDelegate: DelegateBaseClass { + #if os(iOS) var fallbackDelegate: UIApplicationDelegate? // WIP @@ -26,14 +37,5 @@ class AppDelegate: UIResponder { let canSelfRespond = AppDelegate.instancesRespond(to: aSelector) return canDelegateRespond || canSelfRespond } + #endif } -#elseif os(watchOS) -import WatchKit -class AppDelegate { - -} -#elseif os(macOS) -import AppKit -class AppDelegate { -} -#endif diff --git a/Sources/OpenSwiftUI/Internal/Test/_Benchmark.swift b/Sources/OpenSwiftUI/Internal/Test/_Benchmark.swift deleted file mode 100644 index 8ec926c3..00000000 --- a/Sources/OpenSwiftUI/Internal/Test/_Benchmark.swift +++ /dev/null @@ -1,3 +0,0 @@ -public protocol _Benchmark: _Test { - func measure(host: _BenchmarkHost) -> [Double] -} diff --git a/Sources/OpenSwiftUI/AppStructure/AppOrganization/internal/TestApp.swift b/Sources/OpenSwiftUI/Test/TestApp.swift similarity index 100% rename from Sources/OpenSwiftUI/AppStructure/AppOrganization/internal/TestApp.swift rename to Sources/OpenSwiftUI/Test/TestApp.swift diff --git a/Sources/OpenSwiftUI/Internal/Test/TestIDView.swift b/Sources/OpenSwiftUI/Test/TestIDView.swift similarity index 100% rename from Sources/OpenSwiftUI/Internal/Test/TestIDView.swift rename to Sources/OpenSwiftUI/Test/TestIDView.swift diff --git a/Sources/OpenSwiftUI/Test/TestingAppDelegate.swift b/Sources/OpenSwiftUI/Test/TestingAppDelegate.swift new file mode 100644 index 00000000..4bf5b8d0 --- /dev/null +++ b/Sources/OpenSwiftUI/Test/TestingAppDelegate.swift @@ -0,0 +1,13 @@ +#if os(iOS) +import UIKit +#elseif os(macOS) +import AppKit +#endif + +class TestingAppDelegate: DelegateBaseClass { + static var performanceTests: [_PerformanceTest]? + + #if os(iOS) + static var connectCallback: ((UIWindow) -> Void)? + #endif +} diff --git a/Sources/OpenSwiftUI/Test/_Benchmark.swift b/Sources/OpenSwiftUI/Test/_Benchmark.swift new file mode 100644 index 00000000..80ed5457 --- /dev/null +++ b/Sources/OpenSwiftUI/Test/_Benchmark.swift @@ -0,0 +1,10 @@ +public protocol _Benchmark: _Test { + func measure(host: _BenchmarkHost) -> [Double] +} + +extension _TestApp { + public func runBenchmarks(_ benchmarks: [_Benchmark]) -> Never { + let _ = RootView() + fatalError("TODO") + } +} diff --git a/Sources/OpenSwiftUI/Internal/Test/_BenchmarkHost.swift b/Sources/OpenSwiftUI/Test/_BenchmarkHost.swift similarity index 100% rename from Sources/OpenSwiftUI/Internal/Test/_BenchmarkHost.swift rename to Sources/OpenSwiftUI/Test/_BenchmarkHost.swift diff --git a/Sources/OpenSwiftUI/Test/_PerformanceTest.swift b/Sources/OpenSwiftUI/Test/_PerformanceTest.swift new file mode 100644 index 00000000..76a19e4b --- /dev/null +++ b/Sources/OpenSwiftUI/Test/_PerformanceTest.swift @@ -0,0 +1,58 @@ +// +// _PerformanceTest.swift +// OpenSwiftUI +// +// Created by Kyle on 2023/1/9. +// Lastest Version: iOS 15.5 +// Status: WIP + +#if os(iOS) +import UIKit +#elseif os(macOS) +import AppKit +#endif + +internal import OpenSwiftUIShims + +public protocol _PerformanceTest: _Test { + var name: String { get } + func runTest(host: _BenchmarkHost, options: [AnyHashable: Any]) +} + +extension __App { + public static func _registerPerformanceTests(_ tests: [_PerformanceTest]) { + TestingAppDelegate.performanceTests = tests + } +} + +extension _TestApp { + public func runPerformanceTests(_ tests: [_PerformanceTest]) -> Never { + fatalError("TODO") + } +} + +extension _BenchmarkHost { + public func _started(test: _PerformanceTest) { + #if os(iOS) + UIApplication.shared.startedTest(test.name) + #else + fatalError("TODO") + #endif + } + + public func _finished(test: _PerformanceTest) { + #if os(iOS) + UIApplication.shared.finishedTest(test.name) + #else + fatalError("TODO") + #endif + } + + public func _failed(test: _PerformanceTest) { + #if os(iOS) + UIApplication.shared.failedTest(test.name, withFailure: nil) + #else + fatalError("TODO") + #endif + } +} diff --git a/Sources/OpenSwiftUI/Internal/Test/_Test.swift b/Sources/OpenSwiftUI/Test/_Test.swift similarity index 100% rename from Sources/OpenSwiftUI/Internal/Test/_Test.swift rename to Sources/OpenSwiftUI/Test/_Test.swift diff --git a/Sources/OpenSwiftUIShims/include/OpenSwiftUI_SPI.h b/Sources/OpenSwiftUIShims/include/OpenSwiftUI_SPI.h new file mode 100644 index 00000000..5ca9230a --- /dev/null +++ b/Sources/OpenSwiftUIShims/include/OpenSwiftUI_SPI.h @@ -0,0 +1,22 @@ +// +// OpenSwiftUI_SPI.h +// +// +// Created by Kyle on 2024/1/9. +// + +#ifndef OpenSwiftUI_SPI_h +#define OpenSwiftUI_SPI_h + +#if __has_include() +#import +@interface UIApplication (OpenSwiftUI_SPI) +- (void)startedTest:(nullable NSString *)name; +- (void)finishedTest:(nullable NSString *)name; +- (void)failedTest:(nullable NSString *)name withFailure:(nullable NSError*)failure; +@end +#else + +#endif + +#endif /* OpenSwiftUI_SPI_h */