-
Notifications
You must be signed in to change notification settings - Fork 20
chore: Migrate some obj-c
code to Swift
in WireImages
- WPB-15697
#2426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c5cea4c
Convert `ZMIImageProperties` to swift
samwyndham 17d6a98
Migrate `ImagePreprocessorTests.testThatItCanCalculateTheSizeOfAnImag…
samwyndham 1ba5d66
Migrate `ImagePreprocessorTests.testThatItReturnsZeroSizeIfFileIsNotA…
samwyndham ff74ed5
Migrate `ImagePreprocessorTests.testThatItReturnsTheRotatedSizeForIma…
samwyndham 1fefe47
Migrate `ImagePreprocessorTests.testThatItReturnsTheRotatedSizeForIma…
samwyndham da51070
Migrate `ImagePreprocessorTests.testThatItReturnsTheRotatedSizeForIma…
samwyndham e95ddab
Migrate `ImagePreprocessorTests.testThatItReturnsZeroSizeIfFileDoesNo…
samwyndham 85b8e6a
Migrate `ImagePreprocessorTests.testThatItCanCalculateTheSizeOfAnImag…
samwyndham 4599737
Migrate `ImagePreprocessorTests.testThatItReturnsZeroSizeIfDataIsNotA…
samwyndham ee96a77
Migrate `static OperationQueue.serialQueue(name:)`
samwyndham 465a0ae
Delete `waitUntilAllOperationsAreFinishedWithTimeout`
samwyndham 5927402
Migrate `ImageLoadOperationTests.testThatItDoesNotCrashOnInvalidData()`
samwyndham 1ad72b5
Migrate `ImageLoadOperationTests.testThatItDoesNotLoadWhenCancelled()`
samwyndham e6f6238
Migrate `ImageLoadOperationTests.testThatItLoadsJPEGData()`
samwyndham eb06a7f
Convert WireImages tests to folder
samwyndham 01b34e8
Migrate `ZMImageOwner`
samwyndham 4c5b478
Lint & format
samwyndham aade9a5
Use `@objcMembers` in `ZMIImageProperties`
samwyndham b719aa0
Fix compilation errors
samwyndham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
wire-ios-images/Sources/Image Processing/ImageProperties.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// Wire | ||
// Copyright (C) 2025 Wire Swiss GmbH | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import CoreGraphics | ||
import Foundation | ||
|
||
@objc | ||
public class ZMIImageProperties: NSObject { | ||
@objc public let size: CGSize | ||
@objc public let length: UInt | ||
@objc public let mimeType: String | ||
|
||
@objc | ||
public init(size: CGSize, length: UInt, mimeType: String) { | ||
self.size = size | ||
self.length = length | ||
self.mimeType = mimeType | ||
} | ||
|
||
public override var description: String { | ||
"{ length: \(length), type: \(mimeType), size: (\(size.width), \(size.height)}" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 0 additions & 44 deletions
44
wire-ios-images/Sources/Image Processing/ZMIImageProperties.m
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// | ||
// Wire | ||
// Copyright (C) 2025 Wire Swiss GmbH | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import UniformTypeIdentifiers | ||
import WireTesting | ||
import XCTest | ||
|
||
@testable import WireImages | ||
|
||
final class ImageLoadOperationTests: ZMTBaseTest { | ||
|
||
func testThatItLoadsJPEGData() throws { | ||
// given | ||
let imageData = try XCTUnwrap(data(forResource: "unsplash_medium_exif_2", extension: "jpg")) | ||
let sut = try XCTUnwrap(ZMImageLoadOperation(imageData: imageData)) | ||
expectation(for: NSPredicate(format: "isFinished == YES"), evaluatedWith: sut, handler: nil) | ||
|
||
// when | ||
sut.start() | ||
waitForExpectations(timeout: 5) | ||
|
||
// then | ||
let tiffDictionary = try XCTUnwrap( | ||
sut.sourceImageProperties[kCGImagePropertyTIFFDictionary] as? [AnyHashable: Any] | ||
) | ||
XCTAssertNotNil(sut.cgImage) | ||
XCTAssertEqual(tiffDictionary[kCGImagePropertyTIFFOrientation] as? Int, 2) | ||
XCTAssertEqual(sut.sourceImageProperties[kCGImagePropertyOrientation] as? Int, 2) | ||
XCTAssertEqual(sut.sourceImageProperties[kCGImagePropertyPixelHeight] as? Double, 346) | ||
XCTAssertEqual(sut.sourceImageProperties[kCGImagePropertyPixelWidth] as? Double, 531) | ||
XCTAssertEqual(sut.originalImageData, imageData) | ||
XCTAssertEqual(sut.computedImageProperties.mimeType, UTType.jpeg.identifier) | ||
XCTAssertEqual(sut.tiffOrientation, 2) | ||
XCTAssertEqual(sut.computedImageProperties.size, CGSize(width: 531, height: 346)) | ||
} | ||
|
||
func testThatItDoesNotLoadWhenCancelled() throws { | ||
// given | ||
let imageData = try XCTUnwrap(data(forResource: "unsplash_medium", extension: "jpg")) | ||
let sut = try XCTUnwrap(ZMImageLoadOperation(imageData: imageData)) | ||
sut.cancel() | ||
expectation(for: NSPredicate(format: "isFinished == YES"), evaluatedWith: sut, handler: nil) | ||
|
||
// when | ||
sut.start() | ||
waitForExpectations(timeout: 5) | ||
|
||
// then | ||
XCTAssertNil(sut.cgImage) | ||
XCTAssertNil(sut.sourceImageProperties) | ||
} | ||
|
||
func testThatItDoesNotCrashOnInvalidData() throws { | ||
// given | ||
let imageData = try XCTUnwrap(data(forResource: "Lorem Ipsum", extension: "txt")) | ||
let sut = try XCTUnwrap(ZMImageLoadOperation(imageData: imageData)) | ||
expectation(for: NSPredicate(format: "isFinished == YES"), evaluatedWith: sut, handler: nil) | ||
samwyndham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// when | ||
sut.start() | ||
waitForExpectations(timeout: 5) | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.