Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Test thread safety of proj context generation
Sponsored by ICSM
  • Loading branch information
nyalldawson committed Mar 19, 2019
1 parent 3ce0acc commit d7abfb4
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/src/core/CMakeLists.txt
Expand Up @@ -176,6 +176,7 @@ SET(TESTS
testqgspoint.cpp
testqgsproject.cpp
testqgsprojectstorage.cpp
testqgsprojutils.cpp
testqgsproperty.cpp
testqgis.cpp
testqgsrasterfilewriter.cpp
Expand Down
71 changes: 71 additions & 0 deletions tests/src/core/testqgsprojutils.cpp
@@ -0,0 +1,71 @@
/***************************************************************************
testqgsprojutils.cpp
--------------------------------------
Date : March 2019
Copyright : (C) 2019 Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgstest.h"
#include <QPixmap>

#include "qgsapplication.h"
#include "qgslogger.h"

//header for class being tested
#include "qgsprojutils.h"
#include <QtConcurrent>

class TestQgsProjUtils: public QObject
{
Q_OBJECT
private slots:
void initTestCase();
void cleanupTestCase();
void threadSafeContext();

};


void TestQgsProjUtils::initTestCase()
{
QgsApplication::init();
QgsApplication::createDatabase();
QgsApplication::initQgis();
QgsApplication::showSettings();
}

void TestQgsProjUtils::cleanupTestCase()
{
QgsApplication::exitQgis();
}


struct ProjContextWrapper
{
explicit ProjContextWrapper()
{}

void operator()( int )
{
QVERIFY( QgsProjContext::get() );
// TODO - do something with the context?
}
};

void TestQgsProjUtils::threadSafeContext()
{
// smash proj context generation over many threads
QVector< int > list;
list.resize( 100 );
QtConcurrent::blockingMap( list, ProjContextWrapper() );
}

QGSTEST_MAIN( TestQgsProjUtils )
#include "testqgsprojutils.moc"

0 comments on commit d7abfb4

Please sign in to comment.