From fa6aa63f0d4e03e916590b6faf777618d7a675b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20P=C3=A5lsson?= Date: Thu, 6 Feb 2014 12:38:06 +0100 Subject: Added BrowserConfig class and tests --- browser/browserconfig.cpp | 35 ++++++++++++++++++++++++++ browser/browserconfig.h | 30 ++++++++++++++++++++++ browser/unit-tests/browserview/testbrowser.cpp | 10 ++++++++ browser/unit-tests/browserview/testbrowser.h | 1 + 4 files changed, 76 insertions(+) create mode 100644 browser/browserconfig.cpp create mode 100644 browser/browserconfig.h diff --git a/browser/browserconfig.cpp b/browser/browserconfig.cpp new file mode 100644 index 0000000..89297a8 --- /dev/null +++ b/browser/browserconfig.cpp @@ -0,0 +1,35 @@ +/** + * Copyright (C) 2014, Pelagicore + * + * Author: Jonatan Palsson + * + * This file is part of the GENIVI project Browser Proof-Of-Concept + * For further information, see http://genivi.org/ + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#include + +#include "browserconfig.h" + +template void BrowserConfig::setValue(BrowserConfig::BrowserConfigKey, int); +template void BrowserConfig::setValue(BrowserConfig::BrowserConfigKey, QString); +template int BrowserConfig::getValue(BrowserConfig::BrowserConfigKey); +template QString BrowserConfig::getValue(BrowserConfig::BrowserConfigKey); + +BrowserConfig::BrowserConfig() { + m_qsettings = new QSettings("browserpoc"); +} + +template +T BrowserConfig::getValue(BrowserConfig::BrowserConfigKey key) { + return m_qsettings->value(QString(key)).value(); +} + +template +void BrowserConfig::setValue(BrowserConfig::BrowserConfigKey key, T value) { + m_qsettings->setValue(QString(key), value); + m_qsettings->sync(); +} diff --git a/browser/browserconfig.h b/browser/browserconfig.h new file mode 100644 index 0000000..c95c624 --- /dev/null +++ b/browser/browserconfig.h @@ -0,0 +1,30 @@ +/** + * Copyright (C) 2014, Pelagicore + * + * Author: Jonatan Palsson + * + * This file is part of the GENIVI project Browser Proof-Of-Concept + * For further information, see http://genivi.org/ + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#include +#include + +class BrowserConfig : public QObject{ +Q_OBJECT +public: + enum BrowserConfigKey {CONFIG_CACHESIZE}; + BrowserConfig(); + + template + T getValue(BrowserConfigKey); + + template + void setValue(BrowserConfigKey, T); + +private: + QSettings *m_qsettings = NULL; +}; diff --git a/browser/unit-tests/browserview/testbrowser.cpp b/browser/unit-tests/browserview/testbrowser.cpp index a5b3a59..eaaa731 100644 --- a/browser/unit-tests/browserview/testbrowser.cpp +++ b/browser/unit-tests/browserview/testbrowser.cpp @@ -7,6 +7,7 @@ #include "testbrowser.h" #include "../../browserview.h" +#include "../../browserconfig.h" /////////////// Test cases /////////////// @@ -191,4 +192,13 @@ void TestBrowser::testCanGetFavicon () { QVERIFY(QFileInfo(fileName).size() > 0); } +void TestBrowser::testCanSetGetConfigParameter() { + BrowserConfig conf; + conf.setValue(BrowserConfig::CONFIG_CACHESIZE, 1337); + QVERIFY(conf.getValue(BrowserConfig::CONFIG_CACHESIZE) == 1337); + + conf.setValue(BrowserConfig::CONFIG_CACHESIZE, "1337"); + QVERIFY(conf.getValue(BrowserConfig::CONFIG_CACHESIZE).compare("1337") == 0); +} + QTEST_MAIN (TestBrowser); diff --git a/browser/unit-tests/browserview/testbrowser.h b/browser/unit-tests/browserview/testbrowser.h index b1e5014..4464876 100644 --- a/browser/unit-tests/browserview/testbrowser.h +++ b/browser/unit-tests/browserview/testbrowser.h @@ -16,4 +16,5 @@ private slots: void testGetUrl(); void testCanCreateScreenshot(); void testCanGetFavicon(); + void testCanSetGetConfigParameter(); }; -- cgit v1.2.1