From bba6e49261968c36ddbc7a7f1af4b702dda3981b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trond=20Kjern=C3=A5sen?= Date: Wed, 25 Aug 2010 14:16:29 +0200 Subject: Rework some of the threaded tests a bit. --- tests/auto/qglthreads/tst_qglthreads.cpp | 64 ++++++++++++++++---------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/tests/auto/qglthreads/tst_qglthreads.cpp b/tests/auto/qglthreads/tst_qglthreads.cpp index eb31e07..c136133 100644 --- a/tests/auto/qglthreads/tst_qglthreads.cpp +++ b/tests/auto/qglthreads/tst_qglthreads.cpp @@ -510,39 +510,35 @@ private: bool fail; }; -class PainterThreads +template +class PaintThreadManager { public: - PainterThreads(int count, bool drawOnWidgets) : numThreads(count) - , useWidgets(drawOnWidgets) + PaintThreadManager(int count) : numThreads(count) { for (int i=0; iresize(150, 150); - widgets.at(i)->show(); - QTest::qWaitForWindowShown(widgets.at(i)); - widgets.at(i)->doneCurrent(); - } else { - painters.append(new ThreadPainter(pixmaps.at(i))); + painters.append(new ThreadPainter(devices.at(i))); + if (devices.at(i)->devType() == QInternal::Widget) { + QWidget *widget = static_cast(devices.at(i)); + widget->resize(150, 150); + widget->show(); + QTest::qWaitForWindowShown(widget); + if (widget->inherits("QGLWidget")) { + QGLWidget *glWidget = static_cast(widget); + glWidget->doneCurrent(); + } } painters.at(i)->moveToThread(threads.at(i)); painters.at(i)->connect(threads.at(i), SIGNAL(started()), painters.at(i), SLOT(draw())); } } - ~PainterThreads() { + ~PaintThreadManager() { qDeleteAll(threads); qDeleteAll(painters); - if (useWidgets) - qDeleteAll(widgets); - else - qDeleteAll(pixmaps); + qDeleteAll(devices); } @@ -572,11 +568,9 @@ public: private: QList threads; - QList pixmaps; - QList widgets; + QList devices; QList painters; int numThreads; - bool useWidgets; }; @@ -585,10 +579,10 @@ void tst_QGLThreads::painterOnGLWidgetInThread() #ifdef Q_OS_MAC QSKIP("OpenGL threading tests are currently disabled on Mac as they were causing reboots", SkipAll); #endif - PainterThreads threads(5, true); - threads.start(); + PaintThreadManager painterThreads(5); + painterThreads.start(); - while (threads.areRunning()) { + while (painterThreads.areRunning()) { qApp->processEvents(); #ifdef Q_WS_WIN Sleep(100); @@ -596,18 +590,24 @@ void tst_QGLThreads::painterOnGLWidgetInThread() usleep(100 * 1000); #endif } - QVERIFY(!threads.failed()); + QVERIFY(!painterThreads.failed()); } +class Pixmap : public QPixmap +{ +public: + Pixmap() : QPixmap(200, 200) {} +}; + void tst_QGLThreads::painterOnPixmapInThread() { #ifdef Q_WS_X11 - QSKIP("Drawing text to XPixmaps in threads currently doesn't work.", SkipAll); + QSKIP("Drawing text in threads onto X11 drawables currently crashes on some X11 servers.", SkipAll); #endif - PainterThreads threads(5, false); - threads.start(); + PaintThreadManager painterThreads(5); + painterThreads.start(); - while (threads.areRunning()) { + while (painterThreads.areRunning()) { qApp->processEvents(); #ifdef Q_WS_WIN Sleep(100); @@ -615,7 +615,7 @@ void tst_QGLThreads::painterOnPixmapInThread() usleep(100 * 1000); #endif } - QVERIFY(!threads.failed()); + QVERIFY(!painterThreads.failed()); } int main(int argc, char **argv) -- cgit v0.12