Skip to content
Permalink
Browse files

More unit tests

  • Loading branch information
nyalldawson committed Feb 8, 2019
1 parent ceaf97b commit 8ad2d7291f2d1f1ea30060b7cbbf3b7f0d9eba1d
Showing with 32 additions and 0 deletions.
  1. +14 −0 tests/src/core/testqgsdataitem.cpp
  2. +18 −0 tests/src/gui/testqgsfilewidget.cpp
@@ -47,6 +47,7 @@ class TestQgsDataItem : public QObject
void cleanup() {} // will be called after every testfunction.

void testValid();
void testDirItem();
void testDirItemChildren();
void testLayerItemType();
void testProjectItemCreation();
@@ -110,6 +111,19 @@ void TestQgsDataItem::testValid()
QVERIFY( isValidDirItem( mDirItem ) );
}

void TestQgsDataItem::testDirItem()
{
std::unique_ptr< QgsDirectoryItem > dirItem = qgis::make_unique< QgsDirectoryItem >( nullptr, QStringLiteral( "Test" ), TEST_DATA_DIR );
QCOMPARE( dirItem->dirPath(), TEST_DATA_DIR );
QCOMPARE( dirItem->name(), QStringLiteral( "Test" ) );

QVERIFY( dirItem->hasDragEnabled() );
QgsMimeDataUtils::Uri mime = dirItem->mimeUri();
QVERIFY( mime.isValid() );
QCOMPARE( mime.uri, TEST_DATA_DIR );
QCOMPARE( mime.layerType, QStringLiteral( "directory" ) );
}

void TestQgsDataItem::testDirItemChildren()
{
QgsSettings settings;
@@ -18,6 +18,8 @@

#include "qgsfilewidget.h"
#include "qgsmimedatautils.h"
#include "qgsdataitem.h"
#include "qgsbrowsermodel.h"
#include <memory>

class TestQgsFileWidget: public QObject
@@ -115,6 +117,15 @@ void TestQgsFileWidget::testDroppedFiles()
qobject_cast< QgsFileDropEdit * >( w->lineEdit() )->dropEvent( event.get() );
QCOMPARE( w->lineEdit()->text(), TEST_DATA_DIR + QStringLiteral( "/mesh/quad_and_triangle.2dm" ) );

QgsBrowserModel m;
m.initialize();
QgsLayerItem *layerItem = new QgsLayerItem( nullptr, QStringLiteral( "Test" ), QString(), TEST_DATA_DIR + QStringLiteral( "/mesh/quad_and_triangle.txt" ), QgsLayerItem::Mesh, "mdal" );
m.driveItems().first()->addChild( layerItem );
mime.reset( m.mimeData( QModelIndexList() << m.findItem( layerItem ) ) );
event.reset( new QDropEvent( QPointF( 1, 1 ), Qt::CopyAction, mime.get(), Qt::LeftButton, Qt::NoModifier ) );
qobject_cast< QgsFileDropEdit * >( w->lineEdit() )->dropEvent( event.get() );
QCOMPARE( w->lineEdit()->text(), QString( TEST_DATA_DIR ) + QStringLiteral( "/mesh/quad_and_triangle.txt" ) );

mime.reset( new QMimeData() );
mime->setUrls( QList<QUrl>() << QUrl::fromLocalFile( TEST_DATA_DIR + QStringLiteral( "/bug5598.shp" ) ) );
event.reset( new QDropEvent( QPointF( 1, 1 ), Qt::CopyAction, mime.get(), Qt::LeftButton, Qt::NoModifier ) );
@@ -156,6 +167,13 @@ void TestQgsFileWidget::testDroppedFiles()
qobject_cast< QgsFileDropEdit * >( w->lineEdit() )->dropEvent( event.get() );
QCOMPARE( w->lineEdit()->text(), QString( TEST_DATA_DIR ) );

// integration test - dropping a directory item's mime data
QgsDirectoryItem *dirItem = new QgsDirectoryItem( nullptr, QStringLiteral( "Test" ), TEST_DATA_DIR + QStringLiteral( "/mesh" ) );
m.driveItems().first()->addChild( dirItem );
mime.reset( m.mimeData( QModelIndexList() << m.findItem( dirItem ) ) );
event.reset( new QDropEvent( QPointF( 1, 1 ), Qt::CopyAction, mime.get(), Qt::LeftButton, Qt::NoModifier ) );
qobject_cast< QgsFileDropEdit * >( w->lineEdit() )->dropEvent( event.get() );
QCOMPARE( w->lineEdit()->text(), QString( TEST_DATA_DIR ) + QStringLiteral( "/mesh" ) );
}

void TestQgsFileWidget::testMultipleFiles()

0 comments on commit 8ad2d72

Please sign in to comment.
You can’t perform that action at this time.