From 02be545a7616b5d8e10ddecba411d01fd20df869 Mon Sep 17 00:00:00 2001 From: Lene Preuss Date: Fri, 28 Mar 2014 18:55:08 +0100 Subject: [PATCH] added test for ChangeDir (#30) --- tests/Test_ChangeDir.cpp | 37 +++++++++++++++++++++++++++++++++++++ tests/Test_ChangeDir.h | 32 ++++++++++++++++++++++++++++++++ tests/main.cpp | 7 +++++-- tests/tests.pro | 2 ++ 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 tests/Test_ChangeDir.cpp create mode 100644 tests/Test_ChangeDir.h diff --git a/tests/Test_ChangeDir.cpp b/tests/Test_ChangeDir.cpp new file mode 100644 index 00000000..2ec5f50a --- /dev/null +++ b/tests/Test_ChangeDir.cpp @@ -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 + +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")); +} \ No newline at end of file diff --git a/tests/Test_ChangeDir.h b/tests/Test_ChangeDir.h new file mode 100644 index 00000000..79a0c5b7 --- /dev/null +++ b/tests/Test_ChangeDir.h @@ -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 + +class Test_ChangeDir: public QObject { + + Q_OBJECT + +private slots: + + void initTestCase(); + + void dirIsChanged(); + void changeBackOnExit(); + +private: + QString temp_dir; + +}; + +#endif /* TEST_CHANGEDIR_H */ + diff --git a/tests/main.cpp b/tests/main.cpp index 11480cfb..863fcab1 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -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" @@ -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" @@ -77,6 +78,7 @@ void fillTestsMap() { tests_by_name.insert(std::pair("Object", new Test_Object)); tests_by_name.insert(std::pair("Util", new Test_Util)); tests_by_name.insert(std::pair("FacePolygon", new Test_FacePolygon)); + tests_by_name.insert(std::pair("ChangeDir", new Test_ChangeDir)); } int main(int argc, char **argv) { @@ -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) { diff --git a/tests/tests.pro b/tests/tests.pro index b7d171a8..3f0d7c94 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -59,6 +59,7 @@ SOURCES += Auxiliary/GlobalFunctions.cpp \ HEADERS += \ Test_Util.h \ + Test_ChangeDir.h \ Test_Composite.h \ Test_Rotope.h \ Test_Object.h \ @@ -85,6 +86,7 @@ HEADERS += \ SOURCES += \ Test_Util.cpp \ + Test_ChangeDir.cpp \ Test_Composite.cpp \ Test_Rotope.cpp \ Test_Object.cpp \