LCOV - code coverage report
Current view: top level - writerfilter/qa/cppunittests/misc - misc.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 102 102 100.0 %
Date: 2014-11-03 Functions: 13 14 92.9 %
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 <limits>
      11             : #include <vector>
      12             : 
      13             : #include <boost/tuple/tuple.hpp>
      14             : 
      15             : #include <cppunit/TestAssert.h>
      16             : #include <cppunit/TestFixture.h>
      17             : #include <cppunit/extensions/HelperMacros.h>
      18             : #include <cppunit/plugin/TestPlugIn.h>
      19             : 
      20             : #include <sal/types.h>
      21             : 
      22             : #include <rtl/ustring.hxx>
      23             : #include <dmapper/ConversionHelper.hxx>
      24             : #include <dmapper/DomainMapper_Impl.hxx>
      25             : 
      26             : using namespace std;
      27             : 
      28             : namespace {
      29             : 
      30          12 : class WriterfilterMiscTest
      31             :     : public ::CppUnit::TestFixture
      32             : {
      33             : public:
      34             :     virtual void setUp() SAL_OVERRIDE;
      35             :     virtual void tearDown() SAL_OVERRIDE;
      36             : 
      37             :     void testTwipConversions();
      38             :     void testFieldParameters();
      39             : 
      40           4 :     CPPUNIT_TEST_SUITE(WriterfilterMiscTest);
      41           2 :     CPPUNIT_TEST(testTwipConversions);
      42           2 :     CPPUNIT_TEST(testFieldParameters);
      43           4 :     CPPUNIT_TEST_SUITE_END();
      44             : };
      45             : 
      46           4 : void WriterfilterMiscTest::setUp()
      47             : {
      48           4 : }
      49             : 
      50           4 : void WriterfilterMiscTest::tearDown()
      51             : {
      52           4 : }
      53             : 
      54           2 : void WriterfilterMiscTest::testTwipConversions()
      55             : {
      56             :     using writerfilter::dmapper::ConversionHelper::convertTwipToMM100;
      57             :     using writerfilter::dmapper::ConversionHelper::convertTwipToMM100Unsigned;
      58             : 
      59           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(-2), convertTwipToMM100(-1));
      60           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(-17639), convertTwipToMM100(-10000));
      61           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(-70556), convertTwipToMM100(-40000));
      62           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(2), convertTwipToMM100(1));
      63           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(17639), convertTwipToMM100(10000));
      64           2 :     CPPUNIT_ASSERT_EQUAL(sal_Int32(0), convertTwipToMM100(40000));
      65             : 
      66           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(-1));
      67           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(-10000));
      68           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(-40000));
      69           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(2), convertTwipToMM100Unsigned(1));
      70           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(17639), convertTwipToMM100Unsigned(10000));
      71           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(40000));
      72           2 : }
      73             : 
      74           2 : void WriterfilterMiscTest::testFieldParameters()
      75             : {
      76             :     using writerfilter::dmapper::lcl_SplitFieldCommand;
      77           2 :     boost::tuple<OUString, vector<OUString>, vector<OUString> > result;
      78             : 
      79           2 :     result = lcl_SplitFieldCommand("PAGEREF last_page");
      80           2 :     CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
      81           2 :     CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<1>(result).size());
      82           2 :     CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
      83           2 :     CPPUNIT_ASSERT(boost::get<2>(result).empty());
      84             : 
      85           2 :     result = lcl_SplitFieldCommand(" PAGEREF last_page ");
      86           2 :     CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
      87           2 :     CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<1>(result).size());
      88           2 :     CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
      89             : 
      90           2 :     result = lcl_SplitFieldCommand("pageref last_page");
      91           2 :     CPPUNIT_ASSERT(boost::get<2>(result).empty());
      92           2 :     CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
      93           2 :     CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<1>(result).size());
      94           2 :     CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
      95           2 :     CPPUNIT_ASSERT(boost::get<2>(result).empty());
      96             : 
      97           2 :     result = lcl_SplitFieldCommand("pageref \"last_page\"");
      98           2 :     CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
      99           2 :     CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<1>(result).size());
     100           2 :     CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
     101           2 :     CPPUNIT_ASSERT(boost::get<2>(result).empty());
     102             : 
     103           2 :     result = lcl_SplitFieldCommand("\"PAGEREF\" \"last_page\" \"\" ");
     104           2 :     CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
     105           2 :     CPPUNIT_ASSERT_EQUAL(size_t(2), boost::get<1>(result).size());
     106           2 :     CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
     107           2 :     CPPUNIT_ASSERT_EQUAL(OUString(), boost::get<1>(result)[1]);
     108           2 :     CPPUNIT_ASSERT(boost::get<2>(result).empty());
     109             : 
     110           2 :     result = lcl_SplitFieldCommand("\"PAGEREF\"\"last_page\"  ");
     111           2 :     CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
     112           2 :     CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<1>(result).size());
     113           2 :     CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
     114           2 :     CPPUNIT_ASSERT(boost::get<2>(result).empty());
     115             : 
     116           2 :     result = lcl_SplitFieldCommand("PAGEREF\"last_page\"  ");
     117           2 :     CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
     118           2 :     CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<1>(result).size());
     119           2 :     CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
     120           2 :     CPPUNIT_ASSERT(boost::get<2>(result).empty());
     121             : 
     122           2 :     result = lcl_SplitFieldCommand("\"PAGEREF\"last_page \"\"");
     123           2 :     CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
     124           2 :     CPPUNIT_ASSERT_EQUAL(size_t(2), boost::get<1>(result).size());
     125           2 :     CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
     126           2 :     CPPUNIT_ASSERT_EQUAL(OUString(), boost::get<1>(result)[1]);
     127           2 :     CPPUNIT_ASSERT(boost::get<2>(result).empty());
     128             : 
     129           2 :     result = lcl_SplitFieldCommand("\"PAGEREF\"last_page \"\"");
     130           2 :     CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
     131           2 :     CPPUNIT_ASSERT_EQUAL(size_t(2), boost::get<1>(result).size());
     132           2 :     CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
     133           2 :     CPPUNIT_ASSERT_EQUAL(OUString(), boost::get<1>(result)[1]);
     134           2 :     CPPUNIT_ASSERT(boost::get<2>(result).empty());
     135             : 
     136           2 :     result = lcl_SplitFieldCommand("pageref \"last\\\\pa\\\"ge\"");
     137           2 :     CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
     138           2 :     CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<1>(result).size());
     139           2 :     CPPUNIT_ASSERT_EQUAL(OUString("last\\pa\"ge"), boost::get<1>(result)[0]);
     140           2 :     CPPUNIT_ASSERT(boost::get<2>(result).empty());
     141             : 
     142           2 :     result = lcl_SplitFieldCommand("PAGEREF\"last_page\"\\*");
     143           2 :     CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
     144           2 :     CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<1>(result).size());
     145           2 :     CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
     146           2 :     CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<2>(result).size());
     147           2 :     CPPUNIT_ASSERT_EQUAL(OUString("\\*"), boost::get<2>(result)[0]);
     148             : 
     149           2 :     result = lcl_SplitFieldCommand("PAGEREF  last_page   \\b   foobar ");
     150           2 :     CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
     151           2 :     CPPUNIT_ASSERT_EQUAL(size_t(1), boost::get<1>(result).size());
     152           2 :     CPPUNIT_ASSERT_EQUAL(OUString("last_page"), boost::get<1>(result)[0]);
     153           2 :     CPPUNIT_ASSERT_EQUAL(size_t(2), boost::get<2>(result).size());
     154           2 :     CPPUNIT_ASSERT_EQUAL(OUString("\\B"), boost::get<2>(result)[0]);
     155           2 :     CPPUNIT_ASSERT_EQUAL(OUString("foobar"), boost::get<2>(result)[1]);
     156             : 
     157           2 :     result = lcl_SplitFieldCommand("PAGEREF\\bfoobar\\A\"\"");
     158           2 :     CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), boost::get<0>(result));
     159           2 :     CPPUNIT_ASSERT(boost::get<1>(result).empty());
     160           2 :     CPPUNIT_ASSERT_EQUAL(size_t(4), boost::get<2>(result).size());
     161           2 :     CPPUNIT_ASSERT_EQUAL(OUString("\\B"), boost::get<2>(result)[0]);
     162           2 :     CPPUNIT_ASSERT_EQUAL(OUString("foobar"), boost::get<2>(result)[1]);
     163           2 :     CPPUNIT_ASSERT_EQUAL(OUString("\\A"), boost::get<2>(result)[2]);
     164           2 :     CPPUNIT_ASSERT_EQUAL(OUString(), boost::get<2>(result)[3]);
     165           2 : }
     166             : 
     167           2 : CPPUNIT_TEST_SUITE_REGISTRATION(WriterfilterMiscTest);
     168             : 
     169             : }
     170             : 
     171           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     172             : 
     173             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10