diff options
Diffstat (limited to 'tests/unit/Settings')
-rw-r--r-- | tests/unit/Settings/FieldStyleFactory_test.cpp | 88 | ||||
-rw-r--r-- | tests/unit/Settings/FieldStyleFactory_test.h | 29 | ||||
-rw-r--r-- | tests/unit/Settings/StudySettings_test.cpp | 42 | ||||
-rw-r--r-- | tests/unit/Settings/StudySettings_test.h | 22 | ||||
-rw-r--r-- | tests/unit/Settings/TestSettings.cpp | 16 | ||||
-rw-r--r-- | tests/unit/Settings/TestSettings.h | 11 | ||||
-rw-r--r-- | tests/unit/Settings/set.pri | 10 |
7 files changed, 218 insertions, 0 deletions
diff --git a/tests/unit/Settings/FieldStyleFactory_test.cpp b/tests/unit/Settings/FieldStyleFactory_test.cpp new file mode 100644 index 0000000..be53e7c --- /dev/null +++ b/tests/unit/Settings/FieldStyleFactory_test.cpp @@ -0,0 +1,88 @@ +#include "FieldStyleFactory_test.h" +#include "../../common/printQtTypes.h" +#include "TestSettings.h" + +void FieldStyleFactoryTest::SetUp() +{ + TestSettings::init(); +} + +FieldStyleFactory FieldStyleFactoryTest::getDefaults() +{ + FieldStyleFactory factory; + factory.cardBgColor.setNamedColor("#ffffff"); + factory.setStyle(FieldStyleFactory::DefaultStyle, + {"Times New Roman", 18, true, false, "black" , "", ""}); + factory.setStyle("Example", + {"Times New Roman", 14, false, false, "black", "", "", true, "blue"}); + factory.setStyle("Transcription", + {"Arial", 18, false, false, "black", "/", "/"}); + factory.setStyle("Big", {"Arial", 26, true, false, "black"}); + factory.setStyle("Color1", {"Times New Roman", 18, true, false, "red"}); + factory.setStyle("Color2", {"Times New Roman", 18, true, false, "blue"}); + return factory; +} + +FieldStyleFactory FieldStyleFactoryTest::getUserSettings() +{ + FieldStyleFactory factory; + factory.cardBgColor.setNamedColor("#ffff00"); + factory.setStyle(FieldStyleFactory::DefaultStyle, + {"Georgia", 19, false, true, "#550000", "", ""}); + factory.setStyle("Example", + {"Times New Roman", 15, true, false, "black", "", ""}); + factory.setStyle("Transcription", + {"Verdana", 18, true, false, "black", "[", "]"}); + factory.setStyle("Big", + {"Arial", 27, false, false, "black", "", "", true, "blue"}); + factory.setStyle("Color1", {"Times New Roman", 18, true, false, "green"}); + factory.setStyle("Color2", {"Times New Roman", 18, true, false, "#00FFFF"}); + return factory; +} + +TEST_F(FieldStyleFactoryTest, DefaultValues) +{ + TestFieldStyleFactory factory; + SCOPED_TRACE("Default values"); + factory.check(getDefaults()); +} + +TEST_F(FieldStyleFactoryTest, UserValues) +{ + FieldStyleFactory::inst()->load(); + SCOPED_TRACE("User values"); + static_cast<TestFieldStyleFactory*>(FieldStyleFactory::inst())-> + check(getUserSettings()); +} + +void TestFieldStyleFactory::check(const FieldStyleFactory& expFactory) +{ + ASSERT_EQ(expFactory.cardBgColor.name(), cardBgColor.name()); + checkStyles(expFactory); +} + +void TestFieldStyleFactory::checkStyles(const FieldStyleFactory& expFactory) +{ + ASSERT_EQ(expFactory.getStyleNames(), getStyleNames()); + foreach(QString styleName, getStyleNames()) + { + SCOPED_TRACE(styleName.toStdString()); + checkStyle(expFactory.getStyle(styleName), styleName); + } +} + +void TestFieldStyleFactory::checkStyle(const FieldStyle& expStyle, + const QString& actualStyleName) +{ + FieldStyle actualStyle = getStyle(actualStyleName); + ASSERT_EQ(expStyle.font.family(), actualStyle.font.family()); + ASSERT_EQ(expStyle.font.pointSize(), actualStyle.font.pointSize()); + ASSERT_EQ(expStyle.font.bold(), actualStyle.font.bold()); + ASSERT_EQ(expStyle.font.italic(), actualStyle.font.italic()); + ASSERT_EQ(expStyle.color.name(), actualStyle.color.name()); + ASSERT_EQ(expStyle.prefix, actualStyle.prefix); + ASSERT_EQ(expStyle.suffix, actualStyle.suffix); + ASSERT_EQ(expStyle.hasKeyword, actualStyle.hasKeyword); + if(expStyle.hasKeyword) + ASSERT_EQ(expStyle.keywordColor.name(), actualStyle.keywordColor.name()); +} diff --git a/tests/unit/Settings/FieldStyleFactory_test.h b/tests/unit/Settings/FieldStyleFactory_test.h new file mode 100644 index 0000000..9b7d410 --- /dev/null +++ b/tests/unit/Settings/FieldStyleFactory_test.h @@ -0,0 +1,29 @@ +#ifndef FIELD_STYLE_FACTORY_TEST_H +#define FIELD_STYLE_FACTORY_TEST_H + +#include <gtest/gtest.h> +#include <QtCore> + +#include "../../../src/field-styles/FieldStyleFactory.h" + +class TestFieldStyleFactory: public FieldStyleFactory +{ +public: + void check(const FieldStyleFactory& expFactory); + +private: + void checkStyles(const FieldStyleFactory& expFactory); + void checkStyle(const FieldStyle& expStyle, const QString& actualStyleName); +}; + +class FieldStyleFactoryTest: public testing::Test +{ +public: + static FieldStyleFactory getDefaults(); + static FieldStyleFactory getUserSettings(); + +public: + void SetUp(); +}; + +#endif diff --git a/tests/unit/Settings/StudySettings_test.cpp b/tests/unit/Settings/StudySettings_test.cpp new file mode 100644 index 0000000..d66b8a1 --- /dev/null +++ b/tests/unit/Settings/StudySettings_test.cpp @@ -0,0 +1,42 @@ +#include "StudySettings_test.h" +#include "../../common/printQtTypes.h" +#include "TestSettings.h" + +void StudySettingsTest::SetUp() +{ + TestSettings::init(); +} + +StudySettings StudySettingsTest::getDefaults() +{ + StudySettings defaults; + defaults.dayShift = 3; + return defaults; +} + +StudySettings StudySettingsTest::getUserSettings() +{ + + StudySettings user; + user.dayShift = 4; + return user; +} + +TEST_F(StudySettingsTest, DefaultValues) +{ + StudySettings settings; + SCOPED_TRACE("Default values"); + check(getDefaults(), settings); +} + +TEST_F(StudySettingsTest, UserValues) +{ + StudySettings::inst()->load(); + SCOPED_TRACE("User values"); + check(getUserSettings(), *StudySettings::inst()); +} + +void StudySettingsTest::check(const StudySettings& expected, const StudySettings& actual) +{ + ASSERT_EQ(expected.dayShift, actual.dayShift); +} diff --git a/tests/unit/Settings/StudySettings_test.h b/tests/unit/Settings/StudySettings_test.h new file mode 100644 index 0000000..aa45ead --- /dev/null +++ b/tests/unit/Settings/StudySettings_test.h @@ -0,0 +1,22 @@ +#ifndef STUDY_SETTINGS_TEST_H +#define STUDY_SETTINGS_TEST_H + +#include <gtest/gtest.h> +#include <QtCore> + +#include "../../../src/study/StudySettings.h" + +class StudySettingsTest: public testing::Test +{ +public: + static StudySettings getDefaults(); + static StudySettings getUserSettings(); + +protected: + void check(const StudySettings& expected, const StudySettings& actual); + +public: + void SetUp(); +}; + +#endif diff --git a/tests/unit/Settings/TestSettings.cpp b/tests/unit/Settings/TestSettings.cpp new file mode 100644 index 0000000..1f3fbb4 --- /dev/null +++ b/tests/unit/Settings/TestSettings.cpp @@ -0,0 +1,16 @@ +#include <QtCore> +#include <gtest/gtest.h> + +#include "TestSettings.h" + +void TestSettings::init() +{ + QSettings::setDefaultFormat(QSettings::IniFormat); + QCoreApplication::setOrganizationName("freshmemory"); + QCoreApplication::setApplicationName("freshmemory"); + QString appDir = qApp->applicationDirPath(); + QString userSettingsDir = appDir + "/../common"; + QString systemSettingsDir = appDir + "/../../config"; + QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, userSettingsDir); + QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, systemSettingsDir); +} diff --git a/tests/unit/Settings/TestSettings.h b/tests/unit/Settings/TestSettings.h new file mode 100644 index 0000000..60b8be8 --- /dev/null +++ b/tests/unit/Settings/TestSettings.h @@ -0,0 +1,11 @@ +#ifndef TEST_SETTINGS_H +#define TEST_SETTINGS_H + +class TestSettings +{ +public: + static void init(); + +}; + +#endif diff --git a/tests/unit/Settings/set.pri b/tests/unit/Settings/set.pri new file mode 100644 index 0000000..df1871f --- /dev/null +++ b/tests/unit/Settings/set.pri @@ -0,0 +1,10 @@ +HEADERS += \ + $$PWD/TestSettings.h \ + $$PWD/StudySettings_test.h \ + $$PWD/FieldStyleFactory_test.h + +SOURCES += \ + $$PWD/TestSettings.cpp \ + $$PWD/StudySettings_test.cpp \ + $$PWD/FieldStyleFactory_test.cpp +
\ No newline at end of file |