Skip to content
Merged
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ let package = Package(
"Testing",
],
path: "Sources/Overlays/_Testing_WinSDK",
exclude: ["CMakeLists.txt"],
swiftSettings: .packageSettings + .enableLibraryEvolution()
),

Expand Down
1 change: 1 addition & 0 deletions Sources/Overlays/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ add_subdirectory(_Testing_CoreGraphics)
add_subdirectory(_Testing_CoreImage)
add_subdirectory(_Testing_Foundation)
add_subdirectory(_Testing_UIKit)
add_subdirectory(_Testing_WinSDK)
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ extension AttachableImageFormat {
var enumerator: UnsafeMutablePointer<IEnumUnknown>?
let rCreate = factory.pointee.lpVtbl.pointee.CreateComponentEnumerator(
factory,
DWORD(bitPattern: WICEncoder.rawValue),
DWORD(bitPattern: WICComponentEnumerateDefault.rawValue),
DWORD(WICEncoder.rawValue),
DWORD(WICComponentEnumerateDefault.rawValue),
&enumerator
)
guard rCreate == S_OK, let enumerator else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ extension _AttachableImageWrapper: Attachable, AttachableWrapper where Image: At
let rCreate = CoCreateInstance(
&encoderCLSID,
nil,
DWORD(bitPattern: CLSCTX_INPROC_SERVER.rawValue),
DWORD(CLSCTX_INPROC_SERVER.rawValue),
IID_IWICBitmapEncoder,
&encoder
)
Expand Down Expand Up @@ -93,7 +93,7 @@ extension _AttachableImageWrapper: Attachable, AttachableWrapper where Image: At
guard rCommit == S_OK else {
throw ImageAttachmentError.imageWritingFailed(rCommit)
}
rCommit = stream.pointee.lpVtbl.pointee.Commit(stream, DWORD(bitPattern: STGC_DEFAULT.rawValue))
rCommit = stream.pointee.lpVtbl.pointee.Commit(stream, DWORD(STGC_DEFAULT.rawValue))
guard rCommit == S_OK else {
throw ImageAttachmentError.imageWritingFailed(rCommit)
}
Expand Down
32 changes: 32 additions & 0 deletions Sources/Overlays/_Testing_WinSDK/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2024–2025 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_library(_Testing_WinSDK
Attachments/_AttachableImageWrapper+AttachableWrapper.swift
Attachments/AttachableAsIWICBitmapSource.swift
Attachments/AttachableImageFormat+CLSID.swift
Attachments/Attachment+AttachableAsIWICBitmapSource.swift
Attachments/HBITMAP+AttachableAsIWICBitmapSource.swift
Attachments/HICON+AttachableAsIWICBitmapSource.swift
Attachments/IWICBitmapSource+AttachableAsIWICBitmapSource.swift
Attachments/UnsafeMutablePointer+AttachableAsIWICBitmapSource.swift
Support/Additions/GUIDAdditions.swift
Support/Additions/IPropertyBag2Additions.swift
Support/Additions/IWICImagingFactoryAdditions.swift
ReexportTesting.swift)

target_link_libraries(_Testing_WinSDK PUBLIC
Testing)

target_compile_options(_Testing_WinSDK PRIVATE
-enable-library-evolution
-emit-module-interface -emit-module-interface-path $<TARGET_PROPERTY:_Testing_WinSDK,Swift_MODULE_DIRECTORY>/_Testing_WinSDK.swiftinterface)

_swift_testing_install_target(_Testing_WinSDK)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension IWICImagingFactory {
let rCreate = CoCreateInstance(
CLSID_WICImagingFactory,
nil,
DWORD(bitPattern: CLSCTX_INPROC_SERVER.rawValue),
DWORD(CLSCTX_INPROC_SERVER.rawValue),
IID_IWICImagingFactory,
&factory
)
Expand Down
17 changes: 12 additions & 5 deletions Sources/Testing/Attachments/Images/ImageAttachmentError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,27 @@ package enum ImageAttachmentError: Error {
/// The image could not be converted.
case couldNotConvertImage
#elseif os(Windows)
/// The architecture-specific `HRESULT` type.
#if _pointerBitWidth(_64)
package typealias HRESULT = Int32
#else
package typealias HRESULT = Int
#endif

/// A call to `QueryInterface()` failed.
case queryInterfaceFailed(Any.Type, Int32)
case queryInterfaceFailed(Any.Type, HRESULT)

/// The testing library failed to create a COM object.
case comObjectCreationFailed(Any.Type, Int32)
case comObjectCreationFailed(Any.Type, HRESULT)

/// An image could not be written.
case imageWritingFailed(Int32)
case imageWritingFailed(HRESULT)

/// The testing library failed to get an in-memory stream's underlying buffer.
case globalFromStreamFailed(Int32)
case globalFromStreamFailed(HRESULT)

/// A property could not be written to a property bag.
case propertyBagWritingFailed(String, Int32)
case propertyBagWritingFailed(String, HRESULT)
#endif
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version: 1
modules:
- name: _Testing_WinSDK