Permalink
Browse files

Merge pull request #103 from ImmobilienScout24/retina-image-tests

Support for retina view tests
  • Loading branch information...
2 parents 8ed3a76 + 427da1b commit ca5a8ece57395f3fde8e42077e9ec36509994d9b @johnboiles johnboiles committed Oct 25, 2012
Showing with 20 additions and 3 deletions.
  1. +20 −3 Classes/GHViewTestCase.m
@@ -85,11 +85,13 @@ + (UIImage *)readSavedTestImageWithFilename:(NSString *)filename {
NSString *filePath = [self approvedTestImagePathForFilename:filename];
GHUDebug(@"Trying to load image at path %@", filePath);
// First look in the documents directory for the image
- UIImage *image = [UIImage imageWithContentsOfFile:filePath];
+ UIImage *image = [GHViewTestCase _imageFromFilePath:filePath];
// Otherwise look in the app bundle
if (image) GHUDebug(@"Found image in documents directory");
if (!image) {
- image = [UIImage imageNamed:filename];
+ NSString* extension = [filename pathExtension];
+ filePath = [[NSBundle mainBundle] pathForResource:[filename stringByDeletingPathExtension] ofType:extension];
+ image = [GHViewTestCase _imageFromFilePath:filePath];
if (image) GHUDebug(@"Found image in app bundle");
}
return image;
@@ -115,7 +117,7 @@ + (void)clearTestImages {
+ (UIImage *)imageWithView:(UIView *)view {
[view setNeedsDisplay];
- UIGraphicsBeginImageContext(view.frame.size);
+ UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, [[UIScreen mainScreen] scale]);
CALayer *layer = view.layer;
CGContextRef context = UIGraphicsGetCurrentContext();
[layer renderInContext:context];
@@ -223,6 +225,21 @@ - (void)_setUp {
imageVerifyCount_ = 0;
}
++ (UIImage *)_imageFromFilePath:(NSString *)filePath {
+ UIImage *image;
+
+ NSData *imageData = [NSData dataWithContentsOfFile:filePath];
+ CGFloat scale = [UIScreen mainScreen].scale;
+ if ([UIImage respondsToSelector:@selector(imageWithData:scale:)]) {
+ image = [UIImage imageWithData:imageData scale:scale];
+ }
+ else {
+ UIImage *imageWithoutScale = [UIImage imageWithData:imageData];
+ image = [UIImage imageWithCGImage:imageWithoutScale.CGImage scale:scale orientation:UIImageOrientationUp];
+ }
+ return image;
+}
+
#pragma mark Public
- (CGSize)sizeForView:(UIView *)view {

0 comments on commit ca5a8ec

Please sign in to comment.