UTIConverterTests.swift 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. import XCTest
  21. @testable import ThreemaFramework
  22. class UTIConverterTests: XCTestCase {
  23. private let rawFilename = "Bild-7"
  24. let testBundle: Bundle = Bundle(for: UTIConverterTests.self)
  25. override func setUpWithError() throws {
  26. // Put setup code here. This method is called before the invocation of each test method in the class.
  27. }
  28. override func tearDownWithError() throws {
  29. // Put teardown code here. This method is called after the invocation of each test method in the class.
  30. }
  31. /// This tests the mime type generation from the uti for a selection of raw formats generated with imagemagick.
  32. /// The list was taken from https://stackoverflow.com/a/47612661/2310837.
  33. /// All items not recognized by macOSs Finder were removed.
  34. /// - Throws:
  35. func testGetRawImageMimeType() throws {
  36. let matrix : [(String, Bool)] = [
  37. ("srf", false),
  38. ("sr2", true),
  39. ("raf", false),
  40. ("pef", false),
  41. ("orf", false),
  42. ("nef", false),
  43. ("mrw", false),
  44. ("erf", true),
  45. ("dng", true),
  46. ("dcr", false),
  47. ("crw", true),
  48. ("cr2", false),
  49. ("arw", false),
  50. ("raw", false),
  51. ]
  52. for item in matrix {
  53. let testImageUrl = testBundle.url(forResource:rawFilename, withExtension: item.0)
  54. let uti = UTIConverter.uti(forFileURL: testImageUrl)
  55. let mimeType = UTIConverter.mimeType(fromUTI: uti)
  56. XCTAssert(UTIConverter.type(uti, conformsTo: kUTTypeImage as String), "\(item.0) with uti \(String(describing: uti)) should conform to image but does not")
  57. XCTAssert(UTIConverter.isImageMimeType(mimeType) == item.1, "\(item.0) with mime type \(String(describing: mimeType)) should conform to image \(item.1)")
  58. }
  59. }
  60. }