diff --git a/autotests/menutest.cpp b/autotests/menutest.cpp index 00faff6..1dcef56 100644 --- a/autotests/menutest.cpp +++ b/autotests/menutest.cpp @@ -1,79 +1,79 @@ /************************************************************************************ * Copyright (C) 2014 Aleix Pol Gonzalez * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * ************************************************************************************/ #include #include #include #include #include #include "menutest.h" #include #include QTEST_MAIN(MenuTest) QAction* saveAsAction(Purpose::Menu* menu) { foreach(QAction* action, menu->actions()) { if (action->property("pluginId") == QLatin1String("saveasplugin")) { return action; } } Q_ASSERT(!"Couldn't find the saveas plugin"); return nullptr; } void MenuTest::runJobTest() { Purpose::Menu* menu = new Purpose::Menu; Purpose::AlternativesModel* model = menu->model(); model->setDisabledPlugins({}); - const QString tempfile = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + QStringLiteral("/purposetest"); + const QString tempfile = m_tempDir.path() + QStringLiteral("/purposetest"); QFile::remove(tempfile); const QJsonObject input = QJsonObject { { QStringLiteral("urls"), QJsonArray {QStringLiteral("http://kde.org")} }, { QStringLiteral("mimeType"), QStringLiteral("dummy/thing") }, { QStringLiteral("destinationPath"), QUrl::fromLocalFile(tempfile).url() } }; model->setInputData(input); model->setPluginType(QStringLiteral("Export")); menu->reload(); int error = -1; QJsonObject output; connect(menu, &Purpose::Menu::finished, menu, [&error, &output](const QJsonObject &_output, int _error, const QString &errorMessage) { error = _error; output = _output; if (error != 0) { qDebug() << "job failed with error" << errorMessage; } }); QAction* action = saveAsAction(menu); QSignalSpy s(menu, &Purpose::Menu::finished); action->trigger(); QVERIFY(s.count() || s.wait()); QCOMPARE(error, 0); QCOMPARE(output.count(), 1); QVERIFY(QFile::remove(tempfile)); delete menu; } diff --git a/autotests/menutest.h b/autotests/menutest.h index 2ed7957..0c10d44 100644 --- a/autotests/menutest.h +++ b/autotests/menutest.h @@ -1,30 +1,33 @@ /************************************************************************************ * Copyright (C) 2014 Aleix Pol Gonzalez * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * ************************************************************************************/ #ifndef ALTERNATIVESMODELTEST_H #define ALTERNATIVESMODELTEST_H #include +#include class MenuTest : public QObject { Q_OBJECT private Q_SLOTS: void runJobTest(); +private: + QTemporaryDir m_tempDir; }; #endif