[Libreoffice-commits] core.git: 3 commits - basic/source sw/CppunitTest_sw_macros_test.mk sw/qa

Michael Stahl mstahl at redhat.com
Thu May 22 04:18:09 PDT 2014


 basic/source/inc/namecont.hxx    |    4 +
 basic/source/inc/scriptcont.hxx  |    1 
 basic/source/uno/namecont.cxx    |   97 ++++++++++++++++++++++++++-------------
 basic/source/uno/scriptcont.cxx  |    6 ++
 sw/CppunitTest_sw_macros_test.mk |   62 +++++++++++++-----------
 sw/qa/core/data/odt/fdo68983.odt |binary
 sw/qa/core/macros-test.cxx       |   48 +++++++++++++++++++
 7 files changed, 158 insertions(+), 60 deletions(-)

New commits:
commit 5246fa262450f686674850c53df666422f441c86
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed May 21 22:26:05 2014 +0200

    fdo#68983: basic: if the library is not loaded fully, copy source storage
    
    Also fixes fdo#42899 and fdo#67685 in a different way; the previous fix
    for fdo#42899 caused the problem with password-protected libraries for
    which the password is not known: only the binary representation of the
    BAISC module was stored, not the source code; by simply copying from the
    source storage the problem can be avoided.
    
    It would be possible to ask for the password when storing, but that
    would not work when non-interactive (called via API).
    
    An alternative fix would be to pass in the
    SfxObjectShell::IsSetModifyEnabled() flag and actually reset the BASIC
    library's modify flag correctly, but that requires adding a
    parameter to XStorageBasedLibraryContainer::storeLibrariesToStorage().
    
    (regression from af34774d260a68fc02cd78ba90dd8d4afaf1a2a4 )
    
    Change-Id: I4701401f35171139fc2fe8d225d13d4e533091a0

diff --git a/basic/source/inc/namecont.hxx b/basic/source/inc/namecont.hxx
index 109835a..6355549 100644
--- a/basic/source/inc/namecont.hxx
+++ b/basic/source/inc/namecont.hxx
@@ -582,7 +582,9 @@ private:
     bool mbReadOnlyLink;
     bool mbPreload;
 
+protected:
     bool mbPasswordProtected;
+private:
     bool mbPasswordVerified;
     bool mbDoc50Password;
     OUString maPassword;
@@ -702,6 +704,8 @@ public:
     }
 
 protected:
+    virtual bool isLoadedStorable();
+
     virtual bool SAL_CALL isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const = 0;
 };
 
diff --git a/basic/source/inc/scriptcont.hxx b/basic/source/inc/scriptcont.hxx
index ea09a91..0a331b9 100644
--- a/basic/source/inc/scriptcont.hxx
+++ b/basic/source/inc/scriptcont.hxx
@@ -154,6 +154,7 @@ class SfxScriptLibrary : public SfxLibrary, public SfxScriptLibrary_BASE
         const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler ) SAL_OVERRIDE;
     virtual void storeResourcesToStorage( const ::com::sun::star::uno::Reference
         < ::com::sun::star::embed::XStorage >& xStorage ) SAL_OVERRIDE;
+    virtual bool isLoadedStorable() SAL_OVERRIDE;
 
 public:
     SfxScriptLibrary
diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx
index c3329d1..52d3494f 100644
--- a/basic/source/uno/namecont.cxx
+++ b/basic/source/uno/namecont.cxx
@@ -1909,8 +1909,6 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
 
         if( pImplLib->implIsModified() || bComplete )
         {
-// For the moment don't copy storage (as an optimisation )
-// but instead always write to storage from memory.
 // Testing pImplLib->implIsModified() is not reliable,
 // IMHO the value of pImplLib->implIsModified() should
 // reflect whether the library ( in-memory ) model
@@ -1921,9 +1919,14 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
 // temp storage when saving ( and later sets the root storage of the
 // library container ) and similar madness in dbaccess means some surgery
 // is required to make it possible to successfully use this optimisation
-#if 0
+// It would be possible to do the implSetModified() call below only
+// conditionally, but that would require an additional boolean to be
+// passed in via the XStorageBasedDocument::storeLibrariesToStorage()...
+// 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->implIsModified() && !mbOasis2OOoFormat && xSourceLibrariesStor.is() )
+            if (!mbOldInfoFormat && !pImplLib->isLoadedStorable() &&
+                !mbOasis2OOoFormat && xSourceLibrariesStor.is())
             {
                 try
                 {
@@ -1936,7 +1939,6 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
                 }
             }
             else
-#endif
             {
                 uno::Reference< embed::XStorage > xLibraryStor;
                 if( bStorage )
@@ -3037,6 +3039,11 @@ SfxLibrary::SfxLibrary( ModifiableHelper& _rModifiable, const Type& aType,
 {
 }
 
+bool SfxLibrary::isLoadedStorable()
+{
+    return mbLoaded && (!mbPasswordProtected || mbPasswordVerified);
+}
+
 void SfxLibrary::implSetModified( bool _bIsModified )
 {
     if ( mbIsModified == _bIsModified )
diff --git a/basic/source/uno/scriptcont.cxx b/basic/source/uno/scriptcont.cxx
index 574af68..1606bfc 100644
--- a/basic/source/uno/scriptcont.cxx
+++ b/basic/source/uno/scriptcont.cxx
@@ -1259,6 +1259,12 @@ SfxScriptLibrary::SfxScriptLibrary( ModifiableHelper& _rModifiable,
 {
 }
 
+bool SfxScriptLibrary::isLoadedStorable()
+{
+    // note: mbLoadedSource can only be true for password-protected lib!
+    return SfxLibrary::isLoadedStorable() && (!mbPasswordProtected || mbLoadedSource);
+}
+
 // Provide modify state including resources
 bool SfxScriptLibrary::isModified( void )
 {
diff --git a/sw/CppunitTest_sw_macros_test.mk b/sw/CppunitTest_sw_macros_test.mk
index 385e0c1..7b68eff 100644
--- a/sw/CppunitTest_sw_macros_test.mk
+++ b/sw/CppunitTest_sw_macros_test.mk
@@ -66,35 +66,39 @@ $(eval $(call gb_CppunitTest_use_api,sw_macros_test,\
 $(eval $(call gb_CppunitTest_use_ure,sw_macros_test))
 
 $(eval $(call gb_CppunitTest_use_components,sw_macros_test,\
-    basic/util/sb \
-    comphelper/util/comphelp \
-    configmgr/source/configmgr \
-    dbaccess/util/dba \
-    filter/source/config/cache/filterconfig1 \
-    forms/util/frm \
-    framework/util/fwk \
-    i18npool/util/i18npool \
-    oox/util/oox \
-    package/source/xstor/xstor \
-    package/util/package2 \
-    sax/source/expatwrap/expwrap \
-    sw/util/sw \
-    sw/util/swd \
-    sw/util/msword \
-    sw/util/vbaswobj \
-    scripting/source/basprov/basprov \
-    scripting/util/scriptframe \
-    sfx2/util/sfx \
-    sot/util/sot \
-    svl/source/fsstor/fsstorage \
-    svtools/util/svt \
-    toolkit/util/tk \
-    ucb/source/core/ucb1 \
-    ucb/source/ucp/file/ucpfile1 \
-    ucb/source/ucp/tdoc/ucptdoc1 \
-    unotools/util/utl \
-    unoxml/source/rdf/unordf \
-    unoxml/source/service/unoxml \
+	basic/util/sb \
+	embeddedobj/util/embobj \
+	comphelper/util/comphelp \
+	configmgr/source/configmgr \
+	dbaccess/util/dba \
+	filter/source/config/cache/filterconfig1 \
+	filter/source/storagefilterdetect/storagefd \
+	forms/util/frm \
+	framework/util/fwk \
+	i18npool/util/i18npool \
+	oox/util/oox \
+	package/source/xstor/xstor \
+	package/util/package2 \
+	sax/source/expatwrap/expwrap \
+	scripting/source/basprov/basprov \
+	scripting/util/scriptframe \
+	sfx2/util/sfx \
+	sot/util/sot \
+	svl/source/fsstor/fsstorage \
+	svtools/util/svt \
+	sw/util/msword \
+	sw/util/sw \
+	sw/util/swd \
+	sw/util/vbaswobj \
+	toolkit/util/tk \
+	ucb/source/core/ucb1 \
+	ucb/source/ucp/file/ucpfile1 \
+	ucb/source/ucp/tdoc/ucptdoc1 \
+	unotools/util/utl \
+	unoxml/source/rdf/unordf \
+	unoxml/source/service/unoxml \
+	xmloff/util/xo \
+	xmlsecurity/util/xsec_xmlsec \
 ))
 
 $(eval $(call gb_CppunitTest_use_configuration,sw_macros_test))
diff --git a/sw/qa/core/data/odt/fdo68983.odt b/sw/qa/core/data/odt/fdo68983.odt
new file mode 100644
index 0000000..01df104
Binary files /dev/null and b/sw/qa/core/data/odt/fdo68983.odt differ
diff --git a/sw/qa/core/macros-test.cxx b/sw/qa/core/macros-test.cxx
index d8ad141..f5565bc 100644
--- a/sw/qa/core/macros-test.cxx
+++ b/sw/qa/core/macros-test.cxx
@@ -20,7 +20,11 @@
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
 #include <com/sun/star/document/MacroExecMode.hpp>
+#include <com/sun/star/document/XEmbeddedScripts.hpp>
+#include <com/sun/star/script/XLibraryContainer.hpp>
+#include <com/sun/star/script/XLibraryContainerPassword.hpp>
 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
 #include <com/sun/star/drawing/XShapes.hpp>
 #include <com/sun/star/drawing/XShape.hpp>
@@ -35,6 +39,7 @@
 #include <comphelper/processfactory.hxx>
 
 #include <basic/sbxdef.hxx>
+#include <unotools/tempfile.hxx>
 
 #include <doc.hxx>
 #include "docsh.hxx"
@@ -63,6 +68,7 @@ public:
     void testVba();
 #endif
     void testFdo55289();
+    void testFdo68983();
     CPPUNIT_TEST_SUITE(SwMacrosTest);
 #if !defined(MACOSX) && !defined(WNT)
     //enable this test if you want to play with star basic macros in unit tests
@@ -71,6 +77,7 @@ public:
     CPPUNIT_TEST(testVba);
 #endif
     CPPUNIT_TEST(testFdo55289);
+    CPPUNIT_TEST(testFdo68983);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -190,6 +197,47 @@ void SwMacrosTest::testFdo55289()
     xShapeContent->attach(xEnd);
 }
 
+void SwMacrosTest::testFdo68983()
+{
+    const OUString aFileNameBase("StarBasic.");
+    OUString aFileName;
+    createFileURL("fdo68983.", "odt", aFileName);
+    Reference< com::sun::star::lang::XComponent > xComponent =
+        loadFromDesktop(aFileName, "com.sun.star.text.TextDocument");
+
+    CPPUNIT_ASSERT_MESSAGE("Failed to load StarBasic.ods", xComponent.is());
+
+    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);
+}
+
+
 SwMacrosTest::SwMacrosTest()
       : m_aBaseString("/sw/qa/core/data")
 {
commit 5ca4b9d51046b9b6a36b91c9abd0cc1e7c04b480
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed May 21 19:43:46 2014 +0200

    Revert "fdo#67685 open xSourceLibrariesStor only when needed"
    
    This reverts commit fc9080a0c60f263d00eb71111fcda72b3c0a2ebb.
    
    This bug was apparently introduced by
    af34774d260a68fc02cd78ba90dd8d4afaf1a2a4, which will be reverted
    in the next commit.
    
    Change-Id: I81ccb5bf9cc7e29fbf1e66d02f38268ee1fd1d0c

diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx
index bc5f796..c3329d1 100644
--- a/basic/source/uno/namecont.cxx
+++ b/basic/source/uno/namecont.cxx
@@ -1860,6 +1860,21 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
             DBG_UNHANDLED_EXCEPTION();
             return;
         }
+
+        // open the source storage which might be used to copy yet-unmodified libraries
+        try
+        {
+            if ( mxStorage->hasByName( maLibrariesDir ) || bInplaceStorage )
+            {
+                xSourceLibrariesStor = mxStorage->openStorageElement( maLibrariesDir,
+                                                   bInplaceStorage ? embed::ElementModes::READWRITE : embed::ElementModes::READ );
+            }
+        }
+        catch( const uno::Exception& )
+        {
+            DBG_UNHANDLED_EXCEPTION();
+            return;
+        }
     }
 
     int iArray = 0;
@@ -1988,21 +2003,6 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
     // then we need to clean up the temporary storage we used for this
     if ( bInplaceStorage && !sTempTargetStorName.isEmpty() )
     {
-        // open the source storage which might be used to copy yet-unmodified libraries
-        try
-        {
-            if ( mxStorage->hasByName( maLibrariesDir ) || bInplaceStorage )
-            {
-                xSourceLibrariesStor = mxStorage->openStorageElement( maLibrariesDir,
-                                                   bInplaceStorage ? embed::ElementModes::READWRITE : embed::ElementModes::READ );
-            }
-        }
-        catch( const uno::Exception& )
-        {
-            DBG_UNHANDLED_EXCEPTION();
-            return;
-        }
-
         SAL_WARN_IF(
             !xSourceLibrariesStor.is(), "basic",
             ("SfxLibrariesContainer::storeLibraries_impl: unexpected: we should"
commit 0e21019e0d61911b4c0ddef07691e9f9f6384cba
Author: Michael Stahl <mstahl at redhat.com>
Date:   Tue May 20 22:37:12 2014 +0200

    fdo#68983: Revert "remove #if 0 block (from ...
    
    ... af34774d260a68fc02cd78ba90dd8d4afaf1a2a4)"
    
    This reverts commit cbd1a89676f39135ed2e9c47d20475b2053289b9.
    
    Conflicts:
    	basic/source/uno/namecont.cxx
    
    Change-Id: I665f2e875c6b339ad718ca53fd0e54328efaeaff

diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx
index 8898781..bc5f796 100644
--- a/basic/source/uno/namecont.cxx
+++ b/basic/source/uno/namecont.cxx
@@ -1894,29 +1894,57 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
 
         if( pImplLib->implIsModified() || bComplete )
         {
-            {
-            uno::Reference< embed::XStorage > xLibraryStor;
-            if( bStorage )
+// For the moment don't copy storage (as an optimisation )
+// but instead always write to storage from memory.
+// Testing pImplLib->implIsModified() is not reliable,
+// IMHO the value of pImplLib->implIsModified() should
+// reflect whether the library ( in-memory ) model
+// is in sync with the library container's own storage. Currently
+// whenever the library model is written to *any* storage
+// pImplLib->implSetModified( sal_False ) is called
+// The way the code works, especially the way that sfx uses
+// temp storage when saving ( and later sets the root storage of the
+// library container ) and similar madness in dbaccess means some surgery
+// is required to make it possible to successfully use this optimisation
+#if 0
+            // Can we simply copy the storage?
+            if( !mbOldInfoFormat && !pImplLib->implIsModified() && !mbOasis2OOoFormat && xSourceLibrariesStor.is() )
             {
                 try
                 {
-                    xLibraryStor = xTargetLibrariesStor->openStorageElement(
-                                                                        rLib.aName,
-                                                                        embed::ElementModes::READWRITE );
+                    xSourceLibrariesStor->copyElementTo( rLib.aName, xTargetLibrariesStor, rLib.aName );
                 }
-                catch(const uno::Exception& )
+                catch( const uno::Exception& )
                 {
-                    #if OSL_DEBUG_LEVEL > 0
-                    Any aError( ::cppu::getCaughtException() );
-                    SAL_WARN(
-                        "basic",
-                        "couldn't create sub storage for library \""
-                            << rLib.aName << "\". Exception: "
-                            << comphelper::anyToString(aError));
-                    #endif
-                    throw;
+                    DBG_UNHANDLED_EXCEPTION();
+                    // TODO: error handling?
                 }
             }
+            else
+#endif
+            {
+                uno::Reference< embed::XStorage > xLibraryStor;
+                if( bStorage )
+                {
+                    try
+                    {
+                        xLibraryStor = xTargetLibrariesStor->openStorageElement(
+                                                                        rLib.aName,
+                                                                        embed::ElementModes::READWRITE );
+                    }
+                    catch(const uno::Exception& )
+                    {
+                        #if OSL_DEBUG_LEVEL > 0
+                        Any aError( ::cppu::getCaughtException() );
+                        SAL_WARN(
+                            "basic",
+                            "couldn't create sub storage for library \""
+                                << rLib.aName << "\". Exception: "
+                                << comphelper::anyToString(aError));
+                        #endif
+                        throw;
+                    }
+                }
 
                 // Maybe lib is not loaded?!
                 if( bComplete )


More information about the Libreoffice-commits mailing list