QTestLib and signal emission.
-
I am not sure whats wrong here.. shouldn't QTest::mouseClick emit a signal ?
@void FinallyTest::testCase1()
{
QCheckBox tmp;
tmp.show();QSignalSpy spy(&tmp, SIGNAL(clicked(bool))); QTest::mouseClick( &tmp, Qt::LeftButton ); // simulates signal emision ??? QCOMPARE(spy.count(), 1);
}@
FAIL! : FinallyTest::testCase1() Compared values are not the same
Actual (spy.count()): 0
Expected (1): 1 -
According to the source code for QTest::mouseClick which is:
@switch (action)
{
case MousePress:
me = QMouseEvent(QEvent::MouseButtonPress, pos, widget->mapToGlobal(pos), button, button, stateKey);
break;case MouseRelease: me = QMouseEvent(QEvent::MouseButtonRelease, pos, widget->mapToGlobal(pos), button, 0, stateKey); break; case MouseDClick: me = QMouseEvent(QEvent::MouseButtonDblClick, pos, widget->mapToGlobal(pos), button, button, stateKey); break; case MouseMove: QCursor::setPos(widget->mapToGlobal(pos)); qApp->processEvents(); return; default: QTEST_ASSERT(false);
}@
it uses QMouseEvent, so I would think that no signal is emitted, but QMouseEvent is generated.
-
Great, thanks for the good explanation.
I see that this is excellent way how to investigate problems (and learn more deeply Qt source). I am kind of new to programming, no real experience - university does not count in my opinion =) Maybe or (and others as well) can explain me how to properly browse through Qt modules?
For now i see that each module has *.pro file so i can open each module in Qt Creator as project. Seems fine, but just in case - is there any better way?
Also i am not clear in which file did you find the source code for QTest::mouseClick? in .\qt\src\testlib\ I can see the qtest.h file but not the qtest.cpp ?
Thanks in advance.
-
[quote author="Thanatos" date="1287584432"]
I see that this is excellent way how to investigate problems (and learn more deeply Qt source). I am kind of new to programming, no real experience - university does not count in my opinion =) Maybe or (and others as well) can explain me how to properly browse through Qt modules?For now i see that each module has *.pro file so i can open each module in Qt Creator as project. Seems fine, but just in case - is there any better way?
[/quote]University, I wish I could go to the university again. Just love that time. Anyway, I don't know how to describe the better way. It's just everyone is doing this in his own and more convenient way. I'll tell you how I do it. I read Qt's source code if I have some problems or if I don't understand completely, the way something works. Getting to know Qt modules starts for me from getting to know its API.
[quote author="Thanatos" date="1287584432"]
Also i am not clear in which file did you find the source code for QTest::mouseClick? in .\qt\src\testlib\ I can see the qtest.h file but not the qtest.cpp ?Thanks in advance. [/quote]
I found it in this file src/testlib/qtestmouse.h. The implementation of mouseClick is in this header. You will find several signatures for it.