diff options
author | Mihai Varga <mihai.varga@collabora.com> | 2015-09-09 15:08:26 +0300 |
---|---|---|
committer | Mihai Varga <mihai.varga@collabora.com> | 2015-09-09 18:02:10 +0300 |
commit | 2290efa4a22d42cd9099b63b9138e4ff994c07f9 (patch) | |
tree | 421a915212dc86349f69196ba88fa1ddaa100359 /desktop | |
parent | 98483599b76fe6d0113a657f057ff5ad799ade96 (diff) |
LOK: moved the decalaration of LibLODocument_Impl to make it visible
We needed a better way to test LOK methods that are not app specific,
but are defined in /desktop/source/lib/init.cxx. So the decalaration
needs to be visible.
I also moved the `getStyles` test in the new test file
Change-Id: I98d97dc17a66e72732ca7bd848c131610790f48e
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/CppunitTest_desktop_lib.mk | 68 | ||||
-rw-r--r-- | desktop/Module_desktop.mk | 4 | ||||
-rw-r--r-- | desktop/inc/lib/init.hxx | 27 | ||||
-rw-r--r-- | desktop/qa/data/blank_text.odt | bin | 0 -> 8295 bytes | |||
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 116 | ||||
-rw-r--r-- | desktop/source/lib/init.cxx | 79 |
6 files changed, 252 insertions, 42 deletions
diff --git a/desktop/CppunitTest_desktop_lib.mk b/desktop/CppunitTest_desktop_lib.mk new file mode 100644 index 000000000000..be394600ddf0 --- /dev/null +++ b/desktop/CppunitTest_desktop_lib.mk @@ -0,0 +1,68 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,desktop_lib)) + +$(eval $(call gb_CppunitTest_add_exception_objects,desktop_lib, \ + desktop/qa/desktop_lib/test_desktop_lib \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,desktop_lib, \ + comphelper \ + cppu \ + cppuhelper \ + sal \ + sfx \ + sofficeapp \ + subsequenttest \ + sw \ + test \ + unotest \ + vcl \ + $(gb_UWINAPI) \ +)) + +$(eval $(call gb_CppunitTest_use_external,desktop_lib,boost_headers)) + +$(eval $(call gb_CppunitTest_use_api,desktop_lib,\ + offapi \ + udkapi \ +)) + +$(eval $(call gb_CppunitTest_use_ure,desktop_lib)) + +$(eval $(call gb_CppunitTest_use_vcl,desktop_lib)) + +$(eval $(call gb_CppunitTest_use_components,desktop_lib,\ + comphelper/util/comphelp \ + configmgr/source/configmgr \ + filter/source/config/cache/filterconfig1 \ + filter/source/storagefilterdetect/storagefd \ + framework/util/fwk \ + i18npool/util/i18npool \ + package/source/xstor/xstor \ + package/util/package2 \ + sax/source/expatwrap/expwrap \ + sfx2/util/sfx \ + svl/source/fsstor/fsstorage \ + svtools/util/svt \ + sw/util/sw \ + sw/util/swd \ + toolkit/util/tk \ + ucb/source/core/ucb1 \ + ucb/source/ucp/file/ucpfile1 \ + unoxml/source/service/unoxml \ + xmloff/util/xo \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,desktop_lib)) + +# vim: set noet sw=4 ts=4: diff --git a/desktop/Module_desktop.mk b/desktop/Module_desktop.mk index ab04152731ce..c725a268721e 100644 --- a/desktop/Module_desktop.mk +++ b/desktop/Module_desktop.mk @@ -130,4 +130,8 @@ $(eval $(call gb_Module_add_check_targets,desktop, \ CppunitTest_desktop_version \ )) +$(eval $(call gb_Module_add_check_targets,desktop, \ + CppunitTest_desktop_lib \ +)) + # vim: set ts=4 sw=4 et: diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx new file mode 100644 index 000000000000..b17f82566daf --- /dev/null +++ b/desktop/inc/lib/init.hxx @@ -0,0 +1,27 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#include <LibreOfficeKit/LibreOfficeKit.h> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <boost/shared_ptr.hpp> +#include "../../source/inc/desktopdllapi.h" + +using namespace css; +using namespace boost; + +namespace desktop { + struct DESKTOP_DLLPUBLIC LibLODocument_Impl : public _LibreOfficeKitDocument + { + uno::Reference<css::lang::XComponent> mxComponent; + shared_ptr< LibreOfficeKitDocumentClass > m_pDocumentClass; + + explicit LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent); + ~LibLODocument_Impl(); + }; +} diff --git a/desktop/qa/data/blank_text.odt b/desktop/qa/data/blank_text.odt Binary files differnew file mode 100644 index 000000000000..00b92d785acd --- /dev/null +++ b/desktop/qa/data/blank_text.odt diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx new file mode 100644 index 000000000000..c88a53f41edb --- /dev/null +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> + +#include <boost/property_tree/json_parser.hpp> +#include <comphelper/processfactory.hxx> +#include <sfx2/objsh.hxx> +#include <test/unoapi_test.hxx> + +#include "../../inc/lib/init.hxx" + +using namespace com::sun::star; +using namespace desktop; + +class DesktopLOKTest : public UnoApiTest +{ +public: + DesktopLOKTest() : UnoApiTest("/desktop/qa/data/") + { + } + + virtual ~DesktopLOKTest() + { + } + + virtual void setUp() SAL_OVERRIDE + { + UnoApiTest::setUp(); + mxDesktop.set(frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory()))); + }; + + virtual void tearDown() SAL_OVERRIDE + { + closeDoc(); + UnoApiTest::tearDown(); + }; + + LibLODocument_Impl* loadDoc(const char* pName); + void closeDoc(); + + void runAllTests(); + void testGetStyles(); + + CPPUNIT_TEST_SUITE(DesktopLOKTest); + CPPUNIT_TEST(runAllTests); + CPPUNIT_TEST_SUITE_END(); + + uno::Reference<lang::XComponent> mxComponent; +}; + +LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName) +{ + OUString aFileURL; + createFileURL(OUString::createFromAscii(pName), aFileURL); + mxComponent = loadFromDesktop(aFileURL, "com.sun.star.text.TextDocument"); + if (!mxComponent.is()) + { + CPPUNIT_ASSERT(false); + } + return new LibLODocument_Impl(mxComponent); +} + +void DesktopLOKTest::closeDoc() +{ + if (mxComponent.is()) + { + closeDocument(mxComponent); + mxComponent.clear(); + } +} + +void DesktopLOKTest::runAllTests() +{ + testGetStyles(); +} + +void DesktopLOKTest::testGetStyles() +{ + LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); + boost::property_tree::ptree aTree; + char* pJSON = pDocument->m_pDocumentClass->getStyles(pDocument); + std::stringstream aStream(pJSON); + boost::property_tree::read_json(aStream, aTree); + CPPUNIT_ASSERT( aTree.size() > 0 ); + + for (const std::pair<std::string, boost::property_tree::ptree>& rPair : aTree) + { + CPPUNIT_ASSERT( rPair.second.size() > 0); + if (rPair.first != "CharacterStyles" && + rPair.first != "ParagraphStyles" && + rPair.first != "FrameStyles" && + rPair.first != "PageStyles" && + rPair.first != "NumberingStyles" && + rPair.first != "CellStyles" && + rPair.first != "ShapeStyles") + { + CPPUNIT_FAIL("Unknown style family: " + rPair.first); + } + } + closeDoc(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index c7f3aabb58b7..a20decd3afbe 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -64,6 +64,7 @@ // We also need to hackily be able to start the main libreoffice thread: #include "../app/sofficemain.h" #include "../app/officeipcthread.hxx" +#include "../../inc/lib/init.hxx" using namespace css; using namespace vcl; @@ -72,7 +73,6 @@ using namespace utl; using namespace boost; -struct LibLODocument_Impl; struct LibLibreOffice_Impl; static LibLibreOffice_Impl *gImpl = NULL; @@ -237,51 +237,46 @@ static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis, static void doc_resetSelection (LibreOfficeKitDocument* pThis); static char* doc_getStyles(LibreOfficeKitDocument* pThis); -struct LibLODocument_Impl : public _LibreOfficeKitDocument -{ - uno::Reference<css::lang::XComponent> mxComponent; - shared_ptr< LibreOfficeKitDocumentClass > m_pDocumentClass; - explicit LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) : - mxComponent( xComponent ) +LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) : + mxComponent( xComponent ) +{ + if (!(m_pDocumentClass = gDocumentClass.lock())) { - if (!(m_pDocumentClass = gDocumentClass.lock())) - { - m_pDocumentClass.reset(new LibreOfficeKitDocumentClass); - - m_pDocumentClass->nSize = sizeof(LibreOfficeKitDocument); - - m_pDocumentClass->destroy = doc_destroy; - m_pDocumentClass->saveAs = doc_saveAs; - m_pDocumentClass->getDocumentType = doc_getDocumentType; - m_pDocumentClass->getParts = doc_getParts; - m_pDocumentClass->getPart = doc_getPart; - m_pDocumentClass->setPart = doc_setPart; - m_pDocumentClass->getPartName = doc_getPartName; - m_pDocumentClass->setPartMode = doc_setPartMode; - m_pDocumentClass->paintTile = doc_paintTile; - m_pDocumentClass->getDocumentSize = doc_getDocumentSize; - m_pDocumentClass->initializeForRendering = doc_initializeForRendering; - m_pDocumentClass->registerCallback = doc_registerCallback; - m_pDocumentClass->postKeyEvent = doc_postKeyEvent; - m_pDocumentClass->postMouseEvent = doc_postMouseEvent; - m_pDocumentClass->postUnoCommand = doc_postUnoCommand; - m_pDocumentClass->setTextSelection = doc_setTextSelection; - m_pDocumentClass->getTextSelection = doc_getTextSelection; - m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection; - m_pDocumentClass->resetSelection = doc_resetSelection; - m_pDocumentClass->getStyles = doc_getStyles; - - gDocumentClass = m_pDocumentClass; - } - pClass = m_pDocumentClass.get(); + m_pDocumentClass.reset(new LibreOfficeKitDocumentClass); + + m_pDocumentClass->nSize = sizeof(LibreOfficeKitDocument); + + m_pDocumentClass->destroy = doc_destroy; + m_pDocumentClass->saveAs = doc_saveAs; + m_pDocumentClass->getDocumentType = doc_getDocumentType; + m_pDocumentClass->getParts = doc_getParts; + m_pDocumentClass->getPart = doc_getPart; + m_pDocumentClass->setPart = doc_setPart; + m_pDocumentClass->getPartName = doc_getPartName; + m_pDocumentClass->setPartMode = doc_setPartMode; + m_pDocumentClass->paintTile = doc_paintTile; + m_pDocumentClass->getDocumentSize = doc_getDocumentSize; + m_pDocumentClass->initializeForRendering = doc_initializeForRendering; + m_pDocumentClass->registerCallback = doc_registerCallback; + m_pDocumentClass->postKeyEvent = doc_postKeyEvent; + m_pDocumentClass->postMouseEvent = doc_postMouseEvent; + m_pDocumentClass->postUnoCommand = doc_postUnoCommand; + m_pDocumentClass->setTextSelection = doc_setTextSelection; + m_pDocumentClass->getTextSelection = doc_getTextSelection; + m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection; + m_pDocumentClass->resetSelection = doc_resetSelection; + m_pDocumentClass->getStyles = doc_getStyles; + + gDocumentClass = m_pDocumentClass; } + pClass = m_pDocumentClass.get(); +} - ~LibLODocument_Impl() - { - mxComponent->dispose(); - } -}; +LibLODocument_Impl::~LibLODocument_Impl() +{ + mxComponent->dispose(); +} static void doc_destroy(LibreOfficeKitDocument *pThis) { |