File tree Expand file tree Collapse file tree 5 files changed +92
-0
lines changed
Sources/Overlays/_Testing_UIKit Expand file tree Collapse file tree 5 files changed +92
-0
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,7 @@ let package = Package(
9191 " _Testing_AppKit " ,
9292 " _Testing_CoreGraphics " ,
9393 " _Testing_CoreImage " ,
94+ " _Testing_UIKit " ,
9495 ]
9596 )
9697 ]
@@ -140,6 +141,7 @@ let package = Package(
140141 " _Testing_CoreGraphics " ,
141142 " _Testing_CoreImage " ,
142143 " _Testing_Foundation " ,
144+ " _Testing_UIKit " ,
143145 " MemorySafeTestingTests " ,
144146 ] ,
145147 swiftSettings: . packageSettings
@@ -241,6 +243,16 @@ let package = Package(
241243 // it can only enable Library Evolution itself on those platforms.
242244 swiftSettings: . packageSettings + . enableLibraryEvolution( . whenApple( ) )
243245 ) ,
246+ . target(
247+ name: " _Testing_UIKit " ,
248+ dependencies: [
249+ " Testing " ,
250+ " _Testing_CoreGraphics " ,
251+ " _Testing_CoreImage " ,
252+ ] ,
253+ path: " Sources/Overlays/_Testing_UIKit " ,
254+ swiftSettings: . packageSettings + . enableLibraryEvolution( )
255+ ) ,
244256
245257 // Utility targets: These are utilities intended for use when developing
246258 // this package, not for distribution.
Original file line number Diff line number Diff line change 1+ //
2+ // This source file is part of the Swift.org open source project
3+ //
4+ // Copyright (c) 2024 Apple Inc. and the Swift project authors
5+ // Licensed under Apache License v2.0 with Runtime Library Exception
6+ //
7+ // See https://swift.org/LICENSE.txt for license information
8+ // See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+ //
10+
11+ #if SWT_TARGET_OS_APPLE && canImport(UIKit)
12+ public import UIKit
13+ @_spi ( Experimental) public import _Testing_CoreGraphics
14+ @_spi ( Experimental) private import _Testing_CoreImage
15+
16+ private import ImageIO
17+
18+ @_spi ( Experimental)
19+ extension UIImage : AttachableAsCGImage {
20+ public var attachableCGImage : CGImage {
21+ get throws {
22+ if let cgImage {
23+ return cgImage
24+ } else if let ciImage {
25+ return try ciImage. attachableCGImage
26+ }
27+ throw ImageAttachmentError . couldNotCreateCGImage
28+ }
29+ }
30+
31+ public var _attachmentOrientation : UInt32 {
32+ let result : CGImagePropertyOrientation = switch imageOrientation {
33+ case . up: . up
34+ case . down: . down
35+ case . left: . left
36+ case . right: . right
37+ case . upMirrored: . upMirrored
38+ case . downMirrored: . downMirrored
39+ case . leftMirrored: . leftMirrored
40+ case . rightMirrored: . rightMirrored
41+ @unknown default : . up
42+ }
43+ return result. rawValue
44+ }
45+
46+ public var _attachmentScaleFactor : CGFloat {
47+ scale
48+ }
49+ }
50+ #endif
Original file line number Diff line number Diff line change 1+ //
2+ // This source file is part of the Swift.org open source project
3+ //
4+ // Copyright (c) 2024 Apple Inc. and the Swift project authors
5+ // Licensed under Apache License v2.0 with Runtime Library Exception
6+ //
7+ // See https://swift.org/LICENSE.txt for license information
8+ // See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+ //
10+
11+ @_exported @_spi ( Experimental) @_spi ( ForToolsIntegrationOnly) public import Testing
12+ @_exported @_spi ( Experimental) @_spi ( ForToolsIntegrationOnly) public import _Testing_CoreGraphics
Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ import CoreGraphics
2626import CoreImage
2727@_spi ( Experimental) import _Testing_CoreImage
2828#endif
29+ #if canImport(UIKit)
30+ import UIKit
31+ @_spi ( Experimental) import _Testing_UIKit
32+ #endif
2933#if canImport(UniformTypeIdentifiers)
3034import UniformTypeIdentifiers
3135#endif
@@ -678,6 +682,18 @@ extension AttachmentTests {
678682 }
679683 }
680684#endif
685+
686+ #if canImport(UIKit)
687+ @available ( _uttypesAPI, * )
688+ @Test func attachUIImage( ) throws {
689+ let image = UIImage ( cgImage: try Self . cgImage. get ( ) )
690+ let attachment = Attachment ( image, named: " diamond.jpg " )
691+ #expect( attachment. attachableValue === image)
692+ try attachment. attachableValue. withUnsafeBytes ( for: attachment) { buffer in
693+ #expect( buffer. count > 32 )
694+ }
695+ }
696+ #endif
681697#endif
682698 }
683699}
Original file line number Diff line number Diff line change @@ -24,8 +24,10 @@ struct ExampleSuite {
2424 @Test func example( ) { }
2525}
2626
27+ #if !SWT_NO_EXIT_TESTS
2728func exampleExitTest( ) async {
2829 await #expect( processExitsWith: . success) { }
2930}
31+ #endif
3032
3133#endif
You can’t perform that action at this time.
0 commit comments