ImageMetadataTest.swift (1663B)
1 // 2 // LocationStrippingTest.swift 3 // damusTests 4 // 5 // Created by KernelKind on 2/8/24. 6 // 7 8 import XCTest 9 @testable import damus 10 11 final class ImageMetadataTest : XCTestCase { 12 func testRemoveGPSData() { 13 let bundle = Bundle(for: type(of: self)) 14 guard let imageURL = bundle.url(forResource: "img_with_location", withExtension: "jpeg"), 15 let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first 16 else { 17 XCTFail("Failed to load test image from bundle") 18 return 19 } 20 21 let testOutputURL = documentsDirectory.appendingPathComponent("img_with_location.jpeg") 22 do { 23 if FileManager.default.fileExists(atPath: testOutputURL.path) { 24 try FileManager.default.removeItem(at: testOutputURL) 25 } 26 try FileManager.default.copyItem(at: imageURL, to: testOutputURL) 27 } catch { 28 XCTFail("Setup failed: Unable to copy test image to documents directory - \(error)") 29 return 30 } 31 32 let removalSuccess = removeGPSDataFromImageAndWrite(fromImageURL: testOutputURL) 33 34 XCTAssertTrue(removalSuccess, "GPS data removal was not successful") 35 36 guard let sourceAfterRemoval = CGImageSourceCreateWithURL(testOutputURL as CFURL, nil), 37 let imagePropertiesAfterRemoval = CGImageSourceCopyPropertiesAtIndex(sourceAfterRemoval, 0, nil) as? [String: Any], 38 imagePropertiesAfterRemoval[kCGImagePropertyGPSDictionary as String] == nil else { 39 XCTFail("GPS data was not removed from the image") 40 return 41 } 42 } 43 }