[Libreoffice-commits] core.git: Branch 'feature/vba-export' - 4 commits - oox/CppunitTest_oox_vba_compression.mk oox/qa

Markus Mohrhard markus.mohrhard at googlemail.com
Fri Aug 14 18:05:02 PDT 2015


 oox/CppunitTest_oox_vba_compression.mk      |   50 ++++++++++++
 oox/qa/unit/data/vba/complex1.bin           |binary
 oox/qa/unit/data/vba/reference/complex1.bin |binary
 oox/qa/unit/data/vba/reference/simple1.bin  |binary
 oox/qa/unit/data/vba/reference/simple2.bin  |binary
 oox/qa/unit/data/vba/reference/simple3.bin  |    1 
 oox/qa/unit/data/vba/simple1.bin            |binary
 oox/qa/unit/data/vba/simple2.bin            |binary
 oox/qa/unit/data/vba/simple3.bin            |    1 
 oox/qa/unit/vba_compression.cxx             |  112 +++++++++++++++++++++++++---
 10 files changed, 153 insertions(+), 11 deletions(-)

New commits:
commit 454095d145d516b073085641b0cf6c4c66c1e801
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sat Aug 15 02:57:55 2015 +0200

    forgot to add the test makefile
    
    Change-Id: If68972ac8e0f464869660e60e9bd54197ed0e5e6

diff --git a/oox/CppunitTest_oox_vba_compression.mk b/oox/CppunitTest_oox_vba_compression.mk
new file mode 100644
index 0000000..bb87cb4
--- /dev/null
+++ b/oox/CppunitTest_oox_vba_compression.mk
@@ -0,0 +1,50 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+#
+# 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/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,oox_vba_compression))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,oox_vba_compression,\
+    oox/qa/unit/vba_compression \
+))
+
+$(eval $(call gb_CppunitTest_use_api,oox_vba_compression,\
+    offapi \
+    udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,oox_vba_compression,\
+    basegfx \
+    comphelper \
+    cppu \
+    cppuhelper \
+    editeng \
+    expwrap \
+    drawinglayer \
+    msfilter \
+    sal \
+    i18nlangtag \
+    oox \
+    sax \
+    sfx \
+    svl \
+    svt \
+    svx \
+    svxcore \
+    sot \
+    tl \
+    unotest \
+    utl \
+    vcl \
+    xo \
+    xmlscript \
+    $(gb_UWINAPI) \
+))
+
+# vim: set noet sw=4 ts=4:
commit 5fe9d7a0a179e6a58d2d0a4585f3e5022729b5d1
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sat Aug 15 02:57:23 2015 +0200

    add complext vba compression test
    
    This is based on my real world test document.
    
    Change-Id: I6e6c38aa1ced7fe836a8926c26aa7d488d44e6d9

diff --git a/oox/qa/unit/data/vba/complex1.bin b/oox/qa/unit/data/vba/complex1.bin
new file mode 100644
index 0000000..3902082
Binary files /dev/null and b/oox/qa/unit/data/vba/complex1.bin differ
diff --git a/oox/qa/unit/data/vba/reference/complex1.bin b/oox/qa/unit/data/vba/reference/complex1.bin
new file mode 100644
index 0000000..335b8e8
Binary files /dev/null and b/oox/qa/unit/data/vba/reference/complex1.bin differ
diff --git a/oox/qa/unit/vba_compression.cxx b/oox/qa/unit/vba_compression.cxx
index 715a0e4..4519700 100644
--- a/oox/qa/unit/vba_compression.cxx
+++ b/oox/qa/unit/vba_compression.cxx
@@ -27,6 +27,9 @@ public:
 
     void testSimple3();
 
+    // real stream from a document
+    void testComplex1();
+
     // avoid the BootstrapFixtureBase::setUp and tearDown
     virtual void setUp() SAL_OVERRIDE;
     virtual void tearDown() SAL_OVERRIDE;
@@ -35,6 +38,7 @@ public:
     CPPUNIT_TEST(testSimple1);
     CPPUNIT_TEST(testSimple2);
     CPPUNIT_TEST(testSimple3);
+    CPPUNIT_TEST(testComplex1);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -130,6 +134,28 @@ void TestVbaCompression::testSimple3()
     }
 }
 
+void TestVbaCompression::testComplex1()
+{
+    OUString aTestFile = getPathFromSrc("/oox/qa/unit/data/vba/complex1.bin");
+    OUString aReference = getPathFromSrc("/oox/qa/unit/data/vba/reference/complex1.bin");
+
+    SvMemoryStream aOutputMemoryStream(4096, 4096);
+    SvMemoryStream aReferenceMemoryStream(4096, 4096);
+    ReadFiles(aTestFile, aReference, aOutputMemoryStream, aReferenceMemoryStream, "/tmp/vba_debug_complex1.bin");
+
+    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()
 {
 }
commit 3a56ecc2b6ea191e822067781abebb8d4b30676e
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sat Aug 15 02:42:28 2015 +0200

    fix some of the vba compression tests
    
    Change-Id: Icfb9b63206fe22641ebdef76619fe70e1f5d5e04

diff --git a/oox/qa/unit/data/vba/reference/simple1.bin b/oox/qa/unit/data/vba/reference/simple1.bin
index bd55e2e..a4644fb 100644
Binary files a/oox/qa/unit/data/vba/reference/simple1.bin and b/oox/qa/unit/data/vba/reference/simple1.bin differ
diff --git a/oox/qa/unit/data/vba/reference/simple2.bin b/oox/qa/unit/data/vba/reference/simple2.bin
index 89f448a..5de3f5a 100644
Binary files a/oox/qa/unit/data/vba/reference/simple2.bin and b/oox/qa/unit/data/vba/reference/simple2.bin differ
diff --git a/oox/qa/unit/data/vba/reference/simple3.bin b/oox/qa/unit/data/vba/reference/simple3.bin
new file mode 100644
index 0000000..a38e8a8
--- /dev/null
+++ b/oox/qa/unit/data/vba/reference/simple3.bin
@@ -0,0 +1 @@
+°
diff --git a/oox/qa/unit/data/vba/simple1.bin b/oox/qa/unit/data/vba/simple1.bin
index 61dbbeb..d59c1d5 100644
Binary files a/oox/qa/unit/data/vba/simple1.bin and b/oox/qa/unit/data/vba/simple1.bin differ
diff --git a/oox/qa/unit/data/vba/simple2.bin b/oox/qa/unit/data/vba/simple2.bin
index 9843ad2..1b9b88b 100644
Binary files a/oox/qa/unit/data/vba/simple2.bin and b/oox/qa/unit/data/vba/simple2.bin differ
diff --git a/oox/qa/unit/data/vba/simple3.bin b/oox/qa/unit/data/vba/simple3.bin
new file mode 100644
index 0000000..72060e8
--- /dev/null
+++ b/oox/qa/unit/data/vba/simple3.bin
@@ -0,0 +1 @@
+
diff --git a/oox/qa/unit/vba_compression.cxx b/oox/qa/unit/vba_compression.cxx
index 6a71331..715a0e4 100644
--- a/oox/qa/unit/vba_compression.cxx
+++ b/oox/qa/unit/vba_compression.cxx
@@ -25,6 +25,8 @@ public:
     // a sequence containing one subsequence that can be compressed
     void testSimple2();
 
+    void testSimple3();
+
     // avoid the BootstrapFixtureBase::setUp and tearDown
     virtual void setUp() SAL_OVERRIDE;
     virtual void tearDown() SAL_OVERRIDE;
@@ -32,6 +34,7 @@ public:
     CPPUNIT_TEST_SUITE(TestVbaCompression);
     CPPUNIT_TEST(testSimple1);
     CPPUNIT_TEST(testSimple2);
+    CPPUNIT_TEST(testSimple3);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -70,7 +73,7 @@ void TestVbaCompression::testSimple1()
     ReadFiles(aTestFile, aReference, aOutputMemoryStream,
             aReferenceMemoryStream, "/tmp/vba_debug.bin");
 
-    // CPPUNIT_ASSERT_EQUAL(aReferenceMemoryStream.GetSize(), aOutputMemoryStream.GetSize());
+    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();
@@ -91,8 +94,30 @@ void TestVbaCompression::testSimple2()
     SvMemoryStream aOutputMemoryStream(4096, 4096);
     SvMemoryStream aReferenceMemoryStream(4096, 4096);
     ReadFiles(aTestFile, aReference, aOutputMemoryStream, aReferenceMemoryStream, "/tmp/vba_debug2.bin");
-    //
-    // CPPUNIT_ASSERT_EQUAL(aReferenceMemoryStream.GetSize(), aOutputMemoryStream.GetSize());
+
+    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::testSimple3()
+{
+    OUString aTestFile = getPathFromSrc("/oox/qa/unit/data/vba/simple3.bin");
+    OUString aReference = getPathFromSrc("/oox/qa/unit/data/vba/reference/simple3.bin");
+
+    SvMemoryStream aOutputMemoryStream(4096, 4096);
+    SvMemoryStream aReferenceMemoryStream(4096, 4096);
+    ReadFiles(aTestFile, aReference, aOutputMemoryStream, aReferenceMemoryStream, "/tmp/vba_debug3.bin");
+
+    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();
commit dd4fb1f0fabc463c9def747a438fe9ff5a4d661d
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sat Aug 15 02:24:34 2015 +0200

    add one more test for vba compression
    
    Change-Id: Iba6b4e7b5d26ac7943f72e2a5b3d5d2dc4fc95fd

diff --git a/oox/qa/unit/data/vba/reference/simple2.bin b/oox/qa/unit/data/vba/reference/simple2.bin
new file mode 100644
index 0000000..89f448a
Binary files /dev/null and b/oox/qa/unit/data/vba/reference/simple2.bin differ
diff --git a/oox/qa/unit/data/vba/simple2.bin b/oox/qa/unit/data/vba/simple2.bin
new file mode 100644
index 0000000..9843ad2
--- /dev/null
+++ b/oox/qa/unit/data/vba/simple2.bin
@@ -0,0 +1 @@
+0000000: 0001 0203 0000 0000 0405             .
diff --git a/oox/qa/unit/vba_compression.cxx b/oox/qa/unit/vba_compression.cxx
index b526a3c..6a71331 100644
--- a/oox/qa/unit/vba_compression.cxx
+++ b/oox/qa/unit/vba_compression.cxx
@@ -19,40 +19,79 @@ class TestVbaCompression : public test::BootstrapFixtureBase
 {
 public:
 
+    // just a sequence of bytes that should not be compressed at all
     void testSimple1();
 
+    // a sequence containing one subsequence that can be compressed
+    void testSimple2();
+
     // 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(testSimple2);
     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");
+namespace {
 
-    SvFileStream aInputStream(aTestFile, StreamMode::READ);
+void ReadFiles(const OUString& rTestFile, const OUString& rReference,
+        SvMemoryStream& rOutputMemoryStream, SvMemoryStream& rReferenceMemoryStream,
+        const OUString& rDebugPath)
+{
+    SvFileStream aInputStream(rTestFile, StreamMode::READ);
     SvMemoryStream aInputMemoryStream(4096, 4096);
     aInputMemoryStream.WriteStream(aInputStream);
 
-    SvMemoryStream aOutputMemoryStream(4096, 4096);
-    VBACompression aCompression(aOutputMemoryStream, aInputMemoryStream);
+    VBACompression aCompression(rOutputMemoryStream, aInputMemoryStream);
     aCompression.write();
 
-    SvFileStream aReferenceStream(aReference, StreamMode::READ);
+    SvFileStream aReferenceStream(rReference, StreamMode::READ);
+    rReferenceMemoryStream.WriteStream(aReferenceStream);
+
+    rOutputMemoryStream.Seek(0);
+    SvFileStream aDebugStream(rDebugPath, StreamMode::WRITE);
+    aDebugStream.WriteStream(rOutputMemoryStream);
+}
+
+}
+
+void TestVbaCompression::testSimple1()
+{
+    OUString aTestFile = getPathFromSrc("/oox/qa/unit/data/vba/simple1.bin");
+    OUString aReference = getPathFromSrc("/oox/qa/unit/data/vba/reference/simple1.bin");
+
+    SvMemoryStream aOutputMemoryStream(4096, 4096);
     SvMemoryStream aReferenceMemoryStream(4096, 4096);
-    aReferenceMemoryStream.WriteStream(aReferenceStream);
+    ReadFiles(aTestFile, aReference, aOutputMemoryStream,
+            aReferenceMemoryStream, "/tmp/vba_debug.bin");
+
+    // CPPUNIT_ASSERT_EQUAL(aReferenceMemoryStream.GetSize(), aOutputMemoryStream.GetSize());
 
-    aOutputMemoryStream.Seek(0);
-    SvFileStream aDebugStream("/tmp/vba_debug.bin", StreamMode::WRITE);
-    aDebugStream.WriteStream(aOutputMemoryStream);
+    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::testSimple2()
+{
+    OUString aTestFile = getPathFromSrc("/oox/qa/unit/data/vba/simple2.bin");
+    OUString aReference = getPathFromSrc("/oox/qa/unit/data/vba/reference/simple2.bin");
+
+    SvMemoryStream aOutputMemoryStream(4096, 4096);
+    SvMemoryStream aReferenceMemoryStream(4096, 4096);
+    ReadFiles(aTestFile, aReference, aOutputMemoryStream, aReferenceMemoryStream, "/tmp/vba_debug2.bin");
+    //
     // CPPUNIT_ASSERT_EQUAL(aReferenceMemoryStream.GetSize(), aOutputMemoryStream.GetSize());
 
     const sal_uInt8* pReferenceData = (const sal_uInt8*) aReferenceMemoryStream.GetData();


More information about the Libreoffice-commits mailing list