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

Generated by: LCOV version 1.11