Skip to content

Commit 91f80ef

Browse files
authored
Moved to RMSE for image comparison to account for slight variations in golden image tests (flutter#19658)
Moved to RMSE for image comparison to account for slight variations in golden image production. (also fixed a flakey test)
1 parent ae37971 commit 91f80ef

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenImage.m

+20-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#import <XCTest/XCTest.h>
77
#include <sys/sysctl.h>
88

9+
static const double kRmseThreshold = 0.5;
10+
911
@interface GoldenImage ()
1012

1113
@end
@@ -67,8 +69,24 @@ - (BOOL)compareGoldenToImage:(UIImage*)image {
6769
CGContextDrawImage(contextB, CGRectMake(0, 0, widthA, heightA), imageRefB);
6870
CGContextRelease(contextB);
6971

70-
BOOL isSame = memcmp(rawA.mutableBytes, rawB.mutableBytes, size) == 0;
71-
return isSame;
72+
const char* apos = rawA.mutableBytes;
73+
const char* bpos = rawB.mutableBytes;
74+
double sum = 0.0;
75+
for (size_t i = 0; i < size; ++i, ++apos, ++bpos) {
76+
// Skip transparent pixels.
77+
if (*apos == 0 && *bpos == 0 && i % 4 == 0) {
78+
i += 3;
79+
apos += 3;
80+
bpos += 3;
81+
} else {
82+
double aval = *apos;
83+
double bval = *bpos;
84+
double diff = aval - bval;
85+
sum += diff * diff;
86+
}
87+
}
88+
double rmse = sqrt(sum / size);
89+
return rmse <= kRmseThreshold;
7290
}
7391

7492
NS_INLINE NSString* _platformName() {

testing/scenario_app/ios/Scenarios/ScenariosUITests/UnobstructedPlatformViewTests.m

+1-5
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,8 @@ - (void)testPlatformViewsMaxOverlays {
243243

244244
XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"];
245245
XCTAssertTrue(overlay.exists);
246-
XCTAssertEqual(overlay.frame.origin.x, 75);
247-
XCTAssertEqual(overlay.frame.origin.y, 85);
248-
XCTAssertEqual(overlay.frame.size.width, 150);
249-
XCTAssertEqual(overlay.frame.size.height, 190);
250-
251246
XCTAssertFalse(app.otherElements[@"platform_view[0].overlay[1]"].exists);
247+
XCTAssertTrue(CGRectContainsRect(platform_view.frame, overlay.frame));
252248
}
253249

254250
@end

0 commit comments

Comments
 (0)