diff options
author | Liang Qi <liang.qi@qt.io> | 2016-08-25 14:20:33 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2016-08-25 16:08:09 +0000 |
commit | 13680ceb9a468f824e24e448e932eed3a4ad9007 (patch) | |
tree | 5b8441f3cfc6e2e012172795b9a83f0adc8798fc /tests | |
parent | 095abb192577d61215fcf7ea3a55338c54a3c4b0 (diff) | |
parent | c7cdf3aac7ef9571ce0c0cf25a2c8455c7604451 (diff) |
Merge "Merge remote-tracking branch 'origin/5.6' into 5.7" into refs/staging/5.7
Diffstat (limited to 'tests')
5 files changed, 146 insertions, 61 deletions
diff --git a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp index 1b0ac7a8bc..bd53aa69fe 100644 --- a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp +++ b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp @@ -464,6 +464,19 @@ int throwFunctionReturn() return 0; } +class SlowTask : public QRunnable +{ +public: + static QAtomicInt cancel; + void run() Q_DECL_OVERRIDE { + int iter = 60; + while (--iter && !cancel.load()) + QThread::currentThread()->msleep(25); + } +}; + +QAtomicInt SlowTask::cancel; + void tst_QtConcurrentRun::exceptions() { QThreadPool pool; @@ -504,6 +517,30 @@ void tst_QtConcurrentRun::exceptions() } if (!caught) QFAIL("did not get exception"); + + caught = false; + try { + QtConcurrent::run(&pool, throwFunctionReturn).result(); + } catch (QException &) { + caught = true; + } + QVERIFY2(caught, "did not get exception"); + + // Force the task to be run on this thread. + caught = false; + QThreadPool shortPool; + shortPool.setMaxThreadCount(1); + SlowTask *st = new SlowTask(); + try { + shortPool.start(st); + QtConcurrent::run(&shortPool, throwFunctionReturn).result(); + } catch (QException &) { + caught = true; + } + + SlowTask::cancel.store(true); + + QVERIFY2(caught, "did not get exception"); } #endif diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp index 593706ac0d..61ca1a5ddd 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp +++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp @@ -127,6 +127,7 @@ tst_QMimeDatabase::tst_QMimeDatabase() void tst_QMimeDatabase::initTestCase() { + QLocale::setDefault(QLocale::c()); QVERIFY2(m_temporaryDir.isValid(), qPrintable(m_temporaryDir.errorString())); QStandardPaths::setTestModeEnabled(true); m_localMimeDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/mime"; @@ -445,6 +446,21 @@ void tst_QMimeDatabase::icons() QCOMPARE(pub.genericIconName(), QString::fromLatin1("x-office-document")); } +void tst_QMimeDatabase::comment() +{ + struct RestoreLocale + { + ~RestoreLocale() { QLocale::setDefault(QLocale::c()); } + } restoreLocale; + + QLocale::setDefault(QLocale("de")); + QMimeDatabase db; + QMimeType directory = db.mimeTypeForName(QStringLiteral("inode/directory")); + QCOMPARE(directory.comment(), QStringLiteral("Ordner")); + QLocale::setDefault(QLocale("fr")); + QCOMPARE(directory.comment(), QStringLiteral("dossier")); +} + // In here we do the tests that need some content in a temporary file. // This could also be added to shared-mime-info's testsuite... void tst_QMimeDatabase::mimeTypeForFileWithContent() diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h index 06e875c9e2..4918dc6f4a 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h +++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h @@ -55,6 +55,7 @@ private slots: void listAliases_data(); void listAliases(); void icons(); + void comment(); void mimeTypeForFileWithContent(); void mimeTypeForUrl(); void mimeTypeForData_data(); diff --git a/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp b/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp index 447b6e8468..39f7beca6f 100644 --- a/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp +++ b/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp @@ -152,11 +152,13 @@ static void dumpConfiguration(QTextStream &str) } // On Windows, this will provide addition GPU info similar to the output of dxdiag. - const QVariant gpuInfoV = QGuiApplication::platformNativeInterface()->property("gpu"); - if (gpuInfoV.type() == QVariant::Map) { - const QString description = gpuInfoV.toMap().value(QStringLiteral("printable")).toString(); - if (!description.isEmpty()) - str << "\nGPU:\n" << description << "\n\n"; + if (QGuiApplication::platformNativeInterface()) { + const QVariant gpuInfoV = QGuiApplication::platformNativeInterface()->property("gpu"); + if (gpuInfoV.type() == QVariant::Map) { + const QString description = gpuInfoV.toMap().value(QStringLiteral("printable")).toString(); + if (!description.isEmpty()) + str << "\nGPU:\n" << description << "\n\n"; + } } } diff --git a/tests/manual/qopenglwindow/multiwindow/main.cpp b/tests/manual/qopenglwindow/multiwindow/main.cpp index e2a2d899a0..0788408b47 100644 --- a/tests/manual/qopenglwindow/multiwindow/main.cpp +++ b/tests/manual/qopenglwindow/multiwindow/main.cpp @@ -32,26 +32,22 @@ #include <QOpenGLFunctions> #include <QPainter> #include <QElapsedTimer> +#include <QCommandLineParser> +#include <QScreen> + +const char applicationDescription[] = "\n\ +This application opens multiple windows and continuously schedules updates for\n\ +them. Each of them is a separate QOpenGLWindow so there will be a separate\n\ +context and swapBuffers call for each.\n\ +\n\ +By default the swap interval is 1 so the effect of multiple blocking swapBuffers\n\ +on the main thread can be examined. (the result is likely to be different\n\ +between platforms, for example OS X is buffer queuing meaning that it can\n\ +block outside swap, resulting in perfect vsync for all three windows, while\n\ +other systems that block on swap will kill the frame rate due to blocking the\n\ +thread three times)\ +"; -// This application opens three windows and continuously schedules updates for -// them. Each of them is a separate QOpenGLWindow so there will be a separate -// context and swapBuffers call for each. -// -// By default the swap interval is 1 so the effect of three blocking swapBuffers -// on the main thread can be examined. (the result is likely to be different -// between platforms, for example OS X is buffer queuing meaning that it can -// block outside swap, resulting in perfect vsync for all three windows, while -// other systems that block on swap will kill the frame rate due to blocking the -// thread three times) -// -// Pass --novsync to set a swap interval of 0. This should give an unthrottled -// refresh on all platforms for all three windows. -// -// Passing --vsyncone sets swap interval to 1 for the first window and 0 to the -// others. -// -// Pass --extrawindows N to open N windows in addition to the default 3. -// // For reference, below is a table of some test results. // // swap interval 1 for all swap interval 1 for only one and 0 for others @@ -64,12 +60,15 @@ class Window : public QOpenGLWindow { + Q_OBJECT public: Window(int n) : idx(n) { r = g = b = fps = 0; y = 0; resize(200, 200); - t2.start(); + + connect(this, SIGNAL(frameSwapped()), SLOT(frameSwapped())); + fpsTimer.start(); } void paintGL() { @@ -101,27 +100,52 @@ public: if (y > height() - 20) y = 20; - if (t2.elapsed() > 1000) { - fps = 1000.0 / t.elapsed(); - t2.restart(); - } - t.restart(); - update(); } +public slots: + void frameSwapped() { + ++framesSwapped; + if (fpsTimer.elapsed() > 1000) { + fps = qRound(framesSwapped * (1000.0 / fpsTimer.elapsed())); + framesSwapped = 0; + fpsTimer.restart(); + } + } + private: int idx; - GLfloat r, g, b, fps; + GLfloat r, g, b; int y; - QElapsedTimer t, t2; + + int framesSwapped; + QElapsedTimer fpsTimer; + int fps; }; int main(int argc, char **argv) { QGuiApplication app(argc, argv); + + QCommandLineParser parser; + parser.setApplicationDescription(applicationDescription); + parser.addHelpOption(); + + QCommandLineOption noVsyncOption("novsync", "Disable Vsync by setting swap interval to 0. " + "This should give an unthrottled refresh on all platforms for all windows."); + parser.addOption(noVsyncOption); + + QCommandLineOption vsyncOneOption("vsyncone", "Enable Vsync only for first window, " + "by setting swap interval to 1 for the first window and 0 for the others."); + parser.addOption(vsyncOneOption); + + QCommandLineOption numWindowsOption("numwindows", "Open <N> windows instead of the default 3.", "N", "3"); + parser.addOption(numWindowsOption); + + parser.process(app); + QSurfaceFormat fmt; - if (QGuiApplication::arguments().contains(QLatin1String("--novsync"))) { + if (parser.isSet(noVsyncOption)) { qDebug("swap interval 0 (no throttling)"); fmt.setSwapInterval(0); } else { @@ -129,36 +153,41 @@ int main(int argc, char **argv) } QSurfaceFormat::setDefaultFormat(fmt); - Window w1(0); - if (QGuiApplication::arguments().contains(QLatin1String("--vsyncone"))) { - qDebug("swap interval 1 for first window only"); - QSurfaceFormat w1fmt = fmt; - w1fmt.setSwapInterval(1); - w1.setFormat(w1fmt); - fmt.setSwapInterval(0); - QSurfaceFormat::setDefaultFormat(fmt); - } - Window w2(1); - Window w3(2); - w1.setGeometry(QRect(QPoint(10, 100), w1.size())); - w2.setGeometry(QRect(QPoint(300, 100), w2.size())); - w3.setGeometry(QRect(QPoint(600, 100), w3.size())); - w1.show(); - w2.show(); - w3.show(); - - QList<QWindow *> extraWindows; - int countIdx; - if ((countIdx = QGuiApplication::arguments().indexOf(QLatin1String("--extrawindows"))) >= 0) { - int extraWindowCount = QGuiApplication::arguments().at(countIdx + 1).toInt(); - for (int i = 0; i < extraWindowCount; ++i) { - Window *w = new Window(3 + i); - extraWindows << w; - w->show(); + QRect availableGeometry = app.primaryScreen()->availableGeometry(); + + int numberOfWindows = qMax(parser.value(numWindowsOption).toInt(), 1); + QList<QWindow *> windows; + for (int i = 0; i < numberOfWindows; ++i) { + Window *w = new Window(i + 1); + windows << w; + + if (i == 0 && parser.isSet(vsyncOneOption)) { + qDebug("swap interval 1 for first window only"); + QSurfaceFormat vsyncedSurfaceFormat = fmt; + vsyncedSurfaceFormat.setSwapInterval(1); + w->setFormat(vsyncedSurfaceFormat); + fmt.setSwapInterval(0); + QSurfaceFormat::setDefaultFormat(fmt); } + + static int windowWidth = w->width() + 20; + static int windowHeight = w->height() + 20; + + static int windowsPerRow = availableGeometry.width() / windowWidth; + + int col = i; + int row = col / windowsPerRow; + col -= row * windowsPerRow; + + QPoint position = availableGeometry.topLeft(); + position += QPoint(col * windowWidth, row * windowHeight); + w->setFramePosition(position); + w->show(); } int r = app.exec(); - qDeleteAll(extraWindows); + qDeleteAll(windows); return r; } + +#include "main.moc" |