|
26 | 26 | #include <QObject>
|
27 | 27 | #include <QtTest/QSignalSpy>
|
28 | 28 | #include <QList>
|
| 29 | +#include <QFileInfo> |
29 | 30 | #include "qgis.h"
|
30 | 31 | #include "qgstest.h"
|
31 | 32 | #include "qgsrasterlayer.h"
|
@@ -527,6 +528,7 @@ class TestQgsProcessing: public QObject
|
527 | 528 | void features();
|
528 | 529 | void uniqueValues();
|
529 | 530 | void createIndex();
|
| 531 | + void generateTemporaryDestination(); |
530 | 532 | void parseDestinationString();
|
531 | 533 | void createFeatureSink();
|
532 | 534 | void parameters();
|
@@ -1520,6 +1522,49 @@ void TestQgsProcessing::createIndex()
|
1520 | 1522 | QCOMPARE( ids, QList<QgsFeatureId>() << 2 );
|
1521 | 1523 | }
|
1522 | 1524 |
|
| 1525 | +void TestQgsProcessing::generateTemporaryDestination() |
| 1526 | +{ |
| 1527 | + // setup a context |
| 1528 | + QgsProject p; |
| 1529 | + p.setCrs( QgsCoordinateReferenceSystem::fromEpsgId( 28353 ) ); |
| 1530 | + QgsProcessingContext context; |
| 1531 | + context.setProject( &p ); |
| 1532 | + |
| 1533 | + // destination vector with "." in it's name |
| 1534 | + std::unique_ptr< QgsProcessingParameterVectorDestination > def( new QgsProcessingParameterVectorDestination( "with.inside", QString(), QgsProcessing::TypeVectorAnyGeometry, QString(), false ) ); |
| 1535 | + |
| 1536 | + // check that temporary destination does not have dot at the end when there is no extension |
| 1537 | + QVERIFY( !def->generateTemporaryDestination().endsWith( QLatin1String( "." ) ) ); |
| 1538 | + // check that temporary destination starts with tempFolder |
| 1539 | + QVERIFY( def->generateTemporaryDestination().startsWith( QgsProcessingUtils::tempFolder() ) ); |
| 1540 | + // check that extension with QFileInfo::completeSuffix is "gpkg" |
| 1541 | + QFileInfo f = QFileInfo( def->generateTemporaryDestination() ); |
| 1542 | + QCOMPARE( f.completeSuffix(), QString( "gpkg" ) ); |
| 1543 | + |
| 1544 | + // destination raster with "." in it's name |
| 1545 | + std::unique_ptr< QgsProcessingParameterRasterDestination > def2( new QgsProcessingParameterRasterDestination( "with.inside", QString(), QString(), false ) ); |
| 1546 | + |
| 1547 | + // check that temporary destination does not have dot at the end when there is no extension |
| 1548 | + QVERIFY( !def2->generateTemporaryDestination().endsWith( QLatin1String( "." ) ) ); |
| 1549 | + // check that temporary destination starts with tempFolder |
| 1550 | + QVERIFY( def2->generateTemporaryDestination().startsWith( QgsProcessingUtils::tempFolder() ) ); |
| 1551 | + // check that extension with QFileInfo::completeSuffix is "tif" |
| 1552 | + f = QFileInfo( def2->generateTemporaryDestination() ); |
| 1553 | + QCOMPARE( f.completeSuffix(), QString( "tif" ) ); |
| 1554 | + |
| 1555 | + // destination vector without "." in it's name |
| 1556 | + std::unique_ptr< QgsProcessingParameterVectorDestination > def3( new QgsProcessingParameterVectorDestination( "without_inside", QString(), QgsProcessing::TypeVectorAnyGeometry, QString(), false ) ); |
| 1557 | + |
| 1558 | + // check that temporary destination does not have dot at the end when there is no extension |
| 1559 | + QVERIFY( !def3->generateTemporaryDestination().endsWith( QLatin1String( "." ) ) ); |
| 1560 | + // check that temporary destination starts with tempFolder |
| 1561 | + QVERIFY( def3->generateTemporaryDestination().startsWith( QgsProcessingUtils::tempFolder() ) ); |
| 1562 | + // check that extension with QFileInfo::completeSuffix is "gpkg" |
| 1563 | + f = QFileInfo( def3->generateTemporaryDestination() ); |
| 1564 | + QCOMPARE( f.completeSuffix(), QString( "gpkg" ) ); |
| 1565 | + |
| 1566 | +} |
| 1567 | + |
1523 | 1568 | void TestQgsProcessing::parseDestinationString()
|
1524 | 1569 | {
|
1525 | 1570 | QString providerKey;
|
|
0 commit comments