1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include <IconThemeSelector.hxx>
12 #include <vcl/IconThemeInfo.hxx>
14 #include <cppunit/TestAssert.h>
15 #include <cppunit/TestFixture.h>
16 #include <cppunit/extensions/HelperMacros.h>
17 #include <cppunit/plugin/TestPlugIn.h>
19 class IconThemeSelectorTest
: public CppUnit::TestFixture
21 #ifndef _WIN32 //default theme on Windows is Colibre independently from any desktop environment
22 void BreezeIsReturnedForKde5Desktop();
23 void ElementaryIsReturnedForGnomeDesktop();
24 void ThemeIsOverriddenByPreferredTheme();
25 void ThemeIsOverriddenByHighContrastMode();
26 void NotInstalledThemeDoesNotOverride();
27 void InstalledThemeIsFound();
28 void FirstThemeIsReturnedIfRequestedThemeIsNotFound();
29 void FallbackThemeIsReturnedForEmptyInput();
30 void DifferentPreferredThemesAreInequal();
31 void DifferentHighContrastModesAreInequal();
32 static std::vector
<vcl::IconThemeInfo
> GetFakeInstalledThemes();
35 // Adds code needed to register the test suite
36 CPPUNIT_TEST_SUITE(IconThemeSelectorTest
);
39 CPPUNIT_TEST(BreezeIsReturnedForKde5Desktop
);
40 CPPUNIT_TEST(ElementaryIsReturnedForGnomeDesktop
);
41 CPPUNIT_TEST(ThemeIsOverriddenByPreferredTheme
);
42 CPPUNIT_TEST(ThemeIsOverriddenByHighContrastMode
);
43 CPPUNIT_TEST(NotInstalledThemeDoesNotOverride
);
44 CPPUNIT_TEST(InstalledThemeIsFound
);
45 CPPUNIT_TEST(FirstThemeIsReturnedIfRequestedThemeIsNotFound
);
46 CPPUNIT_TEST(FallbackThemeIsReturnedForEmptyInput
);
47 CPPUNIT_TEST(DifferentPreferredThemesAreInequal
);
48 CPPUNIT_TEST(DifferentHighContrastModesAreInequal
);
51 // End of test suite definition
52 CPPUNIT_TEST_SUITE_END();
57 /*static*/ std::vector
<vcl::IconThemeInfo
>
58 IconThemeSelectorTest::GetFakeInstalledThemes()
60 std::vector
<vcl::IconThemeInfo
> r
;
62 a
.mThemeId
= "breeze";
64 a
.mThemeId
= "elementary";
66 a
.mThemeId
= "colibre";
74 IconThemeSelectorTest::BreezeIsReturnedForKde5Desktop()
76 std::vector
<vcl::IconThemeInfo
> themes
= GetFakeInstalledThemes();
77 vcl::IconThemeSelector s
;
78 OUString r
= s
.SelectIconThemeForDesktopEnvironment(themes
, "plasma5");
79 CPPUNIT_ASSERT_EQUAL_MESSAGE("'breeze' theme is returned for Plasma 5 desktop", OUString("breeze"), r
);
83 IconThemeSelectorTest::ElementaryIsReturnedForGnomeDesktop()
85 std::vector
<vcl::IconThemeInfo
> themes
= GetFakeInstalledThemes();
86 vcl::IconThemeSelector s
;
87 OUString r
= s
.SelectIconThemeForDesktopEnvironment(themes
, "gnome");
88 CPPUNIT_ASSERT_EQUAL_MESSAGE("'elementary' theme is returned for gnome desktop", OUString("elementary"), r
);
92 IconThemeSelectorTest::ThemeIsOverriddenByPreferredTheme()
94 vcl::IconThemeSelector s
;
95 OUString
preferred("breeze");
96 s
.SetPreferredIconTheme(preferred
, false);
97 std::vector
<vcl::IconThemeInfo
> themes
= GetFakeInstalledThemes();
98 OUString selected
= s
.SelectIconThemeForDesktopEnvironment(themes
, "gnome");
99 CPPUNIT_ASSERT_EQUAL_MESSAGE("'elementary' theme is overridden by breeze", preferred
, selected
);
103 IconThemeSelectorTest::ThemeIsOverriddenByHighContrastMode()
105 vcl::IconThemeSelector s
;
106 s
.SetUseHighContrastTheme(true);
107 std::vector
<vcl::IconThemeInfo
> themes
= GetFakeInstalledThemes();
108 OUString selected
= s
.SelectIconTheme(themes
, "breeze");
109 bool sifr
= selected
.startsWith("sifr");
110 CPPUNIT_ASSERT_EQUAL_MESSAGE("'breeze' theme is overridden by high contrast mode", true, sifr
);
111 s
.SetUseHighContrastTheme(false);
112 selected
= s
.SelectIconTheme(themes
, "breeze");
113 CPPUNIT_ASSERT_EQUAL_MESSAGE("'breeze' theme is no longer overridden by high contrast mode",
114 OUString("breeze"), selected
);
118 IconThemeSelectorTest::NotInstalledThemeDoesNotOverride()
120 vcl::IconThemeSelector s
;
121 s
.SetPreferredIconTheme("breeze_foo", false);
122 std::vector
<vcl::IconThemeInfo
> themes
= GetFakeInstalledThemes();
123 OUString selected
= s
.SelectIconTheme(themes
, "colibre");
124 CPPUNIT_ASSERT_EQUAL_MESSAGE("'colibre' theme is not overridden by 'breeze_foo'", OUString("colibre"), selected
);
128 IconThemeSelectorTest::InstalledThemeIsFound()
130 vcl::IconThemeSelector s
;
131 std::vector
<vcl::IconThemeInfo
> themes
= GetFakeInstalledThemes();
132 OUString selected
= s
.SelectIconTheme(themes
, "colibre");
133 CPPUNIT_ASSERT_EQUAL_MESSAGE("'colibre' theme is found", OUString("colibre"), selected
);
137 IconThemeSelectorTest::FirstThemeIsReturnedIfRequestedThemeIsNotFound()
139 vcl::IconThemeSelector s
;
140 std::vector
<vcl::IconThemeInfo
> themes
= GetFakeInstalledThemes();
141 OUString selected
= s
.SelectIconTheme(themes
, "breeze_foo");
142 CPPUNIT_ASSERT_EQUAL_MESSAGE("'breeze' theme is found", themes
.front().GetThemeId(), selected
);
146 IconThemeSelectorTest::FallbackThemeIsReturnedForEmptyInput()
148 vcl::IconThemeSelector s
;
149 OUString selected
= s
.SelectIconTheme(std::vector
<vcl::IconThemeInfo
>(), "colibre");
150 CPPUNIT_ASSERT_EQUAL_MESSAGE("fallback is returned for empty input",
151 OUString(vcl::IconThemeSelector::FALLBACK_LIGHT_ICON_THEME_ID
), selected
);
155 IconThemeSelectorTest::DifferentHighContrastModesAreInequal()
157 vcl::IconThemeSelector s1
;
158 vcl::IconThemeSelector s2
;
159 s1
.SetUseHighContrastTheme(true);
160 s2
.SetUseHighContrastTheme(false);
161 bool equal
= (s1
== s2
);
162 CPPUNIT_ASSERT_EQUAL_MESSAGE("Different high contrast modes are detected as inequal", false, equal
);
166 IconThemeSelectorTest::DifferentPreferredThemesAreInequal()
168 vcl::IconThemeSelector s1
;
169 vcl::IconThemeSelector s2
;
170 s1
.SetPreferredIconTheme("breeze", false);
171 s2
.SetUseHighContrastTheme(true);
172 bool equal
= (s1
== s2
);
173 CPPUNIT_ASSERT_EQUAL_MESSAGE("Different preferred themes are detected as inequal", false, equal
);
178 // Put the test suite in the registry
179 CPPUNIT_TEST_SUITE_REGISTRATION(IconThemeSelectorTest
);
181 CPPUNIT_PLUGIN_IMPLEMENT();
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */