ImageUtilTests.m 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #import "ImagePickerTestImages.h"
  5. @import image_picker;
  6. @import XCTest;
  7. @interface ImageUtilTests : XCTestCase
  8. @end
  9. @implementation ImageUtilTests
  10. - (void)testScaledImage_ShouldBeScaled {
  11. UIImage *image = [UIImage imageWithData:ImagePickerTestImages.JPGTestData];
  12. UIImage *newImage = [FLTImagePickerImageUtil scaledImage:image maxWidth:@3 maxHeight:@2];
  13. XCTAssertEqual(newImage.size.width, 3);
  14. XCTAssertEqual(newImage.size.height, 2);
  15. }
  16. - (void)testScaledGIFImage_ShouldBeScaled {
  17. // gif image that frame size is 3 and the duration is 1 second.
  18. GIFInfo *info = [FLTImagePickerImageUtil scaledGIFImage:ImagePickerTestImages.GIFTestData
  19. maxWidth:@3
  20. maxHeight:@2];
  21. NSArray<UIImage *> *images = info.images;
  22. NSTimeInterval duration = info.interval;
  23. XCTAssertEqual(images.count, 3);
  24. XCTAssertEqual(duration, 1);
  25. for (UIImage *newImage in images) {
  26. XCTAssertEqual(newImage.size.width, 3);
  27. XCTAssertEqual(newImage.size.height, 2);
  28. }
  29. }
  30. @end