From db610363f4142848757312288afd46df0610e906 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sat, 4 Apr 2020 13:07:20 +0800 Subject: [PATCH] Added the test case to ensure the background color encoding options on JPEG works --- Tests/Tests/SDImageCoderTests.m | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Tests/Tests/SDImageCoderTests.m b/Tests/Tests/SDImageCoderTests.m index dbdfc6c0..25ab0632 100644 --- a/Tests/Tests/SDImageCoderTests.m +++ b/Tests/Tests/SDImageCoderTests.m @@ -8,6 +8,7 @@ */ #import "SDTestCase.h" +#import "UIColor+HexString.h" @interface SDWebImageDecoderTests : SDTestCase @@ -82,6 +83,21 @@ expect(decodedImage.size.height).to.equal(image.size.height); } +- (void)test08ThatEncodeAlphaImageToJPGWithBackgroundColor { + NSString * testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImage" ofType:@"png"]; + UIImage *image = [[UIImage alloc] initWithContentsOfFile:testImagePath]; + UIColor *backgroundColor = [UIColor blackColor]; + NSData *encodedData = [SDImageCodersManager.sharedManager encodedDataWithImage:image format:SDImageFormatJPEG options:@{SDImageCoderEncodeBackgroundColor : backgroundColor}]; + expect(encodedData).notTo.beNil(); + UIImage *decodedImage = [SDImageCodersManager.sharedManager decodedImageWithData:encodedData options:nil]; + expect(decodedImage).notTo.beNil(); + expect(decodedImage.size.width).to.equal(image.size.width); + expect(decodedImage.size.height).to.equal(image.size.height); + // Check background color, should not be white but the black color + UIColor *testColor = [decodedImage sd_colorAtPoint:CGPointMake(1, 1)]; + expect(testColor.sd_hexString).equal(backgroundColor.sd_hexString); +} + - (void)test11ThatAPNGPCoderWorks { NSURL *APNGURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImageAnimated" withExtension:@"apng"]; [self verifyCoder:[SDImageAPNGCoder sharedCoder]