LCOV - code coverage report
Current view: top level - vcl/qa/cppunit/app - test_IconThemeInfo.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 46 46 100.0 %
Date: 2014-11-03 Functions: 14 14 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          36 : 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             :     ExceptionIsThrownWhenIdCannotBeDetermined1();
      40             : 
      41             :     void
      42             :     ExceptionIsThrownWhenIdCannotBeDetermined2();
      43             : 
      44             :     // Adds code needed to register the test suite
      45           4 :     CPPUNIT_TEST_SUITE(IconThemeInfoTest);
      46           2 :     CPPUNIT_TEST(UpperCaseDisplayNameIsReturnedForNonDefaultId);
      47           2 :     CPPUNIT_TEST(ThemeIdIsDetectedFromFileNameWithUnderscore);
      48           2 :     CPPUNIT_TEST(ImagesZipIsNotValid);
      49           2 :     CPPUNIT_TEST(ImagesOxygenZipIsValid);
      50           2 :     CPPUNIT_TEST(ExceptionIsThrownWhenIdCannotBeDetermined1);
      51           2 :     CPPUNIT_TEST(ExceptionIsThrownWhenIdCannotBeDetermined2);
      52             : 
      53             :     // End of test suite definition
      54           4 :     CPPUNIT_TEST_SUITE_END();
      55             : };
      56             : 
      57             : void
      58           2 : IconThemeInfoTest::UpperCaseDisplayNameIsReturnedForNonDefaultId()
      59             : {
      60           2 :     OUString id("katze");
      61           4 :     OUString displayName = vcl::IconThemeInfo::ThemeIdToDisplayName(id);
      62           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("theme id is properly uppercased", OUString("Katze"), displayName);
      63           2 : }
      64             : 
      65             : void
      66           2 : IconThemeInfoTest::ImagesZipIsNotValid()
      67             : {
      68           2 :     OUString id("file://images.zip");
      69           2 :     bool valid = vcl::IconThemeInfo::UrlCanBeParsed(id);
      70           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("images.zip is not a valid theme name", false, valid);
      71           2 : }
      72             : 
      73             : void
      74           2 : IconThemeInfoTest::ImagesOxygenZipIsValid()
      75             : {
      76           2 :     OUString id("file://images_oxygen.zip");
      77           2 :     bool valid = vcl::IconThemeInfo::UrlCanBeParsed(id);
      78           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("images_oxygen.zip is a valid theme name", true, valid);
      79           2 : }
      80             : 
      81             : void
      82           2 : IconThemeInfoTest::ThemeIdIsDetectedFromFileNameWithUnderscore()
      83             : {
      84           2 :     OUString fname("images_oxygen.zip");
      85           4 :     OUString sname = vcl::IconThemeInfo::FileNameToThemeId(fname);
      86           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("'oxygen' theme id is returned for 'images_oxygen.zip'", OUString("oxygen"), sname);
      87           2 : }
      88             : 
      89             : void
      90           2 : IconThemeInfoTest::ExceptionIsThrownWhenIdCannotBeDetermined1()
      91             : {
      92           2 :     bool thrown = false;
      93           2 :     OUString fname("images_oxygen");
      94             :     try {
      95           2 :         vcl::IconThemeInfo::FileNameToThemeId(fname);
      96             :     }
      97           4 :     catch (std::runtime_error&) {
      98           2 :         thrown = true;
      99             :     }
     100           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Exception was thrown",true, thrown);
     101           2 : }
     102             : 
     103             : void
     104           2 : IconThemeInfoTest::ExceptionIsThrownWhenIdCannotBeDetermined2()
     105             : {
     106           2 :     bool thrown = false;
     107           2 :     OUString fname("image_oxygen.zip");
     108             :     try {
     109           2 :         vcl::IconThemeInfo::FileNameToThemeId(fname);
     110             :     }
     111           4 :     catch (std::runtime_error&) {
     112           2 :         thrown = true;
     113             :     }
     114           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Exception was thrown", true, thrown);
     115           2 : }
     116             : 
     117             : // Put the test suite in the registry
     118           6 : CPPUNIT_TEST_SUITE_REGISTRATION(IconThemeInfoTest);
     119             : 
     120             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10