-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
6.6.0
-
None
It would be really nice if QCOMPARE would use qFuzzyCompare() for more than just basic comparison of floating point numbers. For example, QVector3D probably should never be compared with == directly; there are other such cases too (like QQuaternion).
I have the code below (obviously closely related to your definition of QCOMPARE) but I think this is the sort of thing that belongs in your code rather than mine.
template<typename T> bool fuzzyCompare( const T &t1, const T &t2, const char *actual, const char *expected, const char *file, int line) { return QTest::compare_helper(qFuzzyCompare(t1, t2), "Compared values are not the same", QTest::toString(t1), QTest::toString(t2), actual, expected, file, line); } #define FUZZY_COMPARE(actual, expected) \ do {\ if (!fuzzyCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ return;\ } while (false)