Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. how to verify QVERIFY ?
Forum Updated to NodeBB v4.3 + New Features

how to verify QVERIFY ?

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
7 Posts 3 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    I cannot find decent description of this macro nor where it outputs when it fails. I did test of one and if "statement" is preceded with (!) - thus forcing failure , I get same results , no output to console.

    I like to redirect the output to regular list widget .

    #define QVERIFY(statement)
    do {
    if (!QTest::qVerify(static_cast<bool>(statement), #statement, "", FILE, LINE))
    return;
    } while (false)

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      QVERIFY is used in unit tests and will do what described in the documentation: "The QVERIFY() macro checks whether the condition is true or not. If it is true, execution continues. If not, a failure is recorded in the test log and the test won't be executed further."

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • A Anonymous_Banned275

        I cannot find decent description of this macro nor where it outputs when it fails. I did test of one and if "statement" is preceded with (!) - thus forcing failure , I get same results , no output to console.

        I like to redirect the output to regular list widget .

        #define QVERIFY(statement)
        do {
        if (!QTest::qVerify(static_cast<bool>(statement), #statement, "", FILE, LINE))
        return;
        } while (false)

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @AnneRanch
        As the code shows and @Christian-Ehrlicher has said, QVERIFY() does not return any result for you see/test. It just calls QTest::qVerify() for you, and exits the function you are in if that fails (returns false).

        Depending on what you want here in your code, if the intention is this must be the case, and if it is not print an error message and exit my whole program --- i.e. you use this while developing, and if it does occur you will fix the code so that it won't happen --- don't forget there is Q_ASSERT(expressionWhichMustBeTrue) for that.

        @Christian-Ehrlicher
        I am interested in the choice of definition for

        #define QVERIFY(statement)
        do {
        if (!QTest::qVerify(static_cast<bool>(statement), #statement, "", FILE, LINE))
        return;
        } while (false)
        

        I understand why they are writing a standalone statement for this. I understand they must not write a "naked"-if for it, because there might be an else in user's code immediately after it. However, why do they bother with that do ... while construct to achieve it? Why is the following, simpler statement not good enough?

        #define QVERIFY(statement)
        {
        if (!QTest::qVerify(static_cast<bool>(statement), #statement, "", FILE, LINE))
        return;
        }
        
        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @JonB: See e.g. the discussion here: https://stackoverflow.com/questions/2314066/do-whilefalse

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          JonBJ 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            @JonB: See e.g. the discussion here: https://stackoverflow.com/questions/2314066/do-whilefalse

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @Christian-Ehrlicher
            Interesting, thank you. Most of the answers, including the "accepted solution", there say to allow break or continue in the body, which of course is not being used in this macro. The presumably "correct" answer there for this macro is https://stackoverflow.com/a/2314201/489865

            In a macro, OTOH, do { something; } while (false) is a convenient way to FORCE a semicolon after the macro invocation, absolutely no other token is allowed to follow

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Anonymous_Banned275
              wrote on last edited by
              #6

              So I made few "mistakes" - searching for "QVERIFY" instead of "QTest".
              Secondly I missed "it writes to the log", hence I need to find out something about this log.
              However , what I gather form this discussion - when the QVERIFY fails it basically exits the process.
              Hence it is back to analyzing the so far unknown "test log"...
              This may be desirable debugging , but definitely not KISS approach , in my opinion.

              JonBJ 1 Reply Last reply
              0
              • A Anonymous_Banned275

                So I made few "mistakes" - searching for "QVERIFY" instead of "QTest".
                Secondly I missed "it writes to the log", hence I need to find out something about this log.
                However , what I gather form this discussion - when the QVERIFY fails it basically exits the process.
                Hence it is back to analyzing the so far unknown "test log"...
                This may be desirable debugging , but definitely not KISS approach , in my opinion.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @AnneRanch said in how to verify QVERIFY ?:

                when the QVERIFY fails it basically exits the process.

                That seems to depend on https://doc.qt.io/qt-5/qtest.html#TestFailMode-enum.

                The test log will presumably just state that the QTest::qVerify failed at the specified line number in the specified file. Similar to a Q_ASSERT.

                Hence it is back to analyzing the so far unknown "test log"...

                I have not used QTest anything, but in the Qt Test Overview docs https://doc.qt.io/qt-5/qtest-overview.html#logging-options seems to show a -o option which determines where the test log file is output?

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved