diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qpainter/tst_qpainter.cpp | 40 | ||||
-rw-r--r-- | tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp | 38 | ||||
-rw-r--r-- | tests/auto/qsoftkeymanager/tst_qsoftkeymanager.cpp | 56 | ||||
-rw-r--r-- | tests/auto/qwidget/tst_qwidget.cpp | 10 |
4 files changed, 130 insertions, 14 deletions
diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp index e4f267d..8ed83cb 100644 --- a/tests/auto/qpainter/tst_qpainter.cpp +++ b/tests/auto/qpainter/tst_qpainter.cpp @@ -238,6 +238,8 @@ private slots: void taskQT4444_dontOverflowDashOffset(); + void painterBegin(); + private: void fillData(); QColor baseColor( int k, int intensity=255 ); @@ -4312,5 +4314,43 @@ void tst_QPainter::taskQT4444_dontOverflowDashOffset() QVERIFY(true); // Don't crash } +void tst_QPainter::painterBegin() +{ + QImage nullImage; + QImage indexed8Image(16, 16, QImage::Format_Indexed8); + QImage rgb32Image(16, 16, QImage::Format_RGB32); + QImage argb32Image(16, 16, QImage::Format_ARGB32_Premultiplied); + + QPainter p; + + // Painting on null image should fail. + QVERIFY(!p.begin(&nullImage)); + + // Check that the painter is not messed up by using it on another image. + QVERIFY(p.begin(&rgb32Image)); + QVERIFY(p.end()); + + // If painting on indexed8 image fails, the painter state should still be OK. + if (p.begin(&indexed8Image)) + QVERIFY(p.end()); + QVERIFY(p.begin(&rgb32Image)); + QVERIFY(p.end()); + + // Try opening a painter on the two different images. + QVERIFY(p.begin(&rgb32Image)); + QVERIFY(!p.begin(&argb32Image)); + QVERIFY(p.end()); + + // Try opening two painters on the same image. + QVERIFY(p.begin(&rgb32Image)); + QPainter q; + QVERIFY(!q.begin(&rgb32Image)); + QVERIFY(!q.end()); + QVERIFY(p.end()); + + // Try ending an inactive painter. + QVERIFY(!p.end()); +} + QTEST_MAIN(tst_QPainter) #include "tst_qpainter.moc" diff --git a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp index 283e489..82c8ccd 100644 --- a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp +++ b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp @@ -109,6 +109,7 @@ private slots: void extension_invoctaion(); void extension(); void isEvaluatingInExtension(); + void hasUncaughtException(); private: double m_testProperty; @@ -2182,5 +2183,42 @@ void tst_QScriptEngineAgent::isEvaluatingInExtension() QVERIFY(spy->wasEvaluating); } +class NewSpy :public QScriptEngineAgent +{ + bool m_result; +public: + NewSpy(QScriptEngine* eng) : QScriptEngineAgent(eng), m_result(false) {} + void functionExit (qint64, const QScriptValue &scriptValue) + { + if (engine()->hasUncaughtException()) m_result = true; + } + + bool isPass() { return m_result; } + void reset() { m_result = false; } +}; + +void tst_QScriptEngineAgent::hasUncaughtException() +{ + QScriptEngine eng; + NewSpy* spy = new NewSpy(&eng); + eng.setAgent(spy); + QScriptValue scriptValue; + + // Check unhandled exception. + eng.evaluate("function init () {Unknown.doSth ();}"); + scriptValue = QScriptValue(eng.globalObject().property("init")).call(); + QVERIFY(eng.hasUncaughtException()); + QVERIFY2(spy->isPass(), "At least one of a functionExit event should set hasUncaughtException flag."); + spy->reset(); + + // Check catched exception. + eng.evaluate("function innerFoo() { throw new Error('ciao') }"); + eng.evaluate("function foo() {try { innerFoo() } catch (e) {} }"); + scriptValue = QScriptValue(eng.globalObject().property("foo")).call(); + QVERIFY(!eng.hasUncaughtException()); + QVERIFY2(spy->isPass(), "At least one of a functionExit event should set hasUncaughtException flag."); +} + + QTEST_MAIN(tst_QScriptEngineAgent) #include "tst_qscriptengineagent.moc" diff --git a/tests/auto/qsoftkeymanager/tst_qsoftkeymanager.cpp b/tests/auto/qsoftkeymanager/tst_qsoftkeymanager.cpp index 832605e..6efa85b 100644 --- a/tests/auto/qsoftkeymanager/tst_qsoftkeymanager.cpp +++ b/tests/auto/qsoftkeymanager/tst_qsoftkeymanager.cpp @@ -43,9 +43,15 @@ #include "qevent.h" #include "qdialog.h" +#include "qpushbutton.h" #include "qdialogbuttonbox.h" #include "private/qsoftkeymanager_p.h" +#ifdef Q_WS_S60 +static const int s60CommandStart = 6000; +#endif + + class tst_QSoftKeyManager : public QObject { Q_OBJECT @@ -171,22 +177,52 @@ void tst_QSoftKeyManager::handleCommand() } /* - This tests that softkey enable state follows the state of widget that owns the action - to which the softkey is related to. + This tests that the state of a widget that owns softkey action is respected when handling the softkey + command. */ void tst_QSoftKeyManager::checkSoftkeyEnableStates() { - QWidget w1, w2; - w1.setEnabled(false); - w2.setEnabled(true); + QDialog w; + QDialogButtonBox *buttons = new QDialogButtonBox( + QDialogButtonBox::RestoreDefaults | QDialogButtonBox::Help, + Qt::Horizontal, + &w); + QPushButton *pBDefaults = buttons->button(QDialogButtonBox::RestoreDefaults); + QPushButton *pBHelp = buttons->button(QDialogButtonBox::Help); + pBHelp->setEnabled(false); + w.show(); + QApplication::processEvents(); - QAction *disabledAction = QSoftKeyManager::createAction(QSoftKeyManager::OkSoftKey, &w1); - QAction *enabledAction = QSoftKeyManager::createAction(QSoftKeyManager::OkSoftKey, &w2); + QSignalSpy spy0(w.actions()[0], SIGNAL(triggered())); //restore defaults action + QSignalSpy spy1(w.actions()[1], SIGNAL(triggered())); //disabled help action - QVERIFY(disabledAction->isEnabled()==false); - QVERIFY(enabledAction->isEnabled()==true); + //Verify that enabled button gets all the action trigger signals and + //disabled button gets none. + for (int i = 0; i < 10; i++) { + //simulate "Restore Defaults" softkey press + qApp->symbianHandleCommand(s60CommandStart); + //simulate "help" softkey press + qApp->symbianHandleCommand(s60CommandStart + 1); + } + QApplication::processEvents(); + QCOMPARE(spy0.count(), 10); + QCOMPARE(spy1.count(), 0); + spy0.clear(); + spy1.clear(); + + for (int i = 0; i < 10; i++) { + //simulate "Restore Defaults" softkey press + qApp->symbianHandleCommand(s60CommandStart); + //simulate "help" softkey press + qApp->symbianHandleCommand(s60CommandStart + 1); + //switch enabled button to disabled and vice versa + pBHelp->setEnabled(!pBHelp->isEnabled()); + pBDefaults->setEnabled(!pBDefaults->isEnabled()); + } + QApplication::processEvents(); + QCOMPARE(spy0.count(), 5); + QCOMPARE(spy1.count(), 5); } - QTEST_MAIN(tst_QSoftKeyManager) #include "tst_qsoftkeymanager.moc" diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index 758821b..1b898f4 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -4362,11 +4362,13 @@ public: } protected: - bool event(QEvent *e){ - if(e->type() == QEvent::WinIdChange) + bool event(QEvent *e) + { + if (e->type() == QEvent::WinIdChange) { ++m_winIdChangeEventCount; - else - return QWidget::event(e); + return true; + } + return QWidget::event(e); } public: int m_winIdChangeEventCount; |