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 30 : 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 2 : CPPUNIT_TEST_SUITE(IconThemeSelectorTest);
57 :
58 1 : CPPUNIT_TEST(OxygenThemeIsReturnedForKde4Desktop);
59 1 : CPPUNIT_TEST(TangoThemeIsReturnedForGtkDesktop);
60 1 : CPPUNIT_TEST(ThemeIsOverriddenByPreferredTheme);
61 1 : CPPUNIT_TEST(ThemeIsOverriddenByHighContrastMode);
62 1 : CPPUNIT_TEST(NotInstalledThemeDoesNotOverride);
63 1 : CPPUNIT_TEST(InstalledThemeIsFound);
64 1 : CPPUNIT_TEST(FirstThemeIsReturnedIfRequestedThemeIsNotFound);
65 1 : CPPUNIT_TEST(FallbackThemeIsReturnedForEmptyInput);
66 1 : CPPUNIT_TEST(DifferentPreferredThemesAreInequal);
67 1 : CPPUNIT_TEST(DifferentHighContrastModesAreInequal);
68 :
69 : // End of test suite definition
70 :
71 5 : CPPUNIT_TEST_SUITE_END();
72 : };
73 :
74 : /*static*/ std::vector<vcl::IconThemeInfo>
75 7 : IconThemeSelectorTest::GetFakeInstalledThemes()
76 : {
77 7 : std::vector<vcl::IconThemeInfo> r;
78 14 : vcl::IconThemeInfo a;
79 7 : a.mThemeId = "tango";
80 7 : r.push_back(a);
81 7 : a.mThemeId = "oxygen";
82 7 : r.push_back(a);
83 7 : a.mThemeId = "hicontrast";
84 7 : r.push_back(a);
85 14 : return r;
86 : }
87 :
88 : void
89 1 : IconThemeSelectorTest::OxygenThemeIsReturnedForKde4Desktop()
90 : {
91 1 : std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
92 2 : vcl::IconThemeSelector s;
93 2 : OUString r = s.SelectIconThemeForDesktopEnvironment(themes, "kde4");
94 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme is returned for kde4 desktop", OUString("oxygen"), r);
95 1 : }
96 :
97 : void
98 1 : IconThemeSelectorTest::TangoThemeIsReturnedForGtkDesktop()
99 : {
100 1 : std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
101 2 : vcl::IconThemeSelector s;
102 2 : OUString r = s.SelectIconThemeForDesktopEnvironment(themes, "gtk");
103 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'tango' theme is returned for kde4 desktop", OUString("tango"), r);
104 1 : }
105 :
106 : void
107 1 : IconThemeSelectorTest::ThemeIsOverriddenByPreferredTheme()
108 : {
109 1 : vcl::IconThemeSelector s;
110 2 : OUString preferred("oxygen");
111 1 : s.SetPreferredIconTheme(preferred);
112 2 : std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
113 2 : OUString selected = s.SelectIconThemeForDesktopEnvironment(themes, "gtk");
114 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'tango' theme is overridden by oxygen", preferred, selected);
115 1 : }
116 :
117 : void
118 1 : IconThemeSelectorTest::ThemeIsOverriddenByHighContrastMode()
119 : {
120 1 : vcl::IconThemeSelector s;
121 1 : s.SetUseHighContrastTheme(true);
122 2 : std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
123 2 : OUString selected = s.SelectIconTheme(themes, "tango");
124 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'tango' theme is overridden by high contrast mode",
125 1 : OUString("hicontrast"), selected);
126 1 : s.SetUseHighContrastTheme(false);
127 1 : selected = s.SelectIconTheme(themes, "tango");
128 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'tango' theme is no longer overridden by high contrast mode",
129 2 : OUString("tango"), selected);
130 1 : }
131 :
132 : void
133 1 : IconThemeSelectorTest::NotInstalledThemeDoesNotOverride()
134 : {
135 1 : vcl::IconThemeSelector s;
136 1 : s.SetPreferredIconTheme("oxygen_katze");
137 2 : std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
138 2 : OUString selected = s.SelectIconTheme(themes, "oxygen");
139 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme is not overridden by 'oxygen_katze'", OUString("oxygen"), selected);
140 1 : }
141 :
142 : void
143 1 : IconThemeSelectorTest::InstalledThemeIsFound()
144 : {
145 1 : vcl::IconThemeSelector s;
146 2 : std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
147 2 : OUString selected = s.SelectIconTheme(themes, "oxygen");
148 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme is found", OUString("oxygen"), selected);
149 1 : }
150 :
151 : void
152 1 : IconThemeSelectorTest::FirstThemeIsReturnedIfRequestedThemeIsNotFound()
153 : {
154 1 : vcl::IconThemeSelector s;
155 2 : std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes();
156 2 : OUString selected = s.SelectIconTheme(themes, "oxygen_katze");
157 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme is found", themes.front().GetThemeId(), selected);
158 1 : }
159 :
160 : void
161 1 : IconThemeSelectorTest::FallbackThemeIsReturnedForEmptyInput()
162 : {
163 1 : vcl::IconThemeSelector s;
164 2 : OUString selected = s.SelectIconTheme(std::vector<vcl::IconThemeInfo>(), "oxygen");
165 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("fallback is returned for empty input",
166 2 : vcl::IconThemeSelector::FALLBACK_ICON_THEME_ID, selected);
167 1 : }
168 :
169 : void
170 1 : IconThemeSelectorTest::DifferentHighContrastModesAreInequal()
171 : {
172 1 : vcl::IconThemeSelector s1;
173 2 : vcl::IconThemeSelector s2;
174 1 : s1.SetUseHighContrastTheme(true);
175 1 : s2.SetUseHighContrastTheme(false);
176 1 : bool equal = (s1 == s2);
177 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Different high contrast modes are detected as inequal", false, equal);
178 1 : }
179 :
180 : void
181 1 : IconThemeSelectorTest::DifferentPreferredThemesAreInequal()
182 : {
183 1 : vcl::IconThemeSelector s1;
184 2 : vcl::IconThemeSelector s2;
185 1 : s1.SetPreferredIconTheme("oxygen");
186 1 : s2.SetUseHighContrastTheme(true);
187 1 : bool equal = (s1 == s2);
188 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Different preferred themes are detected as inequal", false, equal);
189 1 : }
190 :
191 : // Put the test suite in the registry
192 1 : CPPUNIT_TEST_SUITE_REGISTRATION(IconThemeSelectorTest);
193 :
194 4 : CPPUNIT_PLUGIN_IMPLEMENT();
195 :
196 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|