Skip to content

Commit

Permalink
Test Friday! QgsClipper test
Browse files Browse the repository at this point in the history
  • Loading branch information
homann committed Sep 14, 2012
1 parent c328539 commit 3130719
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/src/core/CMakeLists.txt
Expand Up @@ -78,6 +78,7 @@ ENDMACRO (ADD_QGIS_TEST)
#############################################################
# Tests:

ADD_QGIS_TEST(clippertest testqgsclipper.cpp)
ADD_QGIS_TEST(distanceareatest testqgsdistancearea.cpp)
ADD_QGIS_TEST(applicationtest testqgsapplication.cpp)
ADD_QGIS_TEST(expressiontest testqgsexpression.cpp)
Expand Down
69 changes: 69 additions & 0 deletions tests/src/core/testqgsclipper.cpp
@@ -0,0 +1,69 @@
/***************************************************************************
testqgsclipper.cpp
--------------------------------------
Date : Tue 14 Aug 2012
Copyright : (C) 2012 by Magnus Homann
Email : magnus at homann dot se
***************************************************************************
* *
* 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 <QFile>
#include <QTextStream>
#include <QObject>
#include <QString>
#include <QStringList>
#include <qgsapplication.h>
//header for class being tested
#include <qgsclipper.h>
#include <qgspoint.h>
#include "qgslogger.h"

class TestQgsClipper: 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 basic();
};

void TestQgsClipper::initTestCase()
{
//
// Runs once before any tests are run
//
// init QGIS's paths - true means that all path will be inited from prefix
// QgsApplication::init();
// QgsApplication::initQgis();
// QgsApplication::showSettings();
}

void TestQgsClipper::basic()
{
// CQgsClipper is static only
//QgsClipper snipsnip;

QPolygonF polygon;
polygon << QPointF(10.4, 20.5) << QPointF(20.2, 30.2);

QgsRectangle clipRect(10, 10, 25, 30 );

QgsClipper::trimPolygon( polygon, clipRect );

QRectF bBox( polygon.boundingRect() );
QgsRectangle boundingRect( bBox.bottomLeft().x(), bBox.bottomLeft().y(), bBox.topRight().x(), bBox.topRight().y() );

QVERIFY( clipRect.contains( boundingRect ) );
};

QTEST_MAIN( TestQgsClipper )
#include "moc_testqgsclipper.cxx"

0 comments on commit 3130719

Please sign in to comment.