From 7cd404cccc859740e2ed9502da9672ce9525c60d Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Tue, 7 Jan 2020 15:21:47 +0800 Subject: [PATCH] Add test case to ensure that Static WebP does not create CGContext --- SDWebImageWebPCoderTests/SDWebImageWebPCoderTests.m | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/SDWebImageWebPCoderTests/SDWebImageWebPCoderTests.m b/SDWebImageWebPCoderTests/SDWebImageWebPCoderTests.m index f895071..d046396 100644 --- a/SDWebImageWebPCoderTests/SDWebImageWebPCoderTests.m +++ b/SDWebImageWebPCoderTests/SDWebImageWebPCoderTests.m @@ -10,6 +10,7 @@ @import XCTest; #import #import +#import const int64_t kAsyncTestTimeout = 5; @@ -172,6 +173,18 @@ const int64_t kAsyncTestTimeout = 5; } } +- (void)test34StaticImageNotCreateCGContext { + NSURL *staticWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImageStatic" withExtension:@"webp"]; + NSData *data = [NSData dataWithContentsOfURL:staticWebPURL]; + SDImageWebPCoder *coder = [[SDImageWebPCoder alloc] initWithAnimatedImageData:data options:nil]; + XCTAssertTrue(coder.animatedImageFrameCount == 1); + UIImage *image = [coder animatedImageFrameAtIndex:0]; + XCTAssertNotNil(image); + Ivar ivar = class_getInstanceVariable(coder.class, "_canvas"); + CGContextRef canvas = ((CGContextRef (*)(id, Ivar))object_getIvar)(coder, ivar); + XCTAssert(canvas == NULL); +} + @end @implementation SDWebImageWebPCoderTests (Helpers)