Skip to content

Commit 7cd404c

Browse files
committed
Add test case to ensure that Static WebP does not create CGContext
1 parent 6e88c64 commit 7cd404c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

SDWebImageWebPCoderTests/SDWebImageWebPCoderTests.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
@import XCTest;
1111
#import <SDWebImage/SDWebImage.h>
1212
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>
13+
#import <objc/runtime.h>
1314

1415
const int64_t kAsyncTestTimeout = 5;
1516

@@ -172,6 +173,18 @@ - (void)test33AnimatedImageBlendMethod {
172173
}
173174
}
174175

176+
- (void)test34StaticImageNotCreateCGContext {
177+
NSURL *staticWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImageStatic" withExtension:@"webp"];
178+
NSData *data = [NSData dataWithContentsOfURL:staticWebPURL];
179+
SDImageWebPCoder *coder = [[SDImageWebPCoder alloc] initWithAnimatedImageData:data options:nil];
180+
XCTAssertTrue(coder.animatedImageFrameCount == 1);
181+
UIImage *image = [coder animatedImageFrameAtIndex:0];
182+
XCTAssertNotNil(image);
183+
Ivar ivar = class_getInstanceVariable(coder.class, "_canvas");
184+
CGContextRef canvas = ((CGContextRef (*)(id, Ivar))object_getIvar)(coder, ivar);
185+
XCTAssert(canvas == NULL);
186+
}
187+
175188
@end
176189

177190
@implementation SDWebImageWebPCoderTests (Helpers)

0 commit comments

Comments
 (0)