LCOV - code coverage report
Current view: top level - writerfilter/qa/cppunittests/doctok - testdoctok.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 67 9.0 %
Date: 2012-08-25 Functions: 3 16 18.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 206 3.4 %

           Branch data     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                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : #include <osl/process.h>
      21                 :            : #include <cppuhelper/bootstrap.hxx>
      22                 :            : #include "cppunit/TestAssert.h"
      23                 :            : #include "cppunit/TestFixture.h"
      24                 :            : #include "cppunit/extensions/HelperMacros.h"
      25                 :            : #include "cppunit/plugin/TestPlugIn.h"
      26                 :            : #include <ucbhelper/contentbroker.hxx>
      27                 :            : #include <com/sun/star/io/XInputStream.hpp>
      28                 :            : #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
      29                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30                 :            : #include <iostream>
      31                 :            : 
      32                 :            : #include <doctok/WW8Document.hxx>
      33                 :            : 
      34                 :            : namespace testdoctok
      35                 :            : {
      36                 :            : using namespace ::std;
      37                 :            : using namespace ::com::sun::star;
      38                 :            : using namespace ::writerfilter::doctok;
      39                 :            : 
      40                 :          3 : uno::Reference<io::XInputStream> xStream;
      41                 :          3 : uno::Reference<uno::XComponentContext> xContext;
      42                 :          3 : WW8Document::Pointer_t pDocument;
      43                 :          3 : uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xSimpleFileAccess;
      44                 :            : 
      45         [ #  # ]:          0 : class test : public CppUnit::TestFixture
      46                 :            : {
      47                 :            : 
      48                 :            : public:
      49                 :            :     // initialise your test code values here.
      50                 :          0 :     void setUp()
      51                 :            :     {
      52                 :          0 :     }
      53                 :            : 
      54                 :          0 :     void tearDown()
      55                 :            :     {
      56                 :          0 :     }
      57                 :            : 
      58                 :          0 :     void testInitUno()
      59                 :            :     {
      60                 :          0 :         bool bResult = false;
      61                 :            : 
      62                 :            :         // initialise UCB-Broker
      63                 :            :         uno::Reference<uno::XComponentContext>
      64                 :            :             xComponentContext
      65         [ #  # ]:          0 :             (::cppu::defaultBootstrap_InitialComponentContext());
      66                 :            :         OSL_ASSERT( xComponentContext.is() );
      67                 :            : 
      68         [ #  # ]:          0 :         xContext = xComponentContext;
      69                 :            : 
      70                 :            :         uno::Reference<lang::XMultiComponentFactory>
      71 [ #  # ][ #  # ]:          0 :             xFactory(xComponentContext->getServiceManager() );
      72                 :            :         OSL_ASSERT(xFactory.is());
      73                 :            : 
      74         [ #  # ]:          0 :         uno::Sequence<uno::Any> aUcbInitSequence(2);
      75         [ #  # ]:          0 :         aUcbInitSequence[0] <<=
      76         [ #  # ]:          0 :             OUString("Local");
      77         [ #  # ]:          0 :         aUcbInitSequence[1] <<=
      78         [ #  # ]:          0 :             OUString("Office");
      79                 :            : 
      80                 :            :         uno::Reference<lang::XMultiServiceFactory>
      81         [ #  # ]:          0 :             xServiceFactory(xFactory, uno::UNO_QUERY);
      82                 :            :         OSL_ASSERT( xServiceFactory.is() );
      83                 :            : 
      84         [ #  # ]:          0 :         if (xServiceFactory.is())
      85                 :            :         {
      86                 :            :             sal_Bool bRet =
      87                 :            :                 ::ucbhelper::ContentBroker::initialize(xServiceFactory,
      88         [ #  # ]:          0 :                                                        aUcbInitSequence);
      89                 :            : 
      90                 :            :             OSL_ASSERT(bRet);
      91         [ #  # ]:          0 :             if (bRet)
      92                 :            :             {
      93                 :            :                 uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >
      94         [ #  # ]:          0 :                     xNameContainer(xFactory->createInstanceWithContext
      95                 :            :                                        ("com.sun.star.ucb.SimpleFileAccess",
      96 [ #  # ][ #  # ]:          0 :                                     xComponentContext), uno::UNO_QUERY );
      97                 :            : 
      98         [ #  # ]:          0 :                 if (xNameContainer.is())
      99                 :            :                 {
     100         [ #  # ]:          0 :                     xSimpleFileAccess = xNameContainer;
     101                 :            : 
     102                 :          0 :                     bResult = true;
     103                 :          0 :                 }
     104                 :            :             }
     105                 :            :         }
     106                 :            : 
     107 [ #  # ][ #  # ]:          0 :         CPPUNIT_ASSERT_MESSAGE("UNO initialization failed",
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     108   [ #  #  #  # ]:          0 :                                bResult);
     109                 :          0 :     }
     110                 :            : 
     111                 :            :     // insert your test code here.
     112                 :          0 :     void testOpenFile()
     113                 :            :     {
     114                 :          0 :         rtl_uString *dir=NULL;
     115         [ #  # ]:          0 :         osl_getProcessWorkingDir(&dir);
     116                 :          0 :         rtl_uString *fname=NULL;
     117                 :          0 :         rtl_uString_newFromAscii(&fname, "/test.doc");
     118                 :          0 :         rtl_uString *absfile=NULL;
     119                 :          0 :         rtl_uString_newConcat(&absfile, dir, fname);
     120                 :            : 
     121                 :          0 :         OUString sInputFileURL( absfile );
     122                 :            : 
     123         [ #  # ]:          0 :         for (sal_Int32 n = 0; n < sInputFileURL.getLength(); ++n)
     124                 :            :         {
     125                 :          0 :             sal_uChar nC = sInputFileURL[n];
     126                 :            : 
     127 [ #  # ][ #  # ]:          0 :             if (nC < 0xff && isprint(nC))
     128         [ #  # ]:          0 :                 clog << static_cast<char>(nC);
     129                 :            :             else
     130         [ #  # ]:          0 :                 clog << ".";
     131                 :            :         }
     132                 :            : 
     133         [ #  # ]:          0 :         clog << endl;
     134                 :            : 
     135 [ #  # ][ #  # ]:          0 :         xStream = xSimpleFileAccess->openFileRead(sInputFileURL);
                 [ #  # ]
     136                 :            : 
     137                 :            :         WW8Stream::Pointer_t pStream =
     138         [ #  # ]:          0 :             WW8DocumentFactory::createStream(xContext, xStream);
     139                 :            : 
     140 [ #  # ][ #  # ]:          0 :         pDocument.reset(WW8DocumentFactory::createDocument(pStream));
         [ #  # ][ #  # ]
     141                 :            : 
     142 [ #  # ][ #  # ]:          0 :         CPPUNIT_ASSERT_MESSAGE("creating document failed",
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     143   [ #  #  #  # ]:          0 :                                pDocument != NULL);
     144                 :          0 :     }
     145                 :            : 
     146                 :          0 :     void testEvents()
     147                 :            :     {
     148         [ #  # ]:          0 :         ::writerfilter::Stream::Pointer_t pStream = ::writerfilter::createStreamHandler();
     149                 :            : 
     150 [ #  # ][ #  # ]:          0 :         pDocument->resolve(*pStream);
     151                 :          0 :     }
     152                 :            : 
     153                 :          0 :     void testEnd()
     154                 :            :     {
     155                 :          0 :         ::ucbhelper::ContentBroker::deinitialize();
     156                 :          0 :     }
     157                 :            : 
     158                 :            :     // Change the following lines only, if you add, remove or rename
     159                 :            :     // member functions of the current class,
     160                 :            :     // because these macros are need by auto register mechanism.
     161                 :            : 
     162 [ #  # ][ #  # ]:          0 :     CPPUNIT_TEST_SUITE(test);
         [ #  # ][ #  # ]
                 [ #  # ]
     163 [ #  # ][ #  # ]:          0 :     CPPUNIT_TEST(testInitUno);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     164 [ #  # ][ #  # ]:          0 :     CPPUNIT_TEST(testOpenFile);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     165 [ #  # ][ #  # ]:          0 :     CPPUNIT_TEST(testEvents);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     166 [ #  # ][ #  # ]:          0 :     CPPUNIT_TEST(testEnd);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     167 [ #  # ][ #  # ]:          0 :     CPPUNIT_TEST_SUITE_END();
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     168                 :            : }; // class test
     169                 :            : 
     170                 :            : // -----------------------------------------------------------------------------
     171 [ +  - ][ +  - ]:          3 : CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(testdoctok::test, "doctok");
     172                 :            : } // namespace doctok
     173                 :            : 
     174                 :            : 
     175                 :            : // -----------------------------------------------------------------------------
     176                 :            : 
     177 [ +  - ][ +  - ]:         12 : CPPUNIT_PLUGIN_IMPLEMENT();
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
     178                 :            : 
     179                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10