Skip to content

Commit 7eb599a

Browse files
committed
Merge upstream/main into gsoc-development
2 parents c82be0b + 54f919e commit 7eb599a

25 files changed

+1045
-32
lines changed

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
blank_issues_enabled: true
1010
contact_links:
1111
- name: 🌐 Discuss an idea
12-
url: https://forums.swift.org/c/related-projects/swift-testing
12+
url: https://forums.swift.org/c/development/swift-testing/103
1313
about: >
1414
Share an idea with the Swift Testing community.
1515
- name: 📄 Formally propose a change
@@ -18,10 +18,10 @@ contact_links:
1818
Formally propose an addition, removal, or change to the APIs or features
1919
of Swift Testing.
2020
- name: 🙋 Ask a question
21-
url: https://forums.swift.org/c/related-projects/swift-testing
21+
url: https://forums.swift.org/c/swift-users/15
2222
about: >
23-
Ask a question about or get help with Swift Testing. Beginner questions
24-
welcome!
23+
Ask a question or get help by starting a new Forum topic with the 'swift-testing' tag.
24+
Beginner questions welcome!
2525
- name: 🪲 Report an issue with Swift Package Manager
2626
url: https://github.com/swiftlang/swift-package-manager/issues/new/choose
2727
about: >

Package.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ let package = Package(
9292
"_Testing_CoreGraphics",
9393
"_Testing_CoreImage",
9494
"_Testing_UIKit",
95+
"_Testing_WinSDK",
9596
]
9697
)
9798
]
@@ -135,6 +136,7 @@ let package = Package(
135136
"_Testing_CoreImage",
136137
"_Testing_Foundation",
137138
"_Testing_UIKit",
139+
"_Testing_WinSDK",
138140
"MemorySafeTestingTests",
139141
],
140142
swiftSettings: .packageSettings
@@ -246,6 +248,14 @@ let package = Package(
246248
path: "Sources/Overlays/_Testing_UIKit",
247249
swiftSettings: .packageSettings + .enableLibraryEvolution()
248250
),
251+
.target(
252+
name: "_Testing_WinSDK",
253+
dependencies: [
254+
"Testing",
255+
],
256+
path: "Sources/Overlays/_Testing_WinSDK",
257+
swiftSettings: .packageSettings + .enableLibraryEvolution() + [.interoperabilityMode(.Cxx)]
258+
),
249259

250260
// Utility targets: These are utilities intended for use when developing
251261
// this package, not for distribution.
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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

Comments
 (0)