Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTest how to cleanly handle 2 QCoreApplications? the one for QTest::qExec and the one of my app I'm testing ? Except leaking....

QTest how to cleanly handle 2 QCoreApplications? the one for QTest::qExec and the one of my app I'm testing ? Except leaking....

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 404 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.
  • mbruelM Offline
    mbruelM Offline
    mbruel
    wrote on last edited by
    #1

    Hi,
    I'm having a big trouble to handle properly 2 QCoreApplication.
    I launch the test with its own event loop.
    For some test case, when needed, I start the one of my App, I can also quit it.
    But I'm having a massive crash if I try to delete my app, so I need to keep a memory leak...
    That's not a big deal, but it's not ideal.
    I'd like to undestand how to do it properly.
    Anyone has some experience with that?
    My project is ngPost. The branch dev5.0 starts implementing tests.
    If anyone has time or an idea, I'll be super happy !
    My structure is this: a test_ngPost.pro that defines a Macro helper and 2 test cases. ( TestNzbGet is not started and all commented.)
    Basically my Macro allows me to have global statistiques at the end: number of Tests that fails with their number of unitests, I didnt know how to do it in another way. The import thing is that the test ends with exit value the number of all the unit cases that failed.. Usefull for jenkins ;)
    Is there a Qt way?
    Here are my results:

    Configuration version needs update!
    QDEBUG : TestNgTools::onCheckForNewVesion() [MB_LOG] ../src/tests/testNgTools.cpp:127 TestNgTools::onCheckForNewVersionReply: lastRelease:  
    QDEBUG : TestNgTools::onCheckForNewVesion() [MB_LOG] ../src/tests/testNgTools.cpp:127 416 
    QDEBUG : TestNgTools::onCheckForNewVesion() [MB_LOG] ../src/tests/testNgTools.cpp:127 currentBuilt: 
    QDEBUG : TestNgTools::onCheckForNewVesion() [MB_LOG] ../src/tests/testNgTools.cpp:127 400 
    QDEBUG : TestNgTools::onCheckForNewVesion() Deleting ngPost...
    PASS   : TestNgTools::onCheckForNewVesion()
    QWARN  : TestNgTools::onCheckForNewVersionReply() qt.core.qobject.connect: QObject::disconnect: Unexpected nullptr parameter
    QDEBUG : TestNgTools::onCheckForNewVersionReply() Deleting ngPost...
    PASS   : TestNgTools::onCheckForNewVersionReply()
    QDEBUG : TestNgTools::cleanupTestCase() Destruction of the singleton NgLogger
    PASS   : TestNgTools::cleanupTestCase()
    Totals: 7 passed, 0 failed, 0 skipped, 0 blacklisted, 157ms
    ********* Finished testing of TestNgTools *********
    [ TestNgTools ] QTest::qExec return:  0
    
    
    
    
    
    ###############################################
    # Results Macro Test:  "TestNgTools"
    #     - number of use cases:  27
    #     - number of checks:  0
    #     - number of Failures:  0
    ###############################################
    ********* Start testing of TestVesions *********
    Config: Using QtTest library 6.4.0, Qt 6.4.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 10.3.1 20210422 (Red Hat 10.3.1-1)), debian 12
    QDEBUG : TestVesions::initTestCase() Creation of the singleton NgLogger
    PASS   : TestVesions::initTestCase()
    QDEBUG : TestVesions::onTestLoadDefautConfig() onTestLoadDefautConfig...
    QDEBUG : TestVesions::onTestLoadDefautConfig() Config version :  "3.2"
    QDEBUG : TestVesions::onTestLoadDefautConfig() [MB_TODO] why pushing args.join("=") ??  QList("echo \"NZB_POST_CMD echo: <release: __nzbName__> <rarName: __rarName__> <rarPass: __rarPass__> <path: __nzbPath__> <groups: __groups__> <size: __sizeInByte__B> <nbFiles: __nbFiles__> <nbArticles: __nbArticles__> <failed: __nbArticlesFailed__>\"", "echo \"NZB_POST_CMD echo: <release: __nzbName__> <rarName: __rarName__> <rarPass: __rarPass__> <path: __nzbPath__> <groups: __groups__> <size: __sizeInByte__B> <nbFiles: __nbFiles__> <nbArticles: __nbArticles__> <failed: __nbArticlesFailed__>\"", "echo \"NZB_POST_CMD echo: <release: __nzbName__> <rarName: __rarName__> <rarPass: __rarPass__> <path: __nzbPath__> <groups: __groups__> <size: __sizeInByte__B> <nbFiles: __nbFiles__> <nbArticles: __nbArticles__> <failed: __nbArticlesFailed__>\"")
    QDEBUG : TestVesions::onTestLoadDefautConfig() Display progressbar bar
    
    QDEBUG : TestVesions::onTestLoadDefautConfig() Leaking ngPost...
    PASS   : TestVesions::onTestLoadDefautConfig()
    QDEBUG : TestVesions::onTestLoadOldConfig() onTestLoadOldConfig...
    QDEBUG : TestVesions::onTestLoadOldConfig() Leaking ngPost...
    PASS   : TestVesions::onTestLoadOldConfig()
    QDEBUG : TestVesions::cleanupTestCase() Destruction of the singleton NgLogger
    PASS   : TestVesions::cleanupTestCase()
    Totals: 4 passed, 0 failed, 0 skipped, 0 blacklisted, 4ms
    ********* Finished testing of TestVesions *********
    [ TestVesions ] QTest::qExec return:  0
    
    
    
    
    
    ###############################################
    # Results Macro Test:  "TestVesions"
    #     - number of use cases:  0
    #     - number of checks:  0
    #     - number of Failures:  0
    ###############################################
    
    
    
    
    
    ###############################################
    # Overall Tests Results:
    #     - number of Macro Tests:  2
    #     - number of Macro Tests FAILED:  0
    #
    
    #     - number of Unit Tests:  27
    #     - number of Unit Tests FAILED:  0
    ###############################################
    22:38:04: /home/mb/Documents/github/ngPost/build-test_ngPost-Desktop_Qt_6_4_0_GCC_64bit-Debug/ngPost exited with code 0
    
    

    So we can see the tests are lanched independantly and using their own instance of my App. Leaking it allows me to get the result I want but I'm not a fan of this and would like to understant how to do better,
    If anyone can help, it would be welcome ;)

    C 1 Reply Last reply
    0
    • mbruelM mbruel

      Hi,
      I'm having a big trouble to handle properly 2 QCoreApplication.
      I launch the test with its own event loop.
      For some test case, when needed, I start the one of my App, I can also quit it.
      But I'm having a massive crash if I try to delete my app, so I need to keep a memory leak...
      That's not a big deal, but it's not ideal.
      I'd like to undestand how to do it properly.
      Anyone has some experience with that?
      My project is ngPost. The branch dev5.0 starts implementing tests.
      If anyone has time or an idea, I'll be super happy !
      My structure is this: a test_ngPost.pro that defines a Macro helper and 2 test cases. ( TestNzbGet is not started and all commented.)
      Basically my Macro allows me to have global statistiques at the end: number of Tests that fails with their number of unitests, I didnt know how to do it in another way. The import thing is that the test ends with exit value the number of all the unit cases that failed.. Usefull for jenkins ;)
      Is there a Qt way?
      Here are my results:

      Configuration version needs update!
      QDEBUG : TestNgTools::onCheckForNewVesion() [MB_LOG] ../src/tests/testNgTools.cpp:127 TestNgTools::onCheckForNewVersionReply: lastRelease:  
      QDEBUG : TestNgTools::onCheckForNewVesion() [MB_LOG] ../src/tests/testNgTools.cpp:127 416 
      QDEBUG : TestNgTools::onCheckForNewVesion() [MB_LOG] ../src/tests/testNgTools.cpp:127 currentBuilt: 
      QDEBUG : TestNgTools::onCheckForNewVesion() [MB_LOG] ../src/tests/testNgTools.cpp:127 400 
      QDEBUG : TestNgTools::onCheckForNewVesion() Deleting ngPost...
      PASS   : TestNgTools::onCheckForNewVesion()
      QWARN  : TestNgTools::onCheckForNewVersionReply() qt.core.qobject.connect: QObject::disconnect: Unexpected nullptr parameter
      QDEBUG : TestNgTools::onCheckForNewVersionReply() Deleting ngPost...
      PASS   : TestNgTools::onCheckForNewVersionReply()
      QDEBUG : TestNgTools::cleanupTestCase() Destruction of the singleton NgLogger
      PASS   : TestNgTools::cleanupTestCase()
      Totals: 7 passed, 0 failed, 0 skipped, 0 blacklisted, 157ms
      ********* Finished testing of TestNgTools *********
      [ TestNgTools ] QTest::qExec return:  0
      
      
      
      
      
      ###############################################
      # Results Macro Test:  "TestNgTools"
      #     - number of use cases:  27
      #     - number of checks:  0
      #     - number of Failures:  0
      ###############################################
      ********* Start testing of TestVesions *********
      Config: Using QtTest library 6.4.0, Qt 6.4.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 10.3.1 20210422 (Red Hat 10.3.1-1)), debian 12
      QDEBUG : TestVesions::initTestCase() Creation of the singleton NgLogger
      PASS   : TestVesions::initTestCase()
      QDEBUG : TestVesions::onTestLoadDefautConfig() onTestLoadDefautConfig...
      QDEBUG : TestVesions::onTestLoadDefautConfig() Config version :  "3.2"
      QDEBUG : TestVesions::onTestLoadDefautConfig() [MB_TODO] why pushing args.join("=") ??  QList("echo \"NZB_POST_CMD echo: <release: __nzbName__> <rarName: __rarName__> <rarPass: __rarPass__> <path: __nzbPath__> <groups: __groups__> <size: __sizeInByte__B> <nbFiles: __nbFiles__> <nbArticles: __nbArticles__> <failed: __nbArticlesFailed__>\"", "echo \"NZB_POST_CMD echo: <release: __nzbName__> <rarName: __rarName__> <rarPass: __rarPass__> <path: __nzbPath__> <groups: __groups__> <size: __sizeInByte__B> <nbFiles: __nbFiles__> <nbArticles: __nbArticles__> <failed: __nbArticlesFailed__>\"", "echo \"NZB_POST_CMD echo: <release: __nzbName__> <rarName: __rarName__> <rarPass: __rarPass__> <path: __nzbPath__> <groups: __groups__> <size: __sizeInByte__B> <nbFiles: __nbFiles__> <nbArticles: __nbArticles__> <failed: __nbArticlesFailed__>\"")
      QDEBUG : TestVesions::onTestLoadDefautConfig() Display progressbar bar
      
      QDEBUG : TestVesions::onTestLoadDefautConfig() Leaking ngPost...
      PASS   : TestVesions::onTestLoadDefautConfig()
      QDEBUG : TestVesions::onTestLoadOldConfig() onTestLoadOldConfig...
      QDEBUG : TestVesions::onTestLoadOldConfig() Leaking ngPost...
      PASS   : TestVesions::onTestLoadOldConfig()
      QDEBUG : TestVesions::cleanupTestCase() Destruction of the singleton NgLogger
      PASS   : TestVesions::cleanupTestCase()
      Totals: 4 passed, 0 failed, 0 skipped, 0 blacklisted, 4ms
      ********* Finished testing of TestVesions *********
      [ TestVesions ] QTest::qExec return:  0
      
      
      
      
      
      ###############################################
      # Results Macro Test:  "TestVesions"
      #     - number of use cases:  0
      #     - number of checks:  0
      #     - number of Failures:  0
      ###############################################
      
      
      
      
      
      ###############################################
      # Overall Tests Results:
      #     - number of Macro Tests:  2
      #     - number of Macro Tests FAILED:  0
      #
      
      #     - number of Unit Tests:  27
      #     - number of Unit Tests FAILED:  0
      ###############################################
      22:38:04: /home/mb/Documents/github/ngPost/build-test_ngPost-Desktop_Qt_6_4_0_GCC_64bit-Debug/ngPost exited with code 0
      
      

      So we can see the tests are lanched independantly and using their own instance of my App. Leaking it allows me to get the result I want but I'm not a fan of this and would like to understant how to do better,
      If anyone can help, it would be welcome ;)

      C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      Hi,

      From the QCoreApplication docs, "For non-GUI application that uses Qt, there should be exactly one QCoreApplication object."

      It's not clear top me what this means, "For some test case, when needed, I start the one of my App, I can also quit it. But I'm having a massive crash if I try to delete my app, so I need to keep a memory leak..."

      You should be unit testing individual components, not an entire running application.

      1 Reply Last reply
      2
      • mbruelM Offline
        mbruelM Offline
        mbruel
        wrote on last edited by
        #3

        Yes I know but I would also like to do Macro testing...
        Something I'm not understanding, the test.main() doesn't seem to wait for a QThread started to be waited... Is it normal?

        1 Reply Last reply
        0
        • mbruelM Offline
          mbruelM Offline
          mbruel
          wrote on last edited by
          #4

          I found the solution using QTest::qWaitFor cf my project TestVesions

              ConnectionHandler *conHandler = TestUtils::loadXSNewsPartnerConfAndCheckConnection(*_ngPost);
              conHandler->start();
              MB_VERIFY(QTest::qWaitFor([&conHandler]() { return conHandler->isTestDone(); }, 5000), this);
          
          1 Reply Last reply
          0
          • mbruelM mbruel has marked this topic as solved on

          • Login

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