summaryrefslogtreecommitdiffstats
path: root/scaddins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-07-27 11:06:41 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-07-30 10:49:27 +0200
commit6e35794cad555485955c3b43593497dcdbf29840 (patch)
tree430c0299f21fb62faf6d0ba5e04410fafdda14d2 /scaddins
parenttdf#133967: sw_uiwriter: Add unittest (diff)
downloadcore-6e35794cad555485955c3b43593497dcdbf29840.tar.gz
core-6e35794cad555485955c3b43593497dcdbf29840.zip
terminate XDesktop properly in unit tests
So that the UNO constructor work can continue - where we need the desktop to be disposed properly so that all UNO constructors objects have their dispose() called, and they can clean up their global state. We detect this case by changing a SAL_WARN to an assert in Desktop::disposing() (*) in ~ScTabViewShell, don't call EnterHandler, because that tries to create EditEngine's and other stuff, which crashes (*) Need a fake singleton so that the servicemanager calls dispose() on the AnalysAddIn and we can clear the global variable there. Change-Id: Id13b51e17afc16fcbbc65d64281cdf847e4a58cf Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99640 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'scaddins')
-rw-r--r--scaddins/source/analysis/analysis.component2
-rw-r--r--scaddins/source/analysis/analysis.cxx19
-rw-r--r--scaddins/source/analysis/analysis.hxx12
3 files changed, 29 insertions, 4 deletions
diff --git a/scaddins/source/analysis/analysis.component b/scaddins/source/analysis/analysis.component
index 4f287f727ce8..bda78b4e5ab9 100644
--- a/scaddins/source/analysis/analysis.component
+++ b/scaddins/source/analysis/analysis.component
@@ -23,5 +23,7 @@
constructor="scaddins_AnalysisAddIn_get_implementation">
<service name="com.sun.star.sheet.AddIn"/>
<service name="com.sun.star.sheet.addin.Analysis"/>
+ <!-- fake singleton so that the servicemanager calls dispose() on the component and we can free the global var -->
+ <singleton name="com.sun.star.sheet.addin.theAnalysis"/>
</implementation>
</component>
diff --git a/scaddins/source/analysis/analysis.cxx b/scaddins/source/analysis/analysis.cxx
index b951eca29fc6..8b423b86331f 100644
--- a/scaddins/source/analysis/analysis.cxx
+++ b/scaddins/source/analysis/analysis.cxx
@@ -43,6 +43,10 @@ using namespace ::com::sun::star;
using namespace sca::analysis;
using namespace std;
+static osl::Mutex g_InstanceMutex;
+static rtl::Reference<AnalysisAddIn> g_Instance;
+static bool g_Disposed;
+
OUString AnalysisAddIn::GetFuncDescrStr(const char** pResId, sal_uInt16 nStrIndex)
{
return AnalysisResId(pResId[nStrIndex - 1]);
@@ -59,6 +63,7 @@ void AnalysisAddIn::InitData()
}
AnalysisAddIn::AnalysisAddIn( const uno::Reference< uno::XComponentContext >& xContext ) :
+ AnalysisAddIn_Base(m_aMutex),
aAnyConv( xContext )
{
}
@@ -67,6 +72,14 @@ AnalysisAddIn::~AnalysisAddIn()
{
}
+void AnalysisAddIn::dispose()
+{
+ AnalysisAddIn_Base::dispose();
+ osl::MutexGuard aGuard(g_InstanceMutex);
+ g_Instance.clear();
+ g_Disposed = true;
+}
+
sal_Int32 AnalysisAddIn::getDateMode(
const uno::Reference< beans::XPropertySet >& xPropSet,
const uno::Any& rAny )
@@ -1056,7 +1069,11 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
scaddins_AnalysisAddIn_get_implementation(
css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
{
- static rtl::Reference<AnalysisAddIn> g_Instance(new AnalysisAddIn(context));
+ osl::MutexGuard aGuard(g_InstanceMutex);
+ if (g_Disposed)
+ return nullptr;
+ if (!g_Instance)
+ g_Instance.set(new AnalysisAddIn(context));
g_Instance->acquire();
return static_cast<cppu::OWeakObject*>(g_Instance.get());
}
diff --git a/scaddins/source/analysis/analysis.hxx b/scaddins/source/analysis/analysis.hxx
index 5b9d90bdf172..dbfe11a9c2c0 100644
--- a/scaddins/source/analysis/analysis.hxx
+++ b/scaddins/source/analysis/analysis.hxx
@@ -27,7 +27,8 @@
#include <com/sun/star/sheet/addin/XAnalysis.hpp>
#include <com/sun/star/sheet/XCompatibilityNames.hpp>
-#include <cppuhelper/implbase.hxx>
+#include <cppuhelper/compbase.hxx>
+#include <cppuhelper/basemutex.hxx>
#include "analysishelper.hxx"
@@ -36,12 +37,14 @@
namespace com::sun::star::lang { class XMultiServiceFactory; }
namespace com::sun::star::sheet { struct LocalizedName; }
-class AnalysisAddIn : public cppu::WeakImplHelper<
+typedef cppu::WeakComponentImplHelper<
css::sheet::XAddIn,
css::sheet::XCompatibilityNames,
css::sheet::addin::XAnalysis,
css::lang::XServiceName,
- css::lang::XServiceInfo >
+ css::lang::XServiceInfo > AnalysisAddIn_Base;
+
+class AnalysisAddIn : private cppu::BaseMutex, public AnalysisAddIn_Base
{
private:
css::lang::Locale aFuncLoc;
@@ -75,6 +78,9 @@ public:
virtual ~AnalysisAddIn() override;
+ // XComponent
+ virtual void SAL_CALL dispose() override;
+
/// @throws css::uno::RuntimeException
/// @throws css::lang::IllegalArgumentException
double FactDouble( sal_Int32 nNum );