0

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?

cmannett85
  • 21,725
  • 8
  • 76
  • 119

1 Answers1

2

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);
Frank Osterfeld
  • 24,815
  • 5
  • 58
  • 70
  • 1
    The [QCOMPARE](http://qt-project.org/doc/qt-4.8/qtest.html#QCOMPARE) line should actually be: QCOMPARE(distance + 1.0, expected + 1.0) to handle zero values. – JadziaMD Mar 20 '12 at 13:34