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