From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- oox/qa/token/tokenmap-test.cxx | 53 ++ oox/qa/unit/CryptoTest.cxx | 439 ++++++++++++ oox/qa/unit/data/FaultyPathStart.odp | Bin 0 -> 14582 bytes .../data/camera-rotation-revolution-nonwps.pptx | Bin 0 -> 31425 bytes oox/qa/unit/data/camera-rotation-revolution.docx | Bin 0 -> 23748 bytes oox/qa/unit/data/chart-data-label-char-color.docx | Bin 0 -> 26014 bytes oox/qa/unit/data/chart-theme-override.pptx | Bin 0 -> 37016 bytes oox/qa/unit/data/customshape-position.docx | Bin 0 -> 42054 bytes oox/qa/unit/data/dml-groupshape-polygon.docx | Bin 0 -> 24492 bytes oox/qa/unit/data/endParaRPr-newline-textsize.pptx | Bin 0 -> 13349 bytes .../unit/data/gradient-multistep-transparency.pptx | Bin 0 -> 34042 bytes oox/qa/unit/data/graphic-stroke.pptx | Bin 0 -> 29396 bytes oox/qa/unit/data/group-spt202.docx | Bin 0 -> 28238 bytes oox/qa/unit/data/import-characters.pptx | Bin 0 -> 33620 bytes oox/qa/unit/data/import-mce.pptx | Bin 0 -> 33763 bytes oox/qa/unit/data/multiple-group-shapes.docx | Bin 0 -> 29653 bytes oox/qa/unit/data/preset-adjust-value.pptx | Bin 0 -> 33233 bytes oox/qa/unit/data/refer-to-theme-shape-fill.odp | Bin 0 -> 14638 bytes oox/qa/unit/data/refer-to-theme.pptx | Bin 0 -> 33853 bytes oox/qa/unit/data/shape-non-autosize-with-text.docx | Bin 0 -> 35448 bytes oox/qa/unit/data/shape-text-adjust-left.pptx | Bin 0 -> 59199 bytes oox/qa/unit/data/shape-text-alignment.pptx | Bin 0 -> 30844 bytes oox/qa/unit/data/smartart-groupshape.pptx | Bin 0 -> 40995 bytes oox/qa/unit/data/table-shadow.pptx | Bin 0 -> 16837 bytes oox/qa/unit/data/tdf100391_TextAreaRect.odp | Bin 0 -> 13624 bytes oox/qa/unit/data/tdf109169_OctagonBevel.odt | Bin 0 -> 11122 bytes oox/qa/unit/data/tdf112450_vml_polyline.docx | Bin 0 -> 18114 bytes .../data/tdf113187_arcTo_withoutReferences.pptx | Bin 0 -> 14733 bytes oox/qa/unit/data/tdf125582_TextOnCircle.pptx | Bin 0 -> 15956 bytes oox/qa/unit/data/tdf131082.pptx | Bin 0 -> 25881 bytes .../unit/data/tdf137314_vml_rotation_unit_fd.docx | Bin 0 -> 18070 bytes oox/qa/unit/data/tdf141463_GroupTransform.pptx | Bin 0 -> 16921 bytes .../data/tdf141786_PolylineConnectorInGroup.odt | Bin 0 -> 10127 bytes oox/qa/unit/data/tdf141786_RotatedShapeInGroup.odt | Bin 0 -> 15507 bytes oox/qa/unit/data/tdf142602_CustomShapeArrows.odt | Bin 0 -> 11637 bytes oox/qa/unit/data/tdf142605_CurveSize.odp | Bin 0 -> 11220 bytes oox/qa/unit/data/tdf147978_endsubpath.odp | Bin 0 -> 14505 bytes .../unit/data/tdf147978_enhancedPath_commandA.odp | Bin 0 -> 12755 bytes .../data/tdf147978_enhancedPath_commandHIJK.odp | Bin 0 -> 14922 bytes .../unit/data/tdf147978_enhancedPath_commandT.odp | Bin 0 -> 12869 bytes .../unit/data/tdf147978_enhancedPath_commandXY.odp | Bin 0 -> 13166 bytes .../unit/data/tdf147978_enhancedPath_subpath.pptx | Bin 0 -> 15040 bytes oox/qa/unit/data/tdf148784_StretchCommandQ.odp | Bin 0 -> 15311 bytes oox/qa/unit/data/tdf148784_StretchCommandVW.odp | Bin 0 -> 15218 bytes oox/qa/unit/data/tdf148784_StretchXY.odp | Bin 0 -> 11512 bytes .../data/testTdf132557_footerCustomShapes.pptx | Bin 0 -> 20137 bytes oox/qa/unit/data/theme-tint.pptx | Bin 0 -> 16742 bytes oox/qa/unit/data/theme.pptx | Bin 0 -> 33063 bytes oox/qa/unit/data/transparent-text.pptx | Bin 0 -> 32797 bytes oox/qa/unit/data/vba/complex1.bin | Bin 0 -> 1086 bytes oox/qa/unit/data/vba/reference/complex1.bin | Bin 0 -> 579 bytes oox/qa/unit/data/vba/reference/simple1.bin | Bin 0 -> 18 bytes oox/qa/unit/data/vba/reference/simple2.bin | Bin 0 -> 13 bytes oox/qa/unit/data/vba/reference/simple3.bin | 1 + oox/qa/unit/data/vba/reference/spec321.bin | Bin 0 -> 29 bytes oox/qa/unit/data/vba/reference/spec322.bin | Bin 0 -> 51 bytes oox/qa/unit/data/vba/reference/spec323.bin | Bin 0 -> 7 bytes oox/qa/unit/data/vba/simple1.bin | Bin 0 -> 13 bytes oox/qa/unit/data/vba/simple2.bin | Bin 0 -> 11 bytes oox/qa/unit/data/vba/simple3.bin | 1 + oox/qa/unit/data/vba/spec321.bin | 1 + oox/qa/unit/data/vba/spec322.bin | 1 + oox/qa/unit/data/vba/spec323.bin | 1 + oox/qa/unit/data/watermark.docx | Bin 0 -> 21621 bytes oox/qa/unit/drawingml.cxx | 566 +++++++++++++++ oox/qa/unit/export.cxx | 777 +++++++++++++++++++++ oox/qa/unit/mathml.cxx | 71 ++ oox/qa/unit/shape.cxx | 180 +++++ oox/qa/unit/vba_compression.cxx | 255 +++++++ oox/qa/unit/vba_encryption.cxx | 82 +++ oox/qa/unit/vml.cxx | 236 +++++++ 71 files changed, 2664 insertions(+) create mode 100644 oox/qa/token/tokenmap-test.cxx create mode 100644 oox/qa/unit/CryptoTest.cxx create mode 100644 oox/qa/unit/data/FaultyPathStart.odp create mode 100644 oox/qa/unit/data/camera-rotation-revolution-nonwps.pptx create mode 100644 oox/qa/unit/data/camera-rotation-revolution.docx create mode 100644 oox/qa/unit/data/chart-data-label-char-color.docx create mode 100644 oox/qa/unit/data/chart-theme-override.pptx create mode 100644 oox/qa/unit/data/customshape-position.docx create mode 100644 oox/qa/unit/data/dml-groupshape-polygon.docx create mode 100644 oox/qa/unit/data/endParaRPr-newline-textsize.pptx create mode 100644 oox/qa/unit/data/gradient-multistep-transparency.pptx create mode 100644 oox/qa/unit/data/graphic-stroke.pptx create mode 100644 oox/qa/unit/data/group-spt202.docx create mode 100644 oox/qa/unit/data/import-characters.pptx create mode 100644 oox/qa/unit/data/import-mce.pptx create mode 100644 oox/qa/unit/data/multiple-group-shapes.docx create mode 100644 oox/qa/unit/data/preset-adjust-value.pptx create mode 100644 oox/qa/unit/data/refer-to-theme-shape-fill.odp create mode 100644 oox/qa/unit/data/refer-to-theme.pptx create mode 100644 oox/qa/unit/data/shape-non-autosize-with-text.docx create mode 100644 oox/qa/unit/data/shape-text-adjust-left.pptx create mode 100644 oox/qa/unit/data/shape-text-alignment.pptx create mode 100644 oox/qa/unit/data/smartart-groupshape.pptx create mode 100644 oox/qa/unit/data/table-shadow.pptx create mode 100644 oox/qa/unit/data/tdf100391_TextAreaRect.odp create mode 100644 oox/qa/unit/data/tdf109169_OctagonBevel.odt create mode 100644 oox/qa/unit/data/tdf112450_vml_polyline.docx create mode 100644 oox/qa/unit/data/tdf113187_arcTo_withoutReferences.pptx create mode 100644 oox/qa/unit/data/tdf125582_TextOnCircle.pptx create mode 100644 oox/qa/unit/data/tdf131082.pptx create mode 100644 oox/qa/unit/data/tdf137314_vml_rotation_unit_fd.docx create mode 100644 oox/qa/unit/data/tdf141463_GroupTransform.pptx create mode 100644 oox/qa/unit/data/tdf141786_PolylineConnectorInGroup.odt create mode 100644 oox/qa/unit/data/tdf141786_RotatedShapeInGroup.odt create mode 100644 oox/qa/unit/data/tdf142602_CustomShapeArrows.odt create mode 100644 oox/qa/unit/data/tdf142605_CurveSize.odp create mode 100644 oox/qa/unit/data/tdf147978_endsubpath.odp create mode 100644 oox/qa/unit/data/tdf147978_enhancedPath_commandA.odp create mode 100644 oox/qa/unit/data/tdf147978_enhancedPath_commandHIJK.odp create mode 100644 oox/qa/unit/data/tdf147978_enhancedPath_commandT.odp create mode 100644 oox/qa/unit/data/tdf147978_enhancedPath_commandXY.odp create mode 100644 oox/qa/unit/data/tdf147978_enhancedPath_subpath.pptx create mode 100644 oox/qa/unit/data/tdf148784_StretchCommandQ.odp create mode 100644 oox/qa/unit/data/tdf148784_StretchCommandVW.odp create mode 100644 oox/qa/unit/data/tdf148784_StretchXY.odp create mode 100644 oox/qa/unit/data/testTdf132557_footerCustomShapes.pptx create mode 100644 oox/qa/unit/data/theme-tint.pptx create mode 100644 oox/qa/unit/data/theme.pptx create mode 100644 oox/qa/unit/data/transparent-text.pptx create mode 100644 oox/qa/unit/data/vba/complex1.bin create mode 100644 oox/qa/unit/data/vba/reference/complex1.bin create mode 100644 oox/qa/unit/data/vba/reference/simple1.bin create mode 100644 oox/qa/unit/data/vba/reference/simple2.bin create mode 100644 oox/qa/unit/data/vba/reference/simple3.bin create mode 100644 oox/qa/unit/data/vba/reference/spec321.bin create mode 100644 oox/qa/unit/data/vba/reference/spec322.bin create mode 100644 oox/qa/unit/data/vba/reference/spec323.bin create mode 100644 oox/qa/unit/data/vba/simple1.bin create mode 100644 oox/qa/unit/data/vba/simple2.bin create mode 100644 oox/qa/unit/data/vba/simple3.bin create mode 100644 oox/qa/unit/data/vba/spec321.bin create mode 100644 oox/qa/unit/data/vba/spec322.bin create mode 100644 oox/qa/unit/data/vba/spec323.bin create mode 100644 oox/qa/unit/data/watermark.docx create mode 100644 oox/qa/unit/drawingml.cxx create mode 100644 oox/qa/unit/export.cxx create mode 100644 oox/qa/unit/mathml.cxx create mode 100644 oox/qa/unit/shape.cxx create mode 100644 oox/qa/unit/vba_compression.cxx create mode 100644 oox/qa/unit/vba_encryption.cxx create mode 100644 oox/qa/unit/vml.cxx (limited to 'oox/qa') diff --git a/oox/qa/token/tokenmap-test.cxx b/oox/qa/token/tokenmap-test.cxx new file mode 100644 index 000000000..058f7c16e --- /dev/null +++ b/oox/qa/token/tokenmap-test.cxx @@ -0,0 +1,53 @@ +/* -*- 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 +#include + +using namespace com::sun::star::uno; + +namespace oox { + +class TokenmapTest: public CppUnit::TestFixture +{ +public: + void test_roundTrip(); + + CPPUNIT_TEST_SUITE(TokenmapTest); + + CPPUNIT_TEST(test_roundTrip); + CPPUNIT_TEST_SUITE_END(); + +private: + TokenMap tokenMap; +}; + +void TokenmapTest::test_roundTrip() +{ + for ( sal_Int32 nToken = 0; nToken < XML_TOKEN_COUNT; ++nToken ) + { + // check that the getIdentifier <-> getToken roundtrip works + Sequence< sal_Int8 > rUtf8Name = tokenMap.getUtf8TokenName(nToken); + sal_Int32 ret = tokenMap.getTokenFromUTF8( + reinterpret_cast< const char * >(rUtf8Name.getConstArray()), + rUtf8Name.getLength() ); + CPPUNIT_ASSERT_EQUAL(ret, nToken); + } +} + +CPPUNIT_TEST_SUITE_REGISTRATION(TokenmapTest); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/oox/qa/unit/CryptoTest.cxx b/oox/qa/unit/CryptoTest.cxx new file mode 100644 index 000000000..cbdf99b65 --- /dev/null +++ b/oox/qa/unit/CryptoTest.cxx @@ -0,0 +1,439 @@ +/* -*- 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 +#include +#include + +#include +#include +#include +#include + +#if USE_TLS_NSS +#include +#endif + +using namespace css; + +class CryptoTest : public CppUnit::TestFixture +{ +public: + virtual ~CryptoTest() override; + void testCryptoHash(); + void testRoundUp(); + void testStandard2007(); + void testAgileEncryptionVerifier(); + void testAgileEncryptionInfoWritingAndParsing(); + void testAgileDataIntegrityHmacKey(); + void testAgileEncryptingAndDecrypting(); + + CPPUNIT_TEST_SUITE(CryptoTest); + CPPUNIT_TEST(testCryptoHash); + CPPUNIT_TEST(testRoundUp); + CPPUNIT_TEST(testStandard2007); + CPPUNIT_TEST(testAgileEncryptionVerifier); + CPPUNIT_TEST(testAgileEncryptionInfoWritingAndParsing); + CPPUNIT_TEST(testAgileDataIntegrityHmacKey); + CPPUNIT_TEST(testAgileEncryptingAndDecrypting); + CPPUNIT_TEST_SUITE_END(); +}; + +namespace +{ +std::string toString(std::vector const& aInput) +{ + std::stringstream aStream; + for (auto const& aValue : aInput) + { + aStream << std::setw(2) << std::setfill('0') << std::hex << static_cast(aValue); + } + + return aStream.str(); +} +} + +CryptoTest::~CryptoTest() +{ +#if USE_TLS_NSS + NSS_Shutdown(); +#endif +} + +void CryptoTest::testCryptoHash() +{ + // Check examples from Wikipedia (https://en.wikipedia.org/wiki/HMAC) + OString aContentString("The quick brown fox jumps over the lazy dog"); + std::vector aContent(aContentString.getStr(), + aContentString.getStr() + aContentString.getLength()); + std::vector aKey = { 'k', 'e', 'y' }; + { + oox::crypto::CryptoHash aCryptoHash(aKey, oox::crypto::CryptoHashType::SHA1); + aCryptoHash.update(aContent); + std::vector aHash = aCryptoHash.finalize(); + CPPUNIT_ASSERT_EQUAL(std::string("de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9"), + toString(aHash)); + } + + { + oox::crypto::CryptoHash aCryptoHash(aKey, oox::crypto::CryptoHashType::SHA256); + aCryptoHash.update(aContent); + std::vector aHash = aCryptoHash.finalize(); + CPPUNIT_ASSERT_EQUAL( + std::string("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8"), + toString(aHash)); + } + + { + oox::crypto::CryptoHash aCryptoHash(aKey, oox::crypto::CryptoHashType::SHA512); + aCryptoHash.update(aContent); + std::vector aHash = aCryptoHash.finalize(); + CPPUNIT_ASSERT_EQUAL( + std::string("b42af09057bac1e2d41708e48a902e09b5ff7f12ab428a4fe86653c73dd248fb82f948a549" + "f7b791a5b41915ee4d1ec3935357e4e2317250d0372afa2ebeeb3a"), + toString(aHash)); + } +} + +void CryptoTest::testRoundUp() +{ + CPPUNIT_ASSERT_EQUAL(16, oox::crypto::roundUp(16, 16)); + CPPUNIT_ASSERT_EQUAL(32, oox::crypto::roundUp(32, 16)); + CPPUNIT_ASSERT_EQUAL(64, oox::crypto::roundUp(64, 16)); + + CPPUNIT_ASSERT_EQUAL(16, oox::crypto::roundUp(01, 16)); + CPPUNIT_ASSERT_EQUAL(32, oox::crypto::roundUp(17, 16)); + CPPUNIT_ASSERT_EQUAL(32, oox::crypto::roundUp(31, 16)); +} + +void CryptoTest::testStandard2007() +{ + oox::crypto::Standard2007Engine aEngine; + { + aEngine.setupEncryption("Password"); + + SvMemoryStream aEncryptionInfo; + oox::BinaryXOutputStream aBinaryEncryptionInfoOutputStream( + new utl::OSeekableOutputStreamWrapper(aEncryptionInfo), false); + + aEngine.writeEncryptionInfo(aBinaryEncryptionInfoOutputStream); + aBinaryEncryptionInfoOutputStream.close(); + + CPPUNIT_ASSERT_EQUAL(sal_uInt64(224), aEncryptionInfo.GetSize()); + } + + SvMemoryStream aUnencryptedInput; + SvMemoryStream aEncryptedStream; + + OString aTestString = "1234567890ABCDEFG"; + + aUnencryptedInput.WriteBytes(aTestString.getStr(), aTestString.getLength() + 1); + aUnencryptedInput.Seek(STREAM_SEEK_TO_BEGIN); + + { + uno::Reference xInputStream( + new utl::OSeekableInputStreamWrapper(aUnencryptedInput)); + uno::Reference xOutputStream( + new utl::OSeekableOutputStreamWrapper(aEncryptedStream)); + + aEngine.encrypt(xInputStream, xOutputStream, aUnencryptedInput.GetSize()); + + xOutputStream->flush(); + + const sal_uInt8* pData = static_cast(aEncryptedStream.GetData()); + sal_uInt64 nSize = aEncryptedStream.GetSize(); + + std::vector aData(nSize); + std::copy(pData, pData + nSize, aData.data()); + + CPPUNIT_ASSERT_EQUAL(sal_uInt64(40), nSize); + } + + aEncryptedStream.Seek(STREAM_SEEK_TO_BEGIN); + SvMemoryStream aUnencryptedOutput; + + { + oox::BinaryXInputStream aBinaryInputStream( + new utl::OSeekableInputStreamWrapper(aEncryptedStream), true); + oox::BinaryXOutputStream aBinaryOutputStream( + new utl::OSeekableOutputStreamWrapper(aUnencryptedOutput), true); + + aEngine.decrypt(aBinaryInputStream, aBinaryOutputStream); + aBinaryOutputStream.close(); + aBinaryInputStream.close(); + + const char* pData = static_cast(aUnencryptedOutput.GetData()); + sal_uInt64 nSize = aUnencryptedOutput.GetSize(); + + CPPUNIT_ASSERT_EQUAL(sal_uInt64(18), nSize); + + OString aString(pData); + + CPPUNIT_ASSERT_EQUAL(aTestString, aString); + } +} + +void CryptoTest::testAgileEncryptionVerifier() +{ + oox::crypto::AgileEngine aEngine; + + OUString aPassword("Password"); + + aEngine.setupEncryptionParameters({ 100000, 16, 128, 20, 16, OUString("AES"), + OUString("ChainingModeCBC"), OUString("SHA1") }); + + CPPUNIT_ASSERT_EQUAL(true, aEngine.generateAndEncryptVerifierHash(aPassword)); + CPPUNIT_ASSERT_EQUAL(false, aEngine.decryptAndCheckVerifierHash("Wrong")); + CPPUNIT_ASSERT_EQUAL(true, aEngine.decryptAndCheckVerifierHash(aPassword)); + + aEngine.setupEncryptionParameters({ 100000, 16, 256, 64, 16, OUString("AES"), + OUString("ChainingModeCBC"), OUString("SHA512") }); + + CPPUNIT_ASSERT_EQUAL(true, aEngine.generateAndEncryptVerifierHash(aPassword)); + CPPUNIT_ASSERT_EQUAL(false, aEngine.decryptAndCheckVerifierHash("Wrong")); + CPPUNIT_ASSERT_EQUAL(true, aEngine.decryptAndCheckVerifierHash(aPassword)); +} + +void CryptoTest::testAgileEncryptionInfoWritingAndParsing() +{ + OUString aPassword("Password"); + std::vector aKeyDataSalt; + + { // Preset AES128 - SHA1 + SvMemoryStream aEncryptionInfo; + { + oox::crypto::AgileEngine aEngine; + + aEngine.setPreset(oox::crypto::AgileEncryptionPreset::AES_128_SHA1); + aEngine.setupEncryption(aPassword); + aKeyDataSalt = aEngine.getInfo().keyDataSalt; + + oox::BinaryXOutputStream aBinaryEncryptionInfoOutputStream( + new utl::OSeekableOutputStreamWrapper(aEncryptionInfo), true); + + aEngine.writeEncryptionInfo(aBinaryEncryptionInfoOutputStream); + aBinaryEncryptionInfoOutputStream.close(); + + CPPUNIT_ASSERT_EQUAL(sal_uInt64(996), aEncryptionInfo.GetSize()); + } + + aEncryptionInfo.Seek(STREAM_SEEK_TO_BEGIN); + + { + oox::crypto::AgileEngine aEngine; + + uno::Reference xInputStream( + new utl::OSeekableInputStreamWrapper(aEncryptionInfo)); + + xInputStream->skipBytes(4); // Encryption type -> Agile + + CPPUNIT_ASSERT(aEngine.readEncryptionInfo(xInputStream)); + + oox::crypto::AgileEncryptionInfo& rInfo = aEngine.getInfo(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(100000), rInfo.spinCount); + CPPUNIT_ASSERT_EQUAL(sal_Int32(16), rInfo.saltSize); + CPPUNIT_ASSERT_EQUAL(sal_Int32(128), rInfo.keyBits); + CPPUNIT_ASSERT_EQUAL(sal_Int32(20), rInfo.hashSize); + CPPUNIT_ASSERT_EQUAL(sal_Int32(16), rInfo.blockSize); + CPPUNIT_ASSERT_EQUAL(OUString("AES"), rInfo.cipherAlgorithm); + CPPUNIT_ASSERT_EQUAL(OUString("ChainingModeCBC"), rInfo.cipherChaining); + CPPUNIT_ASSERT_EQUAL(OUString("SHA1"), rInfo.hashAlgorithm); + CPPUNIT_ASSERT_EQUAL(toString(aKeyDataSalt), toString(rInfo.keyDataSalt)); + + CPPUNIT_ASSERT_EQUAL(false, aEngine.decryptAndCheckVerifierHash("Wrong")); + CPPUNIT_ASSERT_EQUAL(true, aEngine.decryptAndCheckVerifierHash(aPassword)); + } + } + + { // Preset AES256 - SHA512 + SvMemoryStream aEncryptionInfo; + { + oox::crypto::AgileEngine aEngine; + + aEngine.setPreset(oox::crypto::AgileEncryptionPreset::AES_256_SHA512); + aEngine.setupEncryption(aPassword); + aKeyDataSalt = aEngine.getInfo().keyDataSalt; + + oox::BinaryXOutputStream aBinaryEncryptionInfoOutputStream( + new utl::OSeekableOutputStreamWrapper(aEncryptionInfo), true); + + aEngine.writeEncryptionInfo(aBinaryEncryptionInfoOutputStream); + aBinaryEncryptionInfoOutputStream.close(); + + CPPUNIT_ASSERT_EQUAL(sal_uInt64(1112), aEncryptionInfo.GetSize()); + } + + aEncryptionInfo.Seek(STREAM_SEEK_TO_BEGIN); + + { + oox::crypto::AgileEngine aEngine; + + uno::Reference xInputStream( + new utl::OSeekableInputStreamWrapper(aEncryptionInfo)); + + xInputStream->skipBytes(4); // Encryption type -> Agile + + CPPUNIT_ASSERT(aEngine.readEncryptionInfo(xInputStream)); + + oox::crypto::AgileEncryptionInfo& rInfo = aEngine.getInfo(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(100000), rInfo.spinCount); + CPPUNIT_ASSERT_EQUAL(sal_Int32(16), rInfo.saltSize); + CPPUNIT_ASSERT_EQUAL(sal_Int32(256), rInfo.keyBits); + CPPUNIT_ASSERT_EQUAL(sal_Int32(64), rInfo.hashSize); + CPPUNIT_ASSERT_EQUAL(sal_Int32(16), rInfo.blockSize); + CPPUNIT_ASSERT_EQUAL(OUString("AES"), rInfo.cipherAlgorithm); + CPPUNIT_ASSERT_EQUAL(OUString("ChainingModeCBC"), rInfo.cipherChaining); + CPPUNIT_ASSERT_EQUAL(OUString("SHA512"), rInfo.hashAlgorithm); + CPPUNIT_ASSERT_EQUAL(toString(aKeyDataSalt), toString(rInfo.keyDataSalt)); + + CPPUNIT_ASSERT_EQUAL(false, aEngine.decryptAndCheckVerifierHash("Wrong")); + CPPUNIT_ASSERT_EQUAL(true, aEngine.decryptAndCheckVerifierHash(aPassword)); + } + } +} + +void CryptoTest::testAgileDataIntegrityHmacKey() +{ + OUString aPassword("Password"); + + std::vector aKeyDataSalt; + + std::vector aHmacKey; + std::vector aHmacEncryptedKey; + + SvMemoryStream aEncryptionInfo; + { + oox::crypto::AgileEngine aEngine; + aEngine.setupEncryption(aPassword); + oox::BinaryXOutputStream aBinaryEncryptionInfoOutputStream( + new utl::OSeekableOutputStreamWrapper(aEncryptionInfo), true); + aEngine.writeEncryptionInfo(aBinaryEncryptionInfoOutputStream); + aBinaryEncryptionInfoOutputStream.close(); + + aHmacKey = aEngine.getInfo().hmacKey; + aKeyDataSalt = aEngine.getInfo().keyDataSalt; + aHmacEncryptedKey = aEngine.getInfo().hmacEncryptedKey; + } + + aEncryptionInfo.Seek(STREAM_SEEK_TO_BEGIN); + + { + oox::crypto::AgileEngine aEngine; + + uno::Reference xInputStream( + new utl::OSeekableInputStreamWrapper(aEncryptionInfo)); + + xInputStream->skipBytes(4); // Encryption type -> Agile + + CPPUNIT_ASSERT(aEngine.readEncryptionInfo(xInputStream)); + CPPUNIT_ASSERT(aEngine.generateEncryptionKey(aPassword)); + + CPPUNIT_ASSERT_EQUAL(toString(aKeyDataSalt), toString(aEngine.getInfo().keyDataSalt)); + + CPPUNIT_ASSERT_EQUAL(toString(aHmacEncryptedKey), + toString(aEngine.getInfo().hmacEncryptedKey)); + + CPPUNIT_ASSERT_EQUAL(size_t(64), aHmacKey.size()); + CPPUNIT_ASSERT_EQUAL(toString(aHmacKey), toString(aEngine.getInfo().hmacKey)); + } +} + +void CryptoTest::testAgileEncryptingAndDecrypting() +{ + OUString aPassword("Password"); + + SvMemoryStream aEncryptionInfo; + SvMemoryStream aEncryptedStream; + + OString aTestString = "1234567890ABCDEFGH"; + + { + oox::crypto::AgileEngine aEngine; + + // Setup input + SvMemoryStream aUnencryptedInput; + uno::Reference xInputStream( + new utl::OSeekableInputStreamWrapper(aUnencryptedInput)); + + aUnencryptedInput.WriteBytes(aTestString.getStr(), aTestString.getLength() + 1); + aUnencryptedInput.Seek(STREAM_SEEK_TO_BEGIN); + + // Setup output + uno::Reference xOutputStream( + new utl::OSeekableOutputStreamWrapper(aEncryptedStream)); + + // Write content + aEngine.setupEncryption(aPassword); + aEngine.encrypt(xInputStream, xOutputStream, aUnencryptedInput.GetSize()); + xOutputStream->flush(); + + // Check content + sal_uInt64 nSize = aEncryptedStream.GetSize(); + + CPPUNIT_ASSERT_EQUAL(sal_uInt64(40), nSize); + + // Setup and write encryption info + oox::BinaryXOutputStream aBinaryEncryptionInfoOutputStream( + new utl::OSeekableOutputStreamWrapper(aEncryptionInfo), true); + aEngine.writeEncryptionInfo(aBinaryEncryptionInfoOutputStream); + aBinaryEncryptionInfoOutputStream.close(); + } + + aEncryptedStream.Seek(STREAM_SEEK_TO_BEGIN); + aEncryptionInfo.Seek(STREAM_SEEK_TO_BEGIN); + + { + oox::crypto::AgileEngine aEngine; + + // Read encryption info + uno::Reference xEncryptionInfo( + new utl::OSeekableInputStreamWrapper(aEncryptionInfo)); + + xEncryptionInfo->skipBytes(4); // Encryption type -> Agile + + CPPUNIT_ASSERT(aEngine.readEncryptionInfo(xEncryptionInfo)); + + // Setup password + CPPUNIT_ASSERT(aEngine.generateEncryptionKey(aPassword)); + + // Setup encrypted input stream + oox::BinaryXInputStream aBinaryInputStream( + new utl::OSeekableInputStreamWrapper(aEncryptedStream), true); + + // Setup output stream + SvMemoryStream aUnencryptedOutput; + oox::BinaryXOutputStream aBinaryOutputStream( + new utl::OSeekableOutputStreamWrapper(aUnencryptedOutput), true); + + // Decrypt + aEngine.decrypt(aBinaryInputStream, aBinaryOutputStream); + aBinaryOutputStream.close(); + aBinaryInputStream.close(); + + // Check decrypted output + CPPUNIT_ASSERT_EQUAL(sal_uInt64(19), aUnencryptedOutput.GetSize()); + + OString aString(static_cast(aUnencryptedOutput.GetData())); + CPPUNIT_ASSERT_EQUAL(aTestString, aString); + + // Check data integrity + CPPUNIT_ASSERT_EQUAL(true, aEngine.checkDataIntegrity()); + } +} + +CPPUNIT_TEST_SUITE_REGISTRATION(CryptoTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/qa/unit/data/FaultyPathStart.odp b/oox/qa/unit/data/FaultyPathStart.odp new file mode 100644 index 000000000..219795ffa Binary files /dev/null and b/oox/qa/unit/data/FaultyPathStart.odp differ diff --git a/oox/qa/unit/data/camera-rotation-revolution-nonwps.pptx b/oox/qa/unit/data/camera-rotation-revolution-nonwps.pptx new file mode 100644 index 000000000..db26dc032 Binary files /dev/null and b/oox/qa/unit/data/camera-rotation-revolution-nonwps.pptx differ diff --git a/oox/qa/unit/data/camera-rotation-revolution.docx b/oox/qa/unit/data/camera-rotation-revolution.docx new file mode 100644 index 000000000..74054aa82 Binary files /dev/null and b/oox/qa/unit/data/camera-rotation-revolution.docx differ diff --git a/oox/qa/unit/data/chart-data-label-char-color.docx b/oox/qa/unit/data/chart-data-label-char-color.docx new file mode 100644 index 000000000..0e389f923 Binary files /dev/null and b/oox/qa/unit/data/chart-data-label-char-color.docx differ diff --git a/oox/qa/unit/data/chart-theme-override.pptx b/oox/qa/unit/data/chart-theme-override.pptx new file mode 100644 index 000000000..85243b678 Binary files /dev/null and b/oox/qa/unit/data/chart-theme-override.pptx differ diff --git a/oox/qa/unit/data/customshape-position.docx b/oox/qa/unit/data/customshape-position.docx new file mode 100644 index 000000000..227928f20 Binary files /dev/null and b/oox/qa/unit/data/customshape-position.docx differ diff --git a/oox/qa/unit/data/dml-groupshape-polygon.docx b/oox/qa/unit/data/dml-groupshape-polygon.docx new file mode 100644 index 000000000..6d20b0342 Binary files /dev/null and b/oox/qa/unit/data/dml-groupshape-polygon.docx differ diff --git a/oox/qa/unit/data/endParaRPr-newline-textsize.pptx b/oox/qa/unit/data/endParaRPr-newline-textsize.pptx new file mode 100644 index 000000000..109f818ec Binary files /dev/null and b/oox/qa/unit/data/endParaRPr-newline-textsize.pptx differ diff --git a/oox/qa/unit/data/gradient-multistep-transparency.pptx b/oox/qa/unit/data/gradient-multistep-transparency.pptx new file mode 100644 index 000000000..83946c71b Binary files /dev/null and b/oox/qa/unit/data/gradient-multistep-transparency.pptx differ diff --git a/oox/qa/unit/data/graphic-stroke.pptx b/oox/qa/unit/data/graphic-stroke.pptx new file mode 100644 index 000000000..f4465476f Binary files /dev/null and b/oox/qa/unit/data/graphic-stroke.pptx differ diff --git a/oox/qa/unit/data/group-spt202.docx b/oox/qa/unit/data/group-spt202.docx new file mode 100644 index 000000000..14bf00b50 Binary files /dev/null and b/oox/qa/unit/data/group-spt202.docx differ diff --git a/oox/qa/unit/data/import-characters.pptx b/oox/qa/unit/data/import-characters.pptx new file mode 100644 index 000000000..293380236 Binary files /dev/null and b/oox/qa/unit/data/import-characters.pptx differ diff --git a/oox/qa/unit/data/import-mce.pptx b/oox/qa/unit/data/import-mce.pptx new file mode 100644 index 000000000..65cf1cbab Binary files /dev/null and b/oox/qa/unit/data/import-mce.pptx differ diff --git a/oox/qa/unit/data/multiple-group-shapes.docx b/oox/qa/unit/data/multiple-group-shapes.docx new file mode 100644 index 000000000..c751bcdf6 Binary files /dev/null and b/oox/qa/unit/data/multiple-group-shapes.docx differ diff --git a/oox/qa/unit/data/preset-adjust-value.pptx b/oox/qa/unit/data/preset-adjust-value.pptx new file mode 100644 index 000000000..d1d570a19 Binary files /dev/null and b/oox/qa/unit/data/preset-adjust-value.pptx differ diff --git a/oox/qa/unit/data/refer-to-theme-shape-fill.odp b/oox/qa/unit/data/refer-to-theme-shape-fill.odp new file mode 100644 index 000000000..3a32aa716 Binary files /dev/null and b/oox/qa/unit/data/refer-to-theme-shape-fill.odp differ diff --git a/oox/qa/unit/data/refer-to-theme.pptx b/oox/qa/unit/data/refer-to-theme.pptx new file mode 100644 index 000000000..9f05bf7b0 Binary files /dev/null and b/oox/qa/unit/data/refer-to-theme.pptx differ diff --git a/oox/qa/unit/data/shape-non-autosize-with-text.docx b/oox/qa/unit/data/shape-non-autosize-with-text.docx new file mode 100644 index 000000000..b9ae501f4 Binary files /dev/null and b/oox/qa/unit/data/shape-non-autosize-with-text.docx differ diff --git a/oox/qa/unit/data/shape-text-adjust-left.pptx b/oox/qa/unit/data/shape-text-adjust-left.pptx new file mode 100644 index 000000000..d197425b9 Binary files /dev/null and b/oox/qa/unit/data/shape-text-adjust-left.pptx differ diff --git a/oox/qa/unit/data/shape-text-alignment.pptx b/oox/qa/unit/data/shape-text-alignment.pptx new file mode 100644 index 000000000..ff4ff06f2 Binary files /dev/null and b/oox/qa/unit/data/shape-text-alignment.pptx differ diff --git a/oox/qa/unit/data/smartart-groupshape.pptx b/oox/qa/unit/data/smartart-groupshape.pptx new file mode 100644 index 000000000..81dcee1e5 Binary files /dev/null and b/oox/qa/unit/data/smartart-groupshape.pptx differ diff --git a/oox/qa/unit/data/table-shadow.pptx b/oox/qa/unit/data/table-shadow.pptx new file mode 100644 index 000000000..3247404cb Binary files /dev/null and b/oox/qa/unit/data/table-shadow.pptx differ diff --git a/oox/qa/unit/data/tdf100391_TextAreaRect.odp b/oox/qa/unit/data/tdf100391_TextAreaRect.odp new file mode 100644 index 000000000..b9b9e5b39 Binary files /dev/null and b/oox/qa/unit/data/tdf100391_TextAreaRect.odp differ diff --git a/oox/qa/unit/data/tdf109169_OctagonBevel.odt b/oox/qa/unit/data/tdf109169_OctagonBevel.odt new file mode 100644 index 000000000..2ba39b102 Binary files /dev/null and b/oox/qa/unit/data/tdf109169_OctagonBevel.odt differ diff --git a/oox/qa/unit/data/tdf112450_vml_polyline.docx b/oox/qa/unit/data/tdf112450_vml_polyline.docx new file mode 100644 index 000000000..a31124ee7 Binary files /dev/null and b/oox/qa/unit/data/tdf112450_vml_polyline.docx differ diff --git a/oox/qa/unit/data/tdf113187_arcTo_withoutReferences.pptx b/oox/qa/unit/data/tdf113187_arcTo_withoutReferences.pptx new file mode 100644 index 000000000..1862c0257 Binary files /dev/null and b/oox/qa/unit/data/tdf113187_arcTo_withoutReferences.pptx differ diff --git a/oox/qa/unit/data/tdf125582_TextOnCircle.pptx b/oox/qa/unit/data/tdf125582_TextOnCircle.pptx new file mode 100644 index 000000000..b2c09e515 Binary files /dev/null and b/oox/qa/unit/data/tdf125582_TextOnCircle.pptx differ diff --git a/oox/qa/unit/data/tdf131082.pptx b/oox/qa/unit/data/tdf131082.pptx new file mode 100644 index 000000000..dbe88126f Binary files /dev/null and b/oox/qa/unit/data/tdf131082.pptx differ diff --git a/oox/qa/unit/data/tdf137314_vml_rotation_unit_fd.docx b/oox/qa/unit/data/tdf137314_vml_rotation_unit_fd.docx new file mode 100644 index 000000000..17c8cabc0 Binary files /dev/null and b/oox/qa/unit/data/tdf137314_vml_rotation_unit_fd.docx differ diff --git a/oox/qa/unit/data/tdf141463_GroupTransform.pptx b/oox/qa/unit/data/tdf141463_GroupTransform.pptx new file mode 100644 index 000000000..36c506262 Binary files /dev/null and b/oox/qa/unit/data/tdf141463_GroupTransform.pptx differ diff --git a/oox/qa/unit/data/tdf141786_PolylineConnectorInGroup.odt b/oox/qa/unit/data/tdf141786_PolylineConnectorInGroup.odt new file mode 100644 index 000000000..d40dccac8 Binary files /dev/null and b/oox/qa/unit/data/tdf141786_PolylineConnectorInGroup.odt differ diff --git a/oox/qa/unit/data/tdf141786_RotatedShapeInGroup.odt b/oox/qa/unit/data/tdf141786_RotatedShapeInGroup.odt new file mode 100644 index 000000000..e932cf47b Binary files /dev/null and b/oox/qa/unit/data/tdf141786_RotatedShapeInGroup.odt differ diff --git a/oox/qa/unit/data/tdf142602_CustomShapeArrows.odt b/oox/qa/unit/data/tdf142602_CustomShapeArrows.odt new file mode 100644 index 000000000..bc0357a1a Binary files /dev/null and b/oox/qa/unit/data/tdf142602_CustomShapeArrows.odt differ diff --git a/oox/qa/unit/data/tdf142605_CurveSize.odp b/oox/qa/unit/data/tdf142605_CurveSize.odp new file mode 100644 index 000000000..c797d378f Binary files /dev/null and b/oox/qa/unit/data/tdf142605_CurveSize.odp differ diff --git a/oox/qa/unit/data/tdf147978_endsubpath.odp b/oox/qa/unit/data/tdf147978_endsubpath.odp new file mode 100644 index 000000000..2dfd55de1 Binary files /dev/null and b/oox/qa/unit/data/tdf147978_endsubpath.odp differ diff --git a/oox/qa/unit/data/tdf147978_enhancedPath_commandA.odp b/oox/qa/unit/data/tdf147978_enhancedPath_commandA.odp new file mode 100644 index 000000000..99ddda7c1 Binary files /dev/null and b/oox/qa/unit/data/tdf147978_enhancedPath_commandA.odp differ diff --git a/oox/qa/unit/data/tdf147978_enhancedPath_commandHIJK.odp b/oox/qa/unit/data/tdf147978_enhancedPath_commandHIJK.odp new file mode 100644 index 000000000..49e01bc09 Binary files /dev/null and b/oox/qa/unit/data/tdf147978_enhancedPath_commandHIJK.odp differ diff --git a/oox/qa/unit/data/tdf147978_enhancedPath_commandT.odp b/oox/qa/unit/data/tdf147978_enhancedPath_commandT.odp new file mode 100644 index 000000000..3dcd0d567 Binary files /dev/null and b/oox/qa/unit/data/tdf147978_enhancedPath_commandT.odp differ diff --git a/oox/qa/unit/data/tdf147978_enhancedPath_commandXY.odp b/oox/qa/unit/data/tdf147978_enhancedPath_commandXY.odp new file mode 100644 index 000000000..611225178 Binary files /dev/null and b/oox/qa/unit/data/tdf147978_enhancedPath_commandXY.odp differ diff --git a/oox/qa/unit/data/tdf147978_enhancedPath_subpath.pptx b/oox/qa/unit/data/tdf147978_enhancedPath_subpath.pptx new file mode 100644 index 000000000..bbedc7ab9 Binary files /dev/null and b/oox/qa/unit/data/tdf147978_enhancedPath_subpath.pptx differ diff --git a/oox/qa/unit/data/tdf148784_StretchCommandQ.odp b/oox/qa/unit/data/tdf148784_StretchCommandQ.odp new file mode 100644 index 000000000..3da092b2c Binary files /dev/null and b/oox/qa/unit/data/tdf148784_StretchCommandQ.odp differ diff --git a/oox/qa/unit/data/tdf148784_StretchCommandVW.odp b/oox/qa/unit/data/tdf148784_StretchCommandVW.odp new file mode 100644 index 000000000..bf1054a20 Binary files /dev/null and b/oox/qa/unit/data/tdf148784_StretchCommandVW.odp differ diff --git a/oox/qa/unit/data/tdf148784_StretchXY.odp b/oox/qa/unit/data/tdf148784_StretchXY.odp new file mode 100644 index 000000000..f9df40570 Binary files /dev/null and b/oox/qa/unit/data/tdf148784_StretchXY.odp differ diff --git a/oox/qa/unit/data/testTdf132557_footerCustomShapes.pptx b/oox/qa/unit/data/testTdf132557_footerCustomShapes.pptx new file mode 100644 index 000000000..4dbf3717d Binary files /dev/null and b/oox/qa/unit/data/testTdf132557_footerCustomShapes.pptx differ diff --git a/oox/qa/unit/data/theme-tint.pptx b/oox/qa/unit/data/theme-tint.pptx new file mode 100644 index 000000000..23ab7589d Binary files /dev/null and b/oox/qa/unit/data/theme-tint.pptx differ diff --git a/oox/qa/unit/data/theme.pptx b/oox/qa/unit/data/theme.pptx new file mode 100644 index 000000000..5268e4041 Binary files /dev/null and b/oox/qa/unit/data/theme.pptx differ diff --git a/oox/qa/unit/data/transparent-text.pptx b/oox/qa/unit/data/transparent-text.pptx new file mode 100644 index 000000000..b7b3ede4d Binary files /dev/null and b/oox/qa/unit/data/transparent-text.pptx differ diff --git a/oox/qa/unit/data/vba/complex1.bin b/oox/qa/unit/data/vba/complex1.bin new file mode 100644 index 000000000..390208290 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 000000000..335b8e808 Binary files /dev/null and b/oox/qa/unit/data/vba/reference/complex1.bin differ 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 000000000..a4644fbb7 Binary files /dev/null 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 new file mode 100644 index 000000000..5de3f5ae0 Binary files /dev/null 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 000000000..a38e8a868 --- /dev/null +++ b/oox/qa/unit/data/vba/reference/simple3.bin @@ -0,0 +1 @@ +° diff --git a/oox/qa/unit/data/vba/reference/spec321.bin b/oox/qa/unit/data/vba/reference/spec321.bin new file mode 100644 index 000000000..3120c7f50 Binary files /dev/null and b/oox/qa/unit/data/vba/reference/spec321.bin differ diff --git a/oox/qa/unit/data/vba/reference/spec322.bin b/oox/qa/unit/data/vba/reference/spec322.bin new file mode 100644 index 000000000..7724b62a4 Binary files /dev/null and b/oox/qa/unit/data/vba/reference/spec322.bin differ diff --git a/oox/qa/unit/data/vba/reference/spec323.bin b/oox/qa/unit/data/vba/reference/spec323.bin new file mode 100644 index 000000000..51104ee0b Binary files /dev/null and b/oox/qa/unit/data/vba/reference/spec323.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 000000000..d59c1d5ef Binary files /dev/null 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 new file mode 100644 index 000000000..1b9b88b16 Binary files /dev/null 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 000000000..72060e8a2 --- /dev/null +++ b/oox/qa/unit/data/vba/simple3.bin @@ -0,0 +1 @@ + diff --git a/oox/qa/unit/data/vba/spec321.bin b/oox/qa/unit/data/vba/spec321.bin new file mode 100644 index 000000000..c5d48c9fc --- /dev/null +++ b/oox/qa/unit/data/vba/spec321.bin @@ -0,0 +1 @@ +abcdefghijklmnopqrstuv. \ No newline at end of file diff --git a/oox/qa/unit/data/vba/spec322.bin b/oox/qa/unit/data/vba/spec322.bin new file mode 100644 index 000000000..781c426c0 --- /dev/null +++ b/oox/qa/unit/data/vba/spec322.bin @@ -0,0 +1 @@ +#aaabcdefaaaaghijaaaaaklaaamnopqaaaaaaaaaaaarstuvwxyzaaa \ No newline at end of file diff --git a/oox/qa/unit/data/vba/spec323.bin b/oox/qa/unit/data/vba/spec323.bin new file mode 100644 index 000000000..9ca58b98a --- /dev/null +++ b/oox/qa/unit/data/vba/spec323.bin @@ -0,0 +1 @@ +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \ No newline at end of file diff --git a/oox/qa/unit/data/watermark.docx b/oox/qa/unit/data/watermark.docx new file mode 100644 index 000000000..c9eacff9a Binary files /dev/null and b/oox/qa/unit/data/watermark.docx differ diff --git a/oox/qa/unit/drawingml.cxx b/oox/qa/unit/drawingml.cxx new file mode 100644 index 000000000..dedea55b9 --- /dev/null +++ b/oox/qa/unit/drawingml.cxx @@ -0,0 +1,566 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace ::com::sun::star; + +namespace +{ +/// Gets one child of xShape, which one is specified by nIndex. +uno::Reference getChildShape(const uno::Reference& xShape, + sal_Int32 nIndex) +{ + uno::Reference xGroup(xShape, uno::UNO_QUERY); + CPPUNIT_ASSERT(xGroup.is()); + + CPPUNIT_ASSERT(xGroup->getCount() > nIndex); + + uno::Reference xRet(xGroup->getByIndex(nIndex), uno::UNO_QUERY); + CPPUNIT_ASSERT(xRet.is()); + + return xRet; +} +} + +/// oox drawingml tests. +class OoxDrawingmlTest : public test::BootstrapFixture, public unotest::MacrosTest +{ +private: + uno::Reference mxComponent; + +public: + void setUp() override; + void tearDown() override; + uno::Reference& getComponent() { return mxComponent; } + void load(const OUString& rURL); + void loadAndReload(const OUString& rURL, const OUString& rFilterName); +}; + +void OoxDrawingmlTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void OoxDrawingmlTest::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +void OoxDrawingmlTest::load(const OUString& rURL) { mxComponent = loadFromDesktop(rURL); } + +void OoxDrawingmlTest::loadAndReload(const OUString& rURL, const OUString& rFilterName) +{ + load(rURL); + uno::Reference xStorable(mxComponent, uno::UNO_QUERY); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= rFilterName; + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + mxComponent->dispose(); + validate(aTempFile.GetFileName(), test::OOXML); + mxComponent = loadFromDesktop(aTempFile.GetURL()); +} + +constexpr OUStringLiteral DATA_DIRECTORY = u"/oox/qa/unit/data/"; + +CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testTransparentText) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "transparent-text.pptx"; + loadAndReload(aURL, "Impress Office Open XML"); + + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xParagraph( + xShape->createEnumeration()->nextElement(), uno::UNO_QUERY); + uno::Reference xPortion(xParagraph->createEnumeration()->nextElement(), + uno::UNO_QUERY); + + sal_Int16 nTransparency = 0; + xPortion->getPropertyValue("CharTransparence") >>= nTransparency; + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 75 + // - Actual : 0 + // i.e. the transparency of the character color was lost on import/export. + CPPUNIT_ASSERT_EQUAL(static_cast(75), nTransparency); +} + +CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testTdf131082) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf131082.pptx"; + loadAndReload(aURL, "Impress Office Open XML"); + + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference XPropSet(getChildShape(getChildShape(xShape, 0), 0), + uno::UNO_QUERY); + + drawing::FillStyle eFillStyle = drawing::FillStyle_NONE; + XPropSet->getPropertyValue("FillStyle") >>= eFillStyle; + + // Without the accompanying fix in place, this test would have failed with: + // with drawing::FillStyle_NONE - 0 + CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_SOLID, eFillStyle); +} + +CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testPresetAdjustValue) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "preset-adjust-value.pptx"; + + load(aURL); + + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xShapeProps(xShape, uno::UNO_QUERY); + uno::Sequence aGeoPropSeq; + xShapeProps->getPropertyValue("CustomShapeGeometry") >>= aGeoPropSeq; + comphelper::SequenceAsHashMap aGeoPropMap(aGeoPropSeq); + uno::Sequence aAdjustmentSeq; + aGeoPropMap.getValue("AdjustmentValues") >>= aAdjustmentSeq; + CPPUNIT_ASSERT_EQUAL(static_cast(1), aAdjustmentSeq.getLength()); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 11587 + // - Actual : 10813 + // i.e. the adjust value was set from the placeholder, not from the shape. + CPPUNIT_ASSERT_EQUAL(static_cast(11587), aAdjustmentSeq[0].Value.get()); +} + +CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testChartDataLabelCharColor) +{ + OUString aURL + = m_directories.getURLFromSrc(DATA_DIRECTORY) + "chart-data-label-char-color.docx"; + load(aURL); + + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xModel(xShape->getPropertyValue("Model"), + uno::UNO_QUERY); + uno::Reference xDiagram(xModel->getFirstDiagram(), + uno::UNO_QUERY); + + uno::Reference xCoordinateSystem( + xDiagram->getCoordinateSystems()[0], uno::UNO_QUERY); + + uno::Reference xChartType(xCoordinateSystem->getChartTypes()[0], + uno::UNO_QUERY); + + uno::Reference xDataSeries = xChartType->getDataSeries()[0]; + + uno::Reference xDataPoint = xDataSeries->getDataPointByIndex(0); + + uno::Sequence> aLabels; + xDataPoint->getPropertyValue("CustomLabelFields") >>= aLabels; + uno::Reference xLabel = aLabels[0]; + + sal_Int32 nCharColor = 0; + xLabel->getPropertyValue("CharColor") >>= nCharColor; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 16777215 + // - Actual : -1 + // i.e. the data label had no explicit (white) color. + CPPUNIT_ASSERT_EQUAL(static_cast(0xffffff), nCharColor); +} + +CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testGradientMultiStepTransparency) +{ + // Load a document with a multi-step gradient. + OUString aURL + = m_directories.getURLFromSrc(DATA_DIRECTORY) + "gradient-multistep-transparency.pptx"; + load(aURL); + + // Check the end transparency of the gradient. + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xShape(xDrawPage->getByIndex(1), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Rectangle 4"), xShape->getName()); + uno::Reference xShapeProps(xShape, uno::UNO_QUERY); + awt::Gradient aTransparence; + xShapeProps->getPropertyValue("FillTransparenceGradient") >>= aTransparence; + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 16777215 (0xffffff) + // - Actual : 3487029 (0x353535) + // i.e. the end transparency was not 100%, but was 21%, leading to an unexpected visible line on + // the right of this shape. + CPPUNIT_ASSERT_EQUAL(static_cast(0xffffff), aTransparence.EndColor); +} + +CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testShapeTextAlignment) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "shape-text-alignment.pptx"; + load(aURL); + + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + sal_Int16 nParaAdjust = -1; + CPPUNIT_ASSERT(xShape->getPropertyValue("ParaAdjust") >>= nParaAdjust); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 0 + // - Actual : 3 + // i.e. text which is meant to be left-aligned was centered at a paragraph level. + CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_LEFT, + static_cast(nParaAdjust)); +} + +CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testShapeTextAdjustLeft) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "shape-text-adjust-left.pptx"; + load(aURL); + + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + drawing::TextHorizontalAdjust eAdjust; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 3 (center) + // - Actual : 1 (block) + // i.e. text was center-adjusted, not default-adjusted (~left). + CPPUNIT_ASSERT(xShape->getPropertyValue("TextHorizontalAdjust") >>= eAdjust); + CPPUNIT_ASSERT_EQUAL(drawing::TextHorizontalAdjust_BLOCK, eAdjust); +} + +CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testCameraRotationRevolution) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "camera-rotation-revolution.docx"; + load(aURL); + + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xShape0(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xShape1(xDrawPage->getByIndex(1), uno::UNO_QUERY); + uno::Reference xShapeProps0(xShape0, uno::UNO_QUERY); + uno::Reference xShapeProps1(xShape1, uno::UNO_QUERY); + sal_Int32 nRotateAngle0; + sal_Int32 nRotateAngle1; + xShapeProps0->getPropertyValue("RotateAngle") >>= nRotateAngle0; + xShapeProps1->getPropertyValue("RotateAngle") >>= nRotateAngle1; + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 8000 + // - Actual : 0 + // so the camera rotation would not have been factored into how the shape is displayed + CPPUNIT_ASSERT_EQUAL(static_cast(8000), nRotateAngle0); + CPPUNIT_ASSERT_EQUAL(static_cast(27000), nRotateAngle1); +} + +CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testTdf146534_CameraRotationRevolutionNonWpsShapes) +{ + OUString aURL + = m_directories.getURLFromSrc(DATA_DIRECTORY) + "camera-rotation-revolution-nonwps.pptx"; + load(aURL); + + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xShape0(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xShape1(xDrawPage->getByIndex(1), uno::UNO_QUERY); + uno::Reference xShapeProps0(xShape0, uno::UNO_QUERY); + uno::Reference xShapeProps1(xShape1, uno::UNO_QUERY); + sal_Int32 nRotateAngle0; + sal_Int32 nRotateAngle1; + xShapeProps0->getPropertyValue("RotateAngle") >>= nRotateAngle0; + xShapeProps1->getPropertyValue("RotateAngle") >>= nRotateAngle1; + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 9000 + // - Actual : 0 + // so the camera rotation would not have been factored into how the shape is displayed + CPPUNIT_ASSERT_EQUAL(static_cast(9000), nRotateAngle0); + CPPUNIT_ASSERT_EQUAL(static_cast(30500), nRotateAngle1); +} + +CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testTableShadow) +{ + auto verify = [](const uno::Reference& xComponent) { + uno::Reference xDrawPagesSupplier(xComponent, uno::UNO_QUERY); + uno::Reference xDrawPage( + xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + bool bShadow = false; + CPPUNIT_ASSERT(xShape->getPropertyValue("Shadow") >>= bShadow); + + CPPUNIT_ASSERT(bShadow); + sal_Int32 nColor = 0; + CPPUNIT_ASSERT(xShape->getPropertyValue("ShadowColor") >>= nColor); + CPPUNIT_ASSERT_EQUAL(static_cast(0xff0000), nColor); + }; + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "table-shadow.pptx"; + load(aURL); + // Without the accompanying fix in place, this test would have failed, because shadow on a table + // was lost on import. + verify(getComponent()); + + uno::Reference xStorable(getComponent(), uno::UNO_QUERY); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= OUString("Impress Office Open XML"); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + getComponent()->dispose(); + validate(aTempFile.GetFileName(), test::OOXML); + getComponent() = loadFromDesktop(aTempFile.GetURL()); + // Without the accompanying fix in place, this test would have failed, because shadow on a table + // was lost on export. + verify(getComponent()); +} + +CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testGroupShapeSmartArt) +{ + // Given a file with a smartart inside a group shape: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "smartart-groupshape.pptx"; + + // When loading that file: + load(aURL); + + // Then make sure that the smartart is not just an empty group shape: + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xGroup(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xSmartArt(xGroup->getByIndex(0), uno::UNO_QUERY); + // Without the accompanying fix in place, this test would have failed, because we lost all + // children of the group shape representing the smartart. + CPPUNIT_ASSERT_GREATER(static_cast(0), xSmartArt->getCount()); +} + +CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testTdf142605_CurveSize) +{ + // The document contains a Bezier curve, where the control points are outside the bounding + // rectangle of the shape. Error was, that the export uses a path size which included the + // control points. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf142605_CurveSize.odp"; + loadAndReload(aURL, "Impress Office Open XML"); + + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xShapeProps(xShape, uno::UNO_QUERY); + css::awt::Rectangle aBoundRect; + xShapeProps->getPropertyValue("BoundRect") >>= aBoundRect; + // Without fix, size was 6262 x 3509, and position was 10037|6790. + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(8601), aBoundRect.Width, 1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(4601), aBoundRect.Height, 1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(7699), aBoundRect.X, 1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(5699), aBoundRect.Y, 1); +} + +CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testChartThemeOverride) +{ + // Given a document with 2 slides, slide1 has a chart with a theme override and slide2 has a + // shape: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "chart-theme-override.pptx"; + + // When loading that document: + load(aURL); + + // Then make sure that the slide 2 shape's text color is blue, not red: + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(1), + uno::UNO_QUERY); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xText(xShape->getText(), uno::UNO_QUERY); + uno::Reference xPara(xText->createEnumeration()->nextElement(), + uno::UNO_QUERY); + uno::Reference xPortion(xPara->createEnumeration()->nextElement(), + uno::UNO_QUERY); + sal_Int32 nActual{ 0 }; + xPortion->getPropertyValue("CharColor") >>= nActual; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 4485828 (0x4472c4) + // - Actual : 16711680 (0xff0000) + // i.e. the text color was red, not blue. + CPPUNIT_ASSERT_EQUAL(static_cast(0x4472C4), nActual); +} + +CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testPptxTheme) +{ + // Given a PPTX file with a slide -> master slide -> theme: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "theme.pptx"; + + // When importing the document: + load(aURL); + + // Then make sure the theme + referring to that theme is imported: + // Check the imported theme of the master page: + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage( + xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY); + uno::Reference xMasterpage(xDrawPage->getMasterPage(), uno::UNO_QUERY); + comphelper::SequenceAsHashMap aMap(xMasterpage->getPropertyValue("Theme")); + CPPUNIT_ASSERT_EQUAL(OUString("Office Theme"), aMap["Name"].get()); + // Without the accompanying fix in place, this test would have failed with: + // - Cannot extract an Any(void) to string! + // i.e. the name of the color scheme was lost on import. + CPPUNIT_ASSERT_EQUAL(OUString("Office"), aMap["ColorSchemeName"].get()); + + // Check the last color in the color set, value is from ppt/theme/theme1.xml. + // Without the accompanying fix in place, this test would have failed with: + // - Cannot extract an Any(void) to []long! + auto aColorScheme = aMap["ColorScheme"].get>(); + CPPUNIT_ASSERT_EQUAL(static_cast(12), aColorScheme.getLength()); + CPPUNIT_ASSERT_EQUAL(static_cast(0x954F72), aColorScheme[11]); + + // Check the reference to that theme: + uno::Reference xDrawPageShapes(xDrawPage, uno::UNO_QUERY); + uno::Reference xShape(xDrawPageShapes->getByIndex(0), uno::UNO_QUERY); + uno::Reference xText(xShape->getText(), uno::UNO_QUERY); + uno::Reference xPara(xText->createEnumeration()->nextElement(), + uno::UNO_QUERY); + uno::Reference xPortion(xPara->createEnumeration()->nextElement(), + uno::UNO_QUERY); + // 4 is accent1, see oox::drawingml::Color::getSchemeColorIndex(). + CPPUNIT_ASSERT_EQUAL(static_cast(4), + xPortion->getPropertyValue("CharColorTheme").get()); + // 60000 in the file, just 100th vs 1000th percents. + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 6000 + // - Actual : 10000 + // i.e. we had the default 100% value, not the value from the file. + CPPUNIT_ASSERT_EQUAL(static_cast(6000), + xPortion->getPropertyValue("CharColorLumMod").get()); + + // 40000 in the file, just 100th vs 1000th percents. + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 4000 + // - Actual : 0 + // i.e. we had the default 0% value, not the value from the file. + CPPUNIT_ASSERT_EQUAL(static_cast(4000), + xPortion->getPropertyValue("CharColorLumOff").get()); +} + +CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testTdf132557_footerCustomShapes) +{ + // slide with date, footer, slide number with custom shapes + OUString aURL + = m_directories.getURLFromSrc(DATA_DIRECTORY) + "testTdf132557_footerCustomShapes.pptx"; + // When importing the document: + load(aURL); + + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + + // Test if we were able to import the footer shapes with CustomShape service. + uno::Reference xShapeDateTime(xDrawPage->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.CustomShape"), + xShapeDateTime->getShapeType()); + // Without the accompanying fix in place, this test would have failed with: + // An uncaught exception of type com.sun.star.lang.IndexOutOfBoundsException + // i.e. the shape wasn't on the slide there since it was imported as a property, not a shape. + + uno::Reference xShapeFooter(xDrawPage->getByIndex(1), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.CustomShape"), + xShapeFooter->getShapeType()); + + uno::Reference xShapeSlideNum(xDrawPage->getByIndex(2), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.CustomShape"), + xShapeSlideNum->getShapeType()); +} + +CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testThemeTint) +{ + // Given a document with a table style, using theme color with tinting in the A2 cell: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "theme-tint.pptx"; + + // When loading that document: + load(aURL); + + // Then make sure that we only import theming info to the doc model if the effects are limited + // to lum mod / off that we can handle (i.e. no tint/shade): + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xTable; + CPPUNIT_ASSERT(xShape->getPropertyValue("Model") >>= xTable); + uno::Reference xA1(xTable->getCellByPosition(0, 0), uno::UNO_QUERY); + sal_Int16 nFillColorTheme{}; + CPPUNIT_ASSERT(xA1->getPropertyValue("FillColorTheme") >>= nFillColorTheme); + // This is OK, no problematic effects: + CPPUNIT_ASSERT_EQUAL(static_cast(4), nFillColorTheme); + uno::Reference xA2(xTable->getCellByPosition(0, 1), uno::UNO_QUERY); + CPPUNIT_ASSERT(xA2->getPropertyValue("FillColorTheme") >>= nFillColorTheme); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: -1 + // - Actual : 4 + // i.e. we remembered the theme index, without being able to remember the tint effect, leading + // to a bad background color. + CPPUNIT_ASSERT_EQUAL(static_cast(-1), nFillColorTheme); +} + +CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testTdf113187ConstantArcTo) +{ + OUString aURL + = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf113187_arcTo_withoutReferences.pptx"; + load(aURL); + // Get ViewBox of shape + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xShapeProps(xShape, uno::UNO_QUERY); + uno::Sequence aGeoPropSeq; + xShapeProps->getPropertyValue("CustomShapeGeometry") >>= aGeoPropSeq; + comphelper::SequenceAsHashMap aGeoPropMap(aGeoPropSeq); + // Without the fix width and height of the ViewBox were 0 and thus the shape was not shown. + auto aViewBox = aGeoPropMap["ViewBox"].get(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3600000), aViewBox.Width); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3600000), aViewBox.Height); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/qa/unit/export.cxx b/oox/qa/unit/export.cxx new file mode 100644 index 000000000..90089a994 --- /dev/null +++ b/oox/qa/unit/export.cxx @@ -0,0 +1,777 @@ +/* -*- 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 + +#include +#include + +using namespace ::com::sun::star; + +namespace +{ +/// Covers ooox/source/export/ fixes. +class Test : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools +{ +private: + uno::Reference mxComponent; + utl::TempFile maTempFile; + +public: + void setUp() override; + void tearDown() override; + void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override; + utl::TempFile& getTempFile() { return maTempFile; } + void loadAndSave(const OUString& rURL, const OUString& rFilterName); +}; + +void Test::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void Test::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +void Test::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) +{ + XmlTestTools::registerOOXMLNamespaces(pXmlXpathCtx); +} + +void Test::loadAndSave(const OUString& rURL, const OUString& rFilterName) +{ + mxComponent = loadFromDesktop(rURL); + uno::Reference xStorable(mxComponent, uno::UNO_QUERY); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= rFilterName; + maTempFile.EnableKillingFile(); + xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + mxComponent->dispose(); + mxComponent.clear(); + // too many DOCX validation errors right now + if (rFilterName != "Office Open XML Text") + { + validate(maTempFile.GetFileName(), test::OOXML); + } +} + +constexpr OUStringLiteral DATA_DIRECTORY = u"/oox/qa/unit/data/"; + +CPPUNIT_TEST_FIXTURE(Test, testPolylineConnectorPosition) +{ + // Given a document with a group shape and therein a polyline and a connector. + OUString aURL + = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf141786_PolylineConnectorInGroup.odt"; + // When saving that to DOCX: + loadAndSave(aURL, "Office Open XML Text"); + + // Then make sure polyline and connector have the correct position. + std::unique_ptr pStream = parseExportStream(getTempFile(), "word/document.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + + // For child elements of groups in Writer the position has to be adapted to be relative + // to group instead of being relative to anchor. That was missing for polyline and + // connector. + // Polyline: Without fix it would have failed with expected: 0, actual: 1800360 + assertXPath(pXmlDoc, "//wpg:wgp/wps:wsp[1]/wps:spPr/a:xfrm/a:off", "x", "0"); + // ... failed with expected: 509400, actual: 1229400 + assertXPath(pXmlDoc, "//wpg:wgp/wps:wsp[1]/wps:spPr/a:xfrm/a:off", "y", "509400"); + + // Connector: Without fix it would have failed with expected: 763200, actual: 2563560 + assertXPath(pXmlDoc, "//wpg:wgp/wps:wsp[3]/wps:spPr/a:xfrm/a:off", "x", "763200"); + // ... failed with expected: 0, actual: 720000 + assertXPath(pXmlDoc, "//wpg:wgp/wps:wsp[3]/wps:spPr/a:xfrm/a:off", "y", "0"); + // Polyline and connector were shifted 1800360EMU right, 720000EMU down. +} + +CPPUNIT_TEST_FIXTURE(Test, testRotatedShapePosition) +{ + // Given a document with a group shape and therein a rotated custom shape. + OUString aURL + = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf141786_RotatedShapeInGroup.odt"; + // When saving that to DOCX: + loadAndSave(aURL, "Office Open XML Text"); + + // Then make sure the rotated child shape has the correct position. + std::unique_ptr pStream = parseExportStream(getTempFile(), "word/document.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + + // For a group itself and for shapes outside of groups, the position calculation is done in + // DocxSdrExport. For child elements of groups it has to be done in + // DrawingML::WriteShapeTransformation(), but was missing. + // Without fix it would have failed with expected: 469440, actual: 92160 + // The shape was about 1cm shifted up and partly outside its group. + assertXPath(pXmlDoc, "//wpg:wgp/wps:wsp[1]/wps:spPr/a:xfrm/a:off", "y", "469440"); +} + +CPPUNIT_TEST_FIXTURE(Test, testDmlGroupshapePolygon) +{ + // Given a document with a group shape, containing a single polygon child shape: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "dml-groupshape-polygon.docx"; + + // When saving that to DOCX: + loadAndSave(aURL, "Office Open XML Text"); + + // Then make sure that the group shape, the group shape's child size and the child shape's size + // match: + std::unique_ptr pStream = parseExportStream(getTempFile(), "word/document.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + assertXPath(pXmlDoc, "//wpg:grpSpPr/a:xfrm/a:ext", "cx", "5328360"); + // Without the accompanying fix in place, this test would have failed, the element was + // not written. + assertXPath(pXmlDoc, "//wpg:grpSpPr/a:xfrm/a:chExt", "cx", "5328360"); + assertXPath(pXmlDoc, "//wps:spPr/a:xfrm/a:ext", "cx", "5328360"); +} + +CPPUNIT_TEST_FIXTURE(Test, testCustomShapeArrowExport) +{ + // Given a document with a few different kinds of arrow shapes in it: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf142602_CustomShapeArrows.odt"; + // When saving that to DOCX: + loadAndSave(aURL, "Office Open XML Text"); + + // Then the shapes should retain their correct control values. + std::unique_ptr pStream = parseExportStream(getTempFile(), "word/document.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + + // Without the fix the output OOXML would have no tags in it. + + // Right arrow + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[1]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom", + "prst", "rightArrow"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[1]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[1]", + "fmla", "val 50000"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[1]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[2]", + "fmla", "val 46321"); + + // Left arrow + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[2]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom", + "prst", "leftArrow"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[2]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[1]", + "fmla", "val 50000"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[2]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[2]", + "fmla", "val 52939"); + + // Down arrow + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[3]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom", + "prst", "downArrow"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[3]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[1]", + "fmla", "val 50000"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[3]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[2]", + "fmla", "val 59399"); + + // Up arrow + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[4]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom", + "prst", "upArrow"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[4]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[1]", + "fmla", "val 50000"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[4]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[2]", + "fmla", "val 63885"); + + // Left-right arrow + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[5]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom", + "prst", "leftRightArrow"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[5]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[1]", + "fmla", "val 50000"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[5]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[2]", + "fmla", "val 53522"); + + // Up-down arrow + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[6]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom", + "prst", "upDownArrow"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[6]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[1]", + "fmla", "val 50000"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[6]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[2]", + "fmla", "val 62743"); + + // Right arrow callout + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[7]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom", + "prst", "rightArrowCallout"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[7]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[1]", + "fmla", "val 25002"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[7]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[2]", + "fmla", "val 25000"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[7]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[3]", + "fmla", "val 25052"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[7]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[4]", + "fmla", "val 66667"); + + // Left arrow callout + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[8]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom", + "prst", "leftArrowCallout"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[8]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[1]", + "fmla", "val 25002"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[8]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[2]", + "fmla", "val 25000"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[8]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[3]", + "fmla", "val 25057"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[8]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[4]", + "fmla", "val 66673"); + + // Down arrow callout + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[9]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom", + "prst", "downArrowCallout"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[9]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[1]", + "fmla", "val 29415"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[9]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[2]", + "fmla", "val 29413"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[9]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[3]", + "fmla", "val 16667"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[9]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[4]", + "fmla", "val 66667"); + + // Up arrow callout + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[10]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom", + "prst", "upArrowCallout"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[10]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[1]", + "fmla", "val 31033"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[10]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[2]", + "fmla", "val 31030"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[10]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[3]", + "fmla", "val 16667"); + assertXPath(pXmlDoc, + "//w:r/mc:AlternateContent[10]/mc:Choice/w:drawing/wp:anchor/a:graphic/" + "a:graphicData/wps:wsp/wps:spPr/a:prstGeom/a:avLst/a:gd[4]", + "fmla", "val 66660"); +} + +CPPUNIT_TEST_FIXTURE(Test, testCameraRevolutionGrabBag) +{ + // Given a PPTX file that contains camera revolution (rotation around z axis) applied shapes + OUString aURL + = m_directories.getURLFromSrc(DATA_DIRECTORY) + "camera-rotation-revolution-nonwps.pptx"; + + // When saving that document: + loadAndSave(aURL, "Impress Office Open XML"); + + std::unique_ptr pStream = parseExportStream(getTempFile(), "ppt/slides/slide1.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Then make sure the revolution is exported without a problem: + // First shape textbox: + assertXPath(pXmlDoc, "//p:sp[1]/p:spPr/a:scene3d/a:camera/a:rot", "rev", "5400000"); + + // Second shape rectangle: + assertXPath(pXmlDoc, "//p:sp[2]/p:spPr/a:scene3d/a:camera/a:rot", "rev", "18300000"); + + // Make sure Shape3DProperties don't leak under txBody + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 0 + // - Actual : 1 + // - In <>, XPath '//p:sp[1]/p:txBody/a:bodyPr/a:scene3d/a:camera/a:rot' number of nodes is incorrect + assertXPath(pXmlDoc, "//p:sp[1]/p:txBody/a:bodyPr/a:scene3d/a:camera/a:rot", 0); + assertXPath(pXmlDoc, "//p:sp[2]/p:txBody/a:bodyPr/a:scene3d/a:camera/a:rot", 0); +} + +CPPUNIT_TEST_FIXTURE(Test, testReferToTheme) +{ + // Given a PPTX file that contains references to a theme: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "refer-to-theme.pptx"; + + // When saving that document: + loadAndSave(aURL, "Impress Office Open XML"); + + std::unique_ptr pStream = parseExportStream(getTempFile(), "ppt/slides/slide1.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Then make sure the shape text color is a scheme color: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // - XPath '//p:sp/p:txBody/a:p/a:r/a:rPr/a:solidFill/a:schemeClr' number of nodes is incorrect + // i.e. the element was not written. + assertXPath(pXmlDoc, "//p:sp[1]/p:txBody/a:p/a:r/a:rPr/a:solidFill/a:schemeClr", "val", + "accent1"); + assertXPath(pXmlDoc, "//p:sp[1]/p:txBody/a:p/a:r/a:rPr/a:solidFill/a:schemeClr/a:lumMod", 0); + assertXPath(pXmlDoc, "//p:sp[1]/p:txBody/a:p/a:r/a:rPr/a:solidFill/a:schemeClr/a:lumOff", 0); + + // Second shape: lighter color: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // - XPath '//p:sp[2]/p:txBody/a:p/a:r/a:rPr/a:solidFill/a:schemeClr' number of nodes is incorrect + // i.e. the effects case did not write scheme colors. + assertXPath(pXmlDoc, "//p:sp[2]/p:txBody/a:p/a:r/a:rPr/a:solidFill/a:schemeClr", "val", + "accent1"); + assertXPath(pXmlDoc, "//p:sp[2]/p:txBody/a:p/a:r/a:rPr/a:solidFill/a:schemeClr/a:lumMod", "val", + "40000"); + assertXPath(pXmlDoc, "//p:sp[2]/p:txBody/a:p/a:r/a:rPr/a:solidFill/a:schemeClr/a:lumOff", "val", + "60000"); + + // Third shape, darker color: + assertXPath(pXmlDoc, "//p:sp[3]/p:txBody/a:p/a:r/a:rPr/a:solidFill/a:schemeClr", "val", + "accent1"); + assertXPath(pXmlDoc, "//p:sp[3]/p:txBody/a:p/a:r/a:rPr/a:solidFill/a:schemeClr/a:lumMod", "val", + "75000"); + assertXPath(pXmlDoc, "//p:sp[3]/p:txBody/a:p/a:r/a:rPr/a:solidFill/a:schemeClr/a:lumOff", 0); +} + +CPPUNIT_TEST_FIXTURE(Test, testReferToThemeShapeFill) +{ + // Given an ODP file that contains references to a theme for shape fill: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "refer-to-theme-shape-fill.odp"; + + // When saving that document: + loadAndSave(aURL, "Impress Office Open XML"); + + // Then make sure the shape fill color is a scheme color: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // i.e. the element was not written. Note that this was already working from PPTX + // files via grab-bags, so this test intentionally uses an ODP file as input. + std::unique_ptr pStream = parseExportStream(getTempFile(), "ppt/slides/slide1.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + assertXPath(pXmlDoc, "//p:sp[1]/p:spPr/a:solidFill/a:schemeClr", "val", "accent1"); + // Without the accompanying fix in place, this test would have failed with: + // - XPath '//p:sp[1]/p:spPr/a:solidFill/a:schemeClr/a:lumMod' number of nodes is incorrect + // i.e. the effects of the themed color were lost. + assertXPath(pXmlDoc, "//p:sp[1]/p:spPr/a:solidFill/a:schemeClr/a:lumMod", "val", "40000"); + assertXPath(pXmlDoc, "//p:sp[1]/p:spPr/a:solidFill/a:schemeClr/a:lumOff", "val", "60000"); +} + +CPPUNIT_TEST_FIXTURE(Test, testTdf146690_endParagraphRunPropertiesNewLinesTextSize) +{ + // Given a PPTX file that contains references to a theme: + OUString aURL + = m_directories.getURLFromSrc(DATA_DIRECTORY) + "endParaRPr-newline-textsize.pptx"; + + // When saving that document: + loadAndSave(aURL, "Impress Office Open XML"); + + std::unique_ptr pStream = parseExportStream(getTempFile(), "ppt/slides/slide1.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Make sure the text size is exported correctly: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 500 + // - Actual : 1800 + // i.e. the endParaRPr 'size' wasn't exported correctly + assertXPath(pXmlDoc, "//p:sp[1]/p:txBody/a:p[1]/a:endParaRPr", "sz", "500"); + assertXPath(pXmlDoc, "//p:sp[1]/p:txBody/a:p[2]/a:endParaRPr", "sz", "500"); + assertXPath(pXmlDoc, "//p:sp[1]/p:txBody/a:p[3]/a:endParaRPr", "sz", "500"); +} + +CPPUNIT_TEST_FIXTURE(Test, testTdf147978_endsubpath) +{ + // Given an odp file that contains a non-primitive custom shape with command N + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf147978_endsubpath.odp"; + + // When saving that document: + loadAndSave(aURL, "Impress Office Open XML"); + + std::unique_ptr pStream = parseExportStream(getTempFile(), "ppt/slides/slide1.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Then make sure the pathLst has two child elements, + // Without the accompanying fix in place, only one element a:path was exported. + assertXPathChildren(pXmlDoc, "//a:pathLst", 2); + // and make sure first path with no stroke, second with no fill + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]", "stroke", "0"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[2]", "fill", "none"); +} + +CPPUNIT_TEST_FIXTURE(Test, testTdf147978_commandA) +{ + // Given an odp file that contains a non-primitive custom shape with command N + OUString aURL + = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf147978_enhancedPath_commandA.odp"; + + // When saving that document: + loadAndSave(aURL, "Impress Office Open XML"); + + std::unique_ptr pStream = parseExportStream(getTempFile(), "ppt/slides/slide1.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Then make sure the path has a child element arcTo. Prior to the fix that part of the curve was + // not exported at all. In odp it is a command A. Such does not exist in OOXML and is therefore + // exported as a:lnTo followed by a:arcTo + assertXPath(pXmlDoc, "//a:pathLst/a:path/a:lnTo", 2); + assertXPath(pXmlDoc, "//a:pathLst/a:path/a:arcTo", 1); + // And assert its attribute values + assertXPath(pXmlDoc, "//a:pathLst/a:path/a:arcTo", "wR", "7200"); + assertXPath(pXmlDoc, "//a:pathLst/a:path/a:arcTo", "hR", "5400"); + assertXPath(pXmlDoc, "//a:pathLst/a:path/a:arcTo", "stAng", "7719588"); + assertXPath(pXmlDoc, "//a:pathLst/a:path/a:arcTo", "swAng", "-5799266"); +} + +CPPUNIT_TEST_FIXTURE(Test, testTdf147978_commandT) +{ + // The odp file contains a non-primitive custom shape with commands MTZ + OUString aURL + = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf147978_enhancedPath_commandT.odp"; + + // Export to pptx had only exported the command M and has used a wrong path size + loadAndSave(aURL, "Impress Office Open XML"); + + // Verify the markup: + std::unique_ptr pStream = parseExportStream(getTempFile(), "ppt/slides/slide1.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // File has draw:viewBox="0 0 216 216" + assertXPath(pXmlDoc, "//a:pathLst/a:path", "w", "216"); + assertXPath(pXmlDoc, "//a:pathLst/a:path", "h", "216"); + // Command T is exported as lnTo followed by arcTo. + assertXPath(pXmlDoc, "//a:pathLst/a:path/a:moveTo", 1); + assertXPath(pXmlDoc, "//a:pathLst/a:path/a:lnTo", 1); + assertXPath(pXmlDoc, "//a:pathLst/a:path/a:arcTo", 1); + assertXPath(pXmlDoc, "//a:pathLst/a:path/a:close", 1); + // And assert its values + assertXPath(pXmlDoc, "//a:pathLst/a:path/a:moveTo/a:pt", "x", "108"); + assertXPath(pXmlDoc, "//a:pathLst/a:path/a:moveTo/a:pt", "y", "162"); + assertXPath(pXmlDoc, "//a:pathLst/a:path/a:lnTo/a:pt", "x", "138"); + assertXPath(pXmlDoc, "//a:pathLst/a:path/a:lnTo/a:pt", "y", "110"); + assertXPath(pXmlDoc, "//a:pathLst/a:path/a:arcTo", "wR", "108"); + assertXPath(pXmlDoc, "//a:pathLst/a:path/a:arcTo", "hR", "54"); + assertXPath(pXmlDoc, "//a:pathLst/a:path/a:arcTo", "stAng", "18000000"); + assertXPath(pXmlDoc, "//a:pathLst/a:path/a:arcTo", "swAng", "18000000"); +} + +CPPUNIT_TEST_FIXTURE(Test, testTdf147978_commandXY) +{ + // The odp file contains a non-primitive custom shapes with commands XY + OUString aURL + = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf147978_enhancedPath_commandXY.odp"; + + // Export to pptx had dropped commands X and Y. + loadAndSave(aURL, "Impress Office Open XML"); + + // Verify the markup: + std::unique_ptr pStream = parseExportStream(getTempFile(), "ppt/slides/slide1.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // File has draw:viewBox="0 0 10 10" + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]", "w", "10"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]", "h", "10"); + // Shape has M 0 5 Y 5 0 10 5 5 10 F Y 0 5 N M 10 10 X 0 0 + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]/a:moveTo/a:pt", "x", "0"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]/a:moveTo/a:pt", "y", "5"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]/a:arcTo[1]", "wR", "5"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]/a:arcTo[1]", "hR", "5"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]/a:arcTo[1]", "stAng", "10800000"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]/a:arcTo[1]", "swAng", "5400000"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]/a:arcTo[2]", "stAng", "16200000"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]/a:arcTo[2]", "swAng", "5400000"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]/a:arcTo[3]", "stAng", "0"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]/a:arcTo[3]", "swAng", "5400000"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]/a:arcTo[4]", "stAng", "0"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]/a:arcTo[4]", "swAng", "-5400000"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[2]/a:moveTo/a:pt", "x", "10"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[2]/a:moveTo/a:pt", "y", "10"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[2]/a:arcTo", "wR", "10"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[2]/a:arcTo", "hR", "10"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[2]/a:arcTo", "stAng", "5400000"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[2]/a:arcTo", "swAng", "5400000"); +} + +CPPUNIT_TEST_FIXTURE(Test, testTdf147978_commandHIJK) +{ + // The odp file contains a non-primitive custom shapes with commands H,I,J,K + OUString aURL + = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf147978_enhancedPath_commandHIJK.odp"; + + // Export to pptx had dropped commands X and Y. + loadAndSave(aURL, "Impress Office Open XML"); + + // Verify the markup: + std::unique_ptr pStream = parseExportStream(getTempFile(), "ppt/slides/slide1.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // File has draw:viewBox="0 0 80 80" + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]", "w", "80"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]", "h", "80"); + // File uses from back to front J (lighten), I (lightenLess), normal fill, K (darkenLess), + // H (darken). New feature, old versions did not export these at all. + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]", "fill", "lighten"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[2]", "fill", "lightenLess"); + assertXPathNoAttribute(pXmlDoc, "//a:pathLst/a:path[3]", "fill"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[4]", "fill", "darkenLess"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[5]", "fill", "darken"); +} + +CPPUNIT_TEST_FIXTURE(Test, testTdf147978_subpath) +{ + // The odp file contains a non-primitive custom shapes with commands H,I,J,K + OUString aURL + = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf147978_enhancedPath_subpath.pptx"; + + // Export to pptx had dropped the subpaths. + loadAndSave(aURL, "Impress Office Open XML"); + + // Verify the markup: + std::unique_ptr pStream = parseExportStream(getTempFile(), "ppt/slides/slide1.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // File should have four subpaths with increasing path size + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]", "w", "10"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]", "h", "10"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[2]", "w", "20"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[2]", "h", "20"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[3]", "w", "40"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[3]", "h", "40"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[4]", "w", "80"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[4]", "h", "80"); +} + +CPPUNIT_TEST_FIXTURE(Test, testTdf100391TextAreaRect) +{ + // The document has a custom shape of type "non-primitive" to trigger the custGeom export + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf100391_TextAreaRect.odp"; + // When saving to PPTX the textarea rect was set to default instead of using the actual area + loadAndSave(aURL, "Impress Office Open XML"); + + // Verify the markup. Without fix the values were l="l", t="t", r="r", b="b" + std::unique_ptr pStream = parseExportStream(getTempFile(), "ppt/slides/slide1.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + assertXPath(pXmlDoc, "//a:custGeom/a:rect", "l", "textAreaLeft"); + assertXPath(pXmlDoc, "//a:custGeom/a:rect", "t", "textAreaTop"); + assertXPath(pXmlDoc, "//a:custGeom/a:rect", "r", "textAreaRight"); + assertXPath(pXmlDoc, "//a:custGeom/a:rect", "b", "textAreaBottom"); + // The values are calculated in guides, for example + assertXPath(pXmlDoc, "//a:custGeom/a:gdLst/a:gd[1]", "name", "textAreaLeft"); + assertXPath(pXmlDoc, "//a:custGeom/a:gdLst/a:gd[1]", "fmla", "*/ 1440000 w 2880000"); + // The test reflects the state of Apr 2022. It needs to be adapted when export of handles and + // guides is implemented. +} + +CPPUNIT_TEST_FIXTURE(Test, testTdf109169_OctagonBevel) +{ + // The odp file contains an "Octagon Bevel" shape. Such has shading not in commands H,I,J,K + // but shading is generated in ctor of EnhancedCustomShape2d from the Type value. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf109169_OctagonBevel.odt"; + + // Export to docx had not written a:fill or a:stroke attributes at all. + loadAndSave(aURL, "Office Open XML Text"); + + // Verify the markup: + std::unique_ptr pStream = parseExportStream(getTempFile(), "word/document.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // File should have six subpaths, one with stroke and five with fill + assertXPath(pXmlDoc, "//a:pathLst/a:path[1]", "stroke", "0"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[2]", "fill", "darkenLess"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[3]", "fill", "darken"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[4]", "fill", "darken"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[5]", "fill", "lightenLess"); + assertXPath(pXmlDoc, "//a:pathLst/a:path[6]", "fill", "lighten"); +} + +CPPUNIT_TEST_FIXTURE(Test, testFaultyPathCommandsAWT) +{ + // The odp file contains shapes whose path starts with command A, W, T or L. That is a faulty + // path. LO is tolerant and renders it so that is makes a moveTo to the start point of the arc or + // the end of the line respectively. Export to OOXML does the same now and writes a moveTo + // instead of the normally used lnTo. If a lnTo is written, MS Office shows nothing of the shape. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "FaultyPathStart.odp"; + + loadAndSave(aURL, "Impress Office Open XML"); + + // Verify the markup: + std::unique_ptr pStream = parseExportStream(getTempFile(), "ppt/slides/slide1.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // First child of a:path should be a moveTo in all four shapes. + assertXPath(pXmlDoc, "//p:spTree/p:sp[1]/p:spPr/a:custGeom/a:pathLst/a:path/a:moveTo"); + assertXPath(pXmlDoc, "//p:spTree/p:sp[2]/p:spPr/a:custGeom/a:pathLst/a:path/a:moveTo"); + assertXPath(pXmlDoc, "//p:spTree/p:sp[3]/p:spPr/a:custGeom/a:pathLst/a:path/a:moveTo"); + assertXPath(pXmlDoc, "//p:spTree/p:sp[4]/p:spPr/a:custGeom/a:pathLst/a:path/a:moveTo"); +} + +CPPUNIT_TEST_FIXTURE(Test, testTdf148784StretchXY) +{ + // The document has a custom shapes of type "non-primitive" to trigger the custGeom export. + // They use formulas with 'right' and 'bottom'. + // When saving to PPTX the attributes stretchpoint-x and stretchpoint-y were not considered. The + // line at right and bottom edge were positioned inside as if the shape had a square size. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf148784_StretchXY.odp"; + loadAndSave(aURL, "Impress Office Open XML"); + + // Verify the markup. + std::unique_ptr pStream = parseExportStream(getTempFile(), "ppt/slides/slide1.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + + // x-position of last segment should be same as path width. It was 21600 without fix. + sal_Int32 nWidth + = getXPathContent(pXmlDoc, "//p:spTree/p:sp[1]/p:spPr/a:custGeom/a:pathLst/a:path/@w") + .toInt32(); + sal_Int32 nPosX + = getXPathContent( + pXmlDoc, "//p:spTree/p:sp[1]/p:spPr/a:custGeom/a:pathLst/a:path/a:moveTo[4]/a:pt/@x") + .toInt32(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("StretchX", nWidth, nPosX); + + // y-position of last segment should be same as path height. It was 21600 without fix. + sal_Int32 nHeight + = getXPathContent(pXmlDoc, "//p:spTree/p:sp[2]/p:spPr/a:custGeom/a:pathLst/a:path/@h") + .toInt32(); + sal_Int32 nPosY + = getXPathContent( + pXmlDoc, "//p:spTree/p:sp[2]/p:spPr/a:custGeom/a:pathLst/a:path/a:moveTo[4]/a:pt/@y") + .toInt32(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("StretchY", nHeight, nPosY); + + // The test reflects the state of Apr 2022. It needs to be adapted when export of handles and + // guides is implemented. +} + +CPPUNIT_TEST_FIXTURE(Test, testTdf148784StretchCommandQ) +{ + // The document has a custom shapes of type "non-primitive" to trigger the custGeom export. + // They use formulas with 'right' and 'bottom'. + // When saving to PPTX the attributes stretchpoint-x and stretchpoint-y were not considered. + // That results in wrong arcs on the right or bottom side of the shape. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf148784_StretchCommandQ.odp"; + loadAndSave(aURL, "Impress Office Open XML"); + + // Verify the markup. + std::unique_ptr pStream = parseExportStream(getTempFile(), "ppt/slides/slide1.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + + // x-position of second quadBezTo control should be same as path width. It was 21600 without fix. + sal_Int32 nWidth + = getXPathContent(pXmlDoc, "//p:spTree/p:sp[1]/p:spPr/a:custGeom/a:pathLst/a:path/@w") + .toInt32(); + sal_Int32 nPosX + = getXPathContent( + pXmlDoc, + "//p:spTree/p:sp[1]/p:spPr/a:custGeom/a:pathLst/a:path/a:quadBezTo[2]/a:pt/@x") + .toInt32(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("StretchX", nWidth, nPosX); + + // y-position of third quadBezTo control should be same as path height. It was 21600 without fix. + sal_Int32 nHeight + = getXPathContent(pXmlDoc, "//p:spTree/p:sp[2]/p:spPr/a:custGeom/a:pathLst/a:path/@h") + .toInt32(); + sal_Int32 nPosY + = getXPathContent( + pXmlDoc, + "//p:spTree/p:sp[2]/p:spPr/a:custGeom/a:pathLst/a:path/a:quadBezTo[3]/a:pt/@y") + .toInt32(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("StretchY", nHeight, nPosY); + + // The test reflects the state of Apr 2022. It needs to be adapted when export of handles and + // guides is implemented. +} + +CPPUNIT_TEST_FIXTURE(Test, testTdf148784StretchCommandVW) +{ + // The document has a custom shapes of type "non-primitive" to trigger the custGeom export. + // It should not need adaption when export of handles and guides is implemented because it + // has only fixed values in the path. + // When saving to PPTX the attributes stretchpoint-x and stretchpoint-y were not considered. + // That results in circles instead of ellipses. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf148784_StretchCommandVW.odp"; + loadAndSave(aURL, "Impress Office Open XML"); + + // Verify the markup. + std::unique_ptr pStream = parseExportStream(getTempFile(), "ppt/slides/slide1.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + + // wR of first ArcTo in first shape should be same as path width/2. It was 10800 without fix. + sal_Int32 nHalfWidth + = getXPathContent(pXmlDoc, "//p:spTree/p:sp[1]/p:spPr/a:custGeom/a:pathLst/a:path/@w") + .toInt32() + / 2; + sal_Int32 nWR + = getXPathContent(pXmlDoc, + "//p:spTree/p:sp[1]/p:spPr/a:custGeom/a:pathLst/a:path/a:arcTo[1]/@wR") + .toInt32(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("StretchX", nHalfWidth, nWR); + + // hR of first ArcTo in second shape should be same as path height /2. It was 10800 without fix. + sal_Int32 nHalfHeight + = getXPathContent(pXmlDoc, "//p:spTree/p:sp[2]/p:spPr/a:custGeom/a:pathLst/a:path/@h") + .toInt32() + / 2; + sal_Int32 nHR + = getXPathContent(pXmlDoc, + "//p:spTree/p:sp[2]/p:spPr/a:custGeom/a:pathLst/a:path/a:arcTo[1]/@hR") + .toInt32(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("StretchY", nHalfHeight, nHR); +} +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/qa/unit/mathml.cxx b/oox/qa/unit/mathml.cxx new file mode 100644 index 000000000..3ab87fcbc --- /dev/null +++ b/oox/qa/unit/mathml.cxx @@ -0,0 +1,71 @@ +/* -*- 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 + +using namespace ::com::sun::star; + +/// oox mathml tests. +class OoxMathmlTest : public test::BootstrapFixture, public unotest::MacrosTest +{ +private: + uno::Reference mxComponent; + +public: + void setUp() override; + void tearDown() override; + uno::Reference& getComponent() { return mxComponent; } +}; + +void OoxMathmlTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void OoxMathmlTest::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +constexpr OUStringLiteral DATA_DIRECTORY = u"/oox/qa/unit/data/"; + +CPPUNIT_TEST_FIXTURE(OoxMathmlTest, testImportCharacters) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "import-characters.pptx"; + // Without the accompanying fix in place, this failed with an assertion failure on import. + getComponent() = loadFromDesktop(aURL); +} + +CPPUNIT_TEST_FIXTURE(OoxMathmlTest, testImportMce) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "import-mce.pptx"; + getComponent() = loadFromDesktop(aURL); + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + + // Without the accompanying fix in place, this failed with: + // - Expected: 1 + // - Actual : 2 + // i.e. both the math object and its replacement image was imported, as two separate objects. + CPPUNIT_ASSERT_EQUAL(static_cast(1), xDrawPage->getCount()); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/qa/unit/shape.cxx b/oox/qa/unit/shape.cxx new file mode 100644 index 000000000..345ebb215 --- /dev/null +++ b/oox/qa/unit/shape.cxx @@ -0,0 +1,180 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include + +using namespace ::com::sun::star; + +namespace +{ +/// Gets one child of xShape, which one is specified by nIndex. +uno::Reference getChildShape(const uno::Reference& xShape, + sal_Int32 nIndex) +{ + uno::Reference xGroup(xShape, uno::UNO_QUERY); + CPPUNIT_ASSERT(xGroup.is()); + + CPPUNIT_ASSERT(xGroup->getCount() > nIndex); + + uno::Reference xRet(xGroup->getByIndex(nIndex), uno::UNO_QUERY); + CPPUNIT_ASSERT(xRet.is()); + + return xRet; +} +} + +constexpr OUStringLiteral DATA_DIRECTORY = u"/oox/qa/unit/data/"; + +/// oox shape tests. +class OoxShapeTest : public test::BootstrapFixture, public unotest::MacrosTest +{ +private: + uno::Reference mxComponent; + +public: + void setUp() override; + void tearDown() override; + uno::Reference& getComponent() { return mxComponent; } + void load(std::u16string_view rURL); +}; + +void OoxShapeTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void OoxShapeTest::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +void OoxShapeTest::load(std::u16string_view rFileName) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + rFileName; + mxComponent = loadFromDesktop(aURL); +} + +CPPUNIT_TEST_FIXTURE(OoxShapeTest, testGroupTransform) +{ + load(u"tdf141463_GroupTransform.pptx"); + + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xGroup(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xShape(getChildShape(xGroup, 0), uno::UNO_QUERY); + uno::Reference xPropSet(xShape, uno::UNO_QUERY); + // Without the accompanying fix in place, this test would have failed in several properties. + + sal_Int32 nAngle; + xPropSet->getPropertyValue("ShearAngle") >>= nAngle; + // Failed with - Expected: 0 + // - Actual : -810 + // i.e. the shape was sheared although shearing does not exist in oox + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nAngle); + + xPropSet->getPropertyValue("RotateAngle") >>= nAngle; + // Failed with - Expected: 26000 (is in 1/100deg) + // - Actual : 26481 (is in 1/100deg) + // 100deg in PowerPoint UI = 360deg - 100deg in LO. + CPPUNIT_ASSERT_EQUAL(sal_Int32(26000), nAngle); + + sal_Int32 nActual = xShape->getSize().Width; + // The group has ext.cy=2880000 and chExt.cy=4320000 resulting in Y-scale=2/3. + // The child has ext 2880000 x 1440000. Because of rotation angle 80deg, the Y-scale has to be + // applied to the width, resulting in 2880000 * 2/3 = 1920000EMU = 5333Hmm + // ToDo: Expected value currently 1 off. + // Failed with - Expected: 5332 + // - Actual : 5432 + CPPUNIT_ASSERT_EQUAL(sal_Int32(5332), nActual); +} + +CPPUNIT_TEST_FIXTURE(OoxShapeTest, testMultipleGroupShapes) +{ + load(u"multiple-group-shapes.docx"); + + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 2 + // - Actual : 1 + // i.e. the 2 group shapes from the document were imported as a single one. + CPPUNIT_ASSERT_EQUAL(static_cast(2), xDrawPage->getCount()); +} + +CPPUNIT_TEST_FIXTURE(OoxShapeTest, testCustomshapePosition) +{ + load(u"customshape-position.docx"); + + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + + sal_Int32 nY{}; + xShape->getPropertyValue("VertOrientPosition") >>= nY; + // 581025 in the document. + sal_Int32 nExpected = rtl::math::round(581025.0 / 360); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1614 + // - Actual : 0 + // i.e. the position of the shape was lost on import due to the rounded corners. + CPPUNIT_ASSERT_EQUAL(nExpected, nY); +} + +CPPUNIT_TEST_FIXTURE(OoxShapeTest, testTdf125582_TextOnCircle) +{ + // The document contains a shape with a:prstTxWarp="textCircle" with two paragraphs. + // PowerPoint aligns the bottom of the text with the path, LO had aligned the middle of the + // text with the path, which resulted in smaller text. + load(u"tdf125582_TextOnCircle.pptx"); + + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xPropSet(xShape, uno::UNO_QUERY); + + // BoundRect of Fontwork shape depends on dpi. + if (IsDefaultDPI()) + { + SdrObjCustomShape& rSdrCustomShape( + static_cast(*SdrObject::getSdrObjectFromXShape(xShape))); + // Without the fix in place width was 3639, but should be 4824 for 96dpi. + tools::Rectangle aBoundRect(rSdrCustomShape.GetCurrentBoundRect()); + CPPUNIT_ASSERT_DOUBLES_EQUAL(tools::Long(4824), aBoundRect.GetWidth(), 5); + } + + drawing::TextVerticalAdjust eAdjust; + xPropSet->getPropertyValue("TextVerticalAdjust") >>= eAdjust; + CPPUNIT_ASSERT_EQUAL_MESSAGE("TextVerticalAdjust", drawing::TextVerticalAdjust_BOTTOM, eAdjust); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/qa/unit/vba_compression.cxx b/oox/qa/unit/vba_compression.cxx new file mode 100644 index 000000000..906e30bfc --- /dev/null +++ b/oox/qa/unit/vba_compression.cxx @@ -0,0 +1,255 @@ +/* -*- 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 +#include +#include +#include +#include + +class TestVbaCompression : public CppUnit::TestFixture +{ +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(); + + void testSimple3(); + + // real stream from a document + void testComplex1(); + + // tests taken from the VBA specification + // section 3.2 + + // section 3.2.1 + void testSpec321(); + // section 3.2.2 + void testSpec322(); + // section 3.2.3 + void testSpec323(); + + CPPUNIT_TEST_SUITE(TestVbaCompression); + CPPUNIT_TEST(testSimple1); + CPPUNIT_TEST(testSimple2); + CPPUNIT_TEST(testSimple3); + CPPUNIT_TEST(testComplex1); + CPPUNIT_TEST(testSpec321); + CPPUNIT_TEST(testSpec322); + CPPUNIT_TEST(testSpec323); + CPPUNIT_TEST_SUITE_END(); + +private: + static OUString const & getDebugDirUrl() { + struct DebugDirUrl { + DebugDirUrl() : url("$UserInstallation/debug/") { + rtl::Bootstrap::expandMacros(url); + //TODO: provide an OUString -> OUString expansion function, and which throws on + // failure + auto e = osl::Directory::create(url); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, e); + } + OUString url; + }; + static DebugDirUrl url; + return url.url; + } + + test::Directories m_directories; +}; + +namespace { + +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); + + VBACompression aCompression(rOutputMemoryStream, aInputMemoryStream); + aCompression.write(); + + SvFileStream aReferenceStream(rReference, StreamMode::READ); + rReferenceMemoryStream.WriteStream(aReferenceStream); + + rOutputMemoryStream.Seek(0); + SvFileStream aDebugStream(rDebugPath, StreamMode::WRITE); + aDebugStream.WriteStream(rOutputMemoryStream); +} + +} + +void TestVbaCompression::testSimple1() +{ + OUString aTestFile = m_directories.getPathFromSrc(u"/oox/qa/unit/data/vba/simple1.bin"); + OUString aReference = m_directories.getPathFromSrc(u"/oox/qa/unit/data/vba/reference/simple1.bin"); + + SvMemoryStream aOutputMemoryStream(4096, 4096); + SvMemoryStream aReferenceMemoryStream(4096, 4096); + ReadFiles(aTestFile, aReference, aOutputMemoryStream, + aReferenceMemoryStream, getDebugDirUrl() + "vba_debug.bin"); + + CPPUNIT_ASSERT_EQUAL(aReferenceMemoryStream.GetSize(), aOutputMemoryStream.GetSize()); + + const sal_uInt8* pReferenceData = static_cast( aReferenceMemoryStream.GetData() ); + const sal_uInt8* pData = static_cast( aOutputMemoryStream.GetData() ); + + const sal_uInt64 nSize = std::min(aReferenceMemoryStream.GetSize(), + aOutputMemoryStream.GetSize()); + for (sal_uInt64 i = 0; i < nSize; ++i) + { + CPPUNIT_ASSERT_EQUAL(static_cast(pReferenceData[i]), static_cast(pData[i])); + } +} + +void TestVbaCompression::testSimple2() +{ + OUString aTestFile = m_directories.getPathFromSrc(u"/oox/qa/unit/data/vba/simple2.bin"); + OUString aReference = m_directories.getPathFromSrc(u"/oox/qa/unit/data/vba/reference/simple2.bin"); + + SvMemoryStream aOutputMemoryStream(4096, 4096); + SvMemoryStream aReferenceMemoryStream(4096, 4096); + ReadFiles(aTestFile, aReference, aOutputMemoryStream, aReferenceMemoryStream, getDebugDirUrl() + "vba_debug2.bin"); + + CPPUNIT_ASSERT_EQUAL(aReferenceMemoryStream.GetSize(), aOutputMemoryStream.GetSize()); + + const sal_uInt8* pReferenceData = static_cast( aReferenceMemoryStream.GetData() ); + const sal_uInt8* pData = static_cast( aOutputMemoryStream.GetData() ); + + const sal_uInt64 nSize = std::min(aReferenceMemoryStream.GetSize(), + aOutputMemoryStream.GetSize()); + for (sal_uInt64 i = 0; i < nSize; ++i) + { + CPPUNIT_ASSERT_EQUAL(static_cast(pReferenceData[i]), static_cast(pData[i])); + } +} + +void TestVbaCompression::testSimple3() +{ + OUString aTestFile = m_directories.getPathFromSrc(u"/oox/qa/unit/data/vba/simple3.bin"); + OUString aReference = m_directories.getPathFromSrc(u"/oox/qa/unit/data/vba/reference/simple3.bin"); + + SvMemoryStream aOutputMemoryStream(4096, 4096); + SvMemoryStream aReferenceMemoryStream(4096, 4096); + ReadFiles(aTestFile, aReference, aOutputMemoryStream, aReferenceMemoryStream, getDebugDirUrl() + "vba_debug3.bin"); + + CPPUNIT_ASSERT_EQUAL(aReferenceMemoryStream.GetSize(), aOutputMemoryStream.GetSize()); + + const sal_uInt8* pReferenceData = static_cast( aReferenceMemoryStream.GetData() ); + const sal_uInt8* pData = static_cast( aOutputMemoryStream.GetData() ); + + const sal_uInt64 nSize = std::min(aReferenceMemoryStream.GetSize(), + aOutputMemoryStream.GetSize()); + for (sal_uInt64 i = 0; i < nSize; ++i) + { + CPPUNIT_ASSERT_EQUAL(static_cast(pReferenceData[i]), static_cast(pData[i])); + } +} + +void TestVbaCompression::testComplex1() +{ + OUString aTestFile = m_directories.getPathFromSrc(u"/oox/qa/unit/data/vba/complex1.bin"); + OUString aReference = m_directories.getPathFromSrc(u"/oox/qa/unit/data/vba/reference/complex1.bin"); + + SvMemoryStream aOutputMemoryStream(4096, 4096); + SvMemoryStream aReferenceMemoryStream(4096, 4096); + ReadFiles(aTestFile, aReference, aOutputMemoryStream, aReferenceMemoryStream, getDebugDirUrl() + "vba_debug_complex1.bin"); + + CPPUNIT_ASSERT_EQUAL(aReferenceMemoryStream.GetSize(), aOutputMemoryStream.GetSize()); + + const sal_uInt8* pReferenceData = static_cast( aReferenceMemoryStream.GetData() ); + const sal_uInt8* pData = static_cast( aOutputMemoryStream.GetData() ); + + const sal_uInt64 nSize = std::min(aReferenceMemoryStream.GetSize(), + aOutputMemoryStream.GetSize()); + for (sal_uInt64 i = 0; i < nSize; ++i) + { + CPPUNIT_ASSERT_EQUAL(static_cast(pReferenceData[i]), static_cast(pData[i])); + } +} + +void TestVbaCompression::testSpec321() +{ + OUString aTestFile = m_directories.getPathFromSrc(u"/oox/qa/unit/data/vba/spec321.bin"); + OUString aReference = m_directories.getPathFromSrc(u"/oox/qa/unit/data/vba/reference/spec321.bin"); + + SvMemoryStream aOutputMemoryStream(4096, 4096); + SvMemoryStream aReferenceMemoryStream(4096, 4096); + ReadFiles(aTestFile, aReference, aOutputMemoryStream, aReferenceMemoryStream, getDebugDirUrl() + "vba_debug_spec321.bin"); + + CPPUNIT_ASSERT_EQUAL(aReferenceMemoryStream.GetSize(), aOutputMemoryStream.GetSize()); + + const sal_uInt8* pReferenceData = static_cast( aReferenceMemoryStream.GetData() ); + const sal_uInt8* pData = static_cast( aOutputMemoryStream.GetData() ); + + const sal_uInt64 nSize = std::min(aReferenceMemoryStream.GetSize(), + aOutputMemoryStream.GetSize()); + for (sal_uInt64 i = 0; i < nSize; ++i) + { + CPPUNIT_ASSERT_EQUAL(static_cast(pReferenceData[i]), static_cast(pData[i])); + } +} + +void TestVbaCompression::testSpec322() +{ + OUString aTestFile = m_directories.getPathFromSrc(u"/oox/qa/unit/data/vba/spec322.bin"); + OUString aReference = m_directories.getPathFromSrc(u"/oox/qa/unit/data/vba/reference/spec322.bin"); + + SvMemoryStream aOutputMemoryStream(4096, 4096); + SvMemoryStream aReferenceMemoryStream(4096, 4096); + ReadFiles(aTestFile, aReference, aOutputMemoryStream, aReferenceMemoryStream, getDebugDirUrl() + "vba_debug_spec322.bin"); + + CPPUNIT_ASSERT_EQUAL(aReferenceMemoryStream.GetSize(), aOutputMemoryStream.GetSize()); + + const sal_uInt8* pReferenceData = static_cast( aReferenceMemoryStream.GetData() ); + const sal_uInt8* pData = static_cast( aOutputMemoryStream.GetData() ); + + const sal_uInt64 nSize = std::min(aReferenceMemoryStream.GetSize(), + aOutputMemoryStream.GetSize()); + for (sal_uInt64 i = 0; i < nSize; ++i) + { + CPPUNIT_ASSERT_EQUAL(static_cast(pReferenceData[i]), static_cast(pData[i])); + } +} + +void TestVbaCompression::testSpec323() +{ + OUString aTestFile = m_directories.getPathFromSrc(u"/oox/qa/unit/data/vba/spec323.bin"); + OUString aReference = m_directories.getPathFromSrc(u"/oox/qa/unit/data/vba/reference/spec323.bin"); + + SvMemoryStream aOutputMemoryStream(4096, 4096); + SvMemoryStream aReferenceMemoryStream(4096, 4096); + ReadFiles(aTestFile, aReference, aOutputMemoryStream, aReferenceMemoryStream, getDebugDirUrl() + "vba_debug_spec323.bin"); + + CPPUNIT_ASSERT_EQUAL(aReferenceMemoryStream.GetSize(), aOutputMemoryStream.GetSize()); + + const sal_uInt8* pReferenceData = static_cast( aReferenceMemoryStream.GetData() ); + const sal_uInt8* pData = static_cast( aOutputMemoryStream.GetData() ); + + const sal_uInt64 nSize = std::min(aReferenceMemoryStream.GetSize(), + aOutputMemoryStream.GetSize()); + for (sal_uInt64 i = 0; i < nSize; ++i) + { + CPPUNIT_ASSERT_EQUAL(static_cast(pReferenceData[i]), static_cast(pData[i])); + } +} + +CPPUNIT_TEST_SUITE_REGISTRATION(TestVbaCompression); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/qa/unit/vba_encryption.cxx b/oox/qa/unit/vba_encryption.cxx new file mode 100644 index 000000000..023cc197b --- /dev/null +++ b/oox/qa/unit/vba_encryption.cxx @@ -0,0 +1,82 @@ +/* -*- 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 + +class TestVbaEncryption : public CppUnit::TestFixture +{ +public: +#if 0 + // an initial test for the encryption taken from the spec + void testSimple1(); + + void testSimple2(); +#endif + + void testProjKey1(); + + CPPUNIT_TEST_SUITE(TestVbaEncryption); + // CPPUNIT_TEST(testSimple1); + // CPPUNIT_TEST(testSimple2); + CPPUNIT_TEST(testProjKey1); + CPPUNIT_TEST_SUITE_END(); +}; + +#if 0 +void TestVbaEncryption::testSimple1() +{ + sal_uInt8 nSeed = 0x07; + sal_uInt8 nProjKey = 0xDF; + sal_uInt16 nLength = 0x04; + sal_uInt8 pData[] = { 0x00, 0x00, 0x00, 0x00 }; + + SvMemoryStream aEncryptedStream(4096, 4096); + VBAEncryption aEncryption(pData, nLength, aEncryptedStream, + &nSeed, nProjKey); + aEncryption.write(); +} + +void TestVbaEncryption::testSimple2() +{ + sal_uInt8 nSeed = 0x15; + sal_uInt8 nProjKey = 0xDF; + sal_uInt16 nLength = 0x01; + sal_uInt8 pData[] = { 0xFF }; + + SvMemoryStream aEncryptedStream(4096, 4096); + VBAEncryption aEncryption(pData, nLength, aEncryptedStream, + &nSeed, nProjKey); + aEncryption.write(); + sal_uInt8 pExpectedData[] = "1517CAF1D6F9D7F9D706"; + size_t length = sizeof(pExpectedData); + aEncryptedStream.Seek(0); + for (size_t i = 0; i < length; ++i) + { + unsigned char val = 0; + aEncryptedStream.ReadUChar(val); + CPPUNIT_ASSERT_EQUAL((int)pExpectedData[i], (int)sal_uInt8(val)); + } +} +#endif + +void TestVbaEncryption::testProjKey1() +{ + sal_uInt8 nProjKey = VBAEncryption::calculateProjKey("{917DED54-440B-4FD1-A5C1-74ACF261E600}"); + CPPUNIT_ASSERT_EQUAL(int(0xdf), static_cast(nProjKey)); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(TestVbaEncryption); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/qa/unit/vml.cxx b/oox/qa/unit/vml.cxx new file mode 100644 index 000000000..61730c744 --- /dev/null +++ b/oox/qa/unit/vml.cxx @@ -0,0 +1,236 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace ::com::sun::star; + +constexpr OUStringLiteral DATA_DIRECTORY = u"/oox/qa/unit/data/"; + +/// oox vml tests. +class OoxVmlTest : public test::BootstrapFixture, public unotest::MacrosTest +{ +private: + uno::Reference mxComponent; + +public: + void setUp() override; + void tearDown() override; + uno::Reference& getComponent() { return mxComponent; } + void load(std::u16string_view rURL); +}; + +void OoxVmlTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void OoxVmlTest::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +void OoxVmlTest::load(std::u16string_view rFileName) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + rFileName; + mxComponent = loadFromDesktop(aURL); +} + +CPPUNIT_TEST_FIXTURE(OoxVmlTest, tdf112450_vml_polyline) +{ + // Load a document with v:polyline shapes. Error was, that the size was set to zero and the + // points were zero because of missing decode from length with unit. + load(u"tdf112450_vml_polyline.docx"); + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + { + // This tests a polyline shape which is not closed. + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xShapeProps(xShape, uno::UNO_QUERY); + // Without fix in place, Geometry had 2 points, both 0|0. + drawing::PointSequenceSequence aGeometry; + xShapeProps->getPropertyValue("Geometry") >>= aGeometry; + drawing::PointSequence aPolygon = aGeometry[0]; + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(6879), aPolygon[3].X, 1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(487), aPolygon[3].Y, 1); + // Without fix in place, width and height were zero + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(6879), xShape->getSize().Width, 1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(1926), xShape->getSize().Height, 1); + // After the fix the shape has still to be PolygonKind_PLIN + drawing::PolygonKind ePolygonKind; + xShapeProps->getPropertyValue("PolygonKind") >>= ePolygonKind; + CPPUNIT_ASSERT_EQUAL(drawing::PolygonKind_PLIN, ePolygonKind); + } + { + uno::Reference xShape(xDrawPage->getByIndex(1), uno::UNO_QUERY); + uno::Reference xShapeProps(xShape, uno::UNO_QUERY); + // Without fix in place, Geometry had 2 points, both 0|0. + drawing::PointSequenceSequence aGeometry; + xShapeProps->getPropertyValue("Geometry") >>= aGeometry; + drawing::PointSequence aPolygon = aGeometry[0]; + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(5062), aPolygon[2].X, 1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(2247), aPolygon[2].Y, 1); + // Without fix in place, width and height were zero + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(6163), xShape->getSize().Width, 1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(2247), xShape->getSize().Height, 1); + // Without fix in place the shape was not closed, it had PolygonKind_PLIN + drawing::PolygonKind ePolygonKind; + xShapeProps->getPropertyValue("PolygonKind") >>= ePolygonKind; + CPPUNIT_ASSERT_EQUAL(drawing::PolygonKind_POLY, ePolygonKind); + } + { + // This tests a filled shape where v:polyline does not have attribute coordsize + uno::Reference xShape(xDrawPage->getByIndex(2), uno::UNO_QUERY); + uno::Reference xShapeProps(xShape, uno::UNO_QUERY); + // Without fix in place, Geometry had 2 points, both 0|0. + drawing::PointSequenceSequence aGeometry; + xShapeProps->getPropertyValue("Geometry") >>= aGeometry; + drawing::PointSequence aPolygon = aGeometry[0]; + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(2095), aPolygon[3].X, 1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(608), aPolygon[3].Y, 1); + // Without fix in place, width and height were zero + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(5634), xShape->getSize().Width, 1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(2485), xShape->getSize().Height, 1); + // Without fix in place the shape was not closed, it had PolygonKind_PLIN + drawing::PolygonKind ePolygonKind; + xShapeProps->getPropertyValue("PolygonKind") >>= ePolygonKind; + CPPUNIT_ASSERT_EQUAL(drawing::PolygonKind_POLY, ePolygonKind); + } +} + +CPPUNIT_TEST_FIXTURE(OoxVmlTest, tdf137314_vml_rotation_unit_fd) +{ + // Load a document with a 30deg rotated arc on a drawing canvas. Rotation is given + // as 1966080fd. Error was, that the vml angle unit "fd" was not converted to Degree100. + load(u"tdf137314_vml_rotation_unit_fd.docx"); + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xGroup(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xShape(xGroup->getByIndex(1), uno::UNO_QUERY); + uno::Reference xShapeProps(xShape, uno::UNO_QUERY); + drawing::PolyPolygonBezierCoords aPolyPolygonBezierCoords; + xShapeProps->getPropertyValue("PolyPolygonBezier") >>= aPolyPolygonBezierCoords; + drawing::PointSequence aPolygon = aPolyPolygonBezierCoords.Coordinates[1]; + // Without fix in place, the vector was -1441|1490. + // [1] and [2] are Bezier-curve control points. + sal_Int32 nDiffX = aPolygon[3].X - aPolygon[0].X; + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(1490), nDiffX, 1); + sal_Int32 nDiffY = aPolygon[3].Y - aPolygon[0].Y; + CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(1441), nDiffY, 1); +} + +CPPUNIT_TEST_FIXTURE(OoxVmlTest, testSpt202ShapeType) +{ + // Load a document with a groupshape, 2nd child is a , its type has o:spt set to 202 + // (TextBox). + load(u"group-spt202.docx"); + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xGroup(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xShape(xGroup->getByIndex(1), uno::UNO_QUERY); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: com.sun.star.drawing.TextShape + // - Actual : com.sun.star.drawing.CustomShape + // and then the size of the group shape was incorrect, e.g. its right edge was outside the page + // boundaries. + CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.TextShape"), xShape->getShapeType()); +} + +CPPUNIT_TEST_FIXTURE(OoxVmlTest, testShapeNonAutosizeWithText) +{ + // Load a document which has a group shape, containing a single child. + // 17.78 cm is the full group shape width, 19431/64008 is the child shape's relative width inside + // that, so 5.3975 cm should be the shape width. + load(u"shape-non-autosize-with-text.docx"); + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xGroup(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xShape(xGroup->getByIndex(0), uno::UNO_QUERY); + // Without the accompanying fix in place, this test would have failed with: + // - Actual : 1115 + // - Expected: 5398 + // because the width was determined using its text size, not using the explicit size. + CPPUNIT_ASSERT_EQUAL(static_cast(5398), xShape->getSize().Width); +} + +CPPUNIT_TEST_FIXTURE(OoxVmlTest, testGraphicStroke) +{ + load(u"graphic-stroke.pptx"); + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xDrawPage->getCount()); + + uno::Reference xShape; + uno::Reference xInfo(xDrawPage->getByIndex(0), uno::UNO_QUERY); + if (xInfo->supportsService("com.sun.star.drawing.OLE2Shape")) + xShape.set(xInfo, uno::UNO_QUERY); + + CPPUNIT_ASSERT(xShape.is()); + + drawing::LineStyle eLineStyle{}; + xShape->getPropertyValue("LineStyle") >>= eLineStyle; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // i.e. line style was NONE, not SOLID. + CPPUNIT_ASSERT_EQUAL(drawing::LineStyle_SOLID, eLineStyle); +} + +CPPUNIT_TEST_FIXTURE(OoxVmlTest, testWatermark) +{ + // Given a document with a picture watermark, and the "washout" checkbox is ticked on the Word + // UI: + // When loading that document: + load(u"watermark.docx"); + + // Then make sure the watermark effect is not lost on import: + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + drawing::ColorMode eMode{}; + xShape->getPropertyValue("GraphicColorMode") >>= eMode; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 3 + // - Actual : 0 + // i.e. the color mode was STANDARD, not WATERMARK. + CPPUNIT_ASSERT_EQUAL(drawing::ColorMode_WATERMARK, eMode); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3