Skip to content

Commit d7abfb4

Browse files
committedMar 19, 2019
Test thread safety of proj context generation
Sponsored by ICSM
1 parent 3ce0acc commit d7abfb4

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
 

‎tests/src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ SET(TESTS
176176
testqgspoint.cpp
177177
testqgsproject.cpp
178178
testqgsprojectstorage.cpp
179+
testqgsprojutils.cpp
179180
testqgsproperty.cpp
180181
testqgis.cpp
181182
testqgsrasterfilewriter.cpp

‎tests/src/core/testqgsprojutils.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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

Comments
 (0)
Please sign in to comment.