diff options
author | Tobias Lippert <drtl@fastmail.fm> | 2014-02-09 00:53:28 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-02-21 17:23:50 +0000 |
commit | 076a7eacca48f203f0a8b9aa537e88fea9a88409 (patch) | |
tree | cd95446ac0b80b29658fa2a44030dacb5304a63d /vcl/qa/cppunit/app | |
parent | 1ec263e25d8606c70ac2089d5ceea22750d25daf (diff) |
Bug #63962 Dynamically scan the config directory for icon themes
The hard-coded icon themes have been replaced by a dynamic list
which is filled by scanning the config directory
Conflicts:
include/vcl/settings.hxx
vcl/source/app/settings.cxx
vcl/source/window/window.cxx
Change-Id: Ie3680ffe27d06e375acf22753e036cb6ddabc4ed
Reviewed-on: https://gerrit.libreoffice.org/7935
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/qa/cppunit/app')
-rw-r--r-- | vcl/qa/cppunit/app/test_IconThemeInfo.cxx | 143 | ||||
-rw-r--r-- | vcl/qa/cppunit/app/test_IconThemeScanner.cxx | 86 | ||||
-rw-r--r-- | vcl/qa/cppunit/app/test_IconThemeSelector.cxx | 198 |
3 files changed, 427 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/app/test_IconThemeInfo.cxx b/vcl/qa/cppunit/app/test_IconThemeInfo.cxx new file mode 100644 index 000000000000..e401046757ba --- /dev/null +++ b/vcl/qa/cppunit/app/test_IconThemeInfo.cxx @@ -0,0 +1,143 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/types.h> + +#include <rtl/ustring.hxx> +#include <vcl/IconThemeInfo.hxx> + +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +using namespace vcl; + +class IconThemeInfoTest : public CppUnit::TestFixture +{ + void + UpperCaseDisplayNameIsReturnedForNonDefaultId(); + + void + ImagesZipIsNotValid(); + + void + ImagesOxygenZipIsValid(); + + void + DefaultZipIsValid(); + + void + ThemeIdIsDetectedFromFileNameWithUnderscore(); + + void + ExceptionIsThrownWhenIdCannotBeDetermined1(); + + void + ExceptionIsThrownWhenIdCannotBeDetermined2(); + + void + GalaxyIsReturnedAsDisplayNameForDefaultZip(); + + // Adds code needed to register the test suite + CPPUNIT_TEST_SUITE(IconThemeInfoTest); + CPPUNIT_TEST(UpperCaseDisplayNameIsReturnedForNonDefaultId); + CPPUNIT_TEST(ThemeIdIsDetectedFromFileNameWithUnderscore); + CPPUNIT_TEST(ImagesZipIsNotValid); + CPPUNIT_TEST(ImagesOxygenZipIsValid); + CPPUNIT_TEST(DefaultZipIsValid); + CPPUNIT_TEST(GalaxyIsReturnedAsDisplayNameForDefaultZip); + CPPUNIT_TEST(ExceptionIsThrownWhenIdCannotBeDetermined1); + CPPUNIT_TEST(ExceptionIsThrownWhenIdCannotBeDetermined2); + + // End of test suite definition + CPPUNIT_TEST_SUITE_END(); +}; + +void +IconThemeInfoTest::UpperCaseDisplayNameIsReturnedForNonDefaultId() +{ + OUString id("katze"); + OUString displayName = vcl::IconThemeInfo::ThemeIdToDisplayName(id); + CPPUNIT_ASSERT_EQUAL_MESSAGE("theme id is properly uppercased", OUString("Katze"), displayName); +} + +void +IconThemeInfoTest::ImagesZipIsNotValid() +{ + OUString id("file://images.zip"); + bool valid = vcl::IconThemeInfo::UrlCanBeParsed(id); + CPPUNIT_ASSERT_EQUAL_MESSAGE("images.zip is not a valid theme name", false, valid); +} + +void +IconThemeInfoTest::ImagesOxygenZipIsValid() +{ + OUString id("file://images_oxygen.zip"); + bool valid = vcl::IconThemeInfo::UrlCanBeParsed(id); + CPPUNIT_ASSERT_EQUAL_MESSAGE("images_oxygen.zip is a valid theme name", true, valid); +} + +void +IconThemeInfoTest::DefaultZipIsValid() +{ + OUString id("file://default.zip"); + bool valid = vcl::IconThemeInfo::UrlCanBeParsed(id); + CPPUNIT_ASSERT_EQUAL_MESSAGE("default.zip is a valid theme name", true, valid); +} + + +void +IconThemeInfoTest::ThemeIdIsDetectedFromFileNameWithUnderscore() +{ + OUString fname("images_oxygen.zip"); + OUString sname = vcl::IconThemeInfo::FileNameToThemeId(fname); + CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme id is returned for 'images_oxygen.zip'", OUString("oxygen"), sname); +} + +void +IconThemeInfoTest::ExceptionIsThrownWhenIdCannotBeDetermined1() +{ + bool thrown = false; + OUString fname("images_oxygen"); + try { + OUString sname = vcl::IconThemeInfo::FileNameToThemeId(fname); + } + catch (std::runtime_error&) { + thrown = true; + } + CPPUNIT_ASSERT_EQUAL_MESSAGE("Exception was thrown",true, thrown); +} + +void +IconThemeInfoTest::ExceptionIsThrownWhenIdCannotBeDetermined2() +{ + bool thrown = false; + OUString fname("image_oxygen.zip"); + try { + OUString sname = vcl::IconThemeInfo::FileNameToThemeId(fname); + } + catch (std::runtime_error&) { + thrown = true; + } + CPPUNIT_ASSERT_EQUAL_MESSAGE("Exception was thrown", true, thrown); +} + +void +IconThemeInfoTest::GalaxyIsReturnedAsDisplayNameForDefaultZip() +{ + OUString id("file://default.zip"); + IconThemeInfo i(id); + CPPUNIT_ASSERT_EQUAL_MESSAGE("default.zip is displayed as Galaxy", OUString("Galaxy"), i.GetDisplayName()); +} + +// Put the test suite in the registry +CPPUNIT_TEST_SUITE_REGISTRATION(IconThemeInfoTest); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qa/cppunit/app/test_IconThemeScanner.cxx b/vcl/qa/cppunit/app/test_IconThemeScanner.cxx new file mode 100644 index 000000000000..af2e95703953 --- /dev/null +++ b/vcl/qa/cppunit/app/test_IconThemeScanner.cxx @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/types.h> + +#include <rtl/ustring.hxx> +#include <vcl/IconThemeScanner.hxx> +#include <vcl/IconThemeInfo.hxx> + +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +class IconThemeScannerTest : public CppUnit::TestFixture +{ + void + AddedThemeIsFoundById(); + + void + AddedThemeInfoIsReturned(); + + void + ExceptionIsThrownIfInvalidInfoIsRequested(); + + // Adds code needed to register the test suite + CPPUNIT_TEST_SUITE(IconThemeScannerTest); + CPPUNIT_TEST(AddedThemeIsFoundById); + CPPUNIT_TEST(AddedThemeInfoIsReturned); + CPPUNIT_TEST(ExceptionIsThrownIfInvalidInfoIsRequested); + + // End of test suite definition + CPPUNIT_TEST_SUITE_END(); +}; + +void +IconThemeScannerTest::AddedThemeIsFoundById() +{ + vcl::IconThemeScanner scanner; + OUString theme("file:://images_katze.zip"); + scanner.AddIconThemeByPath(theme); + OUString id = vcl::IconThemeInfo::FileNameToThemeId("images_katze.zip"); + bool found = false; + found = scanner.IconThemeIsInstalled(id); + CPPUNIT_ASSERT_EQUAL_MESSAGE("icon theme could be added by url", true, found); +} + +void +IconThemeScannerTest::AddedThemeInfoIsReturned() +{ + vcl::IconThemeScanner scanner; + OUString theme("file:://images_katze.zip"); + scanner.AddIconThemeByPath(theme); + OUString id = vcl::IconThemeInfo::FileNameToThemeId("images_katze.zip"); + const vcl::IconThemeInfo& info = scanner.GetIconThemeInfo(id); + CPPUNIT_ASSERT_EQUAL_MESSAGE("'katze' icon theme is found from id", theme, info.GetUrlToFile()); +} + +void +IconThemeScannerTest::ExceptionIsThrownIfInvalidInfoIsRequested() +{ + vcl::IconThemeScanner scanner; + OUString theme("file:://images_katze.zip"); + scanner.AddIconThemeByPath(theme); + bool thrown = false; + try + { + scanner.GetIconThemeInfo("hund"); + } + catch (const std::runtime_error&) + { + thrown = true; + } + CPPUNIT_ASSERT_EQUAL_MESSAGE("Exception is thrown if invalid theme info is requested", true, thrown); +} + +// Put the test suite in the registry +CPPUNIT_TEST_SUITE_REGISTRATION(IconThemeScannerTest); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qa/cppunit/app/test_IconThemeSelector.cxx b/vcl/qa/cppunit/app/test_IconThemeSelector.cxx new file mode 100644 index 000000000000..34961e761dcc --- /dev/null +++ b/vcl/qa/cppunit/app/test_IconThemeSelector.cxx @@ -0,0 +1,198 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <vcl/IconThemeSelector.hxx> + +#include <vcl/IconThemeScanner.hxx> +#include <vcl/IconThemeInfo.hxx> + +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +class IconThemeSelectorTest : public CppUnit::TestFixture +{ + void + OxygenThemeIsReturnedForKde4Desktop(); + + void + TangoThemeIsReturnedForGtkDesktop(); + + void + ThemeIsOverriddenByPreferredTheme(); + + void + ThemeIsOverriddenByHighContrastMode(); + + void + NotInstalledThemeDoesNotOverride(); + + void + InstalledThemeIsFound(); + + void + FirstThemeIsReturnedIfRequestedThemeIsNotFound(); + + void + FallbackThemeIsReturnedForEmptyInput(); + + void + DifferentPreferredThemesAreInequal(); + + void + DifferentHighContrastModesAreInequal(); + + static std::vector<vcl::IconThemeInfo> + GetFakeInstalledThemes(); + + // Adds code needed to register the test suite + CPPUNIT_TEST_SUITE(IconThemeSelectorTest); + + CPPUNIT_TEST(OxygenThemeIsReturnedForKde4Desktop); + CPPUNIT_TEST(TangoThemeIsReturnedForGtkDesktop); + CPPUNIT_TEST(ThemeIsOverriddenByPreferredTheme); + CPPUNIT_TEST(ThemeIsOverriddenByHighContrastMode); + CPPUNIT_TEST(NotInstalledThemeDoesNotOverride); + CPPUNIT_TEST(InstalledThemeIsFound); + CPPUNIT_TEST(FirstThemeIsReturnedIfRequestedThemeIsNotFound); + CPPUNIT_TEST(FallbackThemeIsReturnedForEmptyInput); + CPPUNIT_TEST(DifferentPreferredThemesAreInequal); + CPPUNIT_TEST(DifferentHighContrastModesAreInequal); + + // End of test suite definition + + + CPPUNIT_TEST_SUITE_END(); +}; + +/*static*/ std::vector<vcl::IconThemeInfo> +IconThemeSelectorTest::GetFakeInstalledThemes() +{ + std::vector<vcl::IconThemeInfo> r; + vcl::IconThemeInfo a{}; + a.mThemeId = "tango"; + r.push_back(a); + a.mThemeId = "oxygen"; + r.push_back(a); + a.mThemeId = vcl::IconThemeSelector::HIGH_CONTRAST_ICON_THEME_ID; + r.push_back(a); + return r; +} + +void +IconThemeSelectorTest::OxygenThemeIsReturnedForKde4Desktop() +{ + std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes(); + vcl::IconThemeSelector s; + OUString r = s.SelectIconThemeForDesktopEnvironment(themes, "kde4"); + CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme is returned for kde4 desktop", OUString("oxygen"), r); +} + +void +IconThemeSelectorTest::TangoThemeIsReturnedForGtkDesktop() +{ + std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes(); + vcl::IconThemeSelector s; + OUString r = s.SelectIconThemeForDesktopEnvironment(themes, "gtk"); + CPPUNIT_ASSERT_EQUAL_MESSAGE("'tango' theme is returned for kde4 desktop", OUString("tango"), r); +} + +void +IconThemeSelectorTest::ThemeIsOverriddenByPreferredTheme() +{ + vcl::IconThemeSelector s; + OUString preferred("oxygen"); + s.SetPreferredIconTheme(preferred); + std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes(); + OUString selected = s.SelectIconThemeForDesktopEnvironment(themes, "gtk"); + CPPUNIT_ASSERT_EQUAL_MESSAGE("'tango' theme is overridden by oxygen", preferred, selected); +} + +void +IconThemeSelectorTest::ThemeIsOverriddenByHighContrastMode() +{ + vcl::IconThemeSelector s; + s.SetUseHighContrastTheme(true); + std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes(); + OUString selected = s.SelectIconTheme(themes, "tango"); + CPPUNIT_ASSERT_EQUAL_MESSAGE("'tango' theme is overridden by high contrast mode", + vcl::IconThemeSelector::HIGH_CONTRAST_ICON_THEME_ID, selected); + s.SetUseHighContrastTheme(false); + selected = s.SelectIconTheme(themes, "tango"); + CPPUNIT_ASSERT_EQUAL_MESSAGE("'tango' theme is no longer overridden by high contrast mode", + OUString("tango"), selected); +} + +void +IconThemeSelectorTest::NotInstalledThemeDoesNotOverride() +{ + vcl::IconThemeSelector s; + s.SetPreferredIconTheme("oxygen_katze"); + std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes(); + OUString selected = s.SelectIconTheme(themes, "oxygen"); + CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme is not overridden by 'oxygen_katze'", OUString("oxygen"), selected); +} + +void +IconThemeSelectorTest::InstalledThemeIsFound() +{ + vcl::IconThemeSelector s; + std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes(); + OUString selected = s.SelectIconTheme(themes, "oxygen"); + CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme is found", OUString("oxygen"), selected); +} + +void +IconThemeSelectorTest::FirstThemeIsReturnedIfRequestedThemeIsNotFound() +{ + vcl::IconThemeSelector s; + std::vector<vcl::IconThemeInfo> themes = GetFakeInstalledThemes(); + OUString selected = s.SelectIconTheme(themes, "oxygen_katze"); + CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme is found", themes.front().GetThemeId(), selected); +} + +void +IconThemeSelectorTest::FallbackThemeIsReturnedForEmptyInput() +{ + vcl::IconThemeSelector s; + OUString selected = s.SelectIconTheme(std::vector<vcl::IconThemeInfo>{}, "oxygen"); + CPPUNIT_ASSERT_EQUAL_MESSAGE("fallback is returned for empty input", + vcl::IconThemeSelector::FALLBACK_ICON_THEME_ID, selected); +} + +void +IconThemeSelectorTest::DifferentHighContrastModesAreInequal() +{ + vcl::IconThemeSelector s1; + vcl::IconThemeSelector s2; + s1.SetUseHighContrastTheme(true); + s2.SetUseHighContrastTheme(false); + bool equal = (s1 == s2); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Different high contrast modes are detected as inequal", false, equal); +} + +void +IconThemeSelectorTest::DifferentPreferredThemesAreInequal() +{ + vcl::IconThemeSelector s1; + vcl::IconThemeSelector s2; + s1.SetPreferredIconTheme("oxygen"); + s2.SetUseHighContrastTheme("katze"); + bool equal = (s1 == s2); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Different preferred themes are detected as inequal", false, equal); +} + + +// Put the test suite in the registry +CPPUNIT_TEST_SUITE_REGISTRATION(IconThemeSelectorTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |