summaryrefslogtreecommitdiff
path: root/tests/unit/Settings/FieldStyleFactory_test.cpp
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2021-07-14 11:49:10 +1200
committerJedidiah Barber <contact@jedbarber.id.au>2021-07-14 11:49:10 +1200
commitd24f813f3f2a05c112e803e4256b53535895fc98 (patch)
tree601e6ae9a1cd44bcfdcf91739a5ca36aedd827c9 /tests/unit/Settings/FieldStyleFactory_test.cpp
Initial mirror commitHEADmaster
Diffstat (limited to 'tests/unit/Settings/FieldStyleFactory_test.cpp')
-rw-r--r--tests/unit/Settings/FieldStyleFactory_test.cpp88
1 files changed, 88 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());
+}