Moved to RMSE for image comparison to account for slight variations in golden image tests (flutter/engine#19658)

Moved to RMSE for image comparison to account for slight variations in golden image production.  (also fixed a flakey test)
This commit is contained in:
gaaclarke 2020-07-13 16:14:26 -07:00 committed by GitHub
parent 51ef62b895
commit ef11a05735
2 changed files with 21 additions and 7 deletions

View File

@ -6,6 +6,8 @@
#import <XCTest/XCTest.h>
#include <sys/sysctl.h>
static const double kRmseThreshold = 0.5;
@interface GoldenImage ()
@end
@ -67,8 +69,24 @@
CGContextDrawImage(contextB, CGRectMake(0, 0, widthA, heightA), imageRefB);
CGContextRelease(contextB);
BOOL isSame = memcmp(rawA.mutableBytes, rawB.mutableBytes, size) == 0;
return isSame;
const char* apos = rawA.mutableBytes;
const char* bpos = rawB.mutableBytes;
double sum = 0.0;
for (size_t i = 0; i < size; ++i, ++apos, ++bpos) {
// Skip transparent pixels.
if (*apos == 0 && *bpos == 0 && i % 4 == 0) {
i += 3;
apos += 3;
bpos += 3;
} else {
double aval = *apos;
double bval = *bpos;
double diff = aval - bval;
sum += diff * diff;
}
}
double rmse = sqrt(sum / size);
return rmse <= kRmseThreshold;
}
NS_INLINE NSString* _platformName() {

View File

@ -243,12 +243,8 @@
XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"];
XCTAssertTrue(overlay.exists);
XCTAssertEqual(overlay.frame.origin.x, 75);
XCTAssertEqual(overlay.frame.origin.y, 85);
XCTAssertEqual(overlay.frame.size.width, 150);
XCTAssertEqual(overlay.frame.size.height, 190);
XCTAssertFalse(app.otherElements[@"platform_view[0].overlay[1]"].exists);
XCTAssertTrue(CGRectContainsRect(platform_view.frame, overlay.frame));
}
@end