Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add test for QgsLayerDefinition (regression #18981)
- Loading branch information
Showing
2 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/*************************************************************************** | ||
testqgsfilefiledownloader.cpp | ||
-------------------------------------- | ||
Date : 07.06.2018 | ||
Copyright : (C) 2018 Alessandro Pasotti | ||
Email : elpaso at itopen dot it | ||
*************************************************************************** | ||
* * | ||
* 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 <QObject> | ||
#include <QTemporaryFile> | ||
#include <QTemporaryDir> | ||
|
||
#include <qgsapplication.h> | ||
#include <qgsproject.h> | ||
#include <qgslayertree.h> | ||
#include <qgslayerdefinition.h> | ||
|
||
class TestQgsLayerDefinition: public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
TestQgsLayerDefinition() = default; | ||
|
||
private slots: | ||
void initTestCase(); // will be called before the first testfunction is executed. | ||
void cleanupTestCase(); // will be called after the last testfunction was executed. | ||
void init(); // will be called before each testfunction is executed. | ||
void cleanup(); // will be called after every testfunction. | ||
|
||
/** | ||
* test that findLayers() skips invalid layers | ||
*/ | ||
void testFindLayers(); | ||
|
||
/** | ||
* test that export does not crash: regression #18981 | ||
* https://issues.qgis.org/issues/18981 - Save QLR crashes QGIS 3 | ||
*/ | ||
void testExportDoesNotCrash(); | ||
|
||
private: | ||
QTemporaryFile *mTempFile; | ||
}; | ||
|
||
|
||
void TestQgsLayerDefinition::initTestCase() | ||
{ | ||
QgsApplication::init(); | ||
QgsApplication::initQgis(); | ||
|
||
} | ||
|
||
void TestQgsLayerDefinition::cleanupTestCase() | ||
{ | ||
QgsApplication::exitQgis(); | ||
} | ||
|
||
void TestQgsLayerDefinition::init() | ||
{ | ||
mTempFile = new QTemporaryFile(); | ||
QVERIFY( mTempFile->open() ); | ||
mTempFile->close(); | ||
QString errorMessage; | ||
const QString path = QString( TEST_DATA_DIR + QStringLiteral( "/bug_18981_broken.qlr" ) ); | ||
QgsLayerDefinition::loadLayerDefinition( path, QgsProject::instance(), QgsProject::instance()->layerTreeRoot(), errorMessage ); | ||
QVERIFY( errorMessage.isEmpty() ); | ||
} | ||
|
||
|
||
void TestQgsLayerDefinition::cleanup() | ||
{ | ||
delete mTempFile; | ||
} | ||
|
||
void TestQgsLayerDefinition::testFindLayers() | ||
{ | ||
QCOMPARE( QgsProject::instance()->layerTreeRoot()->findLayers().count(), 1 ); | ||
QCOMPARE( QgsProject::instance()->layerTreeRoot()->findLayers().at( 0 )->name(), QStringLiteral( "NewMemory" ) ); | ||
} | ||
|
||
void TestQgsLayerDefinition::testExportDoesNotCrash() | ||
{ | ||
QString errorMessage; | ||
QVERIFY( QgsLayerDefinition::exportLayerDefinition( mTempFile->fileName(), QgsProject::instance()->layerTreeRoot()->children(), errorMessage ) ); | ||
QVERIFY( errorMessage.isEmpty() ); | ||
// Reload | ||
const QString path = QString( TEST_DATA_DIR + QStringLiteral( "/bug_18981_broken.qlr" ) ); | ||
QgsProject::instance()->removeAllMapLayers(); | ||
QgsLayerDefinition::loadLayerDefinition( path, QgsProject::instance(), QgsProject::instance()->layerTreeRoot(), errorMessage ); | ||
testFindLayers(); | ||
} | ||
|
||
|
||
|
||
QGSTEST_MAIN( TestQgsLayerDefinition ) | ||
#include "testqgslayerdefinition.moc" | ||
|
||
|