diff --git a/Tests/Tests/STPSourceTest.m b/Tests/Tests/STPSourceTest.m index a31f4fcc143..eb6e33b5899 100644 --- a/Tests/Tests/STPSourceTest.m +++ b/Tests/Tests/STPSourceTest.m @@ -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; } } @@ -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; } } diff --git a/Tests/Tests/STPTestUtils.h b/Tests/Tests/STPTestUtils.h index ffe769e3c4a..42ff56363db 100644 --- a/Tests/Tests/STPTestUtils.h +++ b/Tests/Tests/STPTestUtils.h @@ -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)