Update the example and test case for the max file size
This commit is contained in:
parent
6a0f5dc73c
commit
6c2651bb25
|
@ -42,8 +42,10 @@
|
||||||
NSLog(@"%@", @"Static WebP load success");
|
NSLog(@"%@", @"Static WebP load success");
|
||||||
}
|
}
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||||
NSData *webpData = [image sd_imageDataAsFormat:SDImageFormatWebP];
|
NSUInteger maxFileSize = 4096;
|
||||||
|
NSData *webpData = [SDImageWebPCoder.sharedCoder encodedDataWithImage:image format:SDImageFormatWebP options:@{SDImageCoderEncodeMaxFileSize : @(maxFileSize)}];
|
||||||
if (webpData) {
|
if (webpData) {
|
||||||
|
NSCAssert(webpData.length <= maxFileSize, @"WebP Encoding with max file size limit works");
|
||||||
NSLog(@"%@", @"WebP encoding success");
|
NSLog(@"%@", @"WebP encoding success");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -182,6 +182,20 @@ const int64_t kAsyncTestTimeout = 5;
|
||||||
XCTAssert(canvas == NULL);
|
XCTAssert(canvas == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)test45WebPEncodingMaxFileSize {
|
||||||
|
NSURL *staticWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImageStatic" withExtension:@"webp"];
|
||||||
|
NSData *data = [NSData dataWithContentsOfURL:staticWebPURL];
|
||||||
|
UIImage *image = [UIImage sd_imageWithWebPData:data];
|
||||||
|
NSData *dataWithNoLimit = [SDImageWebPCoder.sharedCoder encodedDataWithImage:image format:SDImageFormatWebP options:nil];
|
||||||
|
XCTAssertNotNil(dataWithNoLimit);
|
||||||
|
NSUInteger maxFileSize = 8192;
|
||||||
|
NSData *dataWithLimit = [SDImageWebPCoder.sharedCoder encodedDataWithImage:image format:SDImageFormatWebP options:@{SDImageCoderEncodeMaxFileSize : @(maxFileSize)}];
|
||||||
|
XCTAssertNotNil(dataWithLimit);
|
||||||
|
XCTAssertGreaterThan(dataWithNoLimit.length, dataWithLimit.length);
|
||||||
|
XCTAssertGreaterThan(dataWithNoLimit.length, maxFileSize);
|
||||||
|
XCTAssertLessThanOrEqual(dataWithLimit.length, maxFileSize);
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation SDWebImageWebPCoderTests (Helpers)
|
@implementation SDWebImageWebPCoderTests (Helpers)
|
||||||
|
|
Loading…
Reference in New Issue