1
0
mirror of git://jb55.com/damus synced 2024-09-30 00:40:45 +00:00
damus/damusTests/ImageMetadataTest.swift

44 lines
1.6 KiB
Swift
Raw Normal View History

//
// LocationStrippingTest.swift
// damusTests
//
// Created by KernelKind on 2/8/24.
//
import XCTest
@testable import damus
final class ImageMetadataTest : XCTestCase {
func testRemoveGPSData() {
let bundle = Bundle(for: type(of: self))
guard let imageURL = bundle.url(forResource: "img_with_location", withExtension: "jpeg"),
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
else {
XCTFail("Failed to load test image from bundle")
return
}
let testOutputURL = documentsDirectory.appendingPathComponent("img_with_location.jpeg")
do {
if FileManager.default.fileExists(atPath: testOutputURL.path) {
try FileManager.default.removeItem(at: testOutputURL)
}
try FileManager.default.copyItem(at: imageURL, to: testOutputURL)
} catch {
XCTFail("Setup failed: Unable to copy test image to documents directory - \(error)")
return
}
let removalSuccess = removeGPSDataFromImageAndWrite(fromImageURL: testOutputURL)
XCTAssertTrue(removalSuccess, "GPS data removal was not successful")
guard let sourceAfterRemoval = CGImageSourceCreateWithURL(testOutputURL as CFURL, nil),
let imagePropertiesAfterRemoval = CGImageSourceCopyPropertiesAtIndex(sourceAfterRemoval, 0, nil) as? [String: Any],
imagePropertiesAfterRemoval[kCGImagePropertyGPSDictionary as String] == nil else {
XCTFail("GPS data was not removed from the image")
return
}
}
}