|
| 1 | +/*************************************************************************** |
| 2 | + testqgsdoublespinbox.cpp |
| 3 | + -------------------------------------- |
| 4 | + Date : December 2014 |
| 5 | + Copyright : (C) 2014 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 | + |
| 16 | + |
| 17 | +#include <QtTest/QtTest> |
| 18 | + |
| 19 | +#include "qgsfilepickerwidget.h" |
| 20 | + |
| 21 | +class TestQgsFilePickerWidget: public QObject |
| 22 | +{ |
| 23 | + Q_OBJECT |
| 24 | + private slots: |
| 25 | + void initTestCase(); // will be called before the first testfunction is executed. |
| 26 | + void cleanupTestCase(); // will be called after the last testfunction was executed. |
| 27 | + void init(); // will be called before each testfunction is executed. |
| 28 | + void cleanup(); // will be called after every testfunction. |
| 29 | + |
| 30 | + void relativePath(); |
| 31 | + void toUrl(); |
| 32 | + |
| 33 | +}; |
| 34 | + |
| 35 | +void TestQgsFilePickerWidget::initTestCase() |
| 36 | +{ |
| 37 | + |
| 38 | +} |
| 39 | + |
| 40 | +void TestQgsFilePickerWidget::cleanupTestCase() |
| 41 | +{ |
| 42 | +} |
| 43 | + |
| 44 | +void TestQgsFilePickerWidget::init() |
| 45 | +{ |
| 46 | +} |
| 47 | + |
| 48 | +void TestQgsFilePickerWidget::cleanup() |
| 49 | +{ |
| 50 | +} |
| 51 | + |
| 52 | +void TestQgsFilePickerWidget::relativePath() |
| 53 | +{ |
| 54 | + QgsFilePickerWidget* w = new QgsFilePickerWidget(); |
| 55 | + w->setDefaultRoot( "/home/test" ); |
| 56 | + w->setRelativeStorage( QgsFilePickerWidget::Absolute ); |
| 57 | + QCOMPARE( w->relativePath( "/home/test2/file1.ext", true ), QString( "/home/test2/file1.ext" ) ); |
| 58 | + QCOMPARE( w->relativePath( "/home/test2/file2.ext", false ), QString( "/home/test2/file2.ext" ) ); |
| 59 | + w->setRelativeStorage( QgsFilePickerWidget::RelativeDefaultPath ); |
| 60 | + QCOMPARE( w->relativePath( "/home/test2/file3.ext", true ), QString( "../test2/file3.ext" ) ); |
| 61 | + QCOMPARE( w->relativePath( "../test2/file4.ext", true ), QString( "../test2/file4.ext" ) ); |
| 62 | + QCOMPARE( w->relativePath( "/home/test2/file5.ext", false ), QString( "/home/test2/file5.ext" ) ); |
| 63 | + QCOMPARE( w->relativePath( "../test2/file6.ext", false ), QString( "/home/test2/file6.ext" ) ); |
| 64 | +} |
| 65 | + |
| 66 | +void TestQgsFilePickerWidget::toUrl() |
| 67 | +{ |
| 68 | + QgsFilePickerWidget* w = new QgsFilePickerWidget(); |
| 69 | + w->setDefaultRoot( "/home/test" ); |
| 70 | + w->setRelativeStorage( QgsFilePickerWidget::Absolute ); |
| 71 | + w->setFullUrl( true ); |
| 72 | + QCOMPARE( w->toUrl( "/home/test2/file1.ext" ), QString( "<a href=\"file:///home/test2/file1.ext\">/home/test2/file1.ext</a>" ) ); |
| 73 | + w->setFullUrl( false ); |
| 74 | + QCOMPARE( w->toUrl( "/home/test2/file2.ext" ), QString( "<a href=\"file:///home/test2/file2.ext\">file2.ext</a>" ) ); |
| 75 | + w->setRelativeStorage( QgsFilePickerWidget::RelativeDefaultPath ); |
| 76 | + w->setFullUrl( true ); |
| 77 | + QCOMPARE( w->toUrl( "/home/test2/file3.ext" ), QString( "<a href=\"file:///home/test2/file3.ext\">/home/test2/file3.ext</a>" ) ); |
| 78 | + QCOMPARE( w->toUrl( "../test2/file4.ext" ), QString( "<a href=\"file:///home/test2/file4.ext\">../test2/file4.ext</a>" ) ); |
| 79 | + w->setFullUrl( false ); |
| 80 | + QCOMPARE( w->toUrl( "/home/test2/file5.ext" ), QString( "<a href=\"file:///home/test2/file5.ext\">file5.ext</a>" ) ); |
| 81 | + QCOMPARE( w->toUrl( "../test2/file6.ext" ), QString( "<a href=\"file:///home/test2/file6.ext\">file6.ext</a>" ) ); |
| 82 | +} |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +QTEST_MAIN( TestQgsFilePickerWidget ) |
| 87 | +#include "testqgsfilepickerwidget.moc" |
0 commit comments