|
| 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 os(Windows) |
| 12 | +@_spi(Experimental) import Testing |
| 13 | +private import _TestingInternals.GDIPlus |
| 14 | + |
| 15 | +internal import WinSDK |
| 16 | + |
| 17 | +/// A protocol describing images that can be converted to instances of |
| 18 | +/// ``Testing/Attachment``. |
| 19 | +/// |
| 20 | +/// Instances of types conforming to this protocol do not themselves conform to |
| 21 | +/// ``Testing/Attachable``. Instead, the testing library provides additional |
| 22 | +/// initializers on ``Testing/Attachment`` that take instances of such types and |
| 23 | +/// handle converting them to image data when needed. |
| 24 | +/// |
| 25 | +/// The following system-provided image types conform to this protocol and can |
| 26 | +/// be attached to a test: |
| 27 | +/// |
| 28 | +/// - [`HBITMAP`](https://learn.microsoft.com/en-us/windows/win32/gdi/bitmaps) |
| 29 | +/// - [`HICON`](https://learn.microsoft.com/en-us/windows/win32/menurc/icons) |
| 30 | +/// |
| 31 | +/// You do not generally need to add your own conformances to this protocol. If |
| 32 | +/// you have an image in another format that needs to be attached to a test, |
| 33 | +/// first convert it to an instance of one of the types above. |
| 34 | +@_spi(Experimental) |
| 35 | +public protocol _AttachableByAddressAsGDIPlusImage { |
| 36 | + /// Create a GDI+ image representing an instance of this type at the given |
| 37 | + /// address. |
| 38 | + /// |
| 39 | + /// - Parameters: |
| 40 | + /// - imageAddress: The address of the instance of this type. |
| 41 | + /// |
| 42 | + /// - Returns: A pointer to a new GDI+ image representing this image. The |
| 43 | + /// caller is responsible for deleting this image when done with it. |
| 44 | + /// |
| 45 | + /// - Throws: Any error that prevented the creation of the GDI+ image. |
| 46 | + /// |
| 47 | + /// - Note: This function returns a value of C++ type `Gdiplus::Image *`. That |
| 48 | + /// type cannot be directly represented in Swift. If this function returns a |
| 49 | + /// value of any other concrete type, the result is undefined. |
| 50 | + /// |
| 51 | + /// The testing library automatically calls `GdiplusStartup()` and |
| 52 | + /// `GdiplusShutdown()` before and after calling this function. This function |
| 53 | + /// can therefore assume that GDI+ is correctly configured on the current |
| 54 | + /// thread when it is called. |
| 55 | + /// |
| 56 | + /// This function is not part of the public interface of the testing library. |
| 57 | + /// It may be removed in a future update. |
| 58 | + static func _copyAttachableGDIPlusImage(at imageAddress: UnsafeMutablePointer<Self>) throws -> OpaquePointer |
| 59 | + |
| 60 | + /// Clean up any resources at the given address. |
| 61 | + /// |
| 62 | + /// - Parameters: |
| 63 | + /// - imageAddress: The address of the instance of this type. |
| 64 | + /// |
| 65 | + /// The implementation of this function cleans up any resources (such as |
| 66 | + /// handles or COM objects) associated with this value. The testing library |
| 67 | + /// automatically invokes this function as needed. |
| 68 | + /// |
| 69 | + /// This function is not responsible for deleting the image returned from |
| 70 | + /// `_copyAttachableGDIPlusImage(at:)`. |
| 71 | + /// |
| 72 | + /// This function is not part of the public interface of the testing library. |
| 73 | + /// It may be removed in a future update. |
| 74 | + static func _cleanUpAttachment(at imageAddress: UnsafeMutablePointer<Self>) |
| 75 | +} |
| 76 | + |
| 77 | +/// A protocol describing images that can be converted to instances of |
| 78 | +/// ``Testing/Attachment``. |
| 79 | +/// |
| 80 | +/// Instances of types conforming to this protocol do not themselves conform to |
| 81 | +/// ``Testing/Attachable``. Instead, the testing library provides additional |
| 82 | +/// initializers on ``Testing/Attachment`` that take instances of such types and |
| 83 | +/// handle converting them to image data when needed. |
| 84 | +/// |
| 85 | +/// The following system-provided image types conform to this protocol and can |
| 86 | +/// be attached to a test: |
| 87 | +/// |
| 88 | +/// - [`HBITMAP`](https://learn.microsoft.com/en-us/windows/win32/gdi/bitmaps) |
| 89 | +/// - [`HICON`](https://learn.microsoft.com/en-us/windows/win32/menurc/icons) |
| 90 | +/// |
| 91 | +/// You do not generally need to add your own conformances to this protocol. If |
| 92 | +/// you have an image in another format that needs to be attached to a test, |
| 93 | +/// first convert it to an instance of one of the types above. |
| 94 | +@_spi(Experimental) |
| 95 | +public protocol AttachableAsGDIPlusImage { |
| 96 | + /// Create a GDI+ image representing this instance. |
| 97 | + /// |
| 98 | + /// - Returns: A pointer to a new GDI+ image representing this image. The |
| 99 | + /// caller is responsible for deleting this image when done with it. |
| 100 | + /// |
| 101 | + /// - Throws: Any error that prevented the creation of the GDI+ image. |
| 102 | + /// |
| 103 | + /// - Note: This function returns a value of C++ type `Gdiplus::Image *`. That |
| 104 | + /// type cannot be directly represented in Swift. If this function returns a |
| 105 | + /// value of any other concrete type, the result is undefined. |
| 106 | + /// |
| 107 | + /// The testing library automatically calls `GdiplusStartup()` and |
| 108 | + /// `GdiplusShutdown()` before and after calling this function. This function |
| 109 | + /// can therefore assume that GDI+ is correctly configured on the current |
| 110 | + /// thread when it is called. |
| 111 | + /// |
| 112 | + /// This function is not part of the public interface of the testing library. |
| 113 | + /// It may be removed in a future update. |
| 114 | + func _copyAttachableGDIPlusImage() throws -> OpaquePointer |
| 115 | + |
| 116 | + /// Clean up any resources associated with this instance. |
| 117 | + /// |
| 118 | + /// The implementation of this function cleans up any resources (such as |
| 119 | + /// handles or COM objects) associated with this value. The testing library |
| 120 | + /// automatically invokes this function as needed. |
| 121 | + /// |
| 122 | + /// This function is not responsible for deleting the image returned from |
| 123 | + /// `_copyAttachableGDIPlusImage()`. |
| 124 | + /// |
| 125 | + /// This function is not part of the public interface of the testing library. |
| 126 | + /// It may be removed in a future update. |
| 127 | + func _cleanUpAttachment() |
| 128 | +} |
| 129 | +#endif |
0 commit comments