Skip to content

Commit

Permalink
Add tests of crushed PNGs
Browse files Browse the repository at this point in the history
  • Loading branch information
tinder-owenthomas committed Dec 11, 2020
1 parent 6eb8656 commit 934dc4f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions FBSnapshotTestCase.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
13CBB39E1AEE013900B6ADBA /* FBSnapshotTestCasePlatform.m in Sources */ = {isa = PBXBuildFile; fileRef = 13CBB39C1AEE013900B6ADBA /* FBSnapshotTestCasePlatform.m */; };
42F2B74420C0D7A400ABED24 /* rect_shade.png in Resources */ = {isa = PBXBuildFile; fileRef = 42F2B74320C0D7A400ABED24 /* rect_shade.png */; };
42F2B74520C0D7A400ABED24 /* rect_shade.png in Resources */ = {isa = PBXBuildFile; fileRef = 42F2B74320C0D7A400ABED24 /* rect_shade.png */; };
7810BCD4258373B70005AC4A /* rect_crushed.png in Resources */ = {isa = PBXBuildFile; fileRef = 7810BCD3258373B70005AC4A /* rect_crushed.png */; };
7810BCD5258373B70005AC4A /* rect_crushed.png in Resources */ = {isa = PBXBuildFile; fileRef = 7810BCD3258373B70005AC4A /* rect_crushed.png */; };
827137841C63AB7000354E42 /* FBSnapshotTestCase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8271377A1C63AB6F00354E42 /* FBSnapshotTestCase.framework */; };
827137911C63ABE900354E42 /* UIImage+Compare.h in Headers */ = {isa = PBXBuildFile; fileRef = 133564101B59C3F500A4E4BF /* UIImage+Compare.h */; };
827137921C63ABF000354E42 /* UIImage+Diff.h in Headers */ = {isa = PBXBuildFile; fileRef = 133564121B59C3F500A4E4BF /* UIImage+Diff.h */; };
Expand Down Expand Up @@ -78,6 +80,7 @@
13CBB39B1AEE013900B6ADBA /* FBSnapshotTestCasePlatform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBSnapshotTestCasePlatform.h; sourceTree = "<group>"; };
13CBB39C1AEE013900B6ADBA /* FBSnapshotTestCasePlatform.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBSnapshotTestCasePlatform.m; sourceTree = "<group>"; };
42F2B74320C0D7A400ABED24 /* rect_shade.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = rect_shade.png; sourceTree = "<group>"; };
7810BCD3258373B70005AC4A /* rect_crushed.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = rect_crushed.png; sourceTree = "<group>"; };
8271377A1C63AB6F00354E42 /* FBSnapshotTestCase.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FBSnapshotTestCase.framework; sourceTree = BUILT_PRODUCTS_DIR; };
827137831C63AB7000354E42 /* FBSnapshotTestCase tvOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "FBSnapshotTestCase tvOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
B31987F01AB782D000B0A900 /* FBSnapshotTestCase.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FBSnapshotTestCase.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -196,6 +199,7 @@
children = (
42F2B74320C0D7A400ABED24 /* rect_shade.png */,
B76C68271C6BD68100586E5B /* rect.png */,
7810BCD3258373B70005AC4A /* rect_crushed.png */,
E5C2CD611B1F399A00669887 /* square_with_pixel.png */,
B32447D91AB78B5E00B1D6FF /* square_with_text.png */,
B32447DA1AB78B5E00B1D6FF /* square-copy.png */,
Expand Down Expand Up @@ -384,6 +388,7 @@
827137A21C63AC0D00354E42 /* square-copy.png in Resources */,
827137A31C63AC0D00354E42 /* square.png in Resources */,
827137A11C63AC0900354E42 /* square_with_text.png in Resources */,
7810BCD5258373B70005AC4A /* rect_crushed.png in Resources */,
42F2B74520C0D7A400ABED24 /* rect_shade.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -404,6 +409,7 @@
E5C2CD621B1F399A00669887 /* square_with_pixel.png in Resources */,
B32447DE1AB78B5E00B1D6FF /* square.png in Resources */,
B32447DD1AB78B5E00B1D6FF /* square-copy.png in Resources */,
7810BCD4258373B70005AC4A /* rect_crushed.png in Resources */,
42F2B74420C0D7A400ABED24 /* rect_shade.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
31 changes: 31 additions & 0 deletions FBSnapshotTestCaseTests/FBSnapshotControllerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,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
Expand Down
Binary file added FBSnapshotTestCaseTests/rect_crushed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 934dc4f

Please sign in to comment.