Skip to content
Permalink
Browse files

Added basic unit test for map layer class

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7680 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux
timlinux committed Nov 29, 2007
1 parent 70c83d6 commit 1a2ddfce2a7048af87e8bba48844629188311250
Showing with 94 additions and 0 deletions.
  1. +12 −0 tests/src/core/CMakeLists.txt
  2. +82 −0 tests/src/core/testqgsmaplayer.cpp
@@ -97,6 +97,18 @@ ADD_DEPENDENCIES(qgis_rasterlayertest qgis_rasterlayertestmoc)
TARGET_LINK_LIBRARIES(qgis_rasterlayertest ${QT_LIBRARIES} qgis_core)
INSTALL(TARGETS qgis_rasterlayertest RUNTIME DESTINATION ${QGIS_BIN_DIR})
ADD_TEST(qgis_rasterlayertest ${QGIS_BIN_DIR}/qgis_rasterlayertest)
#
# QgsMapLayer test
#
SET(qgis_maplayertest_SRCS testqgsmaplayer.cpp)
SET(qgis_maplayertest_MOC_CPPS testqgsmaplayer.cpp)
QT4_WRAP_CPP(qgis_maplayertest_MOC_SRCS ${qgis_maplayertest_MOC_CPPS})
ADD_CUSTOM_TARGET(qgis_maplayertestmoc ALL DEPENDS ${qgis_maplayertest_MOC_SRCS})
ADD_EXECUTABLE(qgis_maplayertest ${qgis_maplayertest_SRCS})
ADD_DEPENDENCIES(qgis_maplayertest qgis_maplayertestmoc)
TARGET_LINK_LIBRARIES(qgis_maplayertest ${QT_LIBRARIES} qgis_core)
INSTALL(TARGETS qgis_maplayertest RUNTIME DESTINATION ${QGIS_BIN_DIR})
ADD_TEST(qgis_maplayertest ${QGIS_BIN_DIR}/qgis_maplayertest)



@@ -0,0 +1,82 @@
/***************************************************************************
testqgsvectorfilewriter.cpp
--------------------------------------
Date : Sun Sep 16 12:22:54 AKDT 2007
Copyright : (C) 2007 by Gary E. Sherman
Email : sherman at mrcc dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <QtTest>
#include <QObject>
#include <QString>
#include <QStringList>
#include <QObject>
#include <iostream>
#include <QApplication>
#include <QFileInfo>
#include <QDir>

//qgis includes...
#include <qgsmaplayer.h>
#include <qgsvectorlayer.h>
#include <qgsapplication.h>
#include <qgsproviderregistry.h>

/** \ingroup UnitTests
* This is a unit test for the QgsMapLayer class.
*/
class TestQgsMapLayer: public QObject
{
Q_OBJECT;
private slots:
void initTestCase();// will be called before the first testfunction is executed.
void cleanupTestCase(){};// will be called after the last testfunction was executed.
void init(){};// will be called before each testfunction is executed.
void cleanup(){};// will be called after every testfunction.

void isValid();
private:
QgsMapLayer * mpLayer;
};

void TestQgsMapLayer::initTestCase()
{
// init QGIS's paths - true means that all path will be inited from prefix
QString qgisPath = QCoreApplication::applicationDirPath ();
QgsApplication::setPrefixPath(qgisPath, TRUE);
#ifdef Q_OS_LINUX
QgsApplication::setPkgDataPath(qgisPath + "/../share/qgis");
QgsApplication::setPluginPath(qgisPath + "/../lib/qgis");
#endif
// Instantiate the plugin directory so that providers are loaded
QgsProviderRegistry::instance(QgsApplication::pluginPath());

//create some objects that will be used in all tests...

std::cout << "Prefix PATH: " << QgsApplication::prefixPath().toLocal8Bit().data() << std::endl;
std::cout << "Plugin PATH: " << QgsApplication::pluginPath().toLocal8Bit().data() << std::endl;
std::cout << "PkgData PATH: " << QgsApplication::pkgDataPath().toLocal8Bit().data() << std::endl;
std::cout << "User DB PATH: " << QgsApplication::qgisUserDbFilePath().toLocal8Bit().data() << std::endl;

//create a map layer that will be used in all tests...
QString myFileName (TEST_DATA_DIR); //defined in CmakeLists.txt
myFileName = myFileName + QDir::separator() + "points.shp";
QFileInfo myMapFileInfo ( myFileName );
mpLayer = new QgsVectorLayer ( myMapFileInfo.filePath(),
myMapFileInfo.completeBaseName(), "ogr" );
}

void TestQgsMapLayer::isValid()
{
QVERIFY ( mpLayer->isValid() );
}

QTEST_MAIN(TestQgsMapLayer)
#include "moc_testqgsmaplayer.cxx"

0 comments on commit 1a2ddfc

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