Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCaha committed Dec 5, 2023
1 parent c6b038f commit 3be318e
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/gui/testfileselectorwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <QString>

#include <QtTest/QtTest>

#include "fileselectorwidget.h"

#include "testsettings.h"

using ViewshedBinaries::FileSelectorWidget;

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

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

void sendKeysNotPath()
{
widget->clearValue();
widget->setStorageMode( FileSelectorWidget::StorageMode::GetFile );

QSignalSpy spyFileChanged( widget, &FileSelectorWidget::fileChanged );

QTest::keyClicks( widget->mText, "a/b/c" );

QCOMPARE( spyFileChanged.count(), 0 );
QCOMPARE( widget->mFilePath, QString() );
}

void sendKeysPath()
{
widget->clearValue();
widget->setStorageMode( FileSelectorWidget::StorageMode::GetFile );

QSignalSpy spyFileChanged( widget, &FileSelectorWidget::fileChanged );

QTest::keyClicks( widget->mText, QString( TEST_DATA_DSM ) );

QCOMPARE( spyFileChanged.count(), 1 );
QCOMPARE( widget->mFilePath, TEST_DATA_DSM );
}

void sendKeysFolder()
{
widget->clearValue();
widget->setStorageMode( FileSelectorWidget::StorageMode::GetDirectory );

QSignalSpy spyFileChanged( widget, &FileSelectorWidget::fileChanged );

QTest::keyClicks( widget->mText, QString( TEST_DATA_RESULTS_DIR ) );

QCOMPARE( spyFileChanged.count(), 16 );
QCOMPARE( widget->mFilePath, TEST_DATA_RESULTS_DIR );
}

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

QTEST_MAIN( ViewshedBinaries::TestFileSelectorWidget )

#include "testfileselectorwidget.moc"

0 comments on commit 3be318e

Please sign in to comment.