LCOV - code coverage report
Current view: top level - vcl/qa/cppunit/app - test_IconThemeInfo.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 60 60 100.0 %
Date: 2015-06-13 12:38:46 Functions: 19 19 100.0 %
Legend: Lines: hit not hit

          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             :     ThemeIdIsDetectedFromFileNameWithUnderscore();
      37             : 
      38             :     void
      39             :     DisplayNameForHicontrastIsHighContrast();
      40             : 
      41             :     void
      42             :     DisplayNameForTango_testingIsTangoTesting();
      43             : 
      44             :     void
      45             :     ExceptionIsThrownWhenIdCannotBeDetermined1();
      46             : 
      47             :     void
      48             :     ExceptionIsThrownWhenIdCannotBeDetermined2();
      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(DisplayNameForHicontrastIsHighContrast);
      57           1 :     CPPUNIT_TEST(DisplayNameForTango_testingIsTangoTesting);
      58           1 :     CPPUNIT_TEST(ExceptionIsThrownWhenIdCannotBeDetermined1);
      59           1 :     CPPUNIT_TEST(ExceptionIsThrownWhenIdCannotBeDetermined2);
      60             : 
      61             :     // End of test suite definition
      62           5 :     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::ThemeIdIsDetectedFromFileNameWithUnderscore()
      91             : {
      92           1 :     OUString fname("images_oxygen.zip");
      93           2 :     OUString sname = vcl::IconThemeInfo::FileNameToThemeId(fname);
      94           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme id is returned for 'images_oxygen.zip'", OUString("oxygen"), sname);
      95           1 : }
      96             : 
      97             : void
      98           1 : IconThemeInfoTest::ExceptionIsThrownWhenIdCannotBeDetermined1()
      99             : {
     100           1 :     bool thrown = false;
     101           1 :     OUString fname("images_oxygen");
     102             :     try {
     103           1 :         vcl::IconThemeInfo::FileNameToThemeId(fname);
     104             :     }
     105           2 :     catch (std::runtime_error&) {
     106           1 :         thrown = true;
     107             :     }
     108           1 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Exception was thrown",true, thrown);
     109           1 : }
     110             : 
     111             : void
     112           1 : IconThemeInfoTest::ExceptionIsThrownWhenIdCannotBeDetermined2()
     113             : {
     114           1 :     bool thrown = false;
     115           1 :     OUString fname("image_oxygen.zip");
     116             :     try {
     117           1 :         vcl::IconThemeInfo::FileNameToThemeId(fname);
     118             :     }
     119           2 :     catch (std::runtime_error&) {
     120           1 :         thrown = true;
     121             :     }
     122           1 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Exception was thrown", true, thrown);
     123           1 : }
     124             : 
     125             : void
     126           1 : IconThemeInfoTest::DisplayNameForHicontrastIsHighContrast()
     127             : {
     128           1 :     OUString id("hicontrast");
     129           2 :     OUString expected("High Contrast");
     130           2 :     OUString displayName = vcl::IconThemeInfo::ThemeIdToDisplayName(id);
     131           2 :     CPPUNIT_ASSERT_EQUAL(expected, displayName);
     132           1 : }
     133             : 
     134             : void
     135           1 : IconThemeInfoTest::DisplayNameForTango_testingIsTangoTesting()
     136             : {
     137           1 :     OUString id("tango_testing");
     138           2 :     OUString expected("Tango Testing");
     139           2 :     OUString displayName = vcl::IconThemeInfo::ThemeIdToDisplayName(id);
     140           2 :     CPPUNIT_ASSERT_EQUAL(expected, displayName);
     141           1 : }
     142             : 
     143             : // Put the test suite in the registry
     144           3 : CPPUNIT_TEST_SUITE_REGISTRATION(IconThemeInfoTest);
     145             : 
     146             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11