Skip to content

Commit

Permalink
Add _BenchmarkHost and _PerformanceTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Jan 9, 2024
1 parent 348d2e6 commit 70721ef
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 0 additions & 3 deletions Sources/OpenSwiftUI/Internal/Test/_Benchmark.swift

This file was deleted.

File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions Sources/OpenSwiftUI/Test/TestingAppDelegate.swift
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions Sources/OpenSwiftUI/Test/_Benchmark.swift
Original file line number Diff line number Diff line change
@@ -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")
}
}
58 changes: 58 additions & 0 deletions Sources/OpenSwiftUI/Test/_PerformanceTest.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
File renamed without changes.
22 changes: 22 additions & 0 deletions Sources/OpenSwiftUIShims/include/OpenSwiftUI_SPI.h
Original file line number Diff line number Diff line change
@@ -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(<UIKit/UIKit.h>)
#import <UIKit/UIKit.h>
@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 */

0 comments on commit 70721ef

Please sign in to comment.