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/.
12 #include <sal/types.h>
14 #include <rtl/ustring.hxx>
15 #include <vcl/IconThemeInfo.hxx>
17 #include <cppunit/TestAssert.h>
18 #include <cppunit/TestFixture.h>
19 #include <cppunit/extensions/HelperMacros.h>
20 #include <cppunit/plugin/TestPlugIn.h>
24 class IconThemeInfoTest
: public CppUnit::TestFixture
27 UpperCaseDisplayNameIsReturnedForNonDefaultId();
30 ImagesZipIsNotValid();
33 ImagesOxygenZipIsValid();
36 ThemeIdIsDetectedFromFileNameWithUnderscore();
39 ExceptionIsThrownWhenIdCannotBeDetermined1();
42 ExceptionIsThrownWhenIdCannotBeDetermined2();
44 // Adds code needed to register the test suite
45 CPPUNIT_TEST_SUITE(IconThemeInfoTest
);
46 CPPUNIT_TEST(UpperCaseDisplayNameIsReturnedForNonDefaultId
);
47 CPPUNIT_TEST(ThemeIdIsDetectedFromFileNameWithUnderscore
);
48 CPPUNIT_TEST(ImagesZipIsNotValid
);
49 CPPUNIT_TEST(ImagesOxygenZipIsValid
);
50 CPPUNIT_TEST(ExceptionIsThrownWhenIdCannotBeDetermined1
);
51 CPPUNIT_TEST(ExceptionIsThrownWhenIdCannotBeDetermined2
);
53 // End of test suite definition
54 CPPUNIT_TEST_SUITE_END();
58 IconThemeInfoTest::UpperCaseDisplayNameIsReturnedForNonDefaultId()
61 OUString displayName
= vcl::IconThemeInfo::ThemeIdToDisplayName(id
);
62 CPPUNIT_ASSERT_EQUAL_MESSAGE("theme id is properly uppercased", OUString("Katze"), displayName
);
66 IconThemeInfoTest::ImagesZipIsNotValid()
68 OUString
id("file://images.zip");
69 bool valid
= vcl::IconThemeInfo::UrlCanBeParsed(id
);
70 CPPUNIT_ASSERT_EQUAL_MESSAGE("images.zip is not a valid theme name", false, valid
);
74 IconThemeInfoTest::ImagesOxygenZipIsValid()
76 OUString
id("file://images_oxygen.zip");
77 bool valid
= vcl::IconThemeInfo::UrlCanBeParsed(id
);
78 CPPUNIT_ASSERT_EQUAL_MESSAGE("images_oxygen.zip is a valid theme name", true, valid
);
82 IconThemeInfoTest::ThemeIdIsDetectedFromFileNameWithUnderscore()
84 OUString
fname("images_oxygen.zip");
85 OUString sname
= vcl::IconThemeInfo::FileNameToThemeId(fname
);
86 CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme id is returned for 'images_oxygen.zip'", OUString("oxygen"), sname
);
90 IconThemeInfoTest::ExceptionIsThrownWhenIdCannotBeDetermined1()
93 OUString
fname("images_oxygen");
95 vcl::IconThemeInfo::FileNameToThemeId(fname
);
97 catch (std::runtime_error
&) {
100 CPPUNIT_ASSERT_EQUAL_MESSAGE("Exception was thrown",true, thrown
);
104 IconThemeInfoTest::ExceptionIsThrownWhenIdCannotBeDetermined2()
107 OUString
fname("image_oxygen.zip");
109 vcl::IconThemeInfo::FileNameToThemeId(fname
);
111 catch (std::runtime_error
&) {
114 CPPUNIT_ASSERT_EQUAL_MESSAGE("Exception was thrown", true, thrown
);
117 // Put the test suite in the registry
118 CPPUNIT_TEST_SUITE_REGISTRATION(IconThemeInfoTest
);
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */