Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-75503

QTRY_COMPARE is not safe for use with floating point numbers

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.12
    • Testing: qtestlib
    • None

    Description

      The following code will pass, but only after 10 seconds:

      QTRY_COMPARE(-51.99999999999994, -52)
      

      The implementation:

      // Will try to wait for the comparison to become successful while allowing event processing
      #define QTRY_COMPARE_WITH_TIMEOUT(expr, expected, timeout) \
      do { \
          QTRY_IMPL(((expr) == (expected)), timeout);\
          QCOMPARE((expr), expected); \
      } while (false)
      
      #define QTRY_COMPARE(expr, expected) QTRY_COMPARE_WITH_TIMEOUT((expr), expected, 5000)
      

      The QTRY_IMPL call uses operator == for comparison, which fails. That macro repeats the loop twice to see if a longer wait would have made the test pass. The default timeout is 5 seconds, so the end result is that the test waits a whole 10 seconds before passing when doing the QCOMPARE (which uses qFuzzyCompare()).

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            macadder Jason McDonald
            mitch_curtis Mitch Curtis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes