summaryrefslogtreecommitdiff
path: root/tests/unit/Settings/FieldStyleFactory_test.cpp
blob: be53e7cbb6da5f76ad32c2b32322616b0daf0d96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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());
}