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 <vcl/IconThemeSelector.hxx>
12 #include <vcl/IconThemeScanner.hxx>
13 #include <vcl/IconThemeInfo.hxx>
15 #include <cppunit/TestAssert.h>
16 #include <cppunit/TestFixture.h>
17 #include <cppunit/extensions/HelperMacros.h>
18 #include <cppunit/plugin/TestPlugIn.h>
20 class IconThemeSelectorTest
: public CppUnit::TestFixture
23 OxygenThemeIsReturnedForKde4Desktop();
26 TangoThemeIsReturnedForGtkDesktop();
29 ThemeIsOverriddenByPreferredTheme();
32 ThemeIsOverriddenByHighContrastMode();
35 NotInstalledThemeDoesNotOverride();
38 InstalledThemeIsFound();
41 FirstThemeIsReturnedIfRequestedThemeIsNotFound();
44 FallbackThemeIsReturnedForEmptyInput();
47 DifferentPreferredThemesAreInequal();
50 DifferentHighContrastModesAreInequal();
52 static std::vector
<vcl::IconThemeInfo
>
53 GetFakeInstalledThemes();
55 // Adds code needed to register the test suite
56 CPPUNIT_TEST_SUITE(IconThemeSelectorTest
);
58 CPPUNIT_TEST(OxygenThemeIsReturnedForKde4Desktop
);
59 CPPUNIT_TEST(TangoThemeIsReturnedForGtkDesktop
);
60 CPPUNIT_TEST(ThemeIsOverriddenByPreferredTheme
);
61 CPPUNIT_TEST(ThemeIsOverriddenByHighContrastMode
);
62 CPPUNIT_TEST(NotInstalledThemeDoesNotOverride
);
63 CPPUNIT_TEST(InstalledThemeIsFound
);
64 CPPUNIT_TEST(FirstThemeIsReturnedIfRequestedThemeIsNotFound
);
65 CPPUNIT_TEST(FallbackThemeIsReturnedForEmptyInput
);
66 CPPUNIT_TEST(DifferentPreferredThemesAreInequal
);
67 CPPUNIT_TEST(DifferentHighContrastModesAreInequal
);
69 // End of test suite definition
71 CPPUNIT_TEST_SUITE_END();
74 /*static*/ std::vector
<vcl::IconThemeInfo
>
75 IconThemeSelectorTest::GetFakeInstalledThemes()
77 std::vector
<vcl::IconThemeInfo
> r
;
81 a
.mThemeId
= "oxygen";
83 a
.mThemeId
= "hicontrast";
89 IconThemeSelectorTest::OxygenThemeIsReturnedForKde4Desktop()
91 std::vector
<vcl::IconThemeInfo
> themes
= GetFakeInstalledThemes();
92 vcl::IconThemeSelector s
;
93 OUString r
= s
.SelectIconThemeForDesktopEnvironment(themes
, "kde4");
94 CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme is returned for kde4 desktop", OUString("oxygen"), r
);
98 IconThemeSelectorTest::TangoThemeIsReturnedForGtkDesktop()
100 std::vector
<vcl::IconThemeInfo
> themes
= GetFakeInstalledThemes();
101 vcl::IconThemeSelector s
;
102 OUString r
= s
.SelectIconThemeForDesktopEnvironment(themes
, "gtk");
103 CPPUNIT_ASSERT_EQUAL_MESSAGE("'tango' theme is returned for kde4 desktop", OUString("tango"), r
);
107 IconThemeSelectorTest::ThemeIsOverriddenByPreferredTheme()
109 vcl::IconThemeSelector s
;
110 OUString
preferred("oxygen");
111 s
.SetPreferredIconTheme(preferred
);
112 std::vector
<vcl::IconThemeInfo
> themes
= GetFakeInstalledThemes();
113 OUString selected
= s
.SelectIconThemeForDesktopEnvironment(themes
, "gtk");
114 CPPUNIT_ASSERT_EQUAL_MESSAGE("'tango' theme is overridden by oxygen", preferred
, selected
);
118 IconThemeSelectorTest::ThemeIsOverriddenByHighContrastMode()
120 vcl::IconThemeSelector s
;
121 s
.SetUseHighContrastTheme(true);
122 std::vector
<vcl::IconThemeInfo
> themes
= GetFakeInstalledThemes();
123 OUString selected
= s
.SelectIconTheme(themes
, "tango");
124 CPPUNIT_ASSERT_EQUAL_MESSAGE("'tango' theme is overridden by high contrast mode",
125 OUString("hicontrast"), selected
);
126 s
.SetUseHighContrastTheme(false);
127 selected
= s
.SelectIconTheme(themes
, "tango");
128 CPPUNIT_ASSERT_EQUAL_MESSAGE("'tango' theme is no longer overridden by high contrast mode",
129 OUString("tango"), selected
);
133 IconThemeSelectorTest::NotInstalledThemeDoesNotOverride()
135 vcl::IconThemeSelector s
;
136 s
.SetPreferredIconTheme("oxygen_katze");
137 std::vector
<vcl::IconThemeInfo
> themes
= GetFakeInstalledThemes();
138 OUString selected
= s
.SelectIconTheme(themes
, "oxygen");
139 CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme is not overridden by 'oxygen_katze'", OUString("oxygen"), selected
);
143 IconThemeSelectorTest::InstalledThemeIsFound()
145 vcl::IconThemeSelector s
;
146 std::vector
<vcl::IconThemeInfo
> themes
= GetFakeInstalledThemes();
147 OUString selected
= s
.SelectIconTheme(themes
, "oxygen");
148 CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme is found", OUString("oxygen"), selected
);
152 IconThemeSelectorTest::FirstThemeIsReturnedIfRequestedThemeIsNotFound()
154 vcl::IconThemeSelector s
;
155 std::vector
<vcl::IconThemeInfo
> themes
= GetFakeInstalledThemes();
156 OUString selected
= s
.SelectIconTheme(themes
, "oxygen_katze");
157 CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme is found", themes
.front().GetThemeId(), selected
);
161 IconThemeSelectorTest::FallbackThemeIsReturnedForEmptyInput()
163 vcl::IconThemeSelector s
;
164 OUString selected
= s
.SelectIconTheme(std::vector
<vcl::IconThemeInfo
>(), "oxygen");
165 CPPUNIT_ASSERT_EQUAL_MESSAGE("fallback is returned for empty input",
166 vcl::IconThemeSelector::FALLBACK_ICON_THEME_ID
, selected
);
170 IconThemeSelectorTest::DifferentHighContrastModesAreInequal()
172 vcl::IconThemeSelector s1
;
173 vcl::IconThemeSelector s2
;
174 s1
.SetUseHighContrastTheme(true);
175 s2
.SetUseHighContrastTheme(false);
176 bool equal
= (s1
== s2
);
177 CPPUNIT_ASSERT_EQUAL_MESSAGE("Different high contrast modes are detected as inequal", false, equal
);
181 IconThemeSelectorTest::DifferentPreferredThemesAreInequal()
183 vcl::IconThemeSelector s1
;
184 vcl::IconThemeSelector s2
;
185 s1
.SetPreferredIconTheme("oxygen");
186 s2
.SetUseHighContrastTheme(true);
187 bool equal
= (s1
== s2
);
188 CPPUNIT_ASSERT_EQUAL_MESSAGE("Different preferred themes are detected as inequal", false, equal
);
191 // Put the test suite in the registry
192 CPPUNIT_TEST_SUITE_REGISTRATION(IconThemeSelectorTest
);
194 CPPUNIT_PLUGIN_IMPLEMENT();
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */