bump product version to 5.0.4.1
[LibreOffice.git] / vcl / qa / cppunit / app / test_IconThemeInfo.cxx
blob2a199d27793a0f93196c81c08ccbe785011b6653
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 <stdexcept>
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>
22 using namespace vcl;
24 class IconThemeInfoTest : public CppUnit::TestFixture
26 void
27 UpperCaseDisplayNameIsReturnedForNonDefaultId();
29 void
30 ImagesZipIsNotValid();
32 void
33 ImagesOxygenZipIsValid();
35 void
36 ThemeIdIsDetectedFromFileNameWithUnderscore();
38 void
39 ExceptionIsThrownWhenIdCannotBeDetermined1();
41 void
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();
57 void
58 IconThemeInfoTest::UpperCaseDisplayNameIsReturnedForNonDefaultId()
60 OUString id("katze");
61 OUString displayName = vcl::IconThemeInfo::ThemeIdToDisplayName(id);
62 CPPUNIT_ASSERT_EQUAL_MESSAGE("theme id is properly uppercased", OUString("Katze"), displayName);
65 void
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);
73 void
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);
81 void
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);
89 void
90 IconThemeInfoTest::ExceptionIsThrownWhenIdCannotBeDetermined1()
92 bool thrown = false;
93 OUString fname("images_oxygen");
94 try {
95 vcl::IconThemeInfo::FileNameToThemeId(fname);
97 catch (std::runtime_error&) {
98 thrown = true;
100 CPPUNIT_ASSERT_EQUAL_MESSAGE("Exception was thrown",true, thrown);
103 void
104 IconThemeInfoTest::ExceptionIsThrownWhenIdCannotBeDetermined2()
106 bool thrown = false;
107 OUString fname("image_oxygen.zip");
108 try {
109 vcl::IconThemeInfo::FileNameToThemeId(fname);
111 catch (std::runtime_error&) {
112 thrown = true;
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: */