diff --git a/Package.swift b/Package.swift index dc481a163..a6f7c6f36 100644 --- a/Package.swift +++ b/Package.swift @@ -90,6 +90,7 @@ let package = Package( targets: [ "_Testing_AppKit", "_Testing_CoreGraphics", + "_Testing_CoreImage", ] ) ] @@ -137,6 +138,7 @@ let package = Package( "Testing", "_Testing_AppKit", "_Testing_CoreGraphics", + "_Testing_CoreImage", "_Testing_Foundation", "MemorySafeTestingTests", ], @@ -218,6 +220,15 @@ let package = Package( path: "Sources/Overlays/_Testing_CoreGraphics", swiftSettings: .packageSettings + .enableLibraryEvolution() ), + .target( + name: "_Testing_CoreImage", + dependencies: [ + "Testing", + "_Testing_CoreGraphics", + ], + path: "Sources/Overlays/_Testing_CoreImage", + swiftSettings: .packageSettings + .enableLibraryEvolution() + ), .target( name: "_Testing_Foundation", dependencies: [ diff --git a/Sources/Overlays/_Testing_AppKit/ReexportTesting.swift b/Sources/Overlays/_Testing_AppKit/ReexportTesting.swift index 3716f1f01..ce80a70d9 100644 --- a/Sources/Overlays/_Testing_AppKit/ReexportTesting.swift +++ b/Sources/Overlays/_Testing_AppKit/ReexportTesting.swift @@ -8,5 +8,5 @@ // See https://swift.org/CONTRIBUTORS.txt for Swift project authors // -@_exported public import Testing -@_exported public import _Testing_CoreGraphics +@_exported @_spi(Experimental) @_spi(ForToolsIntegrationOnly) public import Testing +@_exported @_spi(Experimental) @_spi(ForToolsIntegrationOnly) public import _Testing_CoreGraphics diff --git a/Sources/Overlays/_Testing_CoreGraphics/Attachments/AttachableAsCGImage.swift b/Sources/Overlays/_Testing_CoreGraphics/Attachments/AttachableAsCGImage.swift index b470534df..689d06b66 100644 --- a/Sources/Overlays/_Testing_CoreGraphics/Attachments/AttachableAsCGImage.swift +++ b/Sources/Overlays/_Testing_CoreGraphics/Attachments/AttachableAsCGImage.swift @@ -24,6 +24,7 @@ private import ImageIO /// be attached to a test: /// /// - [`CGImage`](https://developer.apple.com/documentation/coregraphics/cgimage) +/// - [`CIImage`](https://developer.apple.com/documentation/coreimage/ciimage) /// - [`NSImage`](https://developer.apple.com/documentation/appkit/nsimage) /// (macOS) /// diff --git a/Sources/Overlays/_Testing_CoreGraphics/Attachments/Attachment+AttachableAsCGImage.swift b/Sources/Overlays/_Testing_CoreGraphics/Attachments/Attachment+AttachableAsCGImage.swift index 7e6836ef5..3835ddaf0 100644 --- a/Sources/Overlays/_Testing_CoreGraphics/Attachments/Attachment+AttachableAsCGImage.swift +++ b/Sources/Overlays/_Testing_CoreGraphics/Attachments/Attachment+AttachableAsCGImage.swift @@ -31,6 +31,7 @@ extension Attachment { /// ``AttachableAsCGImage`` protocol and can be attached to a test: /// /// - [`CGImage`](https://developer.apple.com/documentation/coregraphics/cgimage) + /// - [`CIImage`](https://developer.apple.com/documentation/coreimage/ciimage) /// - [`NSImage`](https://developer.apple.com/documentation/appkit/nsimage) /// (macOS) /// @@ -68,6 +69,7 @@ extension Attachment { /// ``AttachableAsCGImage`` protocol and can be attached to a test: /// /// - [`CGImage`](https://developer.apple.com/documentation/coregraphics/cgimage) + /// - [`CIImage`](https://developer.apple.com/documentation/coreimage/ciimage) /// - [`NSImage`](https://developer.apple.com/documentation/appkit/nsimage) /// (macOS) /// diff --git a/Sources/Overlays/_Testing_CoreGraphics/Attachments/_AttachableImageWrapper.swift b/Sources/Overlays/_Testing_CoreGraphics/Attachments/_AttachableImageWrapper.swift index f109e3409..6bb1e0d75 100644 --- a/Sources/Overlays/_Testing_CoreGraphics/Attachments/_AttachableImageWrapper.swift +++ b/Sources/Overlays/_Testing_CoreGraphics/Attachments/_AttachableImageWrapper.swift @@ -47,6 +47,7 @@ import UniformTypeIdentifiers /// to the ``AttachableAsCGImage`` protocol and can be attached to a test: /// /// - [`CGImage`](https://developer.apple.com/documentation/coregraphics/cgimage) +/// - [`CIImage`](https://developer.apple.com/documentation/coreimage/ciimage) /// - [`NSImage`](https://developer.apple.com/documentation/appkit/nsimage) /// (macOS) @_spi(Experimental) diff --git a/Sources/Overlays/_Testing_CoreImage/Attachments/CIImage+AttachableAsCGImage.swift b/Sources/Overlays/_Testing_CoreImage/Attachments/CIImage+AttachableAsCGImage.swift new file mode 100644 index 000000000..9a8278a83 --- /dev/null +++ b/Sources/Overlays/_Testing_CoreImage/Attachments/CIImage+AttachableAsCGImage.swift @@ -0,0 +1,33 @@ +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2024 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for Swift project authors +// + +#if SWT_TARGET_OS_APPLE && canImport(CoreImage) +public import CoreImage +@_spi(Experimental) public import _Testing_CoreGraphics + +@_spi(Experimental) +extension CIImage: AttachableAsCGImage { + public var attachableCGImage: CGImage { + get throws { + guard let result = CIContext().createCGImage(self, from: extent) else { + throw ImageAttachmentError.couldNotCreateCGImage + } + return result + } + } + + public func _makeCopyForAttachment() -> Self { + // CIImage is documented as thread-safe, but does not conform to Sendable. + // It conforms to NSCopying but does not actually copy itself, so there's no + // point in calling copy(). + self + } +} +#endif diff --git a/Sources/Overlays/_Testing_CoreImage/ReexportTesting.swift b/Sources/Overlays/_Testing_CoreImage/ReexportTesting.swift new file mode 100644 index 000000000..ce80a70d9 --- /dev/null +++ b/Sources/Overlays/_Testing_CoreImage/ReexportTesting.swift @@ -0,0 +1,12 @@ +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2024 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for Swift project authors +// + +@_exported @_spi(Experimental) @_spi(ForToolsIntegrationOnly) public import Testing +@_exported @_spi(Experimental) @_spi(ForToolsIntegrationOnly) public import _Testing_CoreGraphics diff --git a/Tests/TestingTests/AttachmentTests.swift b/Tests/TestingTests/AttachmentTests.swift index bb1573bb9..0f3f8a2ed 100644 --- a/Tests/TestingTests/AttachmentTests.swift +++ b/Tests/TestingTests/AttachmentTests.swift @@ -22,6 +22,10 @@ import _Testing_Foundation import CoreGraphics @_spi(Experimental) import _Testing_CoreGraphics #endif +#if canImport(CoreImage) +import CoreImage +@_spi(Experimental) import _Testing_CoreImage +#endif #if canImport(UniformTypeIdentifiers) import UniformTypeIdentifiers #endif @@ -598,6 +602,18 @@ extension AttachmentTests { } #endif +#if canImport(CoreImage) + @available(_uttypesAPI, *) + @Test func attachCIImage() throws { + let image = CIImage(cgImage: try Self.cgImage.get()) + let attachment = Attachment(image, named: "diamond.jpg") + #expect(attachment.attachableValue === image) + try attachment.attachableValue.withUnsafeBytes(for: attachment) { buffer in + #expect(buffer.count > 32) + } + } +#endif + #if canImport(AppKit) static var nsImage: NSImage { get throws {