summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2016-03-04 23:01:18 +0100
committerCaolán McNamara <caolanm@redhat.com>2016-03-09 10:12:32 +0000
commitb3f2b2529dc4ed313f423d29551577b6dfed4258 (patch)
treea58d0db001d3aeb748f5c6f6e6e1596707910b90
parente6a8fb33a948adf367baca31d54e1eb2f3ff0dc4 (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/23042 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--basic/source/uno/namecont.cxx17
-rw-r--r--sw/qa/core/macros-test.cxx86
2 files changed, 101 insertions, 2 deletions
diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx
index ab47f0146db2..c23c09e68ed6 100644
--- a/basic/source/uno/namecont.cxx
+++ b/basic/source/uno/namecont.cxx
@@ -1950,8 +1950,21 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
// fdo#68983: If there's a password and the password is not known, only
// copying the storage works!
// Can we simply copy the storage?
- if (!mbOldInfoFormat && !pImplLib->isLoadedStorable() &&
- !mbOasis2OOoFormat && xSourceLibrariesStor.is())
+ bool isCopyStorage = !mbOldInfoFormat && !mbOasis2OOoFormat
+ && !pImplLib->isLoadedStorable()
+ && xSourceLibrariesStor.is() /* null for user profile */;
+ if (isCopyStorage)
+ {
+ try
+ {
+ xSourceLibrariesStor->isStorageElement(rLib.aName);
+ }
+ catch (container::NoSuchElementException const&)
+ {
+ isCopyStorage = false;
+ }
+ }
+ if (isCopyStorage)
{
try
{
diff --git a/sw/qa/core/macros-test.cxx b/sw/qa/core/macros-test.cxx
index 5b90d8acfe80..b1ca97dc0dbb 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()