Skip to content

Commit

Permalink
added test for ChangeDir (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
lene committed Mar 28, 2014
1 parent e1a77db commit 02be545
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
37 changes: 37 additions & 0 deletions tests/Test_ChangeDir.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* File: Test_ChangeDir.cpp
* Author: lene
*
* Created on 28 March 2014, 18:38
*/

#include "Test_ChangeDir.h"

#include "GlobalFunctions.h"

#include <QTemporaryDir>

using namespace UnitTests;

void Test_ChangeDir::initTestCase() {
}

void Test_ChangeDir::dirIsChanged() {
QTemporaryDir temp_dir;
test(temp_dir.isValid(), std::string("temporary directory created"));
test(QDir::currentPath() != temp_dir.path(), std::string("whut? we already changed to the temp dir?"));
ChangeDir path_change(temp_dir.path());
test(QDir::currentPath() == temp_dir.path(), std::string("path changed"));
}

void Test_ChangeDir::changeBackOnExit() {
QTemporaryDir temp_dir;
test(temp_dir.isValid(), std::string("temporary directory created"));
QString old_path = QDir::currentPath();
test(old_path != temp_dir.path(), std::string("whut? we already changed to the temp dir?"));
{
ChangeDir path_change(temp_dir.path());
test(QDir::currentPath() == temp_dir.path(), std::string("path changed"));
}
test(QDir::currentPath() == old_path, std::string("path changed back when objet went out of scope"));
}
32 changes: 32 additions & 0 deletions tests/Test_ChangeDir.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* File: Test_ChangeDir.h
* Author: lene
*
* Created on 28 March 2014, 18:38
*/

#ifndef TEST_CHANGEDIR_H
#define TEST_CHANGEDIR_H

#include "ChangeDir.h"

#include <QtTest/QtTest>

class Test_ChangeDir: public QObject {

Q_OBJECT

private slots:

void initTestCase();

void dirIsChanged();
void changeBackOnExit();

private:
QString temp_dir;

};

#endif /* TEST_CHANGEDIR_H */

7 changes: 5 additions & 2 deletions tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/

/// Otherwise, only run the latest test suites, as manually defined below
#define RUN_ALL_TESTS 1
#define RUN_ALL_TESTS 0

#include "Test_Rotope.h"
#include "Test_Displayable.h"
Expand All @@ -45,6 +45,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "Test_Util.h"
#include "Test_PartitionedMultithreadedMap.h"
#include "Test_FacePolygon.h"
#include "Test_ChangeDir.h"

#include "Auxiliary/TestRunner.h"

Expand Down Expand Up @@ -77,6 +78,7 @@ void fillTestsMap() {
tests_by_name.insert(std::pair<std::string, QObject *>("Object", new Test_Object));
tests_by_name.insert(std::pair<std::string, QObject *>("Util", new Test_Util));
tests_by_name.insert(std::pair<std::string, QObject *>("FacePolygon", new Test_FacePolygon));
tests_by_name.insert(std::pair<std::string, QObject *>("ChangeDir", new Test_ChangeDir));
}

int main(int argc, char **argv) {
Expand All @@ -99,7 +101,8 @@ int main(int argc, char **argv) {
}
# else
// runner.run(new Test_ArrayList);
runner.run(new Test_FacePolygon);
// runner.run(new Test_FacePolygon);
runner.run(new Test_ChangeDir);
# endif
} else {
for (auto test: tests_to_run) {
Expand Down
2 changes: 2 additions & 0 deletions tests/tests.pro
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ SOURCES += Auxiliary/GlobalFunctions.cpp \

HEADERS += \
Test_Util.h \
Test_ChangeDir.h \
Test_Composite.h \
Test_Rotope.h \
Test_Object.h \
Expand All @@ -85,6 +86,7 @@ HEADERS += \

SOURCES += \
Test_Util.cpp \
Test_ChangeDir.cpp \
Test_Composite.cpp \
Test_Rotope.cpp \
Test_Object.cpp \
Expand Down

0 comments on commit 02be545

Please sign in to comment.