[Libreoffice-commits] core.git: desktop/inc desktop/source vcl/source

Caolán McNamara caolanm at redhat.com
Fri Oct 9 05:06:01 PDT 2015


 desktop/inc/app.hxx        |    7 +++++
 desktop/source/app/app.cxx |   59 ++++++++++++++++++++++++++++++++++++++++++++-
 vcl/source/app/svapp.cxx   |    1 
 3 files changed, 66 insertions(+), 1 deletion(-)

New commits:
commit d5c18dc3e8bb107e8ddf960261bb9257f2e49a35
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Fri Oct 9 11:06:56 2015 +0100

    afl-eventtesting: provide a way to pseudo-restart
    
    i.e. to reset to the initial post-startup state
    
    performance still isn't great unfortunately, 0.7
    cycles per second before this, 2.6 after this
    
    Change-Id: Ib9d83b70f0cf052af36a49ed5bacef295fe9ed11
    Reviewed-on: https://gerrit.libreoffice.org/19269
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/desktop/inc/app.hxx b/desktop/inc/app.hxx
index 92577f8..cd28566 100644
--- a/desktop/inc/app.hxx
+++ b/desktop/inc/app.hxx
@@ -27,6 +27,7 @@
 #include <vcl/timer.hxx>
 #include <tools/resmgr.hxx>
 #include <unotools/bootstrap.hxx>
+#include <com/sun/star/frame/XDesktop2.hpp>
 #include <com/sun/star/task/XStatusIndicator.hpp>
 #include <com/sun/star/uno/Reference.h>
 #include <osl/mutex.hxx>
@@ -156,6 +157,12 @@ class Desktop : public Application
         */
         void                    CheckFirstRun( );
 
+        /** for ui-testing provide a mechanism to pseudo-restart by closing the
+            open frames and reopen the frame that appeared post initial startup
+        */
+        void CloseFrameAndReopen(css::uno::Reference<css::frame::XDesktop2> xDesktop);
+        void DoExecute(css::uno::Reference<css::frame::XDesktop2> xDesktop);
+
         /// does initializations which are necessary for the first run of the office
         static void             DoFirstRunInitializations();
 
diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx
index 58567e9..79b3c86 100644
--- a/desktop/source/app/app.cxx
+++ b/desktop/source/app/app.cxx
@@ -23,6 +23,9 @@
 #include <sal/config.h>
 
 #include <iostream>
+#if defined UNX
+#include <signal.h>
+#endif
 
 #include "app.hxx"
 #include "desktop.hrc"
@@ -47,6 +50,7 @@
 #include <com/sun/star/configuration/CorruptedConfigurationException.hpp>
 #include <com/sun/star/configuration/theDefaultProvider.hpp>
 #include <com/sun/star/util/XFlushable.hpp>
+#include <com/sun/star/util/XModifiable.hpp>
 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
 #include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/frame/StartModule.hpp>
@@ -1270,6 +1274,59 @@ struct ExecuteGlobals
 
 static ExecuteGlobals* pExecGlobals = NULL;
 
+#define PERSIST_MAX 100
+unsigned int persist_cnt;
+
+//This closes the current frame and reopens the initial frame, useful for
+//pseudo-restarting, i.e. attempt to effectively reset to the initial state of
+//the application post start-up for ui-testing
+void Desktop::CloseFrameAndReopen(Reference<XDesktop2> xDesktop)
+{
+    Reference<css::frame::XFrame> xFrame = xDesktop->getActiveFrame();
+    Reference<css::frame::XDispatchProvider> xProvider(xFrame, css::uno::UNO_QUERY);
+
+    css::uno::Reference<css::frame::XController > xController = xFrame->getController();
+    css::uno::Reference<css::frame::XModel> xModel = xController->getModel();
+    css::uno::Reference< css::util::XModifiable > xModifiable(xModel, css::uno::UNO_QUERY);
+    xModifiable->setModified(false);
+
+    css::util::URL aCommand;
+    aCommand.Complete = ".uno:CloseDoc";
+
+    css::uno::Reference<css::uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
+    Reference< css::util::XURLTransformer > xParser = css::util::URLTransformer::create(xContext);
+    xParser->parseStrict(aCommand);
+
+    css::uno::Reference< css::frame::XDispatch > xDispatch = xProvider->queryDispatch(aCommand, OUString(), 0);
+    xDispatch->dispatch(aCommand, css::uno::Sequence< css::beans::PropertyValue >());
+
+    OpenDefault();
+}
+
+//This just calls Execute() for all normal uses of LibreOffice, but for
+//ui-testing if AFL_PERSISTENT is set then on exit it will pseudo-restart (up
+//to PERSIST_MAX times)
+void Desktop::DoExecute(Reference<XDesktop2> xDesktop)
+{
+try_again:
+    {
+        Execute();
+        /* To signal successful completion of a run, we need to deliver
+           SIGSTOP to our own process, then loop to the very beginning
+           once we're resumed by the supervisor process. We do this only
+           if AFL_PERSISTENT is set to retain normal behavior when the
+           program is executed directly; and take note of PERSIST_MAX. */
+        if (getenv("AFL_PERSISTENT") && persist_cnt++ < PERSIST_MAX)
+        {
+            CloseFrameAndReopen(xDesktop);
+#if defined UNX
+            raise(SIGSTOP);
+#endif
+            goto try_again;
+        }
+    }
+}
+
 int Desktop::Main()
 {
     pExecGlobals = new ExecuteGlobals();
@@ -1585,7 +1642,7 @@ int Desktop::Main()
                 // if this run of the office is triggered by restart, some additional actions should be done
                 DoRestartActionsIfNecessary( !rCmdLineArgs.IsInvisible() && !rCmdLineArgs.IsNoQuickstart() );
 
-                Execute();
+                DoExecute(xDesktop);
             }
         }
         catch(const css::document::CorruptedFilterConfigurationException& exFilterCfg)
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index 961d4e6..a583307 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -403,6 +403,7 @@ void Application::Execute()
 {
     ImplSVData* pSVData = ImplGetSVData();
     pSVData->maAppData.mbInAppExecute = true;
+    pSVData->maAppData.mbAppQuit = false;
 
     sal_uInt16 n = GetCommandLineParamCount();
     for (sal_uInt16 i = 0; i != n; ++i)


More information about the Libreoffice-commits mailing list