build fix
[LibreOffice.git] / vcl / qa / cppunit / app / test_IconThemeInfo.cxx
blob812bfe5229f51e4d7de2ef5d76935ada68674485
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 DisplayNameForHicontrastIsHighContrast();
41 void
42 DisplayNameForTango_testingIsTangoTesting();
44 void
45 ExceptionIsThrownWhenIdCannotBeDetermined1();
47 void
48 ExceptionIsThrownWhenIdCannotBeDetermined2();
50 // Adds code needed to register the test suite
51 CPPUNIT_TEST_SUITE(IconThemeInfoTest);
52 CPPUNIT_TEST(UpperCaseDisplayNameIsReturnedForNonDefaultId);
53 CPPUNIT_TEST(ThemeIdIsDetectedFromFileNameWithUnderscore);
54 CPPUNIT_TEST(ImagesZipIsNotValid);
55 CPPUNIT_TEST(ImagesOxygenZipIsValid);
56 CPPUNIT_TEST(DisplayNameForHicontrastIsHighContrast);
57 CPPUNIT_TEST(DisplayNameForTango_testingIsTangoTesting);
58 CPPUNIT_TEST(ExceptionIsThrownWhenIdCannotBeDetermined1);
59 CPPUNIT_TEST(ExceptionIsThrownWhenIdCannotBeDetermined2);
61 // End of test suite definition
62 CPPUNIT_TEST_SUITE_END();
65 void
66 IconThemeInfoTest::UpperCaseDisplayNameIsReturnedForNonDefaultId()
68 OUString id("katze");
69 OUString displayName = vcl::IconThemeInfo::ThemeIdToDisplayName(id);
70 CPPUNIT_ASSERT_EQUAL_MESSAGE("theme id is properly uppercased", OUString("Katze"), displayName);
73 void
74 IconThemeInfoTest::ImagesZipIsNotValid()
76 OUString id("file://images.zip");
77 bool valid = vcl::IconThemeInfo::UrlCanBeParsed(id);
78 CPPUNIT_ASSERT_EQUAL_MESSAGE("images.zip is not a valid theme name", false, valid);
81 void
82 IconThemeInfoTest::ImagesOxygenZipIsValid()
84 OUString id("file://images_oxygen.zip");
85 bool valid = vcl::IconThemeInfo::UrlCanBeParsed(id);
86 CPPUNIT_ASSERT_EQUAL_MESSAGE("images_oxygen.zip is a valid theme name", true, valid);
89 void
90 IconThemeInfoTest::ThemeIdIsDetectedFromFileNameWithUnderscore()
92 OUString fname("images_oxygen.zip");
93 OUString sname = vcl::IconThemeInfo::FileNameToThemeId(fname);
94 CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme id is returned for 'images_oxygen.zip'", OUString("oxygen"), sname);
97 void
98 IconThemeInfoTest::ExceptionIsThrownWhenIdCannotBeDetermined1()
100 bool thrown = false;
101 OUString fname("images_oxygen");
102 try {
103 vcl::IconThemeInfo::FileNameToThemeId(fname);
105 catch (std::runtime_error&) {
106 thrown = true;
108 CPPUNIT_ASSERT_EQUAL_MESSAGE("Exception was thrown",true, thrown);
111 void
112 IconThemeInfoTest::ExceptionIsThrownWhenIdCannotBeDetermined2()
114 bool thrown = false;
115 OUString fname("image_oxygen.zip");
116 try {
117 vcl::IconThemeInfo::FileNameToThemeId(fname);
119 catch (std::runtime_error&) {
120 thrown = true;
122 CPPUNIT_ASSERT_EQUAL_MESSAGE("Exception was thrown", true, thrown);
125 void
126 IconThemeInfoTest::DisplayNameForHicontrastIsHighContrast()
128 OUString id("hicontrast");
129 OUString expected("High Contrast");
130 OUString displayName = vcl::IconThemeInfo::ThemeIdToDisplayName(id);
131 CPPUNIT_ASSERT_EQUAL(expected, displayName);
134 void
135 IconThemeInfoTest::DisplayNameForTango_testingIsTangoTesting()
137 OUString id("tango_testing");
138 OUString expected("Tango Testing");
139 OUString displayName = vcl::IconThemeInfo::ThemeIdToDisplayName(id);
140 CPPUNIT_ASSERT_EQUAL(expected, displayName);
143 // Put the test suite in the registry
144 CPPUNIT_TEST_SUITE_REGISTRATION(IconThemeInfoTest);
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */