Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, June 2007
Unit tests in QT


Message 1 in thread

Hi,

I am trying to write a unit test using QTest but am getting errors when I 
follow the tutorial in QT Assistant, see 
http://doc.trolltech.com/4.3/qtestlib-tutorial.html

Here is my testqstring.h file
********************************

 #include <QtTest/QtTest>

 class TestQString: public QObject
 {
     Q_OBJECT
 private slots:
     void toUpper();
 };

 void TestQString::toUpper()
 {
     QString str = "Hello";
     QCOMPARE(str.toUpper(), QString("HELLO"));
 }

 QTEST_MAIN(TestQString)
 #include "testqstring.moc"

Then from the command like I run
**************************************
 /myTestDirectory$ qmake -project "CONFIG += qtestlib"
 /myTestDirectory$ qmake
 /myTestDirectory$ make

Then I get the error
**********************

/usr/local/Trolltech/Qt-4.3.0/bin/moc -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/mnt/extra/NotBackedUp/qt4-built/Trolltech/Qt-4.3.0/mkspecs/linux-g++ -I. -I/mnt/extra/NotBackedUp/qt4-built/Trolltech/Qt-4.3.0/include/QtCore -I/mnt/extra/NotBackedUp/qt4-built/Trolltech/Qt-4.3.0/include/QtCore -I/mnt/extra/NotBackedUp/qt4-built/Trolltech/Qt-4.3.0/include/QtGui -I/mnt/extra/NotBackedUp/qt4-built/Trolltech/Qt-4.3.0/include/QtGui -I/mnt/extra/NotBackedUp/qt4-built/Trolltech/Qt-4.3.0/include -I/mnt/extra/NotBackedUp/qt4-built/Trolltech/Qt-4.3.0/include/QtTest -I. -I. -I. 
testqstring.h -o moc_testqstring.cpp
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/mnt/extra/NotBackedUp/qt4-built/Trolltech/Qt-4.3.0/mkspecs/linux-g++ -I. -I/mnt/extra/NotBackedUp/qt4-built/Trolltech/Qt-4.3.0/include/QtCore -I/mnt/extra/NotBackedUp/qt4-built/Trolltech/Qt-4.3.0/include/QtCore -I/mnt/extra/NotBackedUp/qt4-built/Trolltech/Qt-4.3.0/include/QtGui -I/mnt/extra/NotBackedUp/qt4-built/Trolltech/Qt-4.3.0/include/QtGui -I/mnt/extra/NotBackedUp/qt4-built/Trolltech/Qt-4.3.0/include -I/mnt/extra/NotBackedUp/qt4-built/Trolltech/Qt-4.3.0/include/QtTest -I. -I. -I. -o 
moc_testqstring.o moc_testqstring.cpp
In file included from moc_testqstring.cpp:10:
testqstring.h:40:28: error: testqstring.moc: No such file or directory
/mnt/extra/NotBackedUp/qt4-built/Trolltech/Qt-4.3.0/include/QtTest/../../tools/qtestlib/src/qtestkeyboard.h: 
In function âvoid QTest::simulateEvent(QWidget*, bool, int, 
Qt::KeyboardModifiers, QString, bool, int)â:
/mnt/extra/NotBackedUp/qt4-built/Trolltech/Qt-4.3.0/include/QtTest/../../tools/qtestlib/src/qtestkeyboard.h:60: 
warning: dereferencing type-punned pointer will break strict-aliasing rules
/mnt/extra/NotBackedUp/qt4-built/Trolltech/Qt-4.3.0/include/QtTest/../../tools/qtestlib/src/qtestmouse.h: 
In function âvoid QTest::mouseEvent(QTest::MouseAction, QWidget*, 
Qt::MouseButton, Qt::KeyboardModifiers, QPoint, int)â:
/mnt/extra/NotBackedUp/qt4-built/Trolltech/Qt-4.3.0/include/QtTest/../../tools/qtestlib/src/qtestmouse.h:93: 
warning: dereferencing type-punned pointer will break strict-aliasing rules
make: *** [moc_testqstring.o] Error 1

The problem?
**************************
I'm guessing it's got to do with the "testqstring.h:40:28: error: 
testqstring.moc: No such file or directory" line. How does testqstring.moc 
get generated? I don't understand this bit at all. Help! I have tried 
changing  #include "testqstring.moc" to  #include "moc_testqstring.cpp" in 
case this was the correct thing to do but still got errors :(

--
 [ signature omitted ] 

Message 2 in thread

On Mon, 2007-06-25 at 16:08 +1200, Declan McGrath wrote:
> Hi,
> 
> I am trying to write a unit test using QTest but am getting errors when I 
> follow the tutorial in QT Assistant, see 
> http://doc.trolltech.com/4.3/qtestlib-tutorial.html
> 
> Here is my testqstring.h file
> ********************************
> 

[snip]

> The problem?
> **************************
> I'm guessing it's got to do with the "testqstring.h:40:28: error: 
> testqstring.moc: No such file or directory" line. How does testqstring.moc 
> get generated? I don't understand this bit at all. Help! I have tried 
> changing  #include "testqstring.moc" to  #include "moc_testqstring.cpp" in 
> case this was the correct thing to do but still got errors :(
> 

In the appropriate circumstances, MOC generates testqstring.moc. The
tutorial page says "Note that if both the declaration and the
implementation of our test class are in a .cpp file, we also need to
include the generated moc file to make Qt's introspection work."

You have put the declaration and implementation in a .h file. Cleanup
with
    make distclean
then rename testqstring.h as testqstring.cpp (or use the one linked from
the tutorial) and start your build steps again.

Regards,

Stephen Jackson



--
 [ signature omitted ] 

Message 3 in thread

Thanks. Spot on!

Dec

On Monday 25 June 2007 16:42, Stephen Jackson wrote:
> On Mon, 2007-06-25 at 16:08 +1200, Declan McGrath wrote:
> > Hi,
> >
> > I am trying to write a unit test using QTest but am getting errors when I
> > follow the tutorial in QT Assistant, see
> > http://doc.trolltech.com/4.3/qtestlib-tutorial.html
> >
> > Here is my testqstring.h file
> > ********************************
>
> [snip]
>
> > The problem?
> > **************************
> > I'm guessing it's got to do with the "testqstring.h:40:28: error:
> > testqstring.moc: No such file or directory" line. How does
> > testqstring.moc get generated? I don't understand this bit at all. Help!
> > I have tried changing  #include "testqstring.moc" to  #include
> > "moc_testqstring.cpp" in case this was the correct thing to do but still
> > got errors :(
>
> In the appropriate circumstances, MOC generates testqstring.moc. The
> tutorial page says "Note that if both the declaration and the
> implementation of our test class are in a .cpp file, we also need to
> include the generated moc file to make Qt's introspection work."
>
> You have put the declaration and implementation in a .h file. Cleanup
> with
>     make distclean
> then rename testqstring.h as testqstring.cpp (or use the one linked from
> the tutorial) and start your build steps again.
>
> Regards,
>
> Stephen Jackson
>
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ]