LCOV - code coverage report
Current view: top level - writerperfect/qa/unit - DirectoryStreamTest.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 59 59 100.0 %
Date: 2014-11-03 Functions: 14 14 100.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 <boost/scoped_ptr.hpp>
      11             : 
      12             : #include <cppunit/extensions/HelperMacros.h>
      13             : 
      14             : #include <comphelper/processfactory.hxx>
      15             : 
      16             : #include <ucbhelper/content.hxx>
      17             : 
      18             : #include <test/bootstrapfixture.hxx>
      19             : 
      20             : #include <writerperfect/DirectoryStream.hxx>
      21             : 
      22             : namespace ucb = com::sun::star::ucb;
      23             : namespace uno = com::sun::star::uno;
      24             : 
      25             : using boost::scoped_ptr;
      26             : 
      27             : using librevenge::RVNGInputStream;
      28             : 
      29             : using writerperfect::DirectoryStream;
      30             : 
      31             : namespace
      32             : {
      33             : 
      34          16 : class DirectoryStreamTest : public test::BootstrapFixture
      35             : {
      36             : public:
      37             :     DirectoryStreamTest();
      38             : 
      39             : public:
      40           4 :     CPPUNIT_TEST_SUITE(DirectoryStreamTest);
      41           2 :     CPPUNIT_TEST(testConstruction);
      42           2 :     CPPUNIT_TEST(testDetection);
      43           2 :     CPPUNIT_TEST(testDataOperations);
      44           2 :     CPPUNIT_TEST(testStructuredOperations);
      45           4 :     CPPUNIT_TEST_SUITE_END();
      46             : 
      47             : private:
      48             :     void testConstruction();
      49             :     void testDetection();
      50             :     void testDataOperations();
      51             :     void testStructuredOperations();
      52             : 
      53             : private:
      54             :     uno::Reference<ucb::XContent> m_xDir;
      55             :     uno::Reference<ucb::XContent> m_xFile;
      56             :     uno::Reference<ucb::XContent> m_xNonexistent;
      57             : };
      58             : 
      59             : static const char g_aDirPath[] = "/writerperfect/qa/unit/data/stream/test.dir";
      60             : static const char g_aNondirPath[] = "/writerperfect/qa/unit/data/stream/test.dir/mimetype";
      61             : static const char g_aNonexistentPath[] = "/writerperfect/qa/unit/data/stream/foo/bar";
      62             : 
      63           8 : DirectoryStreamTest::DirectoryStreamTest()
      64             : {
      65           8 :     const uno::Reference<ucb::XCommandEnvironment> xCmdEnv;
      66          16 :     const uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
      67             : 
      68             :     using ucbhelper::Content;
      69             : 
      70           8 :     m_xDir = Content(getURLFromSrc(g_aDirPath), xCmdEnv, xContext).get();
      71           8 :     m_xFile = Content(getURLFromSrc(g_aNondirPath), xCmdEnv, xContext).get();
      72          16 :     m_xNonexistent = Content(getURLFromSrc(g_aNonexistentPath), xCmdEnv, xContext).get();
      73           8 : }
      74             : 
      75           2 : void DirectoryStreamTest::testConstruction()
      76             : {
      77           2 :     const scoped_ptr<DirectoryStream> pDir(DirectoryStream::createForParent(m_xFile));
      78           2 :     CPPUNIT_ASSERT(bool(pDir));
      79           2 :     CPPUNIT_ASSERT(pDir->isStructured());
      80             : 
      81             :     // this should work for dirs too
      82           4 :     const scoped_ptr<DirectoryStream> pDir2(DirectoryStream::createForParent(m_xDir));
      83           2 :     CPPUNIT_ASSERT(bool(pDir2));
      84           2 :     CPPUNIT_ASSERT(pDir2->isStructured());
      85             : 
      86             :     // for nonexistent dirs nothing is created
      87           4 :     const scoped_ptr<DirectoryStream> pNondir(DirectoryStream::createForParent(m_xNonexistent));
      88           2 :     CPPUNIT_ASSERT(!pNondir);
      89             : 
      90             :     // even if we try harder, just an empty shell is created
      91           4 :     DirectoryStream aNondir2(m_xNonexistent);
      92           4 :     CPPUNIT_ASSERT(!aNondir2.isStructured());
      93           2 : }
      94             : 
      95           2 : void DirectoryStreamTest::testDetection()
      96             : {
      97           2 :     CPPUNIT_ASSERT(DirectoryStream::isDirectory(m_xDir));
      98           2 :     CPPUNIT_ASSERT(!DirectoryStream::isDirectory(m_xFile));
      99           2 :     CPPUNIT_ASSERT(!DirectoryStream::isDirectory(m_xNonexistent));
     100           2 : }
     101             : 
     102           4 : void lcl_testDataOperations(RVNGInputStream &rStream)
     103             : {
     104           4 :     CPPUNIT_ASSERT(rStream.isEnd());
     105           4 :     CPPUNIT_ASSERT_EQUAL(0L, rStream.tell());
     106           4 :     CPPUNIT_ASSERT_EQUAL(-1, rStream.seek(0, librevenge::RVNG_SEEK_CUR));
     107             : 
     108           4 :     unsigned long numBytesRead = 0;
     109           4 :     CPPUNIT_ASSERT(0 == rStream.read(1, numBytesRead));
     110           4 :     CPPUNIT_ASSERT_EQUAL(0UL, numBytesRead);
     111           4 : }
     112             : 
     113           2 : void DirectoryStreamTest::testDataOperations()
     114             : {
     115             :     // data operations do not make sense on a directory -> just dummy
     116             :     // impls.
     117           2 :     DirectoryStream aDir(m_xDir);
     118           2 :     lcl_testDataOperations(aDir);
     119             : 
     120             :     // ... and they are equally empty if we try to pass a file
     121           4 :     DirectoryStream aFile(m_xFile);
     122           4 :     lcl_testDataOperations(aFile);
     123           2 : }
     124             : 
     125           4 : void lcl_testStructuredOperations(RVNGInputStream &rStream)
     126             : {
     127           4 :     CPPUNIT_ASSERT(rStream.isStructured());
     128           4 :     scoped_ptr<RVNGInputStream> pSubstream(rStream.getSubStreamByName("mimetype"));
     129           4 :     CPPUNIT_ASSERT(bool(pSubstream));
     130             : 
     131             :     // TODO: test for other operations when they are implemented =)
     132           4 : }
     133             : 
     134           2 : void DirectoryStreamTest::testStructuredOperations()
     135             : {
     136           2 :     DirectoryStream aDir(m_xDir);
     137           2 :     lcl_testStructuredOperations(aDir);
     138             : 
     139           4 :     scoped_ptr<DirectoryStream> pDir(DirectoryStream::createForParent(m_xFile));
     140           2 :     CPPUNIT_ASSERT(bool(pDir));
     141           4 :     lcl_testStructuredOperations(*pDir.get());
     142           2 : }
     143             : 
     144           2 : CPPUNIT_TEST_SUITE_REGISTRATION(DirectoryStreamTest);
     145             : 
     146           6 : }
     147             : 
     148             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10