From b576f6b17e17083257763d5bcb6bf2b64dd200c3 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 15 Mar 2016 15:16:19 +0100 Subject: A test helper to avoid writing to the data directory. --- common/CMakeLists.txt | 2 ++ common/test.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ common/test.h | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 common/test.cpp create mode 100644 common/test.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 0d61d90..4cb9e91 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -63,6 +63,7 @@ set(command_SRCS domain/event.cpp domain/mail.cpp domain/folder.cpp + test.cpp ${storage_SRCS}) add_library(${PROJECT_NAME} SHARED ${command_SRCS}) @@ -113,6 +114,7 @@ install(FILES inspection.h notification.h bufferadaptor.h + test.h ${CMAKE_CURRENT_BINARY_DIR}/sink_export.h DESTINATION ${INCLUDE_INSTALL_DIR}/${PROJECT_NAME} COMPONENT Devel ) diff --git a/common/test.cpp b/common/test.cpp new file mode 100644 index 0000000..0864f1a --- /dev/null +++ b/common/test.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2014 Christian Mollekopf + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "test.h" + +#include +#include +#include + +void Sink::Test::initTest() +{ + QStandardPaths::setTestModeEnabled(true); + // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); + QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)).removeRecursively(); + // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::DataLocation); + QDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation)).removeRecursively(); + // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); + QDir(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)).removeRecursively(); + // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); + QDir(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)).removeRecursively(); + // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::CacheLocation); + QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)).removeRecursively(); + // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation); + QDir(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)).removeRecursively(); +} diff --git a/common/test.h b/common/test.h new file mode 100644 index 0000000..146b4ac --- /dev/null +++ b/common/test.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2014 Christian Mollekopf + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#pragma once + +#include "sink_export.h" + +namespace Sink { +namespace Test { +/** + * Initialize the test environment. + * + * This makes use of QStandardPaths::setTestModeEnabled to avoid writing to the user directory, + * and clears all data directories. + */ +void SINK_EXPORT initTest(); +} +} -- cgit v1.2.3