Вопрос

I'm currently building a unit test suite for my application, using QTestLib. It's generally pretty straight-forward, but I'm become stuck on how to verify 'return' arguments. For example, if I have a function:

double pointLineSegmentDistance(const QVector2D& start,
                                const QVector2D& end,
                                const QVector2D& point,
                                bool& withinBounds);

The function assigns withinBounds the bounded state of the segment distance analysis. How can I make the QCOMPARE/QVERIFY macros analyse it's state?

Это было полезно?

Решение

Just pass a local variable as argument and verify/compare its value afterwards:

bool withinBounds = false;
const double distance = pointLineSegmentDistance( ..., withinBounds );
QCOMPARE(distance + 1.0, 2.0); //qFuzzyCompare doesn't work well with 0.0
QVERIFY(withinBounds);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top