diff options
author | David Tardon <dtardon@redhat.com> | 2014-06-04 14:30:32 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2014-06-04 15:48:39 +0200 |
commit | e98fbca5818bd60898f64fb41a16509239e09050 (patch) | |
tree | 508c2e7ad6a460550cda23f58d569050fc3d4347 /writerperfect | |
parent | 72d7d1f33bcddaddb5f8589418d0b20f5433845d (diff) |
add unit test for writerperfect::DirectoryStream
Change-Id: I53aaf2355d9f3071544ebcaaee01bd44a30f88fc
Diffstat (limited to 'writerperfect')
10 files changed, 159 insertions, 1 deletions
diff --git a/writerperfect/CppunitTest_writerperfect_stream.mk b/writerperfect/CppunitTest_writerperfect_stream.mk index eef10ee20ba6..2d32844e08b2 100644 --- a/writerperfect/CppunitTest_writerperfect_stream.mk +++ b/writerperfect/CppunitTest_writerperfect_stream.mk @@ -35,6 +35,7 @@ $(eval $(call gb_CppunitTest_use_libraries,writerperfect_stream,\ sot \ test \ tl \ + ucbhelper \ unotest \ utl \ writerperfect \ @@ -52,8 +53,9 @@ $(eval $(call gb_CppunitTest_use_components,writerperfect_stream,\ )) $(eval $(call gb_CppunitTest_add_exception_objects,writerperfect_stream,\ - writerperfect/qa/unit/stream \ + writerperfect/qa/unit/DirectoryStreamTest \ writerperfect/qa/unit/WPXSvStreamTest \ + writerperfect/qa/unit/stream \ )) # vim: set noet sw=4 ts=4: diff --git a/writerperfect/qa/unit/DirectoryStreamTest.cxx b/writerperfect/qa/unit/DirectoryStreamTest.cxx new file mode 100644 index 000000000000..0a279cbc6646 --- /dev/null +++ b/writerperfect/qa/unit/DirectoryStreamTest.cxx @@ -0,0 +1,148 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <boost/scoped_ptr.hpp> + +#include <cppunit/extensions/HelperMacros.h> + +#include <comphelper/processfactory.hxx> + +#include <ucbhelper/content.hxx> + +#include <test/bootstrapfixture.hxx> + +#include <writerperfect/DirectoryStream.hxx> + +namespace ucb = com::sun::star::ucb; +namespace uno = com::sun::star::uno; + +using boost::scoped_ptr; + +using librevenge::RVNGInputStream; + +using writerperfect::DirectoryStream; + +namespace +{ + +class DirectoryStreamTest : public test::BootstrapFixture +{ +public: + DirectoryStreamTest(); + +public: + CPPUNIT_TEST_SUITE(DirectoryStreamTest); + CPPUNIT_TEST(testConstruction); + CPPUNIT_TEST(testDetection); + CPPUNIT_TEST(testDataOperations); + CPPUNIT_TEST(testStructuredOperations); + CPPUNIT_TEST_SUITE_END(); + +private: + void testConstruction(); + void testDetection(); + void testDataOperations(); + void testStructuredOperations(); + +private: + uno::Reference<ucb::XContent> m_xDir; + uno::Reference<ucb::XContent> m_xFile; + uno::Reference<ucb::XContent> m_xNonexistent; +}; + +static const char g_aDirPath[] = "/writerperfect/qa/unit/data/stream/test.dir"; +static const char g_aNondirPath[] = "/writerperfect/qa/unit/data/stream/test.dir/mimetype"; +static const char g_aNonexistentPath[] = "/writerperfect/qa/unit/data/stream/foo/bar"; + +DirectoryStreamTest::DirectoryStreamTest() +{ + const uno::Reference<ucb::XCommandEnvironment> xCmdEnv; + const uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext()); + + using ucbhelper::Content; + + m_xDir = Content(getURLFromSrc(g_aDirPath), xCmdEnv, xContext).get(); + m_xFile = Content(getURLFromSrc(g_aNondirPath), xCmdEnv, xContext).get(); + m_xNonexistent = Content(getURLFromSrc(g_aNonexistentPath), xCmdEnv, xContext).get(); +} + +void DirectoryStreamTest::testConstruction() +{ + const scoped_ptr<DirectoryStream> pDir(DirectoryStream::createForParent(m_xFile)); + CPPUNIT_ASSERT(bool(pDir)); + CPPUNIT_ASSERT(pDir->isStructured()); + + // this should work for dirs too + const scoped_ptr<DirectoryStream> pDir2(DirectoryStream::createForParent(m_xDir)); + CPPUNIT_ASSERT(bool(pDir2)); + CPPUNIT_ASSERT(pDir2->isStructured()); + + // for nonexistent dirs nothing is created + const scoped_ptr<DirectoryStream> pNondir(DirectoryStream::createForParent(m_xNonexistent)); + CPPUNIT_ASSERT(!pNondir); + + // even if we try harder, just an empty shell is created + DirectoryStream aNondir2(m_xNonexistent); + CPPUNIT_ASSERT(!aNondir2.isStructured()); +} + +void DirectoryStreamTest::testDetection() +{ + CPPUNIT_ASSERT(DirectoryStream::isDirectory(m_xDir)); + CPPUNIT_ASSERT(!DirectoryStream::isDirectory(m_xFile)); + CPPUNIT_ASSERT(!DirectoryStream::isDirectory(m_xNonexistent)); +} + +void lcl_testDataOperations(RVNGInputStream &rStream) +{ + CPPUNIT_ASSERT(rStream.isEnd()); + CPPUNIT_ASSERT_EQUAL(0L, rStream.tell()); + CPPUNIT_ASSERT_EQUAL(-1, rStream.seek(0, librevenge::RVNG_SEEK_CUR)); + + unsigned long numBytesRead = 0; + CPPUNIT_ASSERT(0 == rStream.read(1, numBytesRead)); + CPPUNIT_ASSERT_EQUAL(0UL, numBytesRead); +} + +void DirectoryStreamTest::testDataOperations() +{ + // data operations do not make sense on a directory -> just dummy + // impls. + DirectoryStream aDir(m_xDir); + lcl_testDataOperations(aDir); + + // ... and they are equally empty if we try to pass a file + DirectoryStream aFile(m_xFile); + lcl_testDataOperations(aFile); +} + +void lcl_testStructuredOperations(RVNGInputStream &rStream) +{ + CPPUNIT_ASSERT(rStream.isStructured()); + scoped_ptr<RVNGInputStream> pSubstream(rStream.getSubStreamByName("mimetype")); + CPPUNIT_ASSERT(bool(pSubstream)); + + // TODO: test for other operations when they are implemented =) +} + +void DirectoryStreamTest::testStructuredOperations() +{ + DirectoryStream aDir(m_xDir); + lcl_testStructuredOperations(aDir); + + scoped_ptr<DirectoryStream> pDir(DirectoryStream::createForParent(m_xFile)); + CPPUNIT_ASSERT(bool(pDir)); + lcl_testStructuredOperations(*pDir.get()); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(DirectoryStreamTest); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/qa/unit/data/stream/test.dir/META-INF/manifest.xml b/writerperfect/qa/unit/data/stream/test.dir/META-INF/manifest.xml new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/writerperfect/qa/unit/data/stream/test.dir/META-INF/manifest.xml @@ -0,0 +1 @@ + diff --git a/writerperfect/qa/unit/data/stream/test.dir/Thumbnails/thumbnail.png b/writerperfect/qa/unit/data/stream/test.dir/Thumbnails/thumbnail.png new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/writerperfect/qa/unit/data/stream/test.dir/Thumbnails/thumbnail.png @@ -0,0 +1 @@ + diff --git a/writerperfect/qa/unit/data/stream/test.dir/content.xml b/writerperfect/qa/unit/data/stream/test.dir/content.xml new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/writerperfect/qa/unit/data/stream/test.dir/content.xml @@ -0,0 +1 @@ + diff --git a/writerperfect/qa/unit/data/stream/test.dir/manifest.rdf b/writerperfect/qa/unit/data/stream/test.dir/manifest.rdf new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/writerperfect/qa/unit/data/stream/test.dir/manifest.rdf @@ -0,0 +1 @@ + diff --git a/writerperfect/qa/unit/data/stream/test.dir/meta.xml b/writerperfect/qa/unit/data/stream/test.dir/meta.xml new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/writerperfect/qa/unit/data/stream/test.dir/meta.xml @@ -0,0 +1 @@ + diff --git a/writerperfect/qa/unit/data/stream/test.dir/mimetype b/writerperfect/qa/unit/data/stream/test.dir/mimetype new file mode 100644 index 000000000000..2e95b81c92b0 --- /dev/null +++ b/writerperfect/qa/unit/data/stream/test.dir/mimetype @@ -0,0 +1 @@ +application/vnd.oasis.opendocument.text
\ No newline at end of file diff --git a/writerperfect/qa/unit/data/stream/test.dir/settings.xml b/writerperfect/qa/unit/data/stream/test.dir/settings.xml new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/writerperfect/qa/unit/data/stream/test.dir/settings.xml @@ -0,0 +1 @@ + diff --git a/writerperfect/qa/unit/data/stream/test.dir/styles.xml b/writerperfect/qa/unit/data/stream/test.dir/styles.xml new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/writerperfect/qa/unit/data/stream/test.dir/styles.xml @@ -0,0 +1 @@ + |