diff options
Diffstat (limited to 'tests/auto/qapplication')
-rw-r--r-- | tests/auto/qapplication/desktopsettingsaware/desktopsettingsaware.pro | 9 | ||||
-rw-r--r-- | tests/auto/qapplication/test/test.pro | 8 | ||||
-rw-r--r-- | tests/auto/qapplication/tst_qapplication.cpp | 260 |
3 files changed, 262 insertions, 15 deletions
diff --git a/tests/auto/qapplication/desktopsettingsaware/desktopsettingsaware.pro b/tests/auto/qapplication/desktopsettingsaware/desktopsettingsaware.pro index 904a62a..93a03db 100644 --- a/tests/auto/qapplication/desktopsettingsaware/desktopsettingsaware.pro +++ b/tests/auto/qapplication/desktopsettingsaware/desktopsettingsaware.pro @@ -3,13 +3,18 @@ ###################################################################### TEMPLATE = app +!symbian*: { DEPENDPATH += . INCLUDEPATH += . -wince*:TARGET = ../desktopsettingsaware +} +wince*|symbian*:TARGET = ../desktopsettingsaware + # Input SOURCES += main.cpp CONFIG += qt warn_on create_prl link_prl CONFIG -= app_bundle + +!symbian*: { OBJECTS_DIR=.obj/debug-shared MOC_DIR=.moc/debug-shared - +} diff --git a/tests/auto/qapplication/test/test.pro b/tests/auto/qapplication/test/test.pro index cda7940..7c3de3c 100644 --- a/tests/auto/qapplication/test/test.pro +++ b/tests/auto/qapplication/test/test.pro @@ -11,6 +11,14 @@ wince* { DEPLOYMENT = additional deploy someTest } +symbian*: { + additional.sources = ../desktopsettingsaware/desktopsettingsaware.exe + additional.path = desktopsettingsaware + someTest.sources = test.pro + someTest.path = test + DEPLOYMENT = additional deploy someTest +} + win32 { CONFIG(debug, debug|release) { TARGET = ../../debug/tst_qapplication diff --git a/tests/auto/qapplication/tst_qapplication.cpp b/tests/auto/qapplication/tst_qapplication.cpp index 2bfeea0..abcacef 100644 --- a/tests/auto/qapplication/tst_qapplication.cpp +++ b/tests/auto/qapplication/tst_qapplication.cpp @@ -48,6 +48,7 @@ #include "qabstracteventdispatcher.h" #include <QtGui> +#include "private/qapplication_p.h" #include "private/qstylesheetstyle_p.h" #ifdef Q_OS_WINCE #include <windows.h> @@ -56,6 +57,21 @@ //TESTED_CLASS= //TESTED_FILES= +#if defined(Q_OS_SYMBIAN) +// In Symbian, the PluginsPath doesn't specify the only absolute path; just the dir that can be found on any drive +static void addExpectedSymbianPluginsPath(QStringList& expected) +{ + QString installPathPlugins = QDir::fromNativeSeparators(QLibraryInfo::location(QLibraryInfo::PluginsPath)); + QFileInfoList driveList = QDir::drives(); + QListIterator<QFileInfo> iter(driveList); + while (iter.hasNext()) { + QFileInfo testFi(iter.next().canonicalPath().append(installPathPlugins)); + if (testFi.exists()) + expected << testFi.canonicalFilePath(); + } +} +#endif + class tst_QApplication : public QObject { Q_OBJECT @@ -68,6 +84,7 @@ public slots: void init(); void cleanup(); private slots: + void sendEventsOnProcessEvents(); // this must be the first test void getSetCheck(); void staticSetup(); @@ -117,8 +134,36 @@ private slots: void windowsCommandLine_data(); void windowsCommandLine(); + + void touchEventPropagation(); }; +class EventSpy : public QObject +{ + Q_OBJECT + +public: + QList<int> recordedEvents; + bool eventFilter(QObject *, QEvent *event) + { + recordedEvents.append(event->type()); + return false; + } +}; + +void tst_QApplication::sendEventsOnProcessEvents() +{ + int argc = 0; + QApplication app(argc, 0, QApplication::GuiServer); + + EventSpy spy; + app.installEventFilter(&spy); + + QCoreApplication::postEvent(&app, new QEvent(QEvent::Type(QEvent::User + 1))); + QCoreApplication::processEvents(); + QVERIFY(spy.recordedEvents.contains(QEvent::User + 1)); +} + class MyInputContext : public QInputContext { public: @@ -752,9 +797,9 @@ void tst_QApplication::libraryPaths() // current Path. Therefore we need to identify it ourselves // here for the test. QFileInfo filePath; - wchar_t module_name[256]; - GetModuleFileNameW(0, module_name, sizeof(module_name) / sizeof(wchar_t)); - filePath = QString::fromUtf16((ushort *)module_name); + wchar_t module_name[MAX_PATH]; + GetModuleFileName(0, module_name, MAX_PATH); + filePath = QString::fromWCharArray(module_name); QString testDir = filePath.path() + "/test"; #endif QApplication::setLibraryPaths(QStringList() << testDir); @@ -784,7 +829,13 @@ void tst_QApplication::libraryPaths() QStringList actual = QApplication::libraryPaths(); actual.sort(); +#if defined(Q_OS_SYMBIAN) + QStringList expected; + addExpectedSymbianPluginsPath(expected); + expected << appDirPath; +#else QStringList expected = QSet<QString>::fromList((QStringList() << installPathPlugins << appDirPath)).toList(); +#endif expected.sort(); QVERIFY2(isPathListIncluded(actual, expected), @@ -887,7 +938,11 @@ void tst_QApplication::libraryPaths_qt_plugin_path() void tst_QApplication::libraryPaths_qt_plugin_path_2() { -#ifdef Q_OS_UNIX +#ifdef Q_OS_SYMBIAN + QByteArray validPath = "C:\\data"; + QByteArray nonExistentPath = "Z:\\nonexistent"; + QByteArray pluginPath = validPath + ";" + nonExistentPath; +#elif defined(Q_OS_UNIX) QByteArray validPath = QDir("/tmp").canonicalPath().toLatin1(); QByteArray nonExistentPath = "/nonexistent"; QByteArray pluginPath = validPath + ":" + nonExistentPath; @@ -912,19 +967,25 @@ void tst_QApplication::libraryPaths_qt_plugin_path_2() QApplication app(argc, &argv0, QApplication::GuiServer); // library path list should contain the default plus the one valid path +#if defined(Q_OS_SYMBIAN) + // In Symbian, the PluginsPath doesn't specify the only absolute path; just the dir that can be found on any drive + QStringList expected; + addExpectedSymbianPluginsPath(expected); + expected << QDir(app.applicationDirPath()).canonicalPath() + << QDir(QDir::fromNativeSeparators(QString::fromLatin1(validPath))).canonicalPath(); +#else QStringList expected = QStringList() << QLibraryInfo::location(QLibraryInfo::PluginsPath) << QDir(app.applicationDirPath()).canonicalPath() << QDir(QDir::fromNativeSeparators(QString::fromLatin1(validPath))).canonicalPath(); -#ifdef Q_OS_WINCE +# ifdef Q_OS_WINCE expected = QSet<QString>::fromList(expected).toList(); +# endif #endif QVERIFY2(isPathListIncluded(app.libraryPaths(), expected), qPrintable("actual:\n - " + app.libraryPaths().join("\n - ") + "\nexpected:\n - " + expected.join("\n - "))); - - qputenv("QT_PLUGIN_PATH", QByteArray()); } { @@ -936,13 +997,19 @@ void tst_QApplication::libraryPaths_qt_plugin_path_2() // the environment variable here doesn't work qputenv("QT_PLUGIN_PATH", pluginPath); - // library path list should contain the default plus the one valid path + // library path list should contain the default +#if defined(Q_OS_SYMBIAN) + QStringList expected; + addExpectedSymbianPluginsPath(expected); + expected << app.applicationDirPath(); +#else QStringList expected = QStringList() << QLibraryInfo::location(QLibraryInfo::PluginsPath) << app.applicationDirPath(); -#ifdef Q_OS_WINCE +# ifdef Q_OS_WINCE expected = QSet<QString>::fromList(expected).toList(); +# endif #endif QVERIFY(isPathListIncluded(app.libraryPaths(), expected)); @@ -1108,15 +1175,15 @@ void DeleteLaterWidget::runTest() connect(w, SIGNAL(destroyed()), this, SLOT(childDeleted())); w->deleteLater(); - Q_ASSERT(!child_deleted); + QVERIFY(!child_deleted); QDialog dlg; QTimer::singleShot(500, &dlg, SLOT(reject())); dlg.exec(); - Q_ASSERT(!child_deleted); + QVERIFY(!child_deleted); app->processEvents(); - Q_ASSERT(!child_deleted); + QVERIFY(!child_deleted); QTimer::singleShot(500, this, SLOT(checkDeleteLater())); @@ -1127,7 +1194,7 @@ void DeleteLaterWidget::runTest() void DeleteLaterWidget::checkDeleteLater() { - Q_ASSERT(child_deleted); + QVERIFY(child_deleted); close(); } @@ -1379,6 +1446,7 @@ void tst_QApplication::testDeleteLaterProcessEvents() */ void tst_QApplication::desktopSettingsAware() { +#ifndef QT_NO_PROCESS QProcess testProcess; #ifdef Q_OS_WINCE int argc = 0; @@ -1389,6 +1457,13 @@ void tst_QApplication::desktopSettingsAware() testProcess.start("desktopsettingsaware/debug/desktopsettingsaware"); #elif defined(Q_OS_WIN) testProcess.start("desktopsettingsaware/release/desktopsettingsaware"); +#elif defined(Q_OS_SYMBIAN) + testProcess.start("desktopsettingsaware"); +#if defined(Q_CC_NOKIAX86) + QEXPECT_FAIL("", "QProcess on Q_CC_NOKIAX86 cannot launch another Qt application, due to DLL conflicts.", Abort); + // TODO: Remove XFAIL, as soon as we can launch Qt applications from within Qt applications on Symbian + QVERIFY(testProcess.error() != QProcess::FailedToStart); +#endif // defined(Q_CC_NOKIAX86) #else testProcess.start("desktopsettingsaware/desktopsettingsaware"); #endif @@ -1396,6 +1471,7 @@ void tst_QApplication::desktopSettingsAware() QVERIFY(testProcess.waitForFinished(10000)); QCOMPARE(int(testProcess.state()), int(QProcess::NotRunning)); QVERIFY(int(testProcess.error()) != int(QProcess::Crashed)); +#endif } void tst_QApplication::setActiveWindow() @@ -1773,6 +1849,164 @@ void tst_QApplication::windowsCommandLine() #endif } +class TouchEventPropagationTestWidget : public QWidget +{ + Q_OBJECT + +public: + bool seenTouchEvent, acceptTouchEvent, seenMouseEvent, acceptMouseEvent; + + TouchEventPropagationTestWidget(QWidget *parent = 0) + : QWidget(parent), seenTouchEvent(false), acceptTouchEvent(false), seenMouseEvent(false), acceptMouseEvent(false) + { } + + void reset() + { + seenTouchEvent = acceptTouchEvent = seenMouseEvent = acceptMouseEvent = false; + } + + bool event(QEvent *event) + { + switch (event->type()) { + case QEvent::MouseButtonPress: + case QEvent::MouseMove: + case QEvent::MouseButtonRelease: + // qDebug() << objectName() << "seenMouseEvent = true"; + seenMouseEvent = true; + event->setAccepted(acceptMouseEvent); + break; + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: + // qDebug() << objectName() << "seenTouchEvent = true"; + seenTouchEvent = true; + event->setAccepted(acceptTouchEvent); + break; + default: + return QWidget::event(event); + } + return true; + } +}; + +void tst_QApplication::touchEventPropagation() +{ + int argc = 1; + QApplication app(argc, &argv0, QApplication::GuiServer); + + QList<QTouchEvent::TouchPoint> pressedTouchPoints; + QTouchEvent::TouchPoint press(0); + press.setState(Qt::TouchPointPressed); + pressedTouchPoints << press; + + QList<QTouchEvent::TouchPoint> releasedTouchPoints; + QTouchEvent::TouchPoint release(0); + release.setState(Qt::TouchPointReleased); + releasedTouchPoints << release; + + { + // touch event behavior on a window + TouchEventPropagationTestWidget window; + window.setObjectName("1. window"); + + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + QVERIFY(!window.seenTouchEvent); + QVERIFY(!window.seenMouseEvent); + + window.reset(); + window.setAttribute(Qt::WA_AcceptTouchEvents); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + QVERIFY(window.seenTouchEvent); + QVERIFY(!window.seenMouseEvent); + + window.reset(); + window.acceptTouchEvent = true; + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + QVERIFY(window.seenTouchEvent); + QVERIFY(!window.seenMouseEvent); + } + + { + // touch event behavior on a window with a child widget + TouchEventPropagationTestWidget window; + window.setObjectName("2. window"); + TouchEventPropagationTestWidget widget(&window); + widget.setObjectName("2. widget"); + + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + QVERIFY(!widget.seenTouchEvent); + QVERIFY(!widget.seenMouseEvent); + QVERIFY(!window.seenTouchEvent); + QVERIFY(!window.seenMouseEvent); + + window.reset(); + widget.reset(); + widget.setAttribute(Qt::WA_AcceptTouchEvents); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + QVERIFY(widget.seenTouchEvent); + QVERIFY(!widget.seenMouseEvent); + QVERIFY(!window.seenTouchEvent); + QVERIFY(!window.seenMouseEvent); + + window.reset(); + widget.reset(); + widget.acceptMouseEvent = true; + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + QVERIFY(widget.seenTouchEvent); + QVERIFY(!widget.seenMouseEvent); + QVERIFY(!window.seenTouchEvent); + QVERIFY(!window.seenMouseEvent); + + window.reset(); + widget.reset(); + widget.acceptTouchEvent = true; + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + QVERIFY(widget.seenTouchEvent); + QVERIFY(!widget.seenMouseEvent); + QVERIFY(!window.seenTouchEvent); + QVERIFY(!window.seenMouseEvent); + + window.reset(); + widget.reset(); + widget.setAttribute(Qt::WA_AcceptTouchEvents, false); + window.setAttribute(Qt::WA_AcceptTouchEvents); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + QVERIFY(!widget.seenTouchEvent); + QVERIFY(!widget.seenMouseEvent); + QVERIFY(window.seenTouchEvent); + QVERIFY(!window.seenMouseEvent); + + window.reset(); + widget.reset(); + window.acceptTouchEvent = true; + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + QVERIFY(!widget.seenTouchEvent); + QVERIFY(!widget.seenMouseEvent); + QVERIFY(window.seenTouchEvent); + QVERIFY(!window.seenMouseEvent); + + window.reset(); + widget.reset(); + widget.acceptMouseEvent = true; // doesn't matter, touch events are propagated first + window.acceptTouchEvent = true; + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints); + qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints); + QVERIFY(!widget.seenTouchEvent); + QVERIFY(!widget.seenMouseEvent); + QVERIFY(window.seenTouchEvent); + QVERIFY(!window.seenMouseEvent); + } +} + //QTEST_APPLESS_MAIN(tst_QApplication) int main(int argc, char *argv[]) { |