From 4682341c3c590eeab0f4645447c86cb9750b9f9a Mon Sep 17 00:00:00 2001 From: Jeff Kelley Date: Fri, 16 Nov 2018 14:22:33 -0500 Subject: [PATCH] Backport tests to iOS 8.0. --- .../IRLSizeExample.xcodeproj/project.pbxproj | 2 - IRLSize.podspec | 2 +- IRLSizeTests/IRLMeasurementBeWithinMatcher.h | 5 +- IRLSizeTests/IRLMeasurementBeWithinMatcher.m | 21 +- IRLSizeTests/IRLSizeTests.m | 229 +++++++++++++----- 5 files changed, 180 insertions(+), 79 deletions(-) diff --git a/Example/IRLSizeExample.xcodeproj/project.pbxproj b/Example/IRLSizeExample.xcodeproj/project.pbxproj index 39fa41c..6bcc323 100644 --- a/Example/IRLSizeExample.xcodeproj/project.pbxproj +++ b/Example/IRLSizeExample.xcodeproj/project.pbxproj @@ -866,7 +866,6 @@ "$(inherited)", ); INFOPLIST_FILE = "../IRLSizeTests/IRLSizeTests-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; PRODUCT_BUNDLE_IDENTIFIER = "com.detroitlabs.demo.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = xctest; @@ -883,7 +882,6 @@ "$(DEVELOPER_FRAMEWORKS_DIR)", ); INFOPLIST_FILE = "../IRLSizeTests/IRLSizeTests-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; PRODUCT_BUNDLE_IDENTIFIER = "com.detroitlabs.demo.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = xctest; diff --git a/IRLSize.podspec b/IRLSize.podspec index 3c2a0d5..fedc8cd 100644 --- a/IRLSize.podspec +++ b/IRLSize.podspec @@ -31,7 +31,7 @@ Pod::Spec.new do |s| s.dependency 'SDVersion', '~> 4.3.0' s.test_spec 'IRLSizeTests' do |ts| - ts.platform = :ios, '10.0' + ts.platform = :ios, '8.0' ts.source_files = 'IRLSizeTests/*.{h,m}' ts.dependency 'Kiwi' ts.requires_app_host = true diff --git a/IRLSizeTests/IRLMeasurementBeWithinMatcher.h b/IRLSizeTests/IRLMeasurementBeWithinMatcher.h index 445b440..629eb6a 100644 --- a/IRLSizeTests/IRLMeasurementBeWithinMatcher.h +++ b/IRLSizeTests/IRLMeasurementBeWithinMatcher.h @@ -6,14 +6,15 @@ // Copyright © 2018 Detroit Labs. All rights reserved. // +#import #import NS_ASSUME_NONNULL_BEGIN @interface IRLMeasurementBeWithinMatcher : KWMatcher -- (void)beWithin:(double)aDistance ofMeasurement:(NSMeasurement *)aValue; -- (void)equalMeasurement:(NSMeasurement *)aValue withDelta:(double)aDelta; +- (void)beWithin:(double)aDistance ofMeasurement:(NSMeasurement *)aValue IRL_IOS_AVAILABLE(10.0); +- (void)equalMeasurement:(NSMeasurement *)aValue withDelta:(double)aDelta IRL_IOS_AVAILABLE(10.0); @end diff --git a/IRLSizeTests/IRLMeasurementBeWithinMatcher.m b/IRLSizeTests/IRLMeasurementBeWithinMatcher.m index bdc965c..c81c562 100644 --- a/IRLSizeTests/IRLMeasurementBeWithinMatcher.m +++ b/IRLSizeTests/IRLMeasurementBeWithinMatcher.m @@ -14,6 +14,7 @@ #import "NSMeasurement+Equality.h" +IRL_IOS_AVAILABLE(10.0) @interface IRLMeasurementBeWithinMatcher() @property (nonatomic, readwrite) double distance; @@ -37,13 +38,19 @@ + (NSArray *)matcherStrings - (BOOL)evaluate { - NSMeasurement *subject = self.subject; - - NSAssert([subject isKindOfClass:[NSMeasurement class]], - @"This matcher can only be used on NSMeasurement instances."); - - return [subject irl_isEqualToMeasurement:self.otherValue - withDelta:self.distance]; + if (@available(iOS 10.0, *)) { + NSMeasurement *subject = self.subject; + + NSAssert([subject isKindOfClass:[NSMeasurement class]], + @"This matcher can only be used on NSMeasurement instances."); + + return [subject irl_isEqualToMeasurement:self.otherValue + withDelta:self.distance]; + } + else { + NSAssert(false, @"This matcher requires iOS 10 or later."); + return false; + } } #pragma mark - Getting Failure Messages diff --git a/IRLSizeTests/IRLSizeTests.m b/IRLSizeTests/IRLSizeTests.m index 24189b5..c434fc9 100644 --- a/IRLSizeTests/IRLSizeTests.m +++ b/IRLSizeTests/IRLSizeTests.m @@ -27,9 +27,11 @@ it(@"should report the correct height", ^{ \ NSLog(@"Expecting device " #modelEnum " height to equal %f", \ k##sizeEnumPrefix##ScreenHeight); \ - [[UIDevice.currentDevice.irl_physicalScreenHeight should] \ - beWithin:0.01 \ - ofMeasurement:IRL_MM(k##sizeEnumPrefix##ScreenHeight)]; \ + if (@available(iOS 10.0, *)) { \ + [[UIDevice.currentDevice.irl_physicalScreenHeight should] \ + beWithin:0.01 \ + ofMeasurement:IRL_MM(k##sizeEnumPrefix##ScreenHeight)]; \ + } \ [[theValue(UIDevice.currentDevice.irl_rawPhysicalScreenHeight) should] \ beWithin:theValue(0.1) \ of:theValue(k##sizeEnumPrefix##ScreenHeight)]; \ @@ -37,9 +39,11 @@ it(@"should report the correct width", ^{ \ NSLog(@"Expecting device " #modelEnum " width to equal %f", \ k##sizeEnumPrefix##ScreenWidth); \ - [[UIDevice.currentDevice.irl_physicalScreenWidth should] \ - beWithin:0.01 \ - ofMeasurement:IRL_MM(k##sizeEnumPrefix##ScreenWidth)]; \ + if (@available(iOS 10.0, *)) { \ + [[UIDevice.currentDevice.irl_physicalScreenWidth should] \ + beWithin:0.01 \ + ofMeasurement:IRL_MM(k##sizeEnumPrefix##ScreenWidth)]; \ + } \ [[theValue(UIDevice.currentDevice.irl_rawPhysicalScreenWidth) should] \ beWithin:theValue(0.1) \ of:theValue(k##sizeEnumPrefix##ScreenWidth)]; \ @@ -98,12 +102,20 @@ it(@"should estimate the size of a " #size " Inch " #deviceType, ^{ \ NSLog(@"Expecting screen size " #width "⨉" #height " and scale " \ #deviceScale " to equal " #size " inches"); \ - [[UIDevice.currentDevice.irl_physicalScreenHeight should] \ - beWithin:0.01 \ - ofMeasurement:IRL_MM(k##deviceType##size##InchScreenHeight)]; \ - [[UIDevice.currentDevice.irl_physicalScreenWidth should] \ - beWithin:0.01 \ - ofMeasurement:IRL_MM(k##deviceType##size##InchScreenWidth)]; \ + if (@available(iOS 10.0, *)) { \ + [[UIDevice.currentDevice.irl_physicalScreenHeight should] \ + beWithin:0.01 \ + ofMeasurement:IRL_MM(k##deviceType##size##InchScreenHeight)]; \ + [[UIDevice.currentDevice.irl_physicalScreenWidth should] \ + beWithin:0.01 \ + ofMeasurement:IRL_MM(k##deviceType##size##InchScreenWidth)]; \ + } \ + [[theValue(UIDevice.currentDevice.irl_rawPhysicalScreenHeight) should] \ + beWithin:theValue(0.1) \ + of:theValue(k##deviceType##size##InchScreenHeight)]; \ + [[theValue(UIDevice.currentDevice.irl_rawPhysicalScreenWidth) should] \ + beWithin:theValue(0.1) \ + of:theValue(k##deviceType##size##InchScreenWidth)]; \ }); \ }); @@ -238,24 +250,42 @@ it(@"should report the correct size", ^{ - NSMeasurement *expectedSize = - [[NSMeasurement alloc] initWithDoubleValue:0.01654589372 - unit:[NSUnitLength meters]]; - - [[view.irl_physicalWidth should] beWithin:0.01 - ofMeasurement:expectedSize]; - - [[view.irl_physicalHeight should] beWithin:0.01 - ofMeasurement:expectedSize]; + if (@available(iOS 10.0, *)) { + NSMeasurement *expectedSize = IRL_MM(15.5997001499); + + [[view.irl_physicalWidth should] beWithin:0.01 + ofMeasurement:expectedSize]; + + [[view.irl_physicalHeight should] beWithin:0.01 + ofMeasurement:expectedSize]; + } + [[theValue(view.irl_rawPhysicalWidth) should] + beWithin:theValue(0.01) + of:theValue(15.5997001499)]; + + [[theValue(view.irl_rawPhysicalHeight) should] + beWithin:theValue(0.01) + of:theValue(15.5997001499)]; }); it(@"should return the correct transform to resize the view", ^{ - CGAffineTransform transform = - [view irl_transformForPhysicalWidth: - [[NSMeasurement alloc] initWithDoubleValue:0.01 - unit:[NSUnitLength meters]]]; + if (@available(iOS 10.0, *)) { + CGAffineTransform transform = + [view irl_transformForPhysicalWidth:IRL_MM(10)]; + + CGAffineTransform expectedTransform = + CGAffineTransformMakeScale(0.641025602, 0.641025602); + + [[theValue(transform.a) should] equal:expectedTransform.a + withDelta:0.001]; + + [[theValue(transform.d) should] equal:expectedTransform.d + withDelta:0.001]; + } + + CGAffineTransform transform = [view irl_transformForRawPhysicalWidth:10]; CGAffineTransform expectedTransform = CGAffineTransformMakeScale(0.641025602, 0.641025602); @@ -265,7 +295,6 @@ [[theValue(transform.d) should] equal:expectedTransform.d withDelta:0.001]; - }); }); @@ -274,24 +303,43 @@ it(@"should report the correct size", ^{ - NSMeasurement *expectedSize = - [[NSMeasurement alloc] initWithDoubleValue:0.01654589372 - unit:[NSUnitLength meters]]; + if (@available(iOS 10.0, *)) { + NSMeasurement *expectedSize = IRL_MM(15.5997001499); + + [[view.irl_physicalWidth should] beWithin:0.01 + ofMeasurement:expectedSize]; + + [[view.irl_physicalHeight should] beWithin:0.01 + ofMeasurement:expectedSize]; + } - [[view.irl_physicalWidth should] beWithin:0.01 - ofMeasurement:expectedSize]; + [[theValue(view.irl_rawPhysicalWidth) should] + beWithin:theValue(0.01) + of:theValue(15.5997001499)]; - [[view.irl_physicalHeight should] beWithin:0.01 - ofMeasurement:expectedSize]; + [[theValue(view.irl_rawPhysicalHeight) should] + beWithin:theValue(0.01) + of:theValue(15.5997001499)]; }); it(@"should return the correct transform to resize the view", ^{ - CGAffineTransform transform = - [view irl_transformForPhysicalWidth: - [[NSMeasurement alloc] initWithDoubleValue:0.01f - unit:[NSUnitLength meters]]]; + if (@available(iOS 10.0, *)) { + CGAffineTransform transform = + [view irl_transformForPhysicalWidth:IRL_MM(10)]; + + CGAffineTransform expectedTransform = + CGAffineTransformMakeScale(0.641025602, 0.641025602); + + [[theValue(transform.a) should] equal:expectedTransform.a + withDelta:0.001]; + + [[theValue(transform.d) should] equal:expectedTransform.d + withDelta:0.001]; + } + + CGAffineTransform transform = [view irl_transformForRawPhysicalWidth:10]; CGAffineTransform expectedTransform = CGAffineTransformMakeScale(0.641025602, 0.641025602); @@ -317,24 +365,43 @@ it(@"should report the correct size", ^{ - NSMeasurement *expectedSize = - [[NSMeasurement alloc] initWithDoubleValue:0.01654589372 - unit:[NSUnitLength meters]]; + if (@available(iOS 10.0, *)) { + NSMeasurement *expectedSize = IRL_MM(15.597333); + + [[view.irl_physicalWidth should] beWithin:0.01 + ofMeasurement:expectedSize]; + + [[view.irl_physicalHeight should] beWithin:0.01 + ofMeasurement:expectedSize]; + } - [[view.irl_physicalWidth should] beWithin:0.01 - ofMeasurement:expectedSize]; + [[theValue(view.irl_rawPhysicalWidth) should] + beWithin:theValue(0.01) + of:theValue(15.597333)]; - [[view.irl_physicalHeight should] beWithin:0.01 - ofMeasurement:expectedSize]; + [[theValue(view.irl_rawPhysicalHeight) should] + beWithin:theValue(0.01) + of:theValue(15.597333)]; }); it(@"should return the correct transform to resize the view", ^{ - CGAffineTransform transform = - [view irl_transformForPhysicalWidth: - [[NSMeasurement alloc] initWithDoubleValue:0.01 - unit:[NSUnitLength meters]]]; + if (@available(iOS 10.0, *)) { + CGAffineTransform transform = + [view irl_transformForPhysicalWidth:IRL_MM(10)]; + + CGAffineTransform expectedTransform = + CGAffineTransformMakeScale(0.641025602, 0.641025602); + + [[theValue(transform.a) should] equal:expectedTransform.a + withDelta:0.001]; + + [[theValue(transform.d) should] equal:expectedTransform.d + withDelta:0.001]; + } + + CGAffineTransform transform = [view irl_transformForRawPhysicalWidth:10]; CGAffineTransform expectedTransform = CGAffineTransformMakeScale(0.641025602, 0.641025602); @@ -344,6 +411,7 @@ [[theValue(transform.d) should] equal:expectedTransform.d withDelta:0.001]; + }); @@ -358,25 +426,43 @@ it(@"should report the correct size", ^{ - NSMeasurement *expectedSize = - [[NSMeasurement alloc] initWithDoubleValue:0.01654589372 - unit:[NSUnitLength meters]]; + if (@available(iOS 10.0, *)) { + NSMeasurement *expectedSize = IRL_MM(15.597333); + + [[view.irl_physicalWidth should] beWithin:0.01 + ofMeasurement:expectedSize]; + + [[view.irl_physicalHeight should] beWithin:0.01 + ofMeasurement:expectedSize]; + } - [[view.irl_physicalWidth should] beWithin:0.01 - ofMeasurement:expectedSize]; - - [[view.irl_physicalHeight should] beWithin:0.01 - ofMeasurement:expectedSize]; + [[theValue(view.irl_rawPhysicalWidth) should] + beWithin:theValue(0.01) + of:theValue(15.597333)]; + [[theValue(view.irl_rawPhysicalHeight) should] + beWithin:theValue(0.01) + of:theValue(15.597333)]; }); it(@"should return the correct transform to resize the view", ^{ - CGAffineTransform transform = - [view irl_transformForPhysicalWidth: - [[NSMeasurement alloc] initWithDoubleValue:0.01 - unit:[NSUnitLength meters]]]; + if (@available(iOS 10.0, *)) { + CGAffineTransform transform = + [view irl_transformForPhysicalWidth:IRL_MM(10)]; + + CGAffineTransform expectedTransform = + CGAffineTransformMakeScale(0.641025602, 0.641025602); + + [[theValue(transform.a) should] equal:expectedTransform.a + withDelta:0.001]; + + [[theValue(transform.d) should] equal:expectedTransform.d + withDelta:0.001]; + } + + CGAffineTransform transform = [view irl_transformForRawPhysicalWidth:10]; CGAffineTransform expectedTransform = CGAffineTransformMakeScale(0.641025602, 0.641025602); @@ -387,6 +473,7 @@ [[theValue(transform.d) should] equal:expectedTransform.d withDelta:0.001]; + }); }); @@ -416,19 +503,27 @@ it(@"should not return a size", ^{ - [[view.irl_physicalWidth should] beNil]; - [[view.irl_physicalHeight should] beNil]; + if (@available(iOS 10.0, *)) { + [[view.irl_physicalWidth should] beNil]; + [[view.irl_physicalHeight should] beNil]; + } + [[theValue(view.irl_rawPhysicalWidth) should] beZero]; + [[theValue(view.irl_rawPhysicalHeight) should] beZero]; }); it(@"should reuse the view’s transform for resizing", ^{ - NSMeasurement *desiredWidth = - [[NSMeasurement alloc] initWithDoubleValue:0.42 - unit:[NSUnitLength meters]]; + if (@available(iOS 10.0, *)) { + NSMeasurement *desiredWidth = IRL_MM(42); + + CGAffineTransform transform = + [view irl_transformForPhysicalWidth:desiredWidth]; + + [[theValue(CGAffineTransformIsIdentity(transform)) should] beTrue]; + } - CGAffineTransform transform = - [view irl_transformForPhysicalWidth:desiredWidth]; + CGAffineTransform transform = [view irl_transformForRawPhysicalWidth:42]; [[theValue(CGAffineTransformIsIdentity(transform)) should] beTrue];