From 8e9c24f17590013fce7612a2a7b8a78faec63e32 Mon Sep 17 00:00:00 2001 From: Owen Thomas Date: Fri, 22 Oct 2021 13:32:13 -0700 Subject: [PATCH] Add tests of crushed PNGs --- .../FBSnapshotControllerTests.m | 31 ++++++++++++++++++ .../Resources/rect_crushed.png | Bin 0 -> 3180 bytes 2 files changed, 31 insertions(+) create mode 100644 src/iOSSnapshotTestCaseTests/Resources/rect_crushed.png diff --git a/src/iOSSnapshotTestCaseTests/FBSnapshotControllerTests.m b/src/iOSSnapshotTestCaseTests/FBSnapshotControllerTests.m index 9331038..4031be9 100644 --- a/src/iOSSnapshotTestCaseTests/FBSnapshotControllerTests.m +++ b/src/iOSSnapshotTestCaseTests/FBSnapshotControllerTests.m @@ -196,6 +196,37 @@ - (void)testCompareReferenceImageWithLowPixelToleranceShouldMatch XCTAssertNil(error); } +- (void)testCompareReferenceImageToGrayscaleCrushedImageShouldBeEqual +{ + UIImage *referenceImage = [self _bundledImageNamed:@"rect" type:@"png"]; + XCTAssertNotNil(referenceImage); + + // rect_crushed was made by pngcrush version 1.8.13 with default options as shown below. Reduced file size by 67% + // FBSnapshotTestCaseTests$ pngcrush rect.png rect_crushed.png + UIImage *testImage = [self _bundledImageNamed:@"rect_crushed" type:@"png"]; + XCTAssertNotNil(testImage); + + id testClass = nil; + FBSnapshotTestController *controller = [[FBSnapshotTestController alloc] initWithTestClass:testClass]; + NSError *error = nil; + XCTAssertTrue([controller compareReferenceImage:referenceImage toImage:testImage overallTolerance:0 error:&error]); + XCTAssertNil(error); +} + +- (void)testCompareGrayscaleCrushedImageToReferenceImageShouldBeEqual +{ + UIImage *referenceImage = [self _bundledImageNamed:@"rect_crushed" type:@"png"]; + XCTAssertNotNil(referenceImage); + UIImage *testImage = [self _bundledImageNamed:@"rect" type:@"png"]; + XCTAssertNotNil(testImage); + + id testClass = nil; + FBSnapshotTestController *controller = [[FBSnapshotTestController alloc] initWithTestClass:testClass]; + NSError *error = nil; + XCTAssertTrue([controller compareReferenceImage:referenceImage toImage:testImage overallTolerance:0 error:&error]); + XCTAssertNil(error); +} + #pragma mark - Private helper methods - (UIImage *)_bundledImageNamed:(NSString *)name type:(NSString *)type diff --git a/src/iOSSnapshotTestCaseTests/Resources/rect_crushed.png b/src/iOSSnapshotTestCaseTests/Resources/rect_crushed.png new file mode 100644 index 0000000000000000000000000000000000000000..dbcf23074e38acf652c4cb07bf578c8523e04680 GIT binary patch literal 3180 zcmeHJJ*?wI5Z(vP@z6DZ1VR*64iE@A{z>dh7RTsa{J2DryO7JFTz8xGCb4k5#&%xv zs7{FHDnx;V&~;EB6jYQ@fdmp25>#}6M2$qn_$P^zIH!l6goH#C+v}P6zS-HC9q--l zwW}8opFTtgU2M0k9z1Qhx)Pry z*;HaKn=&s70jCtYgSG8+R?v-UE{LDFn@$UnVRU=~p=V23hz$FuK9hPZWTKv(K?$&yk?Gi1c;kK)o8l1#Hi(G_2KLk`){mM9P*}?I&@(Fd`mh*@`=7Uh$MY2jB05 z(4?|yz(~aG<-{`SHq4OX4(K}nsZ`Jj@y5(HrDbqS!FF`(^4QE?y|2hvt7BC?Z}w+ucrTq;0sp+f&XK*$#ZYeKP8Eejsx2 zO={dsnv(?$>On0PCYZO};^@G+(IyeuWZ5l`m}SFun}^%Z==4l1Ys)Q;Bpx30Id{+Y z?OBDEfpUDSLk~{Q2_0@Tvtmd^;tZ9RP3~Bmbn{dShi3B-YG`=?HxEDj;myzCOs==B zqyFIQKfY5A5W4WN@Z&3Ay!Oj;PY5snS^A*$>|=MWg2y+XeLDQAdvN`spMH*y_3h(p K*8MBD-~Ai-(2yhm literal 0 HcmV?d00001