diff options
author | Michael Stahl <mstahl@redhat.com> | 2016-03-04 23:01:18 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2016-03-09 09:55:10 +0000 |
commit | e93270fae07be68a92bdb7d6d964a54412ce983c (patch) | |
tree | fbaacf52fa7dfcbc2f2c67c1643fa06c041dc0e9 /sw | |
parent | 55ec8dd8af96756b00d5a617dc5a58abe73118d6 (diff) |
basic: tdf#87530 don't copy storage that doesn't exist
If the Basic library is newly created it may not have been stored to the
document storage yet.
(regression from 5246fa262450f686674850c53df666422f441c86)
(cherry picked from commit aeb43916366b293935314efe9454c66b4877b9d1)
tdf#87530 finish the regression test
Need to store the document twice to actually reproduce the bug.
(cherry picked from commit 7faecc70c286c0e1a3068b77ccde771640928b37)
Change-Id: I9c2fc1d7446795b9c1c2224671118b2a671dcad8
Reviewed-on: https://gerrit.libreoffice.org/23040
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/core/macros-test.cxx | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/sw/qa/core/macros-test.cxx b/sw/qa/core/macros-test.cxx index 6787d4f707bc..037e89a2fdca 100644 --- a/sw/qa/core/macros-test.cxx +++ b/sw/qa/core/macros-test.cxx @@ -85,6 +85,7 @@ public: #endif void testFdo55289(); void testFdo68983(); + void testFdo87530(); void testFindReplace(); CPPUNIT_TEST_SUITE(SwMacrosTest); #if !defined(MACOSX) && !defined(WNT) @@ -100,6 +101,7 @@ public: #endif CPPUNIT_TEST(testFdo55289); CPPUNIT_TEST(testFdo68983); + CPPUNIT_TEST(testFdo87530); CPPUNIT_TEST(testFindReplace); CPPUNIT_TEST_SUITE_END(); @@ -430,6 +432,90 @@ void SwMacrosTest::testFdo68983() xDocCloseable->close(false); } +void SwMacrosTest::testFdo87530() +{ + Reference<css::lang::XComponent> xComponent = + loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"); + + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + + Sequence<beans::PropertyValue> desc(1); + desc[0].Name = "FilterName"; + desc[0].Value <<= OUString("writer8"); + + { + // insert initial password protected library + Reference<document::XEmbeddedScripts> xDocScr(xComponent, UNO_QUERY_THROW); + Reference<script::XStorageBasedLibraryContainer> xStorBasLib(xDocScr->getBasicLibraries()); + Reference<script::XLibraryContainer> xBasLib(xStorBasLib, UNO_QUERY_THROW); + Reference<script::XLibraryContainerPassword> xBasLibPwd(xStorBasLib, UNO_QUERY_THROW); + Reference<container::XNameContainer> xLibrary(xBasLib->createLibrary("BarLibrary")); + xLibrary->insertByName("BarModule", + uno::makeAny(OUString("Sub Main\nEnd Sub\n"))); + xBasLibPwd->changeLibraryPassword("BarLibrary", "", "foo"); + + Reference<frame::XStorable> xDocStorable(xComponent, UNO_QUERY_THROW); + CPPUNIT_ASSERT(xDocStorable.is()); + + xDocStorable->storeAsURL(aTempFile.GetURL(), desc); + } + + Reference<util::XCloseable>(xComponent, UNO_QUERY_THROW)->close(false); + + // re-load + xComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.text.TextDocument"); + + { + // check that password-protected library survived store and re-load + Reference<document::XEmbeddedScripts> xDocScr(xComponent, UNO_QUERY_THROW); + Reference<script::XStorageBasedLibraryContainer> xStorBasLib(xDocScr->getBasicLibraries()); + Reference<script::XLibraryContainer> xBasLib(xStorBasLib, UNO_QUERY_THROW); + Reference<script::XLibraryContainerPassword> xBasLibPwd(xStorBasLib, UNO_QUERY_THROW); + CPPUNIT_ASSERT(xBasLibPwd->isLibraryPasswordProtected("BarLibrary")); + CPPUNIT_ASSERT(xBasLibPwd->verifyLibraryPassword("BarLibrary", "foo")); + xBasLib->loadLibrary("BarLibrary"); + CPPUNIT_ASSERT(xBasLib->isLibraryLoaded("BarLibrary")); + Reference<container::XNameContainer> xLibrary(xBasLib->getByName("BarLibrary"), UNO_QUERY); + Any module(xLibrary->getByName("BarModule")); + CPPUNIT_ASSERT_EQUAL(module.get<OUString>(), OUString("Sub Main\nEnd Sub\n")); + + // add a second module now - tdf#87530 happened here + Reference<container::XNameContainer> xFooLib(xBasLib->createLibrary("FooLibrary")); + xFooLib->insertByName("FooModule", + uno::makeAny(OUString("Sub Main\nEnd Sub\n"))); + xBasLibPwd->changeLibraryPassword("FooLibrary", "", "foo"); + + // store again + Reference<frame::XStorable> xDocStorable(xComponent, UNO_QUERY_THROW); + CPPUNIT_ASSERT(xDocStorable.is()); + + xDocStorable->store(); + } + + Reference<util::XCloseable>(xComponent, UNO_QUERY_THROW)->close(false); + + // re-load + xComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.text.TextDocument"); + + // check that password-protected library survived store and re-load + Reference<document::XEmbeddedScripts> xDocScr(xComponent, UNO_QUERY_THROW); + Reference<script::XStorageBasedLibraryContainer> xStorBasLib(xDocScr->getBasicLibraries()); + Reference<script::XLibraryContainer> xBasLib(xStorBasLib, UNO_QUERY_THROW); + Reference<script::XLibraryContainerPassword> xBasLibPwd(xStorBasLib, UNO_QUERY_THROW); + CPPUNIT_ASSERT(xBasLibPwd->isLibraryPasswordProtected("FooLibrary")); + CPPUNIT_ASSERT(xBasLibPwd->verifyLibraryPassword("FooLibrary", "foo")); + xBasLib->loadLibrary("FooLibrary"); + CPPUNIT_ASSERT(xBasLib->isLibraryLoaded("FooLibrary")); + Reference<container::XNameContainer> xLibrary(xBasLib->getByName("FooLibrary"), UNO_QUERY); + Any module(xLibrary->getByName("FooModule")); + CPPUNIT_ASSERT_EQUAL(module.get<OUString>(), OUString("Sub Main\nEnd Sub\n")); + + // close + Reference<util::XCloseable>(xComponent, UNO_QUERY_THROW)->close(false); +} + + void SwMacrosTest::testFindReplace() { // we need a full document with view and layout etc. because ::GetNode() |