diff options
author | David Tardon <dtardon@redhat.com> | 2014-03-30 17:41:06 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2014-03-30 19:06:32 +0200 |
commit | b05bf3e503b68f94235a8166601f07963415a904 (patch) | |
tree | 37ada2369406406e687be92658856ff1e1ee026c /writerperfect/qa | |
parent | a4a723c0af8859c9c01cd32d5b2df84e6328024a (diff) |
close the opened document correctly
Change-Id: I457d6a8f547e6b01b83db2d44e32fdcbe2fd718e
Diffstat (limited to 'writerperfect/qa')
-rw-r--r-- | writerperfect/qa/unit/WpftImportTestBase.cxx | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/writerperfect/qa/unit/WpftImportTestBase.cxx b/writerperfect/qa/unit/WpftImportTestBase.cxx index 53e41ab7d5e2..773fa3b26451 100644 --- a/writerperfect/qa/unit/WpftImportTestBase.cxx +++ b/writerperfect/qa/unit/WpftImportTestBase.cxx @@ -15,10 +15,14 @@ #include <com/sun/star/document/XImporter.hpp> #include <com/sun/star/document/XTypeDetection.hpp> #include <com/sun/star/frame/theDesktop.hpp> +#include <com/sun/star/frame/XController.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XModel.hpp> #include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/lang/IllegalArgumentException.hpp> #include <com/sun/star/lang/XComponent.hpp> #include <com/sun/star/ucb/SimpleFileAccess.hpp> +#include <com/sun/star/util/XCloseable.hpp> #include "WpftImportTestBase.hxx" @@ -30,6 +34,7 @@ namespace io = com::sun::star::io; namespace lang = com::sun::star::lang; namespace ucb = com::sun::star::ucb; namespace uno = com::sun::star::uno; +namespace util = com::sun::star::util; namespace writerperfect { @@ -70,12 +75,14 @@ void WpftImportTestBase::tearDown() bool WpftImportTestBase::load(const OUString &, const OUString &rURL, const OUString &, unsigned int, unsigned int, unsigned int) { + // create an empty frame const uno::Reference<lang::XComponent> xDoc( m_xDesktop->loadComponentFromURL(m_aFactoryURL, "_blank", 0, uno::Sequence<beans::PropertyValue>()), uno::UNO_QUERY_THROW); bool result = false; + // try to import the document (and load it into the prepared frame) try { const uno::Reference<document::XImporter> xImporter(m_xFilter, uno::UNO_QUERY_THROW); @@ -105,7 +112,39 @@ bool WpftImportTestBase::load(const OUString &, const OUString &rURL, const OUSt // ignore } - xDoc->dispose(); + // close the opened document + uno::Reference<util::XCloseable> xCloseable(xDoc, uno::UNO_QUERY); + + if (!xCloseable.is()) + { + uno::Reference<frame::XController> xController(xDoc, uno::UNO_QUERY); + + if (!xController.is()) + { + const uno::Reference<frame::XModel> xModel(xDoc, uno::UNO_QUERY); + if (xModel.is()) + xController = xModel->getCurrentController(); + } + + if (xController.is()) + { + const uno::Reference<frame::XFrame> xFrame = xController->getFrame(); + if (xFrame.is()) + xCloseable.set(xFrame, uno::UNO_QUERY); + } + } + + try + { + if (xCloseable.is()) + xCloseable->close(true); + else + xDoc->dispose(); + } + catch (const uno::Exception &) + { + // ignore + } return result; } |