Update the test case about maxPixelSize

This commit is contained in:
DreamPiggy 2020-04-13 11:17:17 +08:00
parent 56ec346a0c
commit 8b935e7927
1 changed files with 21 additions and 2 deletions

View File

@ -262,8 +262,8 @@ const int64_t kAsyncTestTimeout = 5;
thumbnailPixelSize = CGSizeMake(round(thumbnailHeight * ratio), thumbnailHeight); thumbnailPixelSize = CGSizeMake(round(thumbnailHeight * ratio), thumbnailHeight);
} }
// Image/IO's thumbnail API does not always use round to preserve precision, we check ABS <= 1 // Image/IO's thumbnail API does not always use round to preserve precision, we check ABS <= 1
expect(ABS(thumbImage.size.width - thumbnailPixelSize.width) <= 1); expect(ABS(thumbImage.size.width - thumbnailPixelSize.width)).beLessThanOrEqualTo(1);
expect(ABS(thumbImage.size.height - thumbnailPixelSize.height) <= 1); expect(ABS(thumbImage.size.height - thumbnailPixelSize.height)).beLessThanOrEqualTo(1);
if (supportsEncoding) { if (supportsEncoding) {
@ -282,6 +282,25 @@ const int64_t kAsyncTestTimeout = 5;
#if SD_UIKIT #if SD_UIKIT
expect(outputImage.images.count).to.equal(inputImage.images.count); expect(outputImage.images.count).to.equal(inputImage.images.count);
#endif #endif
// check max pixel size encoding with scratch
CGFloat maxWidth = 50;
CGFloat maxHeight = 50;
CGFloat maxRatio = maxWidth / maxHeight;
CGSize maxPixelSize;
if (ratio > maxRatio) {
maxPixelSize = CGSizeMake(maxWidth, round(maxWidth / ratio));
} else {
maxPixelSize = CGSizeMake(round(maxHeight * ratio), maxHeight);
}
NSData *outputMaxImageData = [coder encodedDataWithImage:inputImage format:encodingFormat options:@{SDImageCoderEncodeMaxPixelSize : @(CGSizeMake(maxWidth, maxHeight))}];
UIImage *outputMaxImage = [coder decodedImageWithData:outputMaxImageData options:nil];
// Image/IO's thumbnail API does not always use round to preserve precision, we check ABS <= 1
expect(ABS(outputMaxImage.size.width - maxPixelSize.width)).beLessThanOrEqualTo(1);
expect(ABS(outputMaxImage.size.height - maxPixelSize.height)).beLessThanOrEqualTo(1);
#if SD_UIKIT
expect(outputMaxImage.images.count).to.equal(inputImage.images.count);
#endif
} }
} }