ImageModifierTests.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // ImageModifierTests.swift
  3. // Kingfisher
  4. //
  5. // Created by Ethan Gill on 2017/11/29.
  6. //
  7. // Copyright (c) 2019 Wei Wang <onevcat@gmail.com>
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. import XCTest
  27. import Kingfisher
  28. class ImageModifierTests: XCTestCase {
  29. override func setUp() {
  30. super.setUp()
  31. // Put setup code here. This method is called before the invocation of each test method in the class.
  32. }
  33. override func tearDown() {
  34. // Put teardown code here. This method is called after the invocation of each test method in the class.
  35. super.tearDown()
  36. }
  37. func testAnyImageModifier() {
  38. let m = AnyImageModifier { image in
  39. return image
  40. }
  41. let image = KFCrossPlatformImage(data: testImagePNGData)!
  42. let modifiedImage = m.modify(image)
  43. XCTAssert(modifiedImage == image)
  44. }
  45. #if os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
  46. func testRenderingModeImageModifier() {
  47. let m1 = RenderingModeImageModifier(renderingMode: .alwaysOriginal)
  48. let image = KFCrossPlatformImage(data: testImagePNGData)!
  49. let alwaysOriginalImage = m1.modify(image)
  50. XCTAssert(alwaysOriginalImage.renderingMode == .alwaysOriginal)
  51. let m2 = RenderingModeImageModifier(renderingMode: .alwaysTemplate)
  52. let alwaysTemplateImage = m2.modify(image)
  53. XCTAssert(alwaysTemplateImage.renderingMode == .alwaysTemplate)
  54. }
  55. func testFlipsForRightToLeftLayoutDirectionImageModifier() {
  56. let m = FlipsForRightToLeftLayoutDirectionImageModifier()
  57. let image = KFCrossPlatformImage(data: testImagePNGData)!
  58. let modifiedImage = m.modify(image)
  59. XCTAssert(modifiedImage.flipsForRightToLeftLayoutDirection == true)
  60. }
  61. func testAlignmentRectInsetsImageModifier() {
  62. let insets = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8)
  63. let m = AlignmentRectInsetsImageModifier(alignmentInsets: insets)
  64. let image = KFCrossPlatformImage(data: testImagePNGData)!
  65. let modifiedImage = m.modify(image)
  66. XCTAssert(modifiedImage.alignmentRectInsets == insets)
  67. }
  68. #endif
  69. }