#if canImport(AppKit) import AppKit #elseif canImport(UIKit) import UIKit #endif import XCTest import SwiftyImageIO #if canImport(MobileCoreServices) import MobileCoreServices #endif import Foundation internal let bundle = Bundle(for: Tests.self) class Tests: XCTestCase { func testSourceSupportedIdentifiers() { let identifiers = ImageSource.supportedUTIs() XCTAssert(identifiers.contains(UTI(kUTTypePNG)), "") for identifier in identifiers { XCTAssertTrue(ImageSource.supportsUTI(identifier)) } } func testDestinationSupportedIdentifiers() { let identifiers = ImageDestination.supportedUTIs() XCTAssert(identifiers.contains(UTI(kUTTypePNG)), "") for identifier in identifiers { XCTAssertTrue(ImageDestination.supportsUTI(identifier)) } } func testGifImageSource() { let imageSource = ImageSource(url: gifImageURL, options: nil)! XCTAssert(imageSource.imageCount == 120) XCTAssert(imageSource.status == .statusComplete) for imageIndex in (0.. CGImage { #if os(OSX) let image = NSImage(contentsOfFile: pngImageURL.path)! var imageRect:CGRect = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height) return image.cgImage(forProposedRect: &imageRect, context: nil, hints: nil)! #else return UIImage(contentsOfFile: pngImageURL.path)!.cgImage! #endif } var pngImageURL: URL { return bundle.url(forResource: "sample", withExtension: "png")! } var gifImageURL: URL { return bundle.url(forResource: "gifSample", withExtension: "gif")! } var jpgImageURL: URL { return bundle.url(forResource: "cameraSample", withExtension: "jpg")! } var jpgWithExifImageURL: URL { return bundle.url(forResource: "image_with_gps_data", withExtension: "jpg")! } #if canImport(UIKit) var sampleAnimatedImage: UIImage { var images = Array() for i in 0...10 { images.append(UIImage(named: "giphy\(i)", in: Bundle(for: Tests.self), compatibleWith: nil)!) } return UIImage.animatedImage(with: images, duration: 1)! } #endif func makeSavePath(fileExt: String) -> String { return (FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!.path as NSString).appendingPathComponent("\(UUID().uuidString).\(fileExt)") } }