calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / qa / cppunit / app / test_IconThemeSelector.cxx
blob72ee344b1437ddde1c725fa2038a1002fceff02a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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();
33 #endif
35 // Adds code needed to register the test suite
36 CPPUNIT_TEST_SUITE(IconThemeSelectorTest);
38 #ifndef _WIN32
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);
49 #endif
51 // End of test suite definition
52 CPPUNIT_TEST_SUITE_END();
55 #ifndef _WIN32
57 /*static*/ std::vector<vcl::IconThemeInfo>
58 IconThemeSelectorTest::GetFakeInstalledThemes()
60 std::vector<vcl::IconThemeInfo> r;
61 vcl::IconThemeInfo a;
62 a.mThemeId = "breeze";
63 r.push_back(a);
64 a.mThemeId = "elementary";
65 r.push_back(a);
66 a.mThemeId = "colibre";
67 r.push_back(a);
68 a.mThemeId = "sifr";
69 r.push_back(a);
70 return r;
73 void
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);
82 void
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);
91 void
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);
102 void
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);
117 void
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);
127 void
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);
136 void
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);
145 void
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);
154 void
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);
165 void
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);
176 #endif
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: */