|
| 1 | +/*************************************************************************** |
| 2 | + testqgsmimedatautils.cpp |
| 3 | + -------------------------------------- |
| 4 | + Date : 18.06.2018 |
| 5 | + Copyright : (C) 2018 Alessandro Pasotti |
| 6 | + Email : elpaso at itopen dot it |
| 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 | + |
| 16 | + |
| 17 | +#include "qgstest.h" |
| 18 | +#include <QObject> |
| 19 | + |
| 20 | +#include <qgsmimedatautils.h> |
| 21 | + |
| 22 | +const QString TEST_ENCODED_DATA( "raster:wms:A Fancy WMS From Ciriè City:crs=EPSG\\:2036&dpiMode=7&format=image/png&layers=lidar&styles=default" |
| 23 | + "&url=https\\://geoegl.msp.gouv.qc.:EPSG\\\\:2036\\:EPSG\\\\:3857:image/tiff\\:image/jpeg" ); |
| 24 | + |
| 25 | +class TestQgsMimeDataUtils: public QObject |
| 26 | +{ |
| 27 | + Q_OBJECT |
| 28 | + public: |
| 29 | + TestQgsMimeDataUtils() = default; |
| 30 | + |
| 31 | + private slots: |
| 32 | + void initTestCase(); // will be called before the first testfunction is executed. |
| 33 | + void cleanupTestCase(); // will be called after the last testfunction was executed. |
| 34 | + void init(); // will be called before each testfunction is executed. |
| 35 | + void cleanup(); // will be called after every testfunction. |
| 36 | + |
| 37 | + /** |
| 38 | + * test findLayers() |
| 39 | + */ |
| 40 | + void testEncodeDecode(); |
| 41 | + |
| 42 | +}; |
| 43 | + |
| 44 | + |
| 45 | +void TestQgsMimeDataUtils::initTestCase() |
| 46 | +{ |
| 47 | + QgsApplication::init(); |
| 48 | + QgsApplication::initQgis(); |
| 49 | + |
| 50 | +} |
| 51 | + |
| 52 | +void TestQgsMimeDataUtils::cleanupTestCase() |
| 53 | +{ |
| 54 | + QgsApplication::exitQgis(); |
| 55 | +} |
| 56 | + |
| 57 | +void TestQgsMimeDataUtils::init() |
| 58 | +{ |
| 59 | +} |
| 60 | + |
| 61 | + |
| 62 | +void TestQgsMimeDataUtils::cleanup() |
| 63 | +{ |
| 64 | +} |
| 65 | + |
| 66 | +void TestQgsMimeDataUtils::testEncodeDecode() |
| 67 | +{ |
| 68 | + |
| 69 | + QgsMimeDataUtils::Uri uri; |
| 70 | + uri.layerType = QStringLiteral( "raster" ); |
| 71 | + uri.name = QStringLiteral( "A Fancy WMS From Ciriè City" ); |
| 72 | + uri.providerKey = QStringLiteral( "wms" ); |
| 73 | + uri.supportedCrs << QStringLiteral( "EPSG:2036" ) << QStringLiteral( "EPSG:3857" ) ; |
| 74 | + uri.supportedFormats << QStringLiteral( "image/tiff" ) << QStringLiteral( "image/jpeg" ); |
| 75 | + uri.uri = QStringLiteral( "crs=EPSG:2036&dpiMode=7&format=image/png&layers=lidar&styles=default&url=https://geoegl.msp.gouv.qc." ); |
| 76 | + |
| 77 | + QgsMimeDataUtils::UriList uriList; |
| 78 | + uriList << uri; |
| 79 | + |
| 80 | + QMimeData *mimeData = QgsMimeDataUtils::encodeUriList( uriList ); |
| 81 | + |
| 82 | + QgsMimeDataUtils::Uri uriDecoded( QgsMimeDataUtils::decodeUriList( mimeData )[0] ); |
| 83 | + |
| 84 | + QCOMPARE( uriDecoded.name, uri.name ); |
| 85 | + QCOMPARE( uriDecoded.providerKey, uri.providerKey ); |
| 86 | + QCOMPARE( uriDecoded.supportedFormats, uri.supportedFormats ); |
| 87 | + QCOMPARE( uriDecoded.uri, uri.uri ); |
| 88 | + QCOMPARE( uriDecoded.supportedCrs, uri.supportedCrs ); |
| 89 | + |
| 90 | + QgsMimeDataUtils::decodeUriList( mimeData ); |
| 91 | + |
| 92 | + // Encode representation: |
| 93 | + QString data( uri.data() ); |
| 94 | + |
| 95 | + QCOMPARE( data, TEST_ENCODED_DATA ); |
| 96 | + |
| 97 | + QStringList fragments( QgsMimeDataUtils::decode( data ) ); |
| 98 | + |
| 99 | + QCOMPARE( fragments[0], "raster" ); |
| 100 | + QCOMPARE( fragments[1], "wms" ); |
| 101 | + QCOMPARE( fragments[2], "A Fancy WMS From Ciriè City" ); |
| 102 | + QCOMPARE( fragments[3], "crs=EPSG:2036&dpiMode=7&format=image/png&layers=lidar&styles=default&url=https://geoegl.msp.gouv.qc." ); |
| 103 | + QCOMPARE( fragments[4], "EPSG\\:2036:EPSG\\:3857" ); |
| 104 | + |
| 105 | +} |
| 106 | + |
| 107 | + |
| 108 | +QGSTEST_MAIN( TestQgsMimeDataUtils ) |
| 109 | +#include "testqgsmimedatautils.moc" |
| 110 | + |
| 111 | + |
0 commit comments