VideoURLSenderItemCreatorTest.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 VideoURLSenderItemCreatorTest: XCTestCase {
  23. private let videoName = "Video-1"
  24. override func setUpWithError() throws {
  25. // Put setup code here. This method is called before the invocation of each test method in the class.
  26. AppGroup.setGroupId("group.ch.threema") //THREEMA_GROUP_IDENTIFIER @"group.ch.threema"
  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. func testVideoConversion() throws {
  32. let testBundle: Bundle = Bundle(for: VideoURLSenderItemCreatorTest.self)
  33. let testVideoURL = testBundle.url(forResource: videoName, withExtension: "mp4")
  34. let asset = AVURLAsset(url: testVideoURL!)
  35. let senderItemCreator = VideoURLSenderItemCreator()
  36. let videoURL = senderItemCreator.convertVideo(asset: asset)
  37. let expectation = self.expectation(description: "Video Conversion")
  38. var url : URL?
  39. videoURL.done { vidURL in
  40. url = vidURL
  41. expectation.fulfill()
  42. }.catch { _ in
  43. expectation.fulfill()
  44. }
  45. waitForExpectations(timeout: 60, handler: nil)
  46. let mimeType = UTIConverter.mimeType(fromUTI: UTIConverter.uti(forFileURL: url))
  47. XCTAssert(UTIConverter.isRenderingVideoMimeType(mimeType))
  48. }
  49. func testGetThumbnail() {
  50. let testBundle: Bundle = Bundle(for: VideoURLSenderItemCreatorTest.self)
  51. let testVideoURL = testBundle.url(forResource: videoName, withExtension: "mp4")
  52. let asset = AVURLAsset(url: testVideoURL!)
  53. let senderItemCreator = VideoURLSenderItemCreator()
  54. let expectation = self.expectation(description: "Video Creation")
  55. senderItemCreator.getThumbnail(asset: asset).done { thumbnail in
  56. expectation.fulfill()
  57. }.catch { _ in
  58. XCTFail()
  59. }
  60. waitForExpectations(timeout: 60, handler: nil)
  61. }
  62. func testGarbageURL() {
  63. let urlMatrix : [String] = [
  64. "https://threema.ch/en",
  65. "file://threema.ch/en",
  66. ]
  67. for urlString in urlMatrix {
  68. guard let url = URL(string: urlString) else {
  69. XCTFail("Invalid test parameter \(urlString)")
  70. return
  71. }
  72. let creator = VideoURLSenderItemCreator()
  73. let item = creator.senderItem(from: url)
  74. XCTAssert(item == nil)
  75. }
  76. }
  77. }