From bf6de35302a84aac34be224d22009436d15f6714 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Tue, 30 Jan 2024 15:15:48 +0800 Subject: [PATCH] Added test case `test46WebPEncodingMonochrome` --- Tests/SDWebImageWebPCoderTests.m | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Tests/SDWebImageWebPCoderTests.m b/Tests/SDWebImageWebPCoderTests.m index cbe7365..05d770b 100644 --- a/Tests/SDWebImageWebPCoderTests.m +++ b/Tests/SDWebImageWebPCoderTests.m @@ -218,6 +218,21 @@ const int64_t kAsyncTestTimeout = 5; XCTAssertLessThanOrEqual(dataWithLimit.length, maxFileSize); } +- (void)test46WebPEncodingMonochrome { + CGSize size = CGSizeMake(512, 512); + SDGraphicsImageRendererFormat *format = [[SDGraphicsImageRendererFormat alloc] init]; + format.scale = 1; + SDGraphicsImageRenderer *renderer = [[SDGraphicsImageRenderer alloc] initWithSize:size format:format]; + UIColor *monochromeColor = UIColor.clearColor; + UIImage *monochromeImage = [renderer imageWithActions:^(CGContextRef ctx) { + [monochromeColor setFill]; + CGContextFillRect(ctx, CGRectMake(0, 0, size.width, size.height)); + }]; + XCTAssert(monochromeImage); + NSData *data = [SDImageWebPCoder.sharedCoder encodedDataWithImage:monochromeImage format:SDImageFormatWebP options:nil]; + XCTAssert(data); +} + - (void)testWebPDecodeDoesNotTriggerCACopyImage { NSURL *staticWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestColorspaceStatic" withExtension:@"webp"]; NSData *data = [NSData dataWithContentsOfURL:staticWebPURL];