Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
10 : #include <stdexcept>
11 :
12 : #include <sal/types.h>
13 :
14 : #include <rtl/ustring.hxx>
15 : #include <vcl/IconThemeInfo.hxx>
16 :
17 : #include <cppunit/TestAssert.h>
18 : #include <cppunit/TestFixture.h>
19 : #include <cppunit/extensions/HelperMacros.h>
20 : #include <cppunit/plugin/TestPlugIn.h>
21 :
22 : using namespace vcl;
23 :
24 24 : class IconThemeInfoTest : public CppUnit::TestFixture
25 : {
26 : void
27 : UpperCaseDisplayNameIsReturnedForNonDefaultId();
28 :
29 : void
30 : ImagesZipIsNotValid();
31 :
32 : void
33 : ImagesOxygenZipIsValid();
34 :
35 : void
36 : DefaultZipIsValid();
37 :
38 : void
39 : ThemeIdIsDetectedFromFileNameWithUnderscore();
40 :
41 : void
42 : ExceptionIsThrownWhenIdCannotBeDetermined1();
43 :
44 : void
45 : ExceptionIsThrownWhenIdCannotBeDetermined2();
46 :
47 : void
48 : GalaxyIsReturnedAsDisplayNameForDefaultZip();
49 :
50 : // Adds code needed to register the test suite
51 2 : CPPUNIT_TEST_SUITE(IconThemeInfoTest);
52 1 : CPPUNIT_TEST(UpperCaseDisplayNameIsReturnedForNonDefaultId);
53 1 : CPPUNIT_TEST(ThemeIdIsDetectedFromFileNameWithUnderscore);
54 1 : CPPUNIT_TEST(ImagesZipIsNotValid);
55 1 : CPPUNIT_TEST(ImagesOxygenZipIsValid);
56 1 : CPPUNIT_TEST(DefaultZipIsValid);
57 1 : CPPUNIT_TEST(GalaxyIsReturnedAsDisplayNameForDefaultZip);
58 1 : CPPUNIT_TEST(ExceptionIsThrownWhenIdCannotBeDetermined1);
59 1 : CPPUNIT_TEST(ExceptionIsThrownWhenIdCannotBeDetermined2);
60 :
61 : // End of test suite definition
62 2 : CPPUNIT_TEST_SUITE_END();
63 : };
64 :
65 : void
66 1 : IconThemeInfoTest::UpperCaseDisplayNameIsReturnedForNonDefaultId()
67 : {
68 1 : OUString id("katze");
69 2 : OUString displayName = vcl::IconThemeInfo::ThemeIdToDisplayName(id);
70 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("theme id is properly uppercased", OUString("Katze"), displayName);
71 1 : }
72 :
73 : void
74 1 : IconThemeInfoTest::ImagesZipIsNotValid()
75 : {
76 1 : OUString id("file://images.zip");
77 1 : bool valid = vcl::IconThemeInfo::UrlCanBeParsed(id);
78 1 : CPPUNIT_ASSERT_EQUAL_MESSAGE("images.zip is not a valid theme name", false, valid);
79 1 : }
80 :
81 : void
82 1 : IconThemeInfoTest::ImagesOxygenZipIsValid()
83 : {
84 1 : OUString id("file://images_oxygen.zip");
85 1 : bool valid = vcl::IconThemeInfo::UrlCanBeParsed(id);
86 1 : CPPUNIT_ASSERT_EQUAL_MESSAGE("images_oxygen.zip is a valid theme name", true, valid);
87 1 : }
88 :
89 : void
90 1 : IconThemeInfoTest::DefaultZipIsValid()
91 : {
92 1 : OUString id("file://default.zip");
93 1 : bool valid = vcl::IconThemeInfo::UrlCanBeParsed(id);
94 1 : CPPUNIT_ASSERT_EQUAL_MESSAGE("default.zip is a valid theme name", true, valid);
95 1 : }
96 :
97 : void
98 1 : IconThemeInfoTest::ThemeIdIsDetectedFromFileNameWithUnderscore()
99 : {
100 1 : OUString fname("images_oxygen.zip");
101 2 : OUString sname = vcl::IconThemeInfo::FileNameToThemeId(fname);
102 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme id is returned for 'images_oxygen.zip'", OUString("oxygen"), sname);
103 1 : }
104 :
105 : void
106 1 : IconThemeInfoTest::ExceptionIsThrownWhenIdCannotBeDetermined1()
107 : {
108 1 : bool thrown = false;
109 1 : OUString fname("images_oxygen");
110 : try {
111 1 : vcl::IconThemeInfo::FileNameToThemeId(fname);
112 : }
113 2 : catch (std::runtime_error&) {
114 1 : thrown = true;
115 : }
116 1 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Exception was thrown",true, thrown);
117 1 : }
118 :
119 : void
120 1 : IconThemeInfoTest::ExceptionIsThrownWhenIdCannotBeDetermined2()
121 : {
122 1 : bool thrown = false;
123 1 : OUString fname("image_oxygen.zip");
124 : try {
125 1 : vcl::IconThemeInfo::FileNameToThemeId(fname);
126 : }
127 2 : catch (std::runtime_error&) {
128 1 : thrown = true;
129 : }
130 1 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Exception was thrown", true, thrown);
131 1 : }
132 :
133 : void
134 1 : IconThemeInfoTest::GalaxyIsReturnedAsDisplayNameForDefaultZip()
135 : {
136 1 : OUString id("file://default.zip");
137 2 : IconThemeInfo i(id);
138 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("default.zip is displayed as Galaxy", OUString("Galaxy"), i.GetDisplayName());
139 1 : }
140 :
141 : // Put the test suite in the registry
142 3 : CPPUNIT_TEST_SUITE_REGISTRATION(IconThemeInfoTest);
143 :
144 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|