LCOV - code coverage report
Current view: top level - sw/qa/core - test_ToxLinkProcessor.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 63 64 98.4 %
Date: 2015-06-13 12:38:46 Functions: 19 20 95.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             : 
      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          12 : class ToxLinkProcessorTest : public test::BootstrapFixture
      28             : {
      29             :     void ExceptionIsThrownIfTooManyLinksAreClosed();
      30             :     void AddingAndClosingTwoLinksResultsInTwoClosedLinks();
      31             :     void LinkIsCreatedCorrectly();
      32             :     void LinkSequenceIsPreserved();
      33             : 
      34           2 :     CPPUNIT_TEST_SUITE(ToxLinkProcessorTest);
      35           1 :     CPPUNIT_TEST(ExceptionIsThrownIfTooManyLinksAreClosed);
      36           1 :     CPPUNIT_TEST(AddingAndClosingTwoLinksResultsInTwoClosedLinks);
      37           1 :     CPPUNIT_TEST(LinkIsCreatedCorrectly);
      38           1 :     CPPUNIT_TEST(LinkSequenceIsPreserved);
      39           5 :     CPPUNIT_TEST_SUITE_END();
      40             : public:
      41           4 :     void setUp() SAL_OVERRIDE {
      42           4 :         BootstrapFixture::setUp();
      43           4 :         SwGlobals::ensure();
      44           4 :     }
      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           1 : const OUString ToxLinkProcessorTest::STYLE_NAME_1 = "anyStyle1";
      55           1 : const OUString ToxLinkProcessorTest::STYLE_NAME_2 = "anyStyle2";
      56           1 : const OUString ToxLinkProcessorTest::URL_1 = "anyUrl1";
      57           1 : 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           1 : ToxLinkProcessorTest::ExceptionIsThrownIfTooManyLinksAreClosed()
      63             : {
      64           1 :     ToxLinkProcessor sut;
      65           1 :     sut.StartNewLink(0, STYLE_NAME_1);
      66           1 :     sut.CloseLink(1, URL_1);
      67             :     // fdo#85872 actually it turns out the UI does something like this
      68             :     // so an exception must not be thrown!
      69           1 :     sut.CloseLink(1, URL_1);
      70           1 : }
      71             : 
      72             : void
      73           1 : ToxLinkProcessorTest::AddingAndClosingTwoLinksResultsInTwoClosedLinks()
      74             : {
      75           1 :     ToxLinkProcessor sut;
      76           1 :     sut.StartNewLink(0, STYLE_NAME_1);
      77           1 :     sut.StartNewLink(0, STYLE_NAME_2);
      78           1 :     sut.CloseLink(1, URL_1);
      79           1 :     sut.CloseLink(1, URL_2);
      80           1 :     CPPUNIT_ASSERT_EQUAL(2u, static_cast<unsigned>(sut.mClosedLinks.size()));
      81           1 :     CPPUNIT_ASSERT_MESSAGE("no links are open", sut.mStartedLinks.empty());
      82           1 : }
      83             : 
      84           4 : class ToxLinkProcessorWithOverriddenObtainPoolId : public ToxLinkProcessor {
      85             : public:
      86             :     virtual sal_uInt16
      87           3 :     ObtainPoolId(const OUString& characterStyle) const SAL_OVERRIDE {
      88           3 :         if (characterStyle == ToxLinkProcessorTest::STYLE_NAME_1) {
      89           2 :             return ToxLinkProcessorTest::POOL_ID_1;
      90             :         }
      91           1 :         if (characterStyle == ToxLinkProcessorTest::STYLE_NAME_2) {
      92           1 :             return ToxLinkProcessorTest::POOL_ID_2;
      93             :         }
      94           0 :         return 0;
      95             :     }
      96             : };
      97             : 
      98             : void
      99           1 : ToxLinkProcessorTest::LinkIsCreatedCorrectly()
     100             : {
     101             :     // obtainpoolid needs to be overridden to check what we are
     102           1 :     ToxLinkProcessorWithOverriddenObtainPoolId sut;
     103             : 
     104           1 :     sut.StartNewLink(0, STYLE_NAME_1);
     105           1 :     sut.CloseLink(1, URL_1);
     106             : 
     107           1 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Style is stored correctly in link", STYLE_NAME_1, sut.mClosedLinks.at(0).mINetFormat.GetVisitedFormat());
     108           1 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Url is stored correctly in link", URL_1, sut.mClosedLinks.at(0).mINetFormat.GetValue());
     109           1 : }
     110             : 
     111             : void
     112           1 : ToxLinkProcessorTest::LinkSequenceIsPreserved()
     113             : {
     114             : 
     115             :     // obtainpoolid needs to be overridden to check what we are
     116           1 :     ToxLinkProcessorWithOverriddenObtainPoolId sut;
     117             : 
     118           1 :     sut.StartNewLink(0, STYLE_NAME_1);
     119           1 :     sut.StartNewLink(0, STYLE_NAME_2);
     120           1 :     sut.CloseLink(1, URL_2);
     121           1 :     sut.CloseLink(1, URL_1);
     122             : 
     123             :     // check first closed element
     124           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Style is stored correctly in link",
     125           1 :             STYLE_NAME_2, sut.mClosedLinks.at(0).mINetFormat.GetVisitedFormat());
     126           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Pool id is stored correctly in link",
     127           1 :             POOL_ID_2, sut.mClosedLinks.at(0).mINetFormat.GetINetFormatId());
     128           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Url is stored correctly in link",
     129           1 :             URL_2, sut.mClosedLinks.at(0).mINetFormat.GetValue());
     130             :     // check second closed element
     131           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Style is stored correctly in link",
     132           1 :             STYLE_NAME_1, sut.mClosedLinks.at(1).mINetFormat.GetVisitedFormat());
     133           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Pool id is stored correctly in link",
     134           1 :             POOL_ID_1, sut.mClosedLinks.at(1).mINetFormat.GetINetFormatId());
     135           2 :     CPPUNIT_ASSERT_EQUAL_MESSAGE("Url is stored correctly in link",
     136           2 :             URL_1, sut.mClosedLinks.at(1).mINetFormat.GetValue());
     137           1 : }
     138             : 
     139             : // Put the test suite in the registry
     140           3 : CPPUNIT_TEST_SUITE_REGISTRATION(ToxLinkProcessorTest);
     141             : 
     142             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11