Results 1 to 8 of 8

Thread: QTest and QFETCH

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Unhappy QTest and QFETCH

    Is there any simple way to read the test data from file instead of manually defining the test data with _data-functions? Or do I just have to make a file reader...


    And when I create test class, which uses private slots as test cases, can I still use private functions without messing up the testcases?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTest and QFETCH

    Quote Originally Posted by ManuMies View Post
    Is there any simple way to read the test data from file instead of manually defining the test data with _data-functions? Or do I just have to make a file reader...
    Read data from file/db from within the _data() method and fill the test vector with it.

    And when I create test class, which uses private slots as test cases, can I still use private functions without messing up the testcases?
    Yes, just don't declare them as slots.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3

    Question Re: QTest and QFETCH

    Thanks, that's what I thought.

    And other thing about testing, is there any way to monitor the heapsize with testcases, so I can check if my code is leaking memory? Like UHEAP macros in symbian?

    Qt Code:
    1. __UHEAP_MARK;
    2. QString* string = new QString();
    3. string->copy("test");
    4. delete string;
    5. __UHEAP_MARKEND;
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTest and QFETCH

    Qt itself doesn't have such capabilities. There are dedicated tools for that such as Valgrind.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5

    Default Re: QTest and QFETCH

    Are you saying that there is no way to see, how much memory qt application has currently allocated? Then is it possible by using native C?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTest and QFETCH

    Quote Originally Posted by ManuMies View Post
    Are you saying that there is no way to see, how much memory qt application has currently allocated?
    Not by using means built into Qt.
    Then is it possible by using native C?
    For Linux there is a way. There are system calls returning such information and you can also look into /proc/ to see details about your process. For other platforms - that I do not know.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    May 2009
    Posts
    61
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    5
    Thanked 6 Times in 6 Posts

    Default Re: QTest and QFETCH

    To get back to the original question... I'm trying to read my test cases from an XML file. There I wanted to define the columns and the rows. First case is checking if the program has the right name

    Qt Code:
    1. TDataLoader::fillData(meth) {
    2. QDomElement m = m_Root.firstChildElement(meth);
    3. QDomElement cols = m.firstChildElement(tagColumns);
    4. for(QDomElement col=cols.firstChildElement(tagColumn); !col.isNull(); col=col.nextSiblingElement(tagColumn)) {
    5. QString name = col.attribute(entryName);
    6. QString type = col.attribute(entryType).toLower();
    7. // Simplifying: here is type checking
    8. QTest::addColumn<QString>(name.toLatin1());
    9. }
    10. ...
    11. QDomElement rows = m.firstChildElement(tagRows);
    12. for(QDomElement row=rows.firstChildElement(tagRow); !row.isNull(); row=row.nextSiblingElement(tagRow)) {
    13. QString name = row.attribute(entryName);
    14. QTestData& values = QTest::newRow(name.toLatin1());
    15. QDomNamedNodeMap attrs = row.attributes();
    16. for(int i=0; i<attrs.count(); i++) {
    17. QDomNode node = attrs.item(i);
    18. // Simplifying: needs type casting
    19. values << row.attribute(node.nodeName());
    20. }
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 

    In the test method, I call fillData with the method's name (m_Data is the instance of the data loader):

    Qt Code:
    1. void TTestRunner::testProgram_data()
    2. {
    3. m_Data.fillData("testProgram");
    4. }
    5. void TTestRunner::testProgram()
    6. {
    7. QFETCH(QString, title);
    8. QCOMPARE(QCoreApplication::applicationName(), title);
    9. }
    To copy to clipboard, switch view to plain text mode 

    but what I get is an error:
    Qt Code:
    1. QFETCH: Requested testdata 'title' not available, check your _data function.
    To copy to clipboard, switch view to plain text mode 

    Is it wrong to add additional data to the QTestData reference or am I missing something? The XML file is read correctly:

    Qt Code:
    1. <?xml version="1.0" encoding="utf-8" ?>
    2. <Data>
    3. <testProgram>
    4. <columns>
    5. <column name="title" type="QString" />
    6. </columns>
    7. <rows>
    8. <row name="title" value="targs" />
    9. </rows>
    10. </testProgram>
    11. </Data>
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTest and QFETCH

    Qt Code:
    1. QTest::addColumn<QString>(name.toLatin1());
    To copy to clipboard, switch view to plain text mode 
    This should be:
    Qt Code:
    1. QTest::addColumn<QString>("title");
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    auba (13th June 2009)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.