Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : */
9 :
10 : #include <vcl/IconThemeSelector.hxx>
11 :
12 : #include <vcl/IconThemeScanner.hxx>
13 : #include <vcl/IconThemeInfo.hxx>
14 :
15 : #include <cppunit/TestAssert.h>
16 : #include <cppunit/TestFixture.h>
17 : #include <cppunit/extensions/HelperMacros.h>
18 : #include <cppunit/plugin/TestPlugIn.h>
19 :
20 60 : class IconThemeSelectorTest : public CppUnit::TestFixture
21 : {
22 : void
23 : OxygenThemeIsReturnedForKde4Desktop();
24 :
25 : void
26 : TangoThemeIsReturnedForGtkDesktop();
27 :
28 : void
29 : ThemeIsOverriddenByPreferredTheme();
30 :
31 : void
32 : ThemeIsOverriddenByHighContrastMode();
33 :
34 : void
35 : NotInstalledThemeDoesNotOverride();
36 :
37 : void
38 : InstalledThemeIsFound();
39 :
40 : void
41 : FirstThemeIsReturnedIfRequestedThemeIsNotFound();
42 :
43 : void
44 : FallbackThemeIsReturnedForEmptyInput();
45 :
46 : void
47 : DifferentPreferredThemesAreInequal();
48 :
49 : void
50 : DifferentHighContrastModesAreInequal();
51 :
52 : static std::vector<vcl::IconThemeInfo>
53 : GetFakeInstalledThemes();
54 :
55 : // Adds code needed to register the test suite
56 4 : CPPUNIT_TEST_SUITE(IconThemeSelectorTest);
57 :
58 2 : CPPUNIT_TEST(OxygenThemeIsReturnedForKde4Desktop);
59 2 : CPPUNIT_TEST(TangoThemeIsReturnedForGtkDesktop);
60 2 : CPPUNIT_TEST(ThemeIsOverriddenByPreferredTheme);
61 2 : CPPUNIT_TEST(ThemeIsOverriddenByHighContrastMode);
62 2 : CPPUNIT_TEST(NotInstalledThemeDoesNotOverride);
63 2 : CPPUNIT_TEST(InstalledThemeIsFound);
64 2 : CPPUNIT_TEST(FirstThemeIsReturnedIfRequestedThemeIsNotFound);
65 2 : CPPUNIT_TEST(FallbackThemeIsReturnedForEmptyInput);
66 2 : CPPUNIT_TEST(DifferentPreferredThemesAreInequal);
67 2 : CPPUNIT_TEST(DifferentHighContrastModesAreInequal);
68 :
69 : // End of test suite definition
70 :
71 4 : CPPUNIT_TEST_SUITE_END();
72 : };
73 :
74 : /*static*/ std::vector<vcl::IconThemeInfo>
75 14 : IconThemeSelectorTest::GetFakeInstalledThemes()
76 : {
77 14 : std::vector<vcl::IconThemeInfo> r;
78 28 : vcl::IconThemeInfo a;
79 14 : a.mThemeId = "tango";
80 14 : r.push_back(a);
81 14 : a.mThemeId = "oxygen";
82 14 : r.push_back(a);
83 14 : a.mThemeId = vcl::IconThemeSelector::HIGH_CONTRAST_ICON_THEME_ID;
84 14 : r.push_back(a);
85 28 : return r;
86 : }
87 :
88 : void
89 2 : IconThemeSelectorTest::OxygenThemeIsReturnedForKde4Desktop()
90 : {
91 2 : std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
92 4 : vcl::IconThemeSelector s;
93 4 : OUString r = s.SelectIconThemeForDesktopEnvironment(themes, "kde4");
94 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme is returned for kde4 desktop", OUString("oxygen"), r);
95 2 : }
96 :
97 : void
98 2 : IconThemeSelectorTest::TangoThemeIsReturnedForGtkDesktop()
99 : {
100 2 : std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
101 4 : vcl::IconThemeSelector s;
102 4 : OUString r = s.SelectIconThemeForDesktopEnvironment(themes, "gtk");
103 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'tango' theme is returned for kde4 desktop", OUString("tango"), r);
104 2 : }
105 :
106 : void
107 2 : IconThemeSelectorTest::ThemeIsOverriddenByPreferredTheme()
108 : {
109 2 : vcl::IconThemeSelector s;
110 4 : OUString preferred("oxygen");
111 2 : s.SetPreferredIconTheme(preferred);
112 4 : std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
113 4 : OUString selected = s.SelectIconThemeForDesktopEnvironment(themes, "gtk");
114 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'tango' theme is overridden by oxygen", preferred, selected);
115 2 : }
116 :
117 : void
118 2 : IconThemeSelectorTest::ThemeIsOverriddenByHighContrastMode()
119 : {
120 2 : vcl::IconThemeSelector s;
121 2 : s.SetUseHighContrastTheme(true);
122 4 : std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
123 4 : OUString selected = s.SelectIconTheme(themes, "tango");
124 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'tango' theme is overridden by high contrast mode",
125 2 : vcl::IconThemeSelector::HIGH_CONTRAST_ICON_THEME_ID, selected);
126 2 : s.SetUseHighContrastTheme(false);
127 2 : selected = s.SelectIconTheme(themes, "tango");
128 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'tango' theme is no longer overridden by high contrast mode",
129 4 : OUString("tango"), selected);
130 2 : }
131 :
132 : void
133 2 : IconThemeSelectorTest::NotInstalledThemeDoesNotOverride()
134 : {
135 2 : vcl::IconThemeSelector s;
136 2 : s.SetPreferredIconTheme("oxygen_katze");
137 4 : std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
138 4 : OUString selected = s.SelectIconTheme(themes, "oxygen");
139 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme is not overridden by 'oxygen_katze'", OUString("oxygen"), selected);
140 2 : }
141 :
142 : void
143 2 : IconThemeSelectorTest::InstalledThemeIsFound()
144 : {
145 2 : vcl::IconThemeSelector s;
146 4 : std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
147 4 : OUString selected = s.SelectIconTheme(themes, "oxygen");
148 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme is found", OUString("oxygen"), selected);
149 2 : }
150 :
151 : void
152 2 : IconThemeSelectorTest::FirstThemeIsReturnedIfRequestedThemeIsNotFound()
153 : {
154 2 : vcl::IconThemeSelector s;
155 4 : std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
156 4 : OUString selected = s.SelectIconTheme(themes, "oxygen_katze");
157 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme is found", themes.front().GetThemeId(), selected);
158 2 : }
159 :
160 : void
161 2 : IconThemeSelectorTest::FallbackThemeIsReturnedForEmptyInput()
162 : {
163 2 : vcl::IconThemeSelector s;
164 4 : OUString selected = s.SelectIconTheme(std::vector<vcl::IconThemeInfo>(), "oxygen");
165 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("fallback is returned for empty input",
166 4 : vcl::IconThemeSelector::FALLBACK_ICON_THEME_ID, selected);
167 2 : }
168 :
169 : void
170 2 : IconThemeSelectorTest::DifferentHighContrastModesAreInequal()
171 : {
172 2 : vcl::IconThemeSelector s1;
173 4 : vcl::IconThemeSelector s2;
174 2 : s1.SetUseHighContrastTheme(true);
175 2 : s2.SetUseHighContrastTheme(false);
176 2 : bool equal = (s1 == s2);
177 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Different high contrast modes are detected as inequal", false, equal);
178 2 : }
179 :
180 : void
181 2 : IconThemeSelectorTest::DifferentPreferredThemesAreInequal()
182 : {
183 2 : vcl::IconThemeSelector s1;
184 4 : vcl::IconThemeSelector s2;
185 2 : s1.SetPreferredIconTheme("oxygen");
186 2 : s2.SetUseHighContrastTheme(true);
187 2 : bool equal = (s1 == s2);
188 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Different preferred themes are detected as inequal", false, equal);
189 2 : }
190 :
191 : // Put the test suite in the registry
192 2 : CPPUNIT_TEST_SUITE_REGISTRATION(IconThemeSelectorTest);
193 :
194 8 : CPPUNIT_PLUGIN_IMPLEMENT();
195 :
196 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|