|
| 1 | +/*************************************************************************** |
| 2 | + testqgsprojutils.cpp |
| 3 | + -------------------------------------- |
| 4 | + Date : March 2019 |
| 5 | + Copyright : (C) 2019 Nyall Dawson |
| 6 | + Email : nyall dot dawson at gmail dot com |
| 7 | + *************************************************************************** |
| 8 | + * * |
| 9 | + * This program is free software; you can redistribute it and/or modify * |
| 10 | + * it under the terms of the GNU General Public License as published by * |
| 11 | + * the Free Software Foundation; either version 2 of the License, or * |
| 12 | + * (at your option) any later version. * |
| 13 | + * * |
| 14 | + ***************************************************************************/ |
| 15 | +#include "qgstest.h" |
| 16 | +#include <QPixmap> |
| 17 | + |
| 18 | +#include "qgsapplication.h" |
| 19 | +#include "qgslogger.h" |
| 20 | + |
| 21 | +//header for class being tested |
| 22 | +#include "qgsprojutils.h" |
| 23 | +#include <QtConcurrent> |
| 24 | + |
| 25 | +class TestQgsProjUtils: public QObject |
| 26 | +{ |
| 27 | + Q_OBJECT |
| 28 | + private slots: |
| 29 | + void initTestCase(); |
| 30 | + void cleanupTestCase(); |
| 31 | + void threadSafeContext(); |
| 32 | + |
| 33 | +}; |
| 34 | + |
| 35 | + |
| 36 | +void TestQgsProjUtils::initTestCase() |
| 37 | +{ |
| 38 | + QgsApplication::init(); |
| 39 | + QgsApplication::createDatabase(); |
| 40 | + QgsApplication::initQgis(); |
| 41 | + QgsApplication::showSettings(); |
| 42 | +} |
| 43 | + |
| 44 | +void TestQgsProjUtils::cleanupTestCase() |
| 45 | +{ |
| 46 | + QgsApplication::exitQgis(); |
| 47 | +} |
| 48 | + |
| 49 | + |
| 50 | +struct ProjContextWrapper |
| 51 | +{ |
| 52 | + explicit ProjContextWrapper() |
| 53 | + {} |
| 54 | + |
| 55 | + void operator()( int ) |
| 56 | + { |
| 57 | + QVERIFY( QgsProjContext::get() ); |
| 58 | + // TODO - do something with the context? |
| 59 | + } |
| 60 | +}; |
| 61 | + |
| 62 | +void TestQgsProjUtils::threadSafeContext() |
| 63 | +{ |
| 64 | + // smash proj context generation over many threads |
| 65 | + QVector< int > list; |
| 66 | + list.resize( 100 ); |
| 67 | + QtConcurrent::blockingMap( list, ProjContextWrapper() ); |
| 68 | +} |
| 69 | + |
| 70 | +QGSTEST_MAIN( TestQgsProjUtils ) |
| 71 | +#include "testqgsprojutils.moc" |
0 commit comments