Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
const colors
  • Loading branch information
jmagman committed Mar 12, 2024
commit c59d7dace00887e6e34cffc1de9cf0ca6634a71a
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
@import image_picker_ios.Test;
@import XCTest;

// Corner colors of test image scaled to 3x2. Format is "R G B A".
static NSString *const kColorRepresentation3x2BottomLeftYellow = @"1 0.776471 0 1";
static NSString *const kColorRepresentation3x2TopLeftRed = @"1 0.0666667 0 1";
static NSString *const kColorRepresentation3x2BottomRightCyan = @"0 0.772549 1 1";
static NSString *const kColorRepresentation3x2TopRightBlue = @"0 0.0705882 0.996078 1";

@interface ImageUtilTests : XCTestCase
@end

Expand Down Expand Up @@ -47,6 +53,17 @@ - (void)testScaledImage_EqualSizeReturnsSameImage {
XCTAssertEqual(image, scaledImage);
}

- (void)testScaledImage_NilSizeReturnsSameImage {
UIImage *image = [UIImage imageWithData:ImagePickerTestImages.JPGTestData];
UIImage *scaledImage = [FLTImagePickerImageUtil scaledImage:image
maxWidth:nil
maxHeight:nil
isMetadataAvailable:YES];

// Assert the same bytes pointer (not just equal objects).
XCTAssertEqual(image, scaledImage);
}

- (void)testScaledImage_ShouldBeScaled {
UIImage *image = [UIImage imageWithData:ImagePickerTestImages.JPGTestData];

Expand All @@ -59,14 +76,15 @@ - (void)testScaledImage_ShouldBeScaled {
XCTAssertEqual(scaledImage.size.width, scaledWidth);
XCTAssertEqual(scaledImage.size.height, scaledHeight);

// Check the corners. Format is "R G B A"
XCTAssertEqualObjects(ColorStringAtPixel(scaledImage, 0, 0), @"1 0.776471 0 1"); // yellow
// Check the corners to make sure nothing has been rotated.
XCTAssertEqualObjects(ColorStringAtPixel(scaledImage, 0, 0),
kColorRepresentation3x2BottomLeftYellow);
XCTAssertEqualObjects(ColorStringAtPixel(scaledImage, 0, scaledHeight - 1),
@"1 0.0666667 0 1"); // red
kColorRepresentation3x2TopLeftRed);
XCTAssertEqualObjects(ColorStringAtPixel(scaledImage, scaledWidth - 1, 0),
@"0 0.772549 1 1"); // cyan
kColorRepresentation3x2BottomRightCyan);
XCTAssertEqualObjects(ColorStringAtPixel(scaledImage, scaledWidth - 1, scaledHeight - 1),
@"0 0.0705882 0.996078 1"); // blue
kColorRepresentation3x2TopRightBlue);
}

- (void)testScaledImage_ShouldBeScaledWithNoMetadata {
Expand All @@ -81,14 +99,15 @@ - (void)testScaledImage_ShouldBeScaledWithNoMetadata {
XCTAssertEqual(scaledImage.size.width, scaledWidth);
XCTAssertEqual(scaledImage.size.height, scaledHeight);

// Check the corners to make sure nothing has been rotated. Format is "R G B A"
XCTAssertEqualObjects(ColorStringAtPixel(scaledImage, 0, 0), @"1 0.776471 0 1"); // yellow
// Check the corners to make sure nothing has been rotated.
XCTAssertEqualObjects(ColorStringAtPixel(scaledImage, 0, 0),
kColorRepresentation3x2BottomLeftYellow);
XCTAssertEqualObjects(ColorStringAtPixel(scaledImage, 0, scaledHeight - 1),
@"1 0.0666667 0 1"); // red
kColorRepresentation3x2TopLeftRed);
XCTAssertEqualObjects(ColorStringAtPixel(scaledImage, scaledWidth - 1, 0),
@"0 0.772549 1 1"); // cyan
kColorRepresentation3x2BottomRightCyan);
XCTAssertEqualObjects(ColorStringAtPixel(scaledImage, scaledWidth - 1, scaledHeight - 1),
@"0 0.0705882 0.996078 1"); // blue
kColorRepresentation3x2TopRightBlue);
}

- (void)testScaledImage_ShouldBeCorrectRotation {
Expand Down