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/IconThemeScanner.hxx>
16 : #include <vcl/IconThemeInfo.hxx>
17 :
18 : #include <cppunit/TestAssert.h>
19 : #include <cppunit/TestFixture.h>
20 : #include <cppunit/extensions/HelperMacros.h>
21 : #include <cppunit/plugin/TestPlugIn.h>
22 :
23 18 : class IconThemeScannerTest : public CppUnit::TestFixture
24 : {
25 : void
26 : AddedThemeIsFoundById();
27 :
28 : void
29 : AddedThemeInfoIsReturned();
30 :
31 : void
32 : ExceptionIsThrownIfInvalidInfoIsRequested();
33 :
34 : // Adds code needed to register the test suite
35 4 : CPPUNIT_TEST_SUITE(IconThemeScannerTest);
36 2 : CPPUNIT_TEST(AddedThemeIsFoundById);
37 2 : CPPUNIT_TEST(AddedThemeInfoIsReturned);
38 2 : CPPUNIT_TEST(ExceptionIsThrownIfInvalidInfoIsRequested);
39 :
40 : // End of test suite definition
41 4 : CPPUNIT_TEST_SUITE_END();
42 : };
43 :
44 : void
45 2 : IconThemeScannerTest::AddedThemeIsFoundById()
46 : {
47 2 : vcl::IconThemeScanner scanner;
48 4 : OUString theme("file:://images_katze.zip");
49 2 : scanner.AddIconThemeByPath(theme);
50 4 : OUString id = vcl::IconThemeInfo::FileNameToThemeId("images_katze.zip");
51 2 : bool found = scanner.IconThemeIsInstalled(id);
52 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("icon theme could be added by url", true, found);
53 2 : }
54 :
55 : void
56 2 : IconThemeScannerTest::AddedThemeInfoIsReturned()
57 : {
58 2 : vcl::IconThemeScanner scanner;
59 4 : OUString theme("file:://images_katze.zip");
60 2 : scanner.AddIconThemeByPath(theme);
61 4 : OUString id = vcl::IconThemeInfo::FileNameToThemeId("images_katze.zip");
62 2 : const vcl::IconThemeInfo& info = scanner.GetIconThemeInfo(id);
63 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'katze' icon theme is found from id", theme, info.GetUrlToFile());
64 2 : }
65 :
66 : void
67 2 : IconThemeScannerTest::ExceptionIsThrownIfInvalidInfoIsRequested()
68 : {
69 2 : vcl::IconThemeScanner scanner;
70 4 : OUString theme("file:://images_katze.zip");
71 2 : scanner.AddIconThemeByPath(theme);
72 2 : bool thrown = false;
73 : try
74 : {
75 4 : scanner.GetIconThemeInfo("hund");
76 : }
77 4 : catch (const std::runtime_error&)
78 : {
79 2 : thrown = true;
80 : }
81 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Exception is thrown if invalid theme info is requested", true, thrown);
82 2 : }
83 :
84 : // Put the test suite in the registry
85 6 : CPPUNIT_TEST_SUITE_REGISTRATION(IconThemeScannerTest);
86 :
87 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|