Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "GoldenImage.h"

#import <XCTest/XCTest.h>
#import <os/log.h>
#include <sys/sysctl.h>

static const double kRmseThreshold = 0.5;
Expand All @@ -29,6 +30,7 @@ - (instancetype)initWithGoldenNamePrefix:(NSString*)prefix {

- (BOOL)compareGoldenToImage:(UIImage*)image {
if (!self.image || !image) {
os_log_error(OS_LOG_DEFAULT, "GOLDEN DIFF FAILED: image does not exists.");
return NO;
}
CGImageRef imageRefA = [self.image CGImage];
Expand All @@ -40,6 +42,7 @@ - (BOOL)compareGoldenToImage:(UIImage*)image {
NSUInteger heightB = CGImageGetHeight(imageRefB);

if (widthA != widthB || heightA != heightB) {
os_log_error(OS_LOG_DEFAULT, "GOLDEN DIFF FAILED: images sizes do not match.");
return NO;
}
NSUInteger bytesPerPixel = 4;
Expand All @@ -48,6 +51,7 @@ - (BOOL)compareGoldenToImage:(UIImage*)image {
NSMutableData* rawB = [NSMutableData dataWithLength:size];

if (!rawA || !rawB) {
os_log_error(OS_LOG_DEFAULT, "GOLDEN DIFF FAILED: image data length do not match.");
return NO;
}

Expand Down Expand Up @@ -87,7 +91,14 @@ - (BOOL)compareGoldenToImage:(UIImage*)image {
}
}
double rmse = sqrt(sum / size);
return rmse <= kRmseThreshold;
if (rmse > kRmseThreshold) {
os_log_error(
OS_LOG_DEFAULT,
"GOLDEN DIFF FAILED: image diff greater than threshold. Current diff: %@, threshold: %@",
@(rmse), @(kRmseThreshold));
return NO;
}
return YES;
}

NS_INLINE NSString* _platformName() {
Expand Down