Skip to content

Commit 70721ef

Browse files
committed
Add _BenchmarkHost and _PerformanceTest
1 parent 348d2e6 commit 70721ef

File tree

11 files changed

+117
-15
lines changed

11 files changed

+117
-15
lines changed

Sources/OpenSwiftUI/AppStructure/AppOrganization/TODO/AppDelegate.swift

+14-12
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,20 @@
77
// Status: WIP
88
// ID: 4475FD12FD59DEBA453321BD91F6EA04
99

10-
#if os(iOS) || os(tvOS)
10+
#if os(iOS)
1111
import UIKit
12-
class AppDelegate: UIResponder {
12+
typealias DelegateBaseClass = UIResponder
13+
#elseif os(macOS)
14+
import AppKit
15+
typealias DelegateBaseClass = NSResponder
16+
#else
17+
import Foundation
18+
// FIXME: Temporarily use NSObject as a placeholder
19+
typealias DelegateBaseClass = NSObject
20+
#endif
21+
22+
class AppDelegate: DelegateBaseClass {
23+
#if os(iOS)
1324
var fallbackDelegate: UIApplicationDelegate?
1425

1526
// WIP
@@ -26,14 +37,5 @@ class AppDelegate: UIResponder {
2637
let canSelfRespond = AppDelegate.instancesRespond(to: aSelector)
2738
return canDelegateRespond || canSelfRespond
2839
}
40+
#endif
2941
}
30-
#elseif os(watchOS)
31-
import WatchKit
32-
class AppDelegate {
33-
34-
}
35-
#elseif os(macOS)
36-
import AppKit
37-
class AppDelegate {
38-
}
39-
#endif

Sources/OpenSwiftUI/Internal/Test/_Benchmark.swift

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#if os(iOS)
2+
import UIKit
3+
#elseif os(macOS)
4+
import AppKit
5+
#endif
6+
7+
class TestingAppDelegate: DelegateBaseClass {
8+
static var performanceTests: [_PerformanceTest]?
9+
10+
#if os(iOS)
11+
static var connectCallback: ((UIWindow) -> Void)?
12+
#endif
13+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public protocol _Benchmark: _Test {
2+
func measure(host: _BenchmarkHost) -> [Double]
3+
}
4+
5+
extension _TestApp {
6+
public func runBenchmarks(_ benchmarks: [_Benchmark]) -> Never {
7+
let _ = RootView()
8+
fatalError("TODO")
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// _PerformanceTest.swift
3+
// OpenSwiftUI
4+
//
5+
// Created by Kyle on 2023/1/9.
6+
// Lastest Version: iOS 15.5
7+
// Status: WIP
8+
9+
#if os(iOS)
10+
import UIKit
11+
#elseif os(macOS)
12+
import AppKit
13+
#endif
14+
15+
internal import OpenSwiftUIShims
16+
17+
public protocol _PerformanceTest: _Test {
18+
var name: String { get }
19+
func runTest(host: _BenchmarkHost, options: [AnyHashable: Any])
20+
}
21+
22+
extension __App {
23+
public static func _registerPerformanceTests(_ tests: [_PerformanceTest]) {
24+
TestingAppDelegate.performanceTests = tests
25+
}
26+
}
27+
28+
extension _TestApp {
29+
public func runPerformanceTests(_ tests: [_PerformanceTest]) -> Never {
30+
fatalError("TODO")
31+
}
32+
}
33+
34+
extension _BenchmarkHost {
35+
public func _started(test: _PerformanceTest) {
36+
#if os(iOS)
37+
UIApplication.shared.startedTest(test.name)
38+
#else
39+
fatalError("TODO")
40+
#endif
41+
}
42+
43+
public func _finished(test: _PerformanceTest) {
44+
#if os(iOS)
45+
UIApplication.shared.finishedTest(test.name)
46+
#else
47+
fatalError("TODO")
48+
#endif
49+
}
50+
51+
public func _failed(test: _PerformanceTest) {
52+
#if os(iOS)
53+
UIApplication.shared.failedTest(test.name, withFailure: nil)
54+
#else
55+
fatalError("TODO")
56+
#endif
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// OpenSwiftUI_SPI.h
3+
//
4+
//
5+
// Created by Kyle on 2024/1/9.
6+
//
7+
8+
#ifndef OpenSwiftUI_SPI_h
9+
#define OpenSwiftUI_SPI_h
10+
11+
#if __has_include(<UIKit/UIKit.h>)
12+
#import <UIKit/UIKit.h>
13+
@interface UIApplication (OpenSwiftUI_SPI)
14+
- (void)startedTest:(nullable NSString *)name;
15+
- (void)finishedTest:(nullable NSString *)name;
16+
- (void)failedTest:(nullable NSString *)name withFailure:(nullable NSError*)failure;
17+
@end
18+
#else
19+
20+
#endif
21+
22+
#endif /* OpenSwiftUI_SPI_h */

0 commit comments

Comments
 (0)