|
| 1 | +/*************************************************************************** |
| 2 | + testqgsproject.cpp |
| 3 | + -------------------------------------- |
| 4 | + Date : June 2014 |
| 5 | + Copyright : (C) 2014 by Martin Dobias |
| 6 | + Email : wonder.sk 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 <QtTest> |
| 16 | +#include <QObject> |
| 17 | + |
| 18 | +#include <qgsapplication.h> |
| 19 | +#include <qgsproject.h> |
| 20 | + |
| 21 | + |
| 22 | +class TestQgsProject : public QObject |
| 23 | +{ |
| 24 | + Q_OBJECT |
| 25 | + private slots: |
| 26 | + void initTestCase();// will be called before the first testfunction is executed. |
| 27 | + void cleanupTestCase();// will be called after the last testfunction was executed. |
| 28 | + void init();// will be called before each testfunction is executed. |
| 29 | + void cleanup();// will be called after every testfunction. |
| 30 | + |
| 31 | + void testReadPath(); |
| 32 | +}; |
| 33 | + |
| 34 | +void TestQgsProject::init() |
| 35 | +{ |
| 36 | +} |
| 37 | + |
| 38 | +void TestQgsProject::cleanup() |
| 39 | +{ |
| 40 | + // will be called after every testfunction. |
| 41 | +} |
| 42 | + |
| 43 | +void TestQgsProject::initTestCase() |
| 44 | +{ |
| 45 | + // Runs once before any tests are run |
| 46 | +} |
| 47 | + |
| 48 | + |
| 49 | +void TestQgsProject::cleanupTestCase() |
| 50 | +{ |
| 51 | + // Runs once after all tests are run |
| 52 | +} |
| 53 | + |
| 54 | +void TestQgsProject::testReadPath() |
| 55 | +{ |
| 56 | + QgsProject* prj = QgsProject::instance(); |
| 57 | + // this is a bit hacky as we do not really load such project |
| 58 | + prj->setFileName( "/home/qgis/a-project-file.qgs" ); // not expected to exist |
| 59 | + // make sure we work with relative paths! |
| 60 | + prj->writeEntry( "Paths", "Absolute", false ); |
| 61 | + |
| 62 | + QCOMPARE( prj->readPath( "./x.shp" ), QString( "/home/qgis/x.shp" ) ); |
| 63 | + QCOMPARE( prj->readPath( "../x.shp" ), QString( "/home/x.shp" ) ); |
| 64 | + |
| 65 | + // TODO: old style (seems QGIS < 1.3) - needs existing project file and existing file |
| 66 | + // QCOMPARE( prj->readPath( "x.shp" ), QString( "/home/qgis/x.shp" ) ); |
| 67 | + |
| 68 | + // VSI: /vsizip, /vsitar, /vsigzip, *.zip, *.gz, *.tgz, ... |
| 69 | + |
| 70 | + QCOMPARE( prj->readPath( "./x.gz" ), QString( "/home/qgis/x.gz" ) ); |
| 71 | + QCOMPARE( prj->readPath( "/vsigzip/./x.gz" ), QString( "/vsigzip//home/qgis/x.gz" ) ); // not sure how useful this really is... |
| 72 | + |
| 73 | +} |
| 74 | + |
| 75 | + |
| 76 | +QTEST_MAIN( TestQgsProject ) |
| 77 | +#include "moc_testqgsproject.cxx" |
0 commit comments