Skip to content

Commit

Permalink
Fix test failures on iOS 9: compare PNG data of UIImages
Browse files Browse the repository at this point in the history
Also, fixing `testPaymentMethodTemplateImage()` for non-Card sources. It was missing
the assertion
  • Loading branch information
danj-stripe committed Aug 2, 2018
1 parent f3fcec1 commit d1e3669
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Tests/Tests/STPSourceTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,10 @@ - (void)testPaymentMethodImage {

switch (source.type) {
case STPSourceTypeCard:
XCTAssertEqualObjects(source.image, [STPImageLibrary brandImageForCardBrand:source.cardDetails.brand]);
AssertEqualImages(source.image, [STPImageLibrary brandImageForCardBrand:source.cardDetails.brand]);
break;
default:
XCTAssertEqualObjects(source.image, [STPImageLibrary brandImageForCardBrand:STPCardBrandUnknown]);
AssertEqualImages(source.image, [STPImageLibrary brandImageForCardBrand:STPCardBrandUnknown]);
break;
}
}
Expand All @@ -492,10 +492,10 @@ - (void)testPaymentMethodTemplateImage {

switch (source.type) {
case STPSourceTypeCard:
XCTAssertEqualObjects(source.templateImage, [STPImageLibrary templatedBrandImageForCardBrand:source.cardDetails.brand]);
AssertEqualImages(source.templateImage, [STPImageLibrary templatedBrandImageForCardBrand:source.cardDetails.brand]);
break;
default:
[STPImageLibrary templatedBrandImageForCardBrand:STPCardBrandUnknown];
AssertEqualImages(source.templateImage, [STPImageLibrary templatedBrandImageForCardBrand:STPCardBrandUnknown]);
break;
}
}
Expand Down
17 changes: 17 additions & 0 deletions Tests/Tests/STPTestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,20 @@
+ (NSDictionary *)jsonNamed:(NSString *)name;

@end


/**
Custom assertion macro to compare to UIImage instances.
On iOS 9, `XCTAssertEqualObjects` incorrectly fails when provided with identical images.
This just calls `XCTAssertEqualObjects` with the `UIImagePNGRepresentation` of each
image. Can be removed when we drop support for iOS 9.
@param image1 First UIImage to compare
@param image2 Second UIImage to compare
*/
#define AssertEqualImages(image1, image2) \
do { \
XCTAssertEqualObjects(UIImagePNGRepresentation(image1), UIImagePNGRepresentation(image2)); \
} while (0)

0 comments on commit d1e3669

Please sign in to comment.