diff --git a/tests/auto/settings/settings.pro b/tests/auto/settings/settings.pro new file mode 100644 index 00000000..1c9678b5 --- /dev/null +++ b/tests/auto/settings/settings.pro @@ -0,0 +1,5 @@ +include(../../../guh.pri) +include(../autotests.pri) + +TARGET = testsettings +SOURCES += testsettings.cpp diff --git a/tests/auto/settings/testsettings.cpp b/tests/auto/settings/testsettings.cpp new file mode 100644 index 00000000..25acb99f --- /dev/null +++ b/tests/auto/settings/testsettings.cpp @@ -0,0 +1,101 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2015 Simon Stürz * + * Copyright (C) 2014 Michael Zanetti * + * * + * This file is part of guh. * + * * + * Guh 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, version 2 of the License. * + * * + * Guh 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 guh. If not, see . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "guhtestbase.h" +#include "guhcore.h" +#include "devicemanager.h" +#include "guhsettings.h" +#include "logging/logentry.h" +#include "plugin/deviceplugin.h" + +#include +#include "guhsettings.h" + +using namespace guhserver; + +class TestSettings : public GuhTestBase +{ + Q_OBJECT + +private: + + +private slots: + void getSetLanguages(); + + +}; + +void TestSettings::getSetLanguages() +{ + enableNotifications(); + + QVariant response; QVariantMap params; + response = injectAndWait("Configuration.GetAvailableLanguages"); + QVERIFY2(response.toMap().value("params").toMap().contains("languages"), "Did not get list of languages"); + QVariantMap responseMap = response.toMap().value("params").toMap(); + QVERIFY2(responseMap.value("languages").toList().count() >= 2, "Avaliable languages list to short: " + responseMap.value("languages").toList().count()); + + QVariantList languageVariantList = responseMap.value("languages").toList(); + + + QSignalSpy notificationSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray))); + + foreach (const QVariant &languageVariant, languageVariantList) { + + // Get current configurations + response = injectAndWait("Configuration.GetConfigurations"); + QVariantMap configurationMap = response.toMap().value("params").toMap(); + + params.clear(); + params.insert("language", languageVariant); + + notificationSpy.clear(); + + // Set language + QVariant response = injectAndWait("Configuration.SetLanguage", params); + verifyConfigurationError(response); + + // Check notification + notificationSpy.wait(500); + QVariantList configurationChangedNotifications = checkNotifications(notificationSpy, "Configuration.LanguageChanged"); + printJson(configurationChangedNotifications); + + // If the language did not change no notification should be emited + if (configurationMap.value("basicConfiguration").toMap().value("language").toString() == languageVariant.toString()) { + QVERIFY2(configurationChangedNotifications.count() == 0, "Got Configuration.LanguageChanged notification but should have not."); + } else { + QVERIFY2(configurationChangedNotifications.count() == 1, "Should get only one Configuration.LanguageChanged notification"); + } + } + + // Reset the language to en_US + params.clear(); response.clear(); + params.insert("language", "en_US"); + + // Set language + response = injectAndWait("Configuration.SetLanguage", params); + verifyConfigurationError(response); +} + +#include "testsettings.moc" +QTEST_MAIN(TestSettings) +