Add test case to ensure that Static WebP does not create CGContext

This commit is contained in:
DreamPiggy 2020-01-07 15:21:47 +08:00
parent 6e88c64f4f
commit 7cd404cccc
1 changed files with 13 additions and 0 deletions

View File

@ -10,6 +10,7 @@
@import XCTest;
#import <SDWebImage/SDWebImage.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>
#import <objc/runtime.h>
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)