You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2014/10/01 01:59:26 UTC

git commit: Added failing iPhone 6/6 Plus tests.

Repository: cordova-plugin-splashscreen
Updated Branches:
  refs/heads/master 95f407ea0 -> 0ffe1c2d4


Added failing iPhone 6/6 Plus tests.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/commit/0ffe1c2d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/tree/0ffe1c2d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/diff/0ffe1c2d

Branch: refs/heads/master
Commit: 0ffe1c2d461ea60fd9535553e07a9f65167569c5
Parents: 95f407e
Author: Shazron Abdullah <sh...@apache.org>
Authored: Tue Sep 30 16:59:47 2014 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Tue Sep 30 16:59:47 2014 -0700

----------------------------------------------------------------------
 src/ios/CDVSplashScreen.h                       | 10 +++++
 src/ios/CDVSplashScreen.m                       | 29 +++++++++++--
 .../CDVSplashScreenLibTests/ImageNameTest.m     | 45 +++++++++++++++++---
 .../project.pbxproj                             |  6 +--
 4 files changed, 76 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/blob/0ffe1c2d/src/ios/CDVSplashScreen.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVSplashScreen.h b/src/ios/CDVSplashScreen.h
index 932ad06..0d6ae39 100644
--- a/src/ios/CDVSplashScreen.h
+++ b/src/ios/CDVSplashScreen.h
@@ -20,6 +20,16 @@
 #import <Foundation/Foundation.h>
 #import <Cordova/CDVPlugin.h>
 
+typedef struct {
+    BOOL iPhone;
+    BOOL iPad;
+    BOOL iPhone5;
+    BOOL iPhone6;
+    BOOL iPhone6Plus;
+    BOOL retina;
+    
+} CDV_iOSDevice;
+
 @interface CDVSplashScreen : CDVPlugin {
     UIActivityIndicatorView* _activityView;
     UIImageView* _imageView;

http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/blob/0ffe1c2d/src/ios/CDVSplashScreen.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVSplashScreen.m b/src/ios/CDVSplashScreen.m
index 53e3688..0846c55 100644
--- a/src/ios/CDVSplashScreen.m
+++ b/src/ios/CDVSplashScreen.m
@@ -23,6 +23,7 @@
 
 #define kSplashScreenDurationDefault 0.25f
 
+
 @implementation CDVSplashScreen
 
 - (void)pluginInitialize
@@ -117,7 +118,27 @@
     [self.viewController.view removeObserver:self forKeyPath:@"bounds"];
 }
 
-- (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(id<CDVScreenOrientationDelegate>)orientationDelegate isIPad:(BOOL)isIPad isIPhone5:(BOOL)isIPhone5
+- (CDV_iOSDevice) getCurrentDevice
+{
+    CDV_iOSDevice device;
+    
+    UIScreen* mainScreen = [UIScreen mainScreen];
+    CGFloat mainScreenHeight = mainScreen.bounds.size.height;
+    
+    device.iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
+    device.iPhone = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone);
+    device.retina = ([mainScreen scale] == 2.0);
+    device.iPhone5 = (device.iPhone && mainScreenHeight == 568.0);
+    // note these below is not a true device detect, for example if you are on an
+    // iPhone 6/6+ but the app is scaled it will prob set iPhone5 as true, but
+    // this is appropriate for detecting the runtime screen environment
+    device.iPhone6 = (device.iPhone && mainScreenHeight == 667.0);
+    device.iPhone6Plus = (device.iPhone && mainScreenHeight == 736.0);
+    
+    return device;
+}
+
+- (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(id<CDVScreenOrientationDelegate>)orientationDelegate device:(CDV_iOSDevice)device
 {
     // Use UILaunchImageFile if specified in plist.  Otherwise, use Default.
     NSString* imageName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchImageFile"];
@@ -135,9 +156,9 @@
         imageName = @"Default";
     }
     
-    if (isIPhone5) {
+    if (device.iPhone5) {
         imageName = [imageName stringByAppendingString:@"-568h"];
-    } else if (isIPad) {
+    } else if (device.iPad) {
         if (isOrientationLocked) {
             imageName = [imageName stringByAppendingString:(supportsLandscape ? @"-Landscape" : @"-Portrait")];
         } else {
@@ -162,7 +183,7 @@
 // Sets the view's frame and image.
 - (void)updateImage
 {
-    NSString* imageName = [self getImageName:self.viewController.interfaceOrientation delegate:(id<CDVScreenOrientationDelegate>)self.viewController isIPad:CDV_IsIPad() isIPhone5:CDV_IsIPhone5()];
+    NSString* imageName = [self getImageName:self.viewController.interfaceOrientation delegate:(id<CDVScreenOrientationDelegate>)self.viewController device:[self getCurrentDevice]];
 
     if (![imageName isEqualToString:_curImageName]) {
         UIImage* img = [UIImage imageNamed:imageName];

http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/blob/0ffe1c2d/tests/ios/CDVSplashScreenTest/CDVSplashScreenLibTests/ImageNameTest.m
----------------------------------------------------------------------
diff --git a/tests/ios/CDVSplashScreenTest/CDVSplashScreenLibTests/ImageNameTest.m b/tests/ios/CDVSplashScreenTest/CDVSplashScreenLibTests/ImageNameTest.m
index 7bb9e96..e9fb642 100644
--- a/tests/ios/CDVSplashScreenTest/CDVSplashScreenLibTests/ImageNameTest.m
+++ b/tests/ios/CDVSplashScreenTest/CDVSplashScreenLibTests/ImageNameTest.m
@@ -23,6 +23,8 @@
 #import "CDVSplashScreen.h"
 #import "ImageNameTestDelegates.h"
 
+const CDV_iOSDevice CDV_iOSDeviceZero = { 0, 0, 0, 0, 0, 0 };
+
 @interface ImageNameTest : XCTestCase
 
 @property (nonatomic, strong) CDVSplashScreen* plugin;
@@ -32,7 +34,7 @@
 @interface CDVSplashScreen ()
 
 // expose private interface
-- (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(id<CDVScreenOrientationDelegate>)orientationDelegate isIPad:(BOOL)isIPad isIPhone5:(BOOL)isIPhone5;
+- (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(id<CDVScreenOrientationDelegate>)orientationDelegate device:(CDV_iOSDevice)device;
 
 @end
 
@@ -53,35 +55,64 @@
 - (void) portraitHelper:(UIInterfaceOrientation)initialOrientation delegate:(id<CDVScreenOrientationDelegate>)delegate
 {
     NSString* name = nil;
+    CDV_iOSDevice device;
     
     // Portrait, non-iPad, non-iPhone5
-    name = [self.plugin getImageName:initialOrientation delegate:delegate isIPad:NO isIPhone5:NO];
+    device = CDV_iOSDeviceZero; device.iPad = NO; device.iPhone5 = NO;
+    name = [self.plugin getImageName:initialOrientation delegate:delegate device:device];
     XCTAssertTrue([@"Default" isEqualToString:name], @"Portrait - 3.5\" iPhone failed (%@)", name);
     
     // Portrait, iPad, non-iPhone5
-    name = [self.plugin getImageName:initialOrientation delegate:delegate isIPad:YES isIPhone5:NO];
+    device = CDV_iOSDeviceZero; device.iPad = YES; device.iPhone5 = NO;
+    name = [self.plugin getImageName:initialOrientation delegate:delegate device:device];
     XCTAssertTrue([@"Default-Portrait" isEqualToString:name], @"Portrait - iPad failed (%@)", name);
     
     // Portrait, non-iPad, iPhone5
-    name = [self.plugin getImageName:initialOrientation delegate:delegate isIPad:NO isIPhone5:YES];
+    device = CDV_iOSDeviceZero; device.iPad = NO; device.iPhone5 = YES;
+    name = [self.plugin getImageName:initialOrientation delegate:delegate device:device];
     XCTAssertTrue([@"Default-568h" isEqualToString:name], @"Portrait - iPhone 5 failed (%@)", name);
+
+    // Portrait, non-iPad, iPhone6
+    device = CDV_iOSDeviceZero; device.iPad = NO; device.iPhone6 = YES;
+    name = [self.plugin getImageName:initialOrientation delegate:delegate device:device];
+    XCTAssertTrue([@"Default-667h" isEqualToString:name], @"Portrait - iPhone 6 failed (%@)", name);
+
+    // Portrait, non-iPad, iPhone6Plus
+    device = CDV_iOSDeviceZero; device.iPad = NO; device.iPhone6Plus = YES;
+    name = [self.plugin getImageName:initialOrientation delegate:delegate device:device];
+    XCTAssertTrue([@"Default-736h" isEqualToString:name], @"Portrait - iPhone 6Plus failed (%@)", name);
 }
 
 - (void) landscapeHelper:(UIInterfaceOrientation)initialOrientation delegate:(id<CDVScreenOrientationDelegate>)delegate
 {
     NSString* name = nil;
+    CDV_iOSDevice device;
     
     // Landscape, non-iPad, non-iPhone5 (does NOT support landscape)
-    name = [self.plugin getImageName:initialOrientation delegate:delegate isIPad:NO isIPhone5:NO];
+    device = CDV_iOSDeviceZero; device.iPad = NO; device.iPhone5 = NO;
+    name = [self.plugin getImageName:initialOrientation delegate:delegate device:device];
     XCTAssertTrue([@"Default" isEqualToString:name], @"Landscape - 3.5\" iPhone failed (%@)", name );
     
     // Landscape, iPad, non-iPhone5 (supports landscape)
-    name = [self.plugin getImageName:initialOrientation delegate:delegate isIPad:YES isIPhone5:NO];
+    device = CDV_iOSDeviceZero; device.iPad = YES; device.iPhone5 = NO;
+    name = [self.plugin getImageName:initialOrientation delegate:delegate device:device];
     XCTAssertTrue([@"Default-Landscape" isEqualToString:name], @"Landscape - iPad failed (%@)", name);
     
     // Landscape, non-iPad, iPhone5 (does NOT support landscape)
-    name = [self.plugin getImageName:initialOrientation delegate:delegate isIPad:NO isIPhone5:YES];
+    device = CDV_iOSDeviceZero; device.iPad = NO; device.iPhone5 = YES;
+    name = [self.plugin getImageName:initialOrientation delegate:delegate device:device];
     XCTAssertTrue([@"Default-568h" isEqualToString:name], @"Landscape - iPhone5 failed (%@)", name);
+
+    // Landscape, non-iPad, iPhone6 (does NOT support landscape)
+    device = CDV_iOSDeviceZero; device.iPad = NO; device.iPhone6 = YES;
+    name = [self.plugin getImageName:initialOrientation delegate:delegate device:device];
+    XCTAssertTrue([@"Default-667h" isEqualToString:name], @"Landscape - iPhone6 failed (%@)", name);
+
+    // Landscape, non-iPad, iPhone6Plus (does support landscape)
+    device = CDV_iOSDeviceZero; device.iPad = NO; device.iPhone6Plus = YES;
+    name = [self.plugin getImageName:initialOrientation delegate:delegate device:device];
+    XCTAssertTrue([@"Default-Landscape-736h" isEqualToString:name], @"Landscape - iPhone6Plus failed (%@)", name);
+
 }
 
 - (void)testPortraitOnly {

http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/blob/0ffe1c2d/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/project.pbxproj b/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/project.pbxproj
index 080e69a..ce820d8 100644
--- a/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/project.pbxproj
+++ b/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/project.pbxproj
@@ -57,8 +57,8 @@
 		7E9F519519DA102000DA31AC /* libCDVSplashScreenLib.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libCDVSplashScreenLib.a; sourceTree = BUILT_PRODUCTS_DIR; };
 		7E9F519F19DA102000DA31AC /* CDVSplashScreenLibTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CDVSplashScreenLibTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
 		7E9F51A219DA102000DA31AC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
-		7E9F51A919DA10AE00DA31AC /* CDVSplashScreen.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVSplashScreen.m; path = ../../../../src/ios/CDVSplashScreen.m; sourceTree = "<group>"; };
-		7E9F51AA19DA10AE00DA31AC /* CDVSplashScreen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVSplashScreen.h; path = ../../../../src/ios/CDVSplashScreen.h; sourceTree = "<group>"; };
+		7E9F51A919DA10AE00DA31AC /* CDVSplashScreen.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVSplashScreen.m; path = ../../../src/ios/CDVSplashScreen.m; sourceTree = SOURCE_ROOT; };
+		7E9F51AA19DA10AE00DA31AC /* CDVSplashScreen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVSplashScreen.h; path = ../../../src/ios/CDVSplashScreen.h; sourceTree = SOURCE_ROOT; };
 		7E9F51B019DA114400DA31AC /* ImageNameTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageNameTest.m; sourceTree = "<group>"; };
 		7E9F51B219DA116500DA31AC /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.0.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; };
 		7E9F51B419DA127E00DA31AC /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.0.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; };
@@ -124,7 +124,7 @@
 				7E9F51AA19DA10AE00DA31AC /* CDVSplashScreen.h */,
 			);
 			path = CDVSplashScreenLib;
-			sourceTree = "<group>";
+			sourceTree = SOURCE_ROOT;
 		};
 		7E9F51A019DA102000DA31AC /* CDVSplashScreenLibTests */ = {
 			isa = PBXGroup;