This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
362 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#import <XCTest/XCTest.h> | ||
#import "FTAssetRenderer.h" | ||
|
||
@interface FTAssetRendererTests : XCTestCase | ||
|
||
@property (nonatomic) FTAssetRenderer *renderer; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#import "FTAssetRendererTests.h" | ||
|
||
@implementation FTAssetRendererTests | ||
|
||
- (void)setUp | ||
{ | ||
[super setUp]; | ||
[[NSFileManager defaultManager] createDirectoryAtPath:[FTAssetRenderer cacheDirectory] | ||
withIntermediateDirectories:YES | ||
attributes:nil | ||
error:NULL]; | ||
self.renderer = [[FTAssetRenderer alloc] initWithURL:nil]; | ||
} | ||
|
||
- (void)tearDown | ||
{ | ||
[super tearDown]; | ||
self.renderer = nil; | ||
[[NSFileManager defaultManager] removeItemAtPath:[FTAssetRenderer cacheDirectory] | ||
error:NULL]; | ||
} | ||
|
||
#pragma mark - caching | ||
|
||
- (void)testCachesInSpecificCacheDirectory | ||
{ | ||
NSString *expected = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0]; | ||
expected = [expected stringByAppendingPathComponent:@"__FTAssetRenderer_Cache__"]; | ||
XCTAssertEqualObjects(expected, [FTAssetRenderer cacheDirectory]); | ||
} | ||
|
||
- (void)testChangesCachePathBasedOnIdentifier | ||
{ | ||
NSString *path = [self.renderer cachePathWithIdentifier:@"normal"]; | ||
XCTAssertEqualObjects(path, [self.renderer cachePathWithIdentifier:@"normal"]); | ||
|
||
NSString *newPath = [self.renderer cachePathWithIdentifier:@"highlighted"]; | ||
XCTAssertFalse([path isEqualToString:newPath]); | ||
XCTAssertEqualObjects(newPath, [self.renderer cachePathWithIdentifier:@"highlighted"]); | ||
} | ||
|
||
//- (void)testRaisesWhenUsedAsMaskAndCachingWithoutCacheIdentifier | ||
//{ | ||
//self.renderer.targetColor = [UIColor redColor]; | ||
|
||
//self.renderer.cache = NO; | ||
//STAssertNoThrow([self.renderer imageWithCacheIdentifier:nil], nil); | ||
|
||
//self.renderer.cache = YES; | ||
//STAssertThrowsSpecificNamed([self.renderer imageWithCacheIdentifier:nil], NSException, @"FTAssetRendererError", nil); | ||
//} | ||
|
||
@end |
4 changes: 2 additions & 2 deletions
4
Tests/FTImageAssetRendererTests.h → ...RendererTests/FTImageAssetRendererTests.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#import "FTImageAssetRendererTests.h" | ||
|
||
@implementation FTImageAssetRendererTests | ||
|
||
- (void)setUp | ||
{ | ||
[super setUp]; | ||
[[NSFileManager defaultManager] createDirectoryAtPath:[FTAssetRenderer cacheDirectory] | ||
withIntermediateDirectories:YES | ||
attributes:nil | ||
error:NULL]; | ||
self.renderer = [FTAssetRenderer rendererForImageNamed:@"restaurant-icon-mask" withExtension:@"png"]; | ||
self.renderer.targetColor = [UIColor redColor]; | ||
} | ||
|
||
- (void)tearDown | ||
{ | ||
[super tearDown]; | ||
self.renderer = nil; | ||
[[NSFileManager defaultManager] removeItemAtPath:[FTAssetRenderer cacheDirectory] | ||
error:NULL]; | ||
} | ||
|
||
- (void)testConvenienceMethodLoadsImageAppropriateForScreenScale | ||
{ | ||
NSString *filename = [[self.renderer.URL lastPathComponent] stringByDeletingPathExtension]; | ||
int scale = (int)[[UIScreen mainScreen] scale]; | ||
if (scale > 1) { | ||
XCTAssertTrue([filename hasSuffix:@"@2x"]); | ||
} else { | ||
XCTAssertFalse([filename hasSuffix:@"@2x"]); | ||
} | ||
} | ||
|
||
- (void)testReturnsImageOfExpectedSizeAndScale | ||
{ | ||
UIImage *result = [self.renderer imageWithCacheIdentifier:@"test"]; | ||
XCTAssertTrue(CGSizeEqualToSize(self.renderer.sourceImage.size, result.size)); | ||
} | ||
|
||
- (void)testCreatesExpectedSizeImageAtCachePath | ||
{ | ||
NSString *path = [self.renderer cachePathWithIdentifier:@"test"]; | ||
[self.renderer imageWithCacheIdentifier:@"test"]; | ||
sleep(1.5); // lame, should check if file exists with timeout | ||
UIImage *result = [UIImage imageWithContentsOfFile:path]; | ||
CGFloat scale = [[UIScreen mainScreen] scale]; | ||
CGSize sourceSize = self.renderer.sourceImage.size; | ||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(sourceSize.width * scale, sourceSize.height * scale), result.size)); | ||
} | ||
|
||
@end |
4 changes: 2 additions & 2 deletions
4
Tests/FTPDFAssetRendererTests.h → ...etRendererTests/FTPDFAssetRendererTests.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#import "FTPDFAssetRendererTests.h" | ||
|
||
// TODO | ||
// * add portrait and landscape fixtures | ||
|
||
@implementation FTPDFAssetRendererTests | ||
|
||
- (void)setUp | ||
{ | ||
[super setUp]; | ||
[[NSFileManager defaultManager] createDirectoryAtPath:[FTAssetRenderer cacheDirectory] | ||
withIntermediateDirectories:YES | ||
attributes:nil | ||
error:NULL]; | ||
self.renderer = [FTAssetRenderer rendererForPDFNamed:@"restaurant-icon-mask"]; | ||
} | ||
|
||
- (void)tearDown | ||
{ | ||
[super tearDown]; | ||
self.renderer = nil; | ||
[[NSFileManager defaultManager] removeItemAtPath:[FTAssetRenderer cacheDirectory] | ||
error:NULL]; | ||
} | ||
|
||
#pragma - mark sizing | ||
|
||
- (void)testByDefaultUsesMediaBoxSizeAsTarget | ||
{ | ||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(88, 88), self.renderer.targetSize)); | ||
} | ||
|
||
- (void)testFitsPDFWithinGivenSizeFillingShortestEdge | ||
{ | ||
[self.renderer fitSize:CGSizeMake(100, 200)]; | ||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 100), self.renderer.targetSize)); | ||
[self.renderer fitSize:CGSizeMake(300, 200)]; | ||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(200, 200), self.renderer.targetSize)); | ||
} | ||
|
||
- (void)testFitsPDFWithinGivenTargetWidth | ||
{ | ||
[self.renderer fitWidth:100]; | ||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 100), self.renderer.targetSize)); | ||
} | ||
|
||
- (void)testFitsPDFWithinGivenTargetHeight | ||
{ | ||
[self.renderer fitHeight:100]; | ||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 100), self.renderer.targetSize)); | ||
} | ||
|
||
#pragma mark - caching | ||
|
||
- (void)testChangesCachePathBasedOnTargetSize | ||
{ | ||
NSString *path = [self.renderer cachePathWithIdentifier:nil]; | ||
XCTAssertEqualObjects(path, [self.renderer cachePathWithIdentifier:nil]); | ||
|
||
self.renderer.targetSize = CGSizeMake(123, 456); | ||
NSString *newPath = [self.renderer cachePathWithIdentifier:nil]; | ||
XCTAssertFalse([path isEqualToString:newPath]); | ||
XCTAssertEqualObjects(newPath, [self.renderer cachePathWithIdentifier:nil]); | ||
} | ||
|
||
- (void)testChangesCachePathBasedOnSourcePageIndex | ||
{ | ||
NSString *path = [self.renderer cachePathWithIdentifier:nil]; | ||
XCTAssertEqualObjects(path, [self.renderer cachePathWithIdentifier:nil]); | ||
|
||
self.renderer.sourcePageIndex = 2; | ||
NSString *newPath = [self.renderer cachePathWithIdentifier:nil]; | ||
XCTAssertFalse([path isEqualToString:newPath]); | ||
XCTAssertEqualObjects(newPath, [self.renderer cachePathWithIdentifier:nil]); | ||
} | ||
|
||
- (void)testRaisesWhenUsedAsMaskAndCachingWithoutCacheIdentifier | ||
{ | ||
self.renderer.targetColor = [UIColor redColor]; | ||
|
||
self.renderer.cache = NO; | ||
XCTAssertNoThrow([self.renderer imageWithCacheIdentifier:nil]); | ||
|
||
self.renderer.cache = YES; | ||
XCTAssertThrowsSpecificNamed([self.renderer imageWithCacheIdentifier:nil], NSException, @"FTAssetRendererError"); | ||
} | ||
|
||
#pragma mark - drawing | ||
|
||
- (void)testReturnsImageOfExpectedSizeAndScale | ||
{ | ||
self.renderer.targetSize = CGSizeMake(100, 50); | ||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 50), [self.renderer image].size)); | ||
} | ||
|
||
- (void)testCreatesExpectedSizeImageAtCachePath | ||
{ | ||
self.renderer.targetSize = CGSizeMake(100, 50); | ||
NSString *path = [self.renderer cachePathWithIdentifier:nil]; | ||
[self.renderer image]; | ||
sleep(1.5); // lame, should check if file exists with timeout | ||
UIImage *image = [UIImage imageWithContentsOfFile:path]; | ||
CGFloat scale = [[UIScreen mainScreen] scale]; | ||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100 * scale, 50 * scale), image.size)); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.