Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / vcl / qa / cppunit / app / test_IconThemeInfo.cxx
blobd2e466d89f944ed905faeb2d6dbd47d19ad51491
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 <rtl/ustring.hxx>
13 #include <vcl/IconThemeInfo.hxx>
15 #include <cppunit/TestAssert.h>
16 #include <cppunit/TestFixture.h>
17 #include <cppunit/extensions/HelperMacros.h>
19 using namespace vcl;
21 class IconThemeInfoTest : public CppUnit::TestFixture
23 void
24 UpperCaseDisplayNameIsReturnedForNonDefaultId();
26 void
27 ImagesZipIsNotValid();
29 void
30 ImagesColibreZipIsValid();
32 void
33 ThemeIdIsDetectedFromFileNameWithUnderscore();
35 void
36 ExceptionIsThrownWhenIdCannotBeDetermined1();
38 void
39 ExceptionIsThrownWhenIdCannotBeDetermined2();
41 // Adds code needed to register the test suite
42 CPPUNIT_TEST_SUITE(IconThemeInfoTest);
43 CPPUNIT_TEST(UpperCaseDisplayNameIsReturnedForNonDefaultId);
44 CPPUNIT_TEST(ThemeIdIsDetectedFromFileNameWithUnderscore);
45 CPPUNIT_TEST(ImagesZipIsNotValid);
46 CPPUNIT_TEST(ImagesColibreZipIsValid);
47 CPPUNIT_TEST(ExceptionIsThrownWhenIdCannotBeDetermined1);
48 CPPUNIT_TEST(ExceptionIsThrownWhenIdCannotBeDetermined2);
50 // End of test suite definition
51 CPPUNIT_TEST_SUITE_END();
54 void
55 IconThemeInfoTest::UpperCaseDisplayNameIsReturnedForNonDefaultId()
57 OUString const id("katze");
58 OUString displayName = vcl::IconThemeInfo::ThemeIdToDisplayName(id);
59 CPPUNIT_ASSERT_EQUAL_MESSAGE("theme id is properly uppercased", OUString("Katze"), displayName);
62 void
63 IconThemeInfoTest::ImagesZipIsNotValid()
65 bool valid = vcl::IconThemeInfo::UrlCanBeParsed("file://images.zip");
66 CPPUNIT_ASSERT_EQUAL_MESSAGE("images.zip is not a valid theme name", false, valid);
69 void
70 IconThemeInfoTest::ImagesColibreZipIsValid()
72 OUString const id("file://images_colibre.zip");
73 bool valid = vcl::IconThemeInfo::UrlCanBeParsed(id);
74 CPPUNIT_ASSERT_EQUAL_MESSAGE("images_colibre.zip is a valid theme name", true, valid);
77 void
78 IconThemeInfoTest::ThemeIdIsDetectedFromFileNameWithUnderscore()
80 OUString const fname("images_colibre.zip");
81 OUString sname = vcl::IconThemeInfo::FileNameToThemeId(fname);
82 CPPUNIT_ASSERT_EQUAL_MESSAGE("'colibre' theme id is returned for 'images_colibre.zip'", OUString("colibre"), sname);
85 void
86 IconThemeInfoTest::ExceptionIsThrownWhenIdCannotBeDetermined1()
88 bool thrown = false;
89 OUString const fname("images_colibre");
90 try {
91 vcl::IconThemeInfo::FileNameToThemeId(fname);
93 catch (std::runtime_error&) {
94 thrown = true;
96 CPPUNIT_ASSERT_EQUAL_MESSAGE("Exception was thrown",true, thrown);
99 void
100 IconThemeInfoTest::ExceptionIsThrownWhenIdCannotBeDetermined2()
102 bool thrown = false;
103 OUString const fname("image_colibre.zip");
104 try {
105 vcl::IconThemeInfo::FileNameToThemeId(fname);
107 catch (std::runtime_error&) {
108 thrown = true;
110 CPPUNIT_ASSERT_EQUAL_MESSAGE("Exception was thrown", true, thrown);
113 // Put the test suite in the registry
114 CPPUNIT_TEST_SUITE_REGISTRATION(IconThemeInfoTest);
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */