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

Generated by: LCOV version 1.10