Port QPathClipper test away from home-grown QCOMPARE

Use a scope guard to print debug info in case of an early return.
Silences clang warning about sprintf being unsafe and deprecated.

Change-Id: Idcbfde1a6f2eb1143f51c1e5ecedbf3fe90d8ec8
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
Volker Hilsheimer 2023-03-01 22:24:43 +01:00
parent 47df0eb513
commit 9ec61d4460

View File

@ -470,15 +470,19 @@ void tst_QPathClipper::clipTest(int subjectIndex, int clipIndex, QPathClipper::O
break;
}
if (expected != inResult) {
char str[256];
const char *opStr =
op == QPathClipper::BoolAnd ? "and" :
op == QPathClipper::BoolOr ? "or" : "sub";
sprintf(str, "Expected: %d, actual: %d, subject: %d, clip: %d, op: %s\n",
int(expected), int(inResult), subjectIndex, clipIndex, opStr);
QFAIL(str);
}
auto failLogger = qScopeGuard([&]{
qCritical().noquote().nospace()
<< "\n\tExpected: " << expected
<< "\n\tActual: " << inResult
<< "\n\tSubject: " << subjectIndex
<< "\n\tClip: " << clipIndex
<< "\n\tOp: " << (op == QPathClipper::BoolAnd
? "and"
: op == QPathClipper::BoolOr
? "or" : "sub");
});
QCOMPARE(inResult, expected);
failLogger.dismiss();
}
}