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

CLONE - Adding QBENCHMARK to a test causes the code outside the QBENCHMARK brackets to be called several times

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2: Important P2: Important
    • None
    • 5.10.1
    • Testing: qtestlib
    • None
    • Windows

      Sample code to reproduce the issue :

      TestExample.h

      #ifndef TESTEXAMPLE_H
      #define TESTEXAMPLE_H
      
      #include <QDebug>
      #include <QObject>
      #include <QtTest/QtTest>
      
      class TestExample : public QObject {
          Q_OBJECT
         private slots:
          void initTestCase();
          void cleanupTestCase();
      
          void testWithoutBenchmark();
          void testWithBenchmark();
      
         private:
          long long _value;
          long long _benchmarkValue;
      };
      
      #endif  // TESTEXAMPLE_H

      TestExample.cpp

       

      #include "TestExample.h"
      
      void TestExample::initTestCase() {
          _value=0;
          _benchmarkValue=0;
      }
      
      void TestExample::cleanupTestCase() {
          QVERIFY(_benchmarkValue > 0);
          QVERIFY(_value == 2);
      }
      
      void TestExample::testWithoutBenchmark() {
          _value++;
          qDebug() << QString::number(_value);
          QVERIFY(_value == 1);
      }
      
      void TestExample::testWithBenchmark() {
          _value++;
          qDebug() << QString::number(_value);
          QVERIFY(_value == 2);
      
          QBENCHMARK {
              _benchmarkValue++;
          }
      }
      
      QTEST_APPLESS_MAIN(TestExample)
      

       

      Expected behavior : both tests passes, and each test is called only once, the code inside the QBENCHMARK brackets is called multiple times.

      Observed behavior : testWithoutBenchmark passes, testWithBenchmark fails because it's called multiple times. Remove the QVERIFY of testWithBenchmark to see how many times the test slot is called though the qDebug output.

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

            macadder Jason McDonald
            fpe fpe
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes