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