summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2016-03-04 23:01:18 +0100
committerMichael Stahl <mstahl@redhat.com>2016-03-07 12:05:32 +0100
commitaeb43916366b293935314efe9454c66b4877b9d1 (patch)
treeee57c63305941e55ef111faa640081f96190c41d
parent4b8c29015d7c70121a161da0f3a85fa4ea0c5987 (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) Change-Id: I9c2fc1d7446795b9c1c2224671118b2a671dcad8
-rw-r--r--basic/source/uno/namecont.cxx17
-rw-r--r--sw/qa/core/macros-test.cxx47
2 files changed, 62 insertions, 2 deletions
diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx
index b83344a3ed33..9608fa15bdda 100644
--- a/basic/source/uno/namecont.cxx
+++ b/basic/source/uno/namecont.cxx
@@ -1946,8 +1946,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 687ac8661103..ab9203e0faae 100644
--- a/sw/qa/core/macros-test.cxx
+++ b/sw/qa/core/macros-test.cxx
@@ -86,6 +86,7 @@ public:
#endif
void testFdo55289();
void testFdo68983();
+ void testFdo87530();
void testFindReplace();
CPPUNIT_TEST_SUITE(SwMacrosTest);
#if !defined(MACOSX) && !defined(_WIN32)
@@ -101,6 +102,7 @@ public:
#endif
CPPUNIT_TEST(testFdo55289);
CPPUNIT_TEST(testFdo68983);
+ CPPUNIT_TEST(testFdo87530);
CPPUNIT_TEST(testFindReplace);
CPPUNIT_TEST_SUITE_END();
@@ -431,6 +433,51 @@ void SwMacrosTest::testFdo68983()
xDocCloseable->close(false);
}
+void SwMacrosTest::testFdo87530()
+{
+ Reference<css::lang::XComponent> xComponent =
+ loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
+
+ {
+ 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);
+ xBasLib->createLibrary("Library1");
+ xBasLibPwd->changeLibraryPassword("Library1", "", "foo");
+ }
+
+ Reference<frame::XStorable> xDocStorable(xComponent, UNO_QUERY_THROW);
+ CPPUNIT_ASSERT(xDocStorable.is());
+
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ Sequence<beans::PropertyValue> desc(1);
+ desc[0].Name = "FilterName";
+ desc[0].Value <<= OUString("writer8");
+ 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("Library1"));
+ CPPUNIT_ASSERT(xBasLibPwd->verifyLibraryPassword("Library1", "foo"));
+ xBasLib->loadLibrary("Library1");
+ CPPUNIT_ASSERT(xBasLib->isLibraryLoaded("Library1"));
+
+ // close
+ Reference<util::XCloseable> xDocCloseable(xComponent, UNO_QUERY_THROW);
+ xDocCloseable->close(false);
+}
+
+
void SwMacrosTest::testFindReplace()
{
// we need a full document with view and layout etc. because ::GetNode()