Skip to content

Commit

Permalink
test gui using QTest
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCaha committed Dec 5, 2023
1 parent 0a5a90d commit c6b038f
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if(NEEDS_QT)
message(STATUS "Using Qt")
set(CMAKE_AUTOMOC TRUE)

find_package(Qt5 COMPONENTS Core Widgets Xml Gui REQUIRED)
find_package(Qt5 COMPONENTS Core Widgets Xml Gui Test REQUIRED)

set(QT_INCLUDES
${Qt5Core_INCLUDE_DIRS}
Expand Down
3 changes: 3 additions & 0 deletions src/bin/fileselectorwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@ namespace ViewshedBinaries
QAction *mClearAction = nullptr;

void clearValue();

friend class TestFileSelectorWidget;
friend class TestViewshedCalculatorWindow;
};
}
2 changes: 2 additions & 0 deletions src/bin/pointwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ namespace ViewshedBinaries
bool mAddCrsLabel = true;
OGRSpatialReference mCrs;

friend class TestPointWidget;
friend class TestViewshedCalculatorWindow;
};
} // namespace ViewshedBinaries
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ ADD_LIBRARY_TEST(testviewshed)
ADD_LIBRARY_TEST(testinverselosalgorithms)
ADD_LIBRARY_TEST(testinverseviewshed)
ADD_LIBRARY_TEST(testviewshedtiming)

ADD_GUI_TEST(testviewshedcalculator)
ADD_GUI_TEST(testpointwidget)
ADD_GUI_TEST(testfileselectorwidget)
72 changes: 72 additions & 0 deletions tests/gui/testpointwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <QString>

#include <QtTest/QtTest>

#include "pointwidget.h"

#include "testsettings.h"

using ViewshedBinaries::PointWidget;

namespace ViewshedBinaries
{
class TestPointWidget : public QObject
{
Q_OBJECT
private slots:

void initTestCase() { widget = new PointWidget(); }

void sendKeysXYWrong()
{
QCOMPARE( widget->mPoint.getX(), 0 );
QCOMPARE( widget->mPoint.getY(), 0 );

QTest::keyClicks( widget->mPointX, "a" );
Q_ASSERT( widget->mPointValid == false );

QTest::keyClicks( widget->mPointY, "-1189108.615" );
}

void sendKeysXY()
{
QCOMPARE( widget->mPoint.getX(), 0 );
QCOMPARE( widget->mPoint.getY(), 0 );

QTest::keyClicks( widget->mPointX, "-336364.021" );
QTest::keyClicks( widget->mPointY, "-1189108.615" );

Q_ASSERT( qFuzzyCompare( widget->mPoint.getX(), -336364.021 ) );
Q_ASSERT( qFuzzyCompare( widget->mPoint.getY(), -1189108.615 ) );
Q_ASSERT( widget->mPointValid );

OGRWktOptions wktOpts = OGRWktOptions();
wktOpts.precision = 3;

QCOMPARE( widget->point().exportToWkt( wktOpts ),
OGRPoint( -336364.021, -1189108.615 ).exportToWkt( wktOpts ) );
Q_ASSERT( widget->crs().IsEmpty() );
}

void changeCrs()
{
Q_ASSERT( widget->crs().IsEmpty() );

OGRSpatialReference crs;
crs.SetFromUserInput( "EPSG:4326" );

widget->setCrs( crs );

Q_ASSERT( widget->crs().IsEmpty() == false );
Q_ASSERT( widget->crs().IsSame( &crs ) );
QCOMPARE( widget->mCrsLabel->text(), "[EPSG:4326]" );
}

private:
PointWidget *widget;
};
} // namespace ViewshedBinaries

QTEST_MAIN( ViewshedBinaries::TestPointWidget )

#include "testpointwidget.moc"
52 changes: 52 additions & 0 deletions tests/gui/testviewshedcalculator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <QDir>
#include <QString>

#include <QtTest/QtTest>

#include "viewshedcalculatorwindow.h"

#include "testsettings.h"

namespace ViewshedBinaries
{
class TestViewshedCalculatorWindow : public QObject
{
Q_OBJECT
private slots:

void initTestCase() { mWindow = new MainCalculatorWindow(); }

void setup()
{
QTest::keyClicks( mWindow->mPointWidget->mPointX, "-336364.021" );
QTest::keyClicks( mWindow->mPointWidget->mPointY, "-1189108.615" );

QTest::keyClicks( mWindow->mFileWidget->mText, QString( TEST_DATA_DSM ) );
QTest::keyClicks( mWindow->mFolderWidget->mText, QString( TEST_DATA_RESULTS_DIR ) );

// QTest::keyClicks( mWindow->mObserverOffset, "1.6" );
// QTest::keyClicks( mWindow->mTargetOffset, "0.0" );
}

// void runViewshed()
// {
// QTest::mouseClick( mWindow->mCalculateButton, Qt::LeftButton );

// // QTest::qWait( 0 );
// QTest::qWait( 15000 );

// QDir directory( TEST_DATA_RESULTS_DIR );
// QStringList rasters = directory.entryList( QStringList() << "*.tif"
// << "*.TIF",
// QDir::Files );
// Q_ASSERT( rasters.count() == 20 );
// }

private:
MainCalculatorWindow *mWindow;
};
} // namespace ViewshedBinaries

QTEST_MAIN( ViewshedBinaries::TestViewshedCalculatorWindow )

#include "testviewshedcalculator.moc"

0 comments on commit c6b038f

Please sign in to comment.