diff options
author | Mohammed Abdul Azeem <azeemmysore@gmail.com> | 2017-05-27 13:17:04 +0530 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2017-06-08 14:27:45 +0200 |
commit | 0632208977a204195a4f5b9e727aed511ece075f (patch) | |
tree | 7386c0dda0678564da169bf35466c70b90552ce2 /package/qa | |
parent | d21a675d3a7deff37fd66adc993d0179d3a39ed7 (diff) |
First cut at moving unzipping into new thread:
XBufferedThreadedStream class buffers data in a new thread,
which will be available to be read from parent thread.
Change-Id: I62d367fa1dec23da39aba24b5c765b57707956bb
Reviewed-on: https://gerrit.libreoffice.org/38135
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'package/qa')
-rw-r--r-- | package/qa/cppunit/test_package.cxx | 116 |
1 files changed, 83 insertions, 33 deletions
diff --git a/package/qa/cppunit/test_package.cxx b/package/qa/cppunit/test_package.cxx index 335f490ddaba..0e1f4778184d 100644 --- a/package/qa/cppunit/test_package.cxx +++ b/package/qa/cppunit/test_package.cxx @@ -27,19 +27,55 @@ namespace public: PackageTest() {} + virtual void setUp() override; + virtual bool load(const OUString &, const OUString &rURL, const OUString &, SfxFilterFlags, SotClipboardFormatId, unsigned int) override; void test(); void testThreadedStreams(); + void testBufferedThreadedStreams(); CPPUNIT_TEST_SUITE(PackageTest); CPPUNIT_TEST(test); CPPUNIT_TEST(testThreadedStreams); + CPPUNIT_TEST(testBufferedThreadedStreams); CPPUNIT_TEST_SUITE_END(); + + private: + uno::Reference<container::XNameAccess> mxNA; + void verifyStreams( std::vector<std::vector<char>> &aBuffers ); }; + void PackageTest::setUp() + { + BootstrapFixtureBase::setUp(); + OUString aURL = m_directories.getURLFromSrc("/package/qa/cppunit/data/a2z.zip"); + + uno::Sequence<beans::NamedValue> aNVs(2); + aNVs[0].Name = "URL"; + aNVs[0].Value <<= aURL; + aNVs[1].Name = "UseBufferedStream"; + aNVs[1].Value <<= true; + + uno::Sequence<uno::Any> aArgs(1); + aArgs[0] <<= aNVs; + + uno::Reference<uno::XComponentContext> xCxt = comphelper::getProcessComponentContext(); + uno::Reference<lang::XMultiComponentFactory> xSvcMgr = xCxt->getServiceManager(); + + uno::Reference<packages::zip::XZipFileAccess2> xZip( + xSvcMgr->createInstanceWithArgumentsAndContext( + "com.sun.star.packages.zip.ZipFileAccess", aArgs, xCxt), + uno::UNO_QUERY); + + CPPUNIT_ASSERT(xZip.is()); + + mxNA = uno::Reference<container::XNameAccess>(xZip, uno::UNO_QUERY); + CPPUNIT_ASSERT(mxNA.is()); + } + bool PackageTest::load(const OUString &, const OUString &rURL, const OUString &, SfxFilterFlags, SotClipboardFormatId, unsigned int) @@ -62,6 +98,20 @@ namespace m_directories.getURLFromSrc("/package/qa/cppunit/data/")); } + void PackageTest::verifyStreams( std::vector<std::vector<char>> &aBuffers ) + { + CPPUNIT_ASSERT_EQUAL(size_t(26), aBuffers.size()); + auto itBuf = aBuffers.begin(); + + for (char c = 'a'; c <= 'z'; ++c, ++itBuf) + { + const std::vector<char>& rBuf = *itBuf; + CPPUNIT_ASSERT_EQUAL(size_t(1048576), rBuf.size()); // 1 MB each. + for (char check : rBuf) + CPPUNIT_ASSERT_EQUAL(c, check); + } + } + // TODO : This test currently doesn't fail even when you set // UseBufferedStream to false. Look into this and replace it with a better // test that actually fails when the aforementioned flag is set to false. @@ -95,30 +145,6 @@ namespace } }; - OUString aURL = m_directories.getURLFromSrc("/package/qa/cppunit/data/a2z.zip"); - - uno::Sequence<beans::NamedValue> aNVs(2); - aNVs[0].Name = "URL"; - aNVs[0].Value <<= aURL; - aNVs[1].Name = "UseBufferedStream"; - aNVs[1].Value <<= true; - - uno::Sequence<uno::Any> aArgs(1); - aArgs[0] <<= aNVs; - - uno::Reference<uno::XComponentContext> xCxt = comphelper::getProcessComponentContext(); - uno::Reference<lang::XMultiComponentFactory> xSvcMgr = xCxt->getServiceManager(); - - uno::Reference<packages::zip::XZipFileAccess2> xZip( - xSvcMgr->createInstanceWithArgumentsAndContext( - "com.sun.star.packages.zip.ZipFileAccess", aArgs, xCxt), - uno::UNO_QUERY); - - CPPUNIT_ASSERT(xZip.is()); - - uno::Reference<container::XNameAccess> xNA(xZip, uno::UNO_QUERY); - CPPUNIT_ASSERT(xNA.is()); - { comphelper::ThreadPool aPool(4); std::shared_ptr<comphelper::ThreadTaskTag> pTag = comphelper::ThreadPool::createThreadTaskTag(); @@ -132,26 +158,50 @@ namespace aName += ".txt"; uno::Reference<io::XInputStream> xStrm; - xNA->getByName(aName) >>= xStrm; + mxNA->getByName(aName) >>= xStrm; CPPUNIT_ASSERT(xStrm.is()); aPool.pushTask(new Worker(pTag, xStrm, *itBuf)); } aPool.waitUntilDone(pTag); + verifyStreams( aTestBuffers ); + } + } - // Verify the streams. - CPPUNIT_ASSERT_EQUAL(size_t(26), aTestBuffers.size()); - itBuf = aTestBuffers.begin(); + void PackageTest::testBufferedThreadedStreams() + { + std::vector<std::vector<char>> aTestBuffers(26); + auto itBuf = aTestBuffers.begin(); + sal_Int32 nReadSize = 0; - for (char c = 'a'; c <= 'z'; ++c, ++itBuf) + for (char c = 'a'; c <= 'z'; ++c, ++itBuf) + { + OUString aName(c); + aName += ".txt"; + + uno::Reference<io::XInputStream> xStrm; + //Size of each stream is 1mb (>10000) => XBufferedThreadedStream + mxNA->getByName(aName) >>= xStrm; + + CPPUNIT_ASSERT(xStrm.is()); + sal_Int32 nSize = xStrm->available(); + + uno::Sequence<sal_Int8> aBytes; + //Read chuncks of increasing size + nReadSize += 1024; + + while (nSize > 0) { - const std::vector<char>& rBuf = *itBuf; - CPPUNIT_ASSERT_EQUAL(size_t(1048576), rBuf.size()); // 1 MB each. - for (char check : rBuf) - CPPUNIT_ASSERT_EQUAL(c, check); + sal_Int32 nBytesRead = xStrm->readBytes(aBytes, nReadSize); + const sal_Int8* p = aBytes.getArray(); + const sal_Int8* pEnd = p + nBytesRead; + std::copy(p, pEnd, std::back_inserter(*itBuf)); + nSize -= nBytesRead; } } + + verifyStreams( aTestBuffers ); } CPPUNIT_TEST_SUITE_REGISTRATION(PackageTest); |