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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* 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 <IconThemeSelector.hxx>
#include <vcl/IconThemeInfo.hxx>
#include <cppunit/TestAssert.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>
class IconThemeSelectorTest : public CppUnit::TestFixture
{
#ifndef _WIN32 //default theme on Windows is Colibre independently from any desktop environment
void BreezeIsReturnedForKde5Desktop();
void ElementaryIsReturnedForGnomeDesktop();
void ThemeIsOverriddenByPreferredTheme();
void ThemeIsOverriddenByHighContrastMode();
void NotInstalledThemeDoesNotOverride();
void InstalledThemeIsFound();
void FirstThemeIsReturnedIfRequestedThemeIsNotFound();
void FallbackThemeIsReturnedForEmptyInput();
void DifferentPreferredThemesAreInequal();
void DifferentHighContrastModesAreInequal();
static std::vector<vcl::IconThemeInfo> GetFakeInstalledThemes();
#endif
// Adds code needed to register the test suite
CPPUNIT_TEST_SUITE(IconThemeSelectorTest);
#ifndef _WIN32
CPPUNIT_TEST(BreezeIsReturnedForKde5Desktop);
CPPUNIT_TEST(ElementaryIsReturnedForGnomeDesktop);
CPPUNIT_TEST(ThemeIsOverriddenByPreferredTheme);
CPPUNIT_TEST(ThemeIsOverriddenByHighContrastMode);
CPPUNIT_TEST(NotInstalledThemeDoesNotOverride);
CPPUNIT_TEST(InstalledThemeIsFound);
CPPUNIT_TEST(FirstThemeIsReturnedIfRequestedThemeIsNotFound);
CPPUNIT_TEST(FallbackThemeIsReturnedForEmptyInput);
CPPUNIT_TEST(DifferentPreferredThemesAreInequal);
CPPUNIT_TEST(DifferentHighContrastModesAreInequal);
#endif
// End of test suite definition
CPPUNIT_TEST_SUITE_END();
};
#ifndef _WIN32
/*static*/ std::vector<vcl::IconThemeInfo>
IconThemeSelectorTest::GetFakeInstalledThemes()
{
std::vector<vcl::IconThemeInfo> r;
vcl::IconThemeInfo a;
a.mThemeId = "breeze";
r.push_back(a);
a.mThemeId = "elementary";
r.push_back(a);
a.mThemeId = "colibre";
r.push_back(a);
a.mThemeId = "sifr";
r.push_back(a);
return r;
}
void
IconThemeSelectorTest::BreezeIsReturnedForKde5Desktop()
{
std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
vcl::IconThemeSelector s;
OUString r = s.SelectIconThemeForDesktopEnvironment(themes, "plasma5");
CPPUNIT_ASSERT_EQUAL_MESSAGE("'breeze' theme is returned for Plasma 5 desktop", OUString("breeze"), r);
}
void
IconThemeSelectorTest::ElementaryIsReturnedForGnomeDesktop()
{
std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
vcl::IconThemeSelector s;
OUString r = s.SelectIconThemeForDesktopEnvironment(themes, "gnome");
CPPUNIT_ASSERT_EQUAL_MESSAGE("'elementary' theme is returned for gnome desktop", OUString("elementary"), r);
}
void
IconThemeSelectorTest::ThemeIsOverriddenByPreferredTheme()
{
vcl::IconThemeSelector s;
OUString preferred("breeze");
s.SetPreferredIconTheme(preferred, false);
std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
OUString selected = s.SelectIconThemeForDesktopEnvironment(themes, "gnome");
CPPUNIT_ASSERT_EQUAL_MESSAGE("'elementary' theme is overridden by breeze", preferred, selected);
}
void
IconThemeSelectorTest::ThemeIsOverriddenByHighContrastMode()
{
vcl::IconThemeSelector s;
s.SetUseHighContrastTheme(true);
std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
OUString selected = s.SelectIconTheme(themes, "breeze");
CPPUNIT_ASSERT_EQUAL_MESSAGE("'breeze' theme is overridden by high contrast mode",
OUString("sifr"), selected);
s.SetUseHighContrastTheme(false);
selected = s.SelectIconTheme(themes, "breeze");
CPPUNIT_ASSERT_EQUAL_MESSAGE("'breeze' theme is no longer overridden by high contrast mode",
OUString("breeze"), selected);
}
void
IconThemeSelectorTest::NotInstalledThemeDoesNotOverride()
{
vcl::IconThemeSelector s;
s.SetPreferredIconTheme("breeze_foo", false);
std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
OUString selected = s.SelectIconTheme(themes, "colibre");
CPPUNIT_ASSERT_EQUAL_MESSAGE("'colibre' theme is not overridden by 'breeze_foo'", OUString("colibre"), selected);
}
void
IconThemeSelectorTest::InstalledThemeIsFound()
{
vcl::IconThemeSelector s;
std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
OUString selected = s.SelectIconTheme(themes, "colibre");
CPPUNIT_ASSERT_EQUAL_MESSAGE("'colibre' theme is found", OUString("colibre"), selected);
}
void
IconThemeSelectorTest::FirstThemeIsReturnedIfRequestedThemeIsNotFound()
{
vcl::IconThemeSelector s;
std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
OUString selected = s.SelectIconTheme(themes, "breeze_foo");
CPPUNIT_ASSERT_EQUAL_MESSAGE("'breeze' theme is found", themes.front().GetThemeId(), selected);
}
void
IconThemeSelectorTest::FallbackThemeIsReturnedForEmptyInput()
{
vcl::IconThemeSelector s;
OUString selected = s.SelectIconTheme(std::vector<vcl::IconThemeInfo>(), "colibre");
CPPUNIT_ASSERT_EQUAL_MESSAGE("fallback is returned for empty input",
OUString(vcl::IconThemeSelector::FALLBACK_ICON_THEME_ID), selected);
}
void
IconThemeSelectorTest::DifferentHighContrastModesAreInequal()
{
vcl::IconThemeSelector s1;
vcl::IconThemeSelector s2;
s1.SetUseHighContrastTheme(true);
s2.SetUseHighContrastTheme(false);
bool equal = (s1 == s2);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Different high contrast modes are detected as inequal", false, equal);
}
void
IconThemeSelectorTest::DifferentPreferredThemesAreInequal()
{
vcl::IconThemeSelector s1;
vcl::IconThemeSelector s2;
s1.SetPreferredIconTheme("breeze", false);
s2.SetUseHighContrastTheme(true);
bool equal = (s1 == s2);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Different preferred themes are detected as inequal", false, equal);
}
#endif
// Put the test suite in the registry
CPPUNIT_TEST_SUITE_REGISTRATION(IconThemeSelectorTest);
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|