tests/benchmarks/uimodels/GraphicsViewBenchmark/testautom/testthread.cpp
changeset 3 41300fa6a67c
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     5 **
       
     6 ** This file is part of the examples of the Qt Toolkit.
       
     7 **
       
     8 ** $QT_BEGIN_LICENSE:LGPL$
       
     9 ** No Commercial Usage
       
    10 ** This file contains pre-release code and may not be distributed.
       
    11 ** You may use this file in accordance with the terms and conditions
       
    12 ** contained in the either Technology Preview License Agreement or the
       
    13 ** Beta Release License Agreement.
       
    14 **
       
    15 ** GNU Lesser General Public License Usage
       
    16 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    17 ** General Public License version 2.1 as published by the Free Software
       
    18 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    19 ** packaging of this file.  Please review the following information to
       
    20 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    22 **
       
    23 ** In addition, as a special exception, Nokia gives you certain
       
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
       
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
       
    26 ** package.
       
    27 **
       
    28 ** GNU General Public License Usage
       
    29 ** Alternatively, this file may be used under the terms of the GNU
       
    30 ** General Public License version 3.0 as published by the Free Software
       
    31 ** Foundation and appearing in the file LICENSE.GPL included in the
       
    32 ** packaging of this file.  Please review the following information to
       
    33 ** ensure the GNU General Public License version 3.0 requirements will be
       
    34 ** met: http://www.gnu.org/copyleft/gpl.html.
       
    35 **
       
    36 ** If you are unsure which license is appropriate for your use, please
       
    37 ** contact the sales department at http://qt.nokia.com/contact.
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include <QDebug>
       
    43 #include <QTimer>
       
    44 
       
    45 #include "testthread.h"
       
    46 #include "theme.h"
       
    47 
       
    48 static const int SleepTimeBetweenCases = 1000;
       
    49 
       
    50 Q_DECLARE_METATYPE(TestThread*)
       
    51 
       
    52 TestThread::TestThread(TestController *ctrl, QObject *parent)
       
    53     : QThread(parent),    
       
    54     m_doExit(false),
       
    55     m_resultLogger(0)
       
    56 {
       
    57     setController(ctrl);
       
    58     connect(controller(), SIGNAL(stop()), this, SLOT(stop()));
       
    59     connect(controller(), SIGNAL(testDone()), this, SLOT(testDone()), Qt::QueuedConnection);
       
    60     connect(this, SIGNAL(changeTheme(Theme::Themes)),
       
    61             controller(), SLOT(changeTheme(Theme::Themes)));
       
    62 
       
    63     connect(this, SIGNAL(fillList(int,Benchmark::ListType,TestFunctionResult*, const QString &)),
       
    64             controller(), SLOT(fillList(int,Benchmark::ListType, TestFunctionResult*, const QString &)),
       
    65             Qt::QueuedConnection);
       
    66 
       
    67     connect(this, SIGNAL(doRotateMainWindow(int)), controller(), SLOT(rotateMainWindow(int)),
       
    68             Qt::QueuedConnection);
       
    69     connect(this, SIGNAL(doSetTwoColumns(bool)), controller(), SLOT(setTwoColumns(bool)),
       
    70             Qt::QueuedConnection);
       
    71 
       
    72     connect(this, SIGNAL(deleteList(TestFunctionResult*, const QString &)),
       
    73             controller(), SLOT(deleteList(TestFunctionResult*, const QString &)),
       
    74             Qt::QueuedConnection);
       
    75     connect(this, SIGNAL(themeChange(int,TestFunctionResult*, const QString &)),
       
    76             controller(), SLOT(themeChange(int,TestFunctionResult*, const QString &)),
       
    77             Qt::QueuedConnection);
       
    78     connect(this, SIGNAL(scrollList(int,TestFunctionResult*, const QString &)),
       
    79             controller(), SLOT(scrollList(int,TestFunctionResult*, const QString &)),
       
    80             Qt::QueuedConnection);
       
    81     connect(this, SIGNAL(forceUpdate(int,TestFunctionResult*, const QString &)),
       
    82             controller(), SLOT(forceUpdate(int,TestFunctionResult*, const QString &)),
       
    83             Qt::QueuedConnection);
       
    84     connect(this, SIGNAL(addToBeginningOfList(int,TestFunctionResult*, const QString &)),
       
    85             controller(), SLOT(addToBeginningOfList(int,TestFunctionResult*, const QString &)),
       
    86             Qt::QueuedConnection);
       
    87     connect(this, SIGNAL(removeFromBeginningOfList(int,TestFunctionResult*, const QString &)),
       
    88             controller(), SLOT(removeFromBeginningOfList(int,TestFunctionResult*, const QString &)),
       
    89             Qt::QueuedConnection);
       
    90 }
       
    91 
       
    92 TestThread::~TestThread()
       
    93 {
       
    94     delete m_resultLogger;
       
    95 }
       
    96 
       
    97 void TestThread::stop()
       
    98 {
       
    99     m_doExit = true;
       
   100     testDone();
       
   101 }
       
   102 
       
   103 void TestThread::testDone()
       
   104 {
       
   105     m_waitCondition.wakeAll();
       
   106 }
       
   107 
       
   108 TestController *TestThread::controller() const
       
   109 {
       
   110     return m_controller;
       
   111 }
       
   112 void TestThread::setController(TestController *ctrl)
       
   113 {
       
   114     m_controller = ctrl;
       
   115 }
       
   116 
       
   117 void TestThread::setResultLogger(ResultLogger *logger)
       
   118 {
       
   119     if (m_resultLogger == logger)
       
   120         return;
       
   121     if (m_resultLogger)
       
   122         delete m_resultLogger;
       
   123     m_resultLogger = logger;
       
   124 }
       
   125 
       
   126 ResultLogger* TestThread::resultLogger() const
       
   127 {
       
   128     return m_resultLogger;
       
   129 }
       
   130 
       
   131 
       
   132 void TestThread::addTestFunctionBenchmark(const QString &functionName, const QString &benchmarkTag, const qreal value)
       
   133 {
       
   134     if (!m_resultLogger)
       
   135         return;
       
   136     TestFunctionResult *f = m_resultLogger->getTestFunctionResult(functionName);
       
   137     if (!f)
       
   138         f = m_resultLogger->createTestFunctionResult(functionName);
       
   139 
       
   140     Benchmark *b = f->createBenchmark();
       
   141     b->setTag(benchmarkTag);
       
   142     b->setValue(value);
       
   143     b->setTheme(Theme::p()->currentThemeName());
       
   144 }
       
   145 
       
   146 void TestThread::setScrollStep(const int step)
       
   147 {
       
   148     controller()->setScrollStep(step);
       
   149 }
       
   150 int TestThread::scrollStep() const
       
   151 {
       
   152     return controller()->scrollStep();
       
   153 }
       
   154 
       
   155 bool TestThread::imageBasedRendering() const
       
   156 {
       
   157     return controller()->imageBasedRendering();
       
   158 }
       
   159 
       
   160 bool TestThread::subtreeCache() const
       
   161 {
       
   162     return controller()->subtreeCache();
       
   163 }
       
   164 
       
   165 void TestThread::rotateMainWindow(const int angle)
       
   166 {
       
   167     if (m_doExit) return;
       
   168     m_mutex.lock();
       
   169     emit doRotateMainWindow(angle);
       
   170     m_waitCondition.wait(&m_mutex);
       
   171     m_mutex.unlock();
       
   172     if (m_doExit) return;
       
   173     msleep(SleepTimeBetweenCases);
       
   174 }
       
   175 
       
   176 int TestThread::mainWindowRotationAngle() const
       
   177 {
       
   178     return controller()->mainWindowRotationAngle();
       
   179 }
       
   180 
       
   181 int TestThread::themeCount() const
       
   182 {
       
   183     return Theme::p()->themes().count();
       
   184 }
       
   185 
       
   186 int TestThread::currentThemeId() const
       
   187 {
       
   188     return int(Theme::p()->theme());
       
   189 }
       
   190 
       
   191 void TestThread::setTheme(int index)
       
   192 {
       
   193     emit changeTheme(Theme::Themes(index));
       
   194     if (m_doExit) return;
       
   195     msleep(SleepTimeBetweenCases);
       
   196 }
       
   197 
       
   198 QString TestThread::currentThemeName() const
       
   199 {
       
   200     return Theme::p()->currentThemeName();
       
   201 }
       
   202 QString TestThread::themeName(int theme) const
       
   203 {
       
   204     return Theme::p()->themes().at(theme);
       
   205 }
       
   206 
       
   207 void TestThread::setImageBasedRendering(const bool imageBasedRendering)
       
   208 {
       
   209     controller()->setImageBasedRendering(imageBasedRendering);
       
   210 }
       
   211 
       
   212 void TestThread::setTwoColumns(const bool twoCols)
       
   213 {
       
   214     if (m_doExit) return;
       
   215     m_mutex.lock();
       
   216     emit doSetTwoColumns(twoCols);
       
   217     m_waitCondition.wait(&m_mutex);
       
   218     m_mutex.unlock();
       
   219     if (m_doExit) return;
       
   220     msleep(SleepTimeBetweenCases);
       
   221 }
       
   222 
       
   223 bool TestThread::twoColumns() const
       
   224 {
       
   225     return controller()->twoColumns();
       
   226 }
       
   227 
       
   228 void TestThread::fillListTest(int itemCount, int listType, TestFunctionResult *testFunctionResult, const QString &tag)
       
   229 {
       
   230     if (m_doExit) return;
       
   231     m_mutex.lock();
       
   232     emit fillList(itemCount, Benchmark::ListType(listType), testFunctionResult, tag);
       
   233     m_waitCondition.wait(&m_mutex);
       
   234     m_mutex.unlock();
       
   235     if (m_doExit) return;
       
   236     msleep(SleepTimeBetweenCases);
       
   237 }
       
   238 
       
   239 void TestThread::deleteListTest(TestFunctionResult *testFunctionResult, const QString &tag)
       
   240 {
       
   241     if (m_doExit) return;
       
   242     m_mutex.lock();
       
   243     emit deleteList(testFunctionResult, tag);
       
   244     m_waitCondition.wait(&m_mutex);
       
   245     m_mutex.unlock();
       
   246     if (m_doExit) return;
       
   247     msleep(SleepTimeBetweenCases);
       
   248 }
       
   249 
       
   250 void TestThread::scrollListTest(int maxTimeMs,TestFunctionResult *testFunctionResult, const QString &tag)
       
   251 {
       
   252     if (m_doExit) return;
       
   253     m_mutex.lock();
       
   254     emit scrollList(maxTimeMs, testFunctionResult, tag);
       
   255     m_waitCondition.wait(&m_mutex);
       
   256     m_mutex.unlock();
       
   257     if (m_doExit) return;
       
   258     msleep(SleepTimeBetweenCases);
       
   259 }
       
   260 
       
   261 void TestThread::addToBeginningOfListTest(int itemCount,TestFunctionResult *testFunctionResult, const QString &tag)
       
   262 {
       
   263     if (m_doExit) return;
       
   264     m_mutex.lock();
       
   265     emit addToBeginningOfList(itemCount, testFunctionResult, tag);
       
   266     m_waitCondition.wait(&m_mutex);
       
   267     m_mutex.unlock();
       
   268     if (m_doExit) return;
       
   269     msleep(SleepTimeBetweenCases);
       
   270 }
       
   271 
       
   272 void TestThread::removeFromBeginningOfListTest(int itemCount, TestFunctionResult *testFunctionResult, const QString &tag)
       
   273 {
       
   274     if (m_doExit) return;
       
   275     m_mutex.lock();
       
   276     emit removeFromBeginningOfList(itemCount, testFunctionResult, tag);
       
   277     m_waitCondition.wait(&m_mutex);
       
   278     m_mutex.unlock();
       
   279     if (m_doExit) return;
       
   280     msleep(SleepTimeBetweenCases);
       
   281 }
       
   282 
       
   283 void TestThread::forceUpdateTest(int updateMaxTime, TestFunctionResult *testFunctionResult, const QString &tag)
       
   284 {
       
   285     if (m_doExit) return;
       
   286     m_mutex.lock();
       
   287     emit forceUpdate(updateMaxTime, testFunctionResult, tag);
       
   288     m_waitCondition.wait(&m_mutex);
       
   289     m_mutex.unlock();
       
   290     if (m_doExit) return;
       
   291     msleep(SleepTimeBetweenCases);
       
   292 }
       
   293 
       
   294 
       
   295 void TestThread::themeChangeTest(int theme, TestFunctionResult *testFunctionResult, const QString &tag)
       
   296 {
       
   297     if (m_doExit) return;
       
   298     m_mutex.lock();
       
   299     emit themeChange(theme, testFunctionResult, tag);
       
   300     m_waitCondition.wait(&m_mutex);
       
   301     m_mutex.unlock();
       
   302     if (m_doExit) return;
       
   303     msleep(SleepTimeBetweenCases);
       
   304 }
       
   305 
       
   306 
       
   307 void TestThread::setSubtreeCache(const bool enabled)
       
   308 {
       
   309     controller()->setSubtreeCache(enabled);
       
   310 }