From 5e4c27820176976771429ad21d7420902597ccb2 Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Sat, 15 Aug 2015 01:22:34 +0200 Subject: add first vba compression test Change-Id: I9e3abebb0ac932b46f7fc96cd37d39023b783af2 --- oox/qa/unit/data/vba/reference/simple1.bin | Bin 0 -> 50 bytes oox/qa/unit/data/vba/simple1.bin | 1 + oox/qa/unit/vba_compression.cxx | 81 +++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 oox/qa/unit/data/vba/reference/simple1.bin create mode 100644 oox/qa/unit/data/vba/simple1.bin create mode 100644 oox/qa/unit/vba_compression.cxx (limited to 'oox/qa') diff --git a/oox/qa/unit/data/vba/reference/simple1.bin b/oox/qa/unit/data/vba/reference/simple1.bin new file mode 100644 index 000000000000..bd55e2ef5f19 Binary files /dev/null and b/oox/qa/unit/data/vba/reference/simple1.bin differ diff --git a/oox/qa/unit/data/vba/simple1.bin b/oox/qa/unit/data/vba/simple1.bin new file mode 100644 index 000000000000..61dbbebf1c3f --- /dev/null +++ b/oox/qa/unit/data/vba/simple1.bin @@ -0,0 +1 @@ +00000000:0001 0203 0405 0607 0809 1011 1213 . diff --git a/oox/qa/unit/vba_compression.cxx b/oox/qa/unit/vba_compression.cxx new file mode 100644 index 000000000000..b526a3c1e073 --- /dev/null +++ b/oox/qa/unit/vba_compression.cxx @@ -0,0 +1,81 @@ +/* -*- 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 + +#include +#include +#include + +#include + +class TestVbaCompression : public test::BootstrapFixtureBase +{ +public: + + void testSimple1(); + + // avoid the BootstrapFixtureBase::setUp and tearDown + virtual void setUp() SAL_OVERRIDE; + virtual void tearDown() SAL_OVERRIDE; + + CPPUNIT_TEST_SUITE(TestVbaCompression); + CPPUNIT_TEST(testSimple1); + CPPUNIT_TEST_SUITE_END(); + +private: +}; + +void TestVbaCompression::testSimple1() +{ + OUString aTestFile = getPathFromSrc("/oox/qa/unit/data/vba/simple1.bin"); + OUString aReference = getPathFromSrc("/oox/qa/unit/data/vba/reference/simple1.bin"); + + SvFileStream aInputStream(aTestFile, StreamMode::READ); + SvMemoryStream aInputMemoryStream(4096, 4096); + aInputMemoryStream.WriteStream(aInputStream); + + SvMemoryStream aOutputMemoryStream(4096, 4096); + VBACompression aCompression(aOutputMemoryStream, aInputMemoryStream); + aCompression.write(); + + SvFileStream aReferenceStream(aReference, StreamMode::READ); + SvMemoryStream aReferenceMemoryStream(4096, 4096); + aReferenceMemoryStream.WriteStream(aReferenceStream); + + aOutputMemoryStream.Seek(0); + SvFileStream aDebugStream("/tmp/vba_debug.bin", StreamMode::WRITE); + aDebugStream.WriteStream(aOutputMemoryStream); + + // CPPUNIT_ASSERT_EQUAL(aReferenceMemoryStream.GetSize(), aOutputMemoryStream.GetSize()); + + const sal_uInt8* pReferenceData = (const sal_uInt8*) aReferenceMemoryStream.GetData(); + const sal_uInt8* pData = (const sal_uInt8*)aOutputMemoryStream.GetData(); + + size_t nSize = std::min(aReferenceMemoryStream.GetSize(), + aOutputMemoryStream.GetSize()); + for (size_t i = 0; i < nSize; ++i) + { + CPPUNIT_ASSERT_EQUAL((int)pReferenceData[i], (int)pData[i]); + } +} + +void TestVbaCompression::setUp() +{ +} + +void TestVbaCompression::tearDown() +{ +} + +CPPUNIT_TEST_SUITE_REGISTRATION(TestVbaCompression); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3