LCOV - code coverage report
Current view: top level - sw/qa/extras/tox - test_ToxLinkProcessor.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 63 64 98.4 %
Date: 2014-11-03 Functions: 16 17 94.1 %
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             : 
      16             : #include <ToxLinkProcessor.hxx>
      17             : 
      18             : #include <cppunit/TestAssert.h>
      19             : #include <cppunit/extensions/HelperMacros.h>
      20             : #include <cppunit/plugin/TestPlugIn.h>
      21             : #include <test/bootstrapfixture.hxx>
      22             : 
      23             : #include <swdll.hxx>
      24             : 
      25             : using namespace sw;
      26             : 
      27          24 : class ToxLinkProcessorTest : public test::BootstrapFixture
      28             : {
      29             :     void ExceptionIsThrownIfTooManyLinksAreClosed();
      30             :     void AddingAndClosingTwoLinksResultsInTwoClosedLinks();
      31             :     void LinkIsCreatedCorrectly();
      32             :     void LinkSequenceIsPreserved();
      33             : 
      34           4 :     CPPUNIT_TEST_SUITE(ToxLinkProcessorTest);
      35           2 :     CPPUNIT_TEST(ExceptionIsThrownIfTooManyLinksAreClosed);
      36           2 :     CPPUNIT_TEST(AddingAndClosingTwoLinksResultsInTwoClosedLinks);
      37           2 :     CPPUNIT_TEST(LinkIsCreatedCorrectly);
      38           2 :     CPPUNIT_TEST(LinkSequenceIsPreserved);
      39           4 :     CPPUNIT_TEST_SUITE_END();
      40             : public:
      41           8 :     void setUp() SAL_OVERRIDE {
      42           8 :         BootstrapFixture::setUp();
      43           8 :         SwGlobals::ensure();
      44           8 :     }
      45             : 
      46             :     static const OUString STYLE_NAME_1;
      47             :     static const OUString STYLE_NAME_2;
      48             :     static const sal_uInt16 POOL_ID_1;
      49             :     static const sal_uInt16 POOL_ID_2;
      50             :     static const OUString URL_1;
      51             :     static const OUString URL_2;
      52             : };
      53             : 
      54           2 : const OUString ToxLinkProcessorTest::STYLE_NAME_1 = "anyStyle1";
      55           2 : const OUString ToxLinkProcessorTest::STYLE_NAME_2 = "anyStyle2";
      56           2 : const OUString ToxLinkProcessorTest::URL_1 = "anyUrl1";
      57           2 : const OUString ToxLinkProcessorTest::URL_2 = "anyUrl2";
      58             : const sal_uInt16 ToxLinkProcessorTest::POOL_ID_1 = 42;
      59             : const sal_uInt16 ToxLinkProcessorTest::POOL_ID_2 = 43;
      60             : 
      61             : void
      62           2 : ToxLinkProcessorTest::ExceptionIsThrownIfTooManyLinksAreClosed()
      63             : {
      64           2 :     ToxLinkProcessor sut;
      65           2 :     sut.StartNewLink(0, STYLE_NAME_1);
      66           2 :     sut.CloseLink(1, URL_1);
      67           2 :     CPPUNIT_ASSERT_THROW(sut.CloseLink(1, URL_1), std::runtime_error);
      68           2 : }
      69             : 
      70             : void
      71           2 : ToxLinkProcessorTest::AddingAndClosingTwoLinksResultsInTwoClosedLinks()
      72             : {
      73           2 :     ToxLinkProcessor sut;
      74           2 :     sut.StartNewLink(0, STYLE_NAME_1);
      75           2 :     sut.StartNewLink(0, STYLE_NAME_2);
      76           2 :     sut.CloseLink(1, URL_1);
      77           2 :     sut.CloseLink(1, URL_2);
      78           2 :     CPPUNIT_ASSERT_EQUAL(2u, static_cast<unsigned>(sut.mClosedLinks.size()));
      79           2 :     CPPUNIT_ASSERT_MESSAGE("no links are open", sut.mStartedLinks.empty());
      80           2 : }
      81             : 
      82           8 : class ToxLinkProcessorWithOverriddenObtainPoolId : public ToxLinkProcessor {
      83             : public:
      84             :     virtual sal_uInt16
      85           6 :     ObtainPoolId(const OUString& characterStyle) const SAL_OVERRIDE {
      86           6 :         if (characterStyle == ToxLinkProcessorTest::STYLE_NAME_1) {
      87           4 :             return ToxLinkProcessorTest::POOL_ID_1;
      88             :         }
      89           2 :         if (characterStyle == ToxLinkProcessorTest::STYLE_NAME_2) {
      90           2 :             return ToxLinkProcessorTest::POOL_ID_2;
      91             :         }
      92           0 :         return 0;
      93             :     }
      94             : };
      95             : 
      96             : void
      97           2 : ToxLinkProcessorTest::LinkIsCreatedCorrectly()
      98             : {
      99             :     // obtainpoolid needs to be overridden to check what we are
     100           2 :     ToxLinkProcessorWithOverriddenObtainPoolId sut;
     101             : 
     102           2 :     sut.StartNewLink(0, STYLE_NAME_1);
     103           2 :     sut.CloseLink(1, URL_1);
     104             : 
     105           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Style is stored correctly in link", STYLE_NAME_1, sut.mClosedLinks.at(0).mINetFmt.GetVisitedFmt());
     106           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Url is stored correctly in link", URL_1, sut.mClosedLinks.at(0).mINetFmt.GetValue());
     107           2 : }
     108             : 
     109             : void
     110           2 : ToxLinkProcessorTest::LinkSequenceIsPreserved()
     111             : {
     112             : 
     113             :     // obtainpoolid needs to be overridden to check what we are
     114           2 :     ToxLinkProcessorWithOverriddenObtainPoolId sut;
     115             : 
     116           2 :     sut.StartNewLink(0, STYLE_NAME_1);
     117           2 :     sut.StartNewLink(0, STYLE_NAME_2);
     118           2 :     sut.CloseLink(1, URL_2);
     119           2 :     sut.CloseLink(1, URL_1);
     120             : 
     121             :     // check first closed element
     122           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Style is stored correctly in link",
     123           2 :             STYLE_NAME_2, sut.mClosedLinks.at(0).mINetFmt.GetVisitedFmt());
     124           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Pool id is stored correctly in link",
     125           2 :             POOL_ID_2, sut.mClosedLinks.at(0).mINetFmt.GetINetFmtId());
     126           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Url is stored correctly in link",
     127           2 :             URL_2, sut.mClosedLinks.at(0).mINetFmt.GetValue());
     128             :     // check second closed element
     129           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Style is stored correctly in link",
     130           2 :             STYLE_NAME_1, sut.mClosedLinks.at(1).mINetFmt.GetVisitedFmt());
     131           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Pool id is stored correctly in link",
     132           2 :             POOL_ID_1, sut.mClosedLinks.at(1).mINetFmt.GetINetFmtId());
     133           4 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Url is stored correctly in link",
     134           4 :             URL_1, sut.mClosedLinks.at(1).mINetFmt.GetValue());
     135           2 : }
     136             : 
     137             : // Put the test suite in the registry
     138           6 : CPPUNIT_TEST_SUITE_REGISTRATION(ToxLinkProcessorTest);
     139             : 
     140             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10