URLSenderItemCreatorTests.swift 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 URLSenderItemCreatorTests: XCTestCase {
  23. let testBundle: Bundle = Bundle(for: ImageURLSenderItemCreatorTest.self)
  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. // necessary for ValidationLogger
  27. AppGroup.setGroupId("group.ch.threema") //THREEMA_GROUP_IDENTIFIER @"group.ch.threema"
  28. }
  29. override func tearDownWithError() throws {
  30. // Put teardown code here. This method is called after the invocation of each test method in the class.
  31. }
  32. func testCreateSenderFromURL() {
  33. let imageURLSenderItemCreatorTest = ImageURLSenderItemCreatorTest()
  34. for item in imageURLSenderItemCreatorTest.testMatrix {
  35. guard let testImageUrl = imageURLSenderItemCreatorTest.testBundle.url(forResource: item.0, withExtension: item.1) else {
  36. XCTFail("Could not create testImageURL")
  37. return
  38. }
  39. guard let senderItem = URLSenderItemCreator.getSenderItem(for: testImageUrl, maxSize: item.2) else {
  40. XCTFail("Could not create senderItem from valid testdata")
  41. return
  42. }
  43. imageURLSenderItemCreatorTest.checkSenderItem(senderItem: senderItem, item: item)
  44. }
  45. }
  46. func testGarbageURL() {
  47. let urlMatrix : [String] = [
  48. "https://threema.ch/en",
  49. "file://threema.ch/en",
  50. ]
  51. for urlString in urlMatrix {
  52. guard let url = URL(string: urlString) else {
  53. XCTFail("Invalid test parameter \(urlString)")
  54. return
  55. }
  56. let item = URLSenderItemCreator.getSenderItem(for: url)
  57. XCTAssert(item == nil, "\(url)")
  58. }
  59. }
  60. }