Added `test47DiskCacheExtendedData` test case

This commit is contained in:
DreamPiggy 2019-11-28 20:54:25 +08:00
parent 5f2a9695d8
commit 5c1351a2fd
2 changed files with 28 additions and 2 deletions

View File

@ -491,6 +491,28 @@ static NSString *kTestImageKeyPNG = @"TestImageKey.png";
}
#endif
- (void)test47DiskCacheExtendedData {
XCTestExpectation *expectation = [self expectationWithDescription:@"SDImageCache extended data read/write works"];
UIImage *image = [self testPNGImage];
NSDictionary *extendedObject = @{@"Test" : @"Object"};
image.sd_extendedObject = extendedObject;
[SDImageCache.sharedImageCache removeImageFromMemoryForKey:kTestImageKeyPNG];
[SDImageCache.sharedImageCache removeImageFromDiskForKey:kTestImageKeyPNG];
// Write extended data
[SDImageCache.sharedImageCache storeImage:image forKey:kTestImageKeyPNG completion:^{
NSData *extendedData = [SDImageCache.sharedImageCache.diskCache extendedDataForKey:kTestImageKeyPNG];
expect(extendedData).toNot.beNil();
// Read extended data
UIImage *newImage = [SDImageCache.sharedImageCache imageFromDiskCacheForKey:kTestImageKeyPNG];
id newExtendedObject = newImage.sd_extendedObject;
expect(extendedObject).equal(newExtendedObject);
// Remove extended data
[SDImageCache.sharedImageCache.diskCache setExtendedData:nil forKey:kTestImageKeyPNG];
[expectation fulfill];
}];
[self waitForExpectationsWithCommonTimeout];
}
#pragma mark - SDImageCache & SDImageCachesManager
- (void)test50SDImageCacheQueryOp {
XCTestExpectation *expectation = [self expectationWithDescription:@"SDImageCache query op works"];

View File

@ -87,12 +87,16 @@
NSArray *names = [SDFileAttributeHelper extendedAttributeNamesAtPath:filePath traverseLink:NO error:nil];
expect(names.count).equal(0);
NSString *attr = @"com.com.hackemist.test";
[SDFileAttributeHelper setExtendedAttribute:@"com.com.hackemist.test" value:extendedData atPath:filePath traverseLink:NO overwrite:YES error:nil];
NSString *attr = @"com.hackemist.test";
[SDFileAttributeHelper setExtendedAttribute:attr value:extendedData atPath:filePath traverseLink:NO overwrite:YES error:nil];
BOOL hasAttr =[SDFileAttributeHelper hasExtendedAttribute:attr atPath:filePath traverseLink:NO error:nil];
expect(hasAttr).beTruthy();
names = [SDFileAttributeHelper extendedAttributeNamesAtPath:filePath traverseLink:NO error:nil];
expect(names.count).equal(1);
expect(names.firstObject).equal(attr);
NSData *queriedData = [SDFileAttributeHelper extendedAttribute:attr atPath:filePath traverseLink:NO error:nil];
expect(extendedData).equal(queriedData);