[Libreoffice-commits] core.git: desktop/CppunitTest_desktop_lib.mk desktop/inc desktop/Module_desktop.mk desktop/qa desktop/source libreofficekit/qa

Mihai Varga mihai.varga at collabora.com
Wed Sep 9 08:02:53 PDT 2015


 desktop/CppunitTest_desktop_lib.mk          |   68 ++++++++++++++++
 desktop/Module_desktop.mk                   |    4 
 desktop/inc/lib/init.hxx                    |   27 ++++++
 desktop/qa/data/blank_text.odt              |binary
 desktop/qa/desktop_lib/test_desktop_lib.cxx |  116 ++++++++++++++++++++++++++++
 desktop/source/lib/init.cxx                 |   79 ++++++++-----------
 libreofficekit/qa/unit/tiledrendering.cxx   |   34 --------
 7 files changed, 252 insertions(+), 76 deletions(-)

New commits:
commit 2290efa4a22d42cd9099b63b9138e4ff994c07f9
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Wed Sep 9 15:08:26 2015 +0300

    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

diff --git a/desktop/CppunitTest_desktop_lib.mk b/desktop/CppunitTest_desktop_lib.mk
new file mode 100644
index 0000000..be39460
--- /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 ab04152..c725a26 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 0000000..b17f825
--- /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
new file mode 100644
index 0000000..00b92d7
Binary files /dev/null and b/desktop/qa/data/blank_text.odt differ
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 0000000..c88a53f
--- /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 c7f3aab..a20decd 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)
 {
diff --git a/libreofficekit/qa/unit/tiledrendering.cxx b/libreofficekit/qa/unit/tiledrendering.cxx
index a4e5525..515fe8e0 100644
--- a/libreofficekit/qa/unit/tiledrendering.cxx
+++ b/libreofficekit/qa/unit/tiledrendering.cxx
@@ -68,7 +68,6 @@ public:
     void testDocumentTypes( Office* pOffice );
     void testImpressSlideNames( Office* pOffice );
     void testCalcSheetNames( Office* pOffice );
-    void testGetStyles( Office* pOffice );
 #if 0
     void testOverlay( Office* pOffice );
 #endif
@@ -95,7 +94,6 @@ void TiledRenderingTest::runAllTests()
     testDocumentTypes( pOffice.get() );
     testImpressSlideNames( pOffice.get() );
     testCalcSheetNames( pOffice.get() );
-    testGetStyles( pOffice.get() );
 #if 0
     testOverlay( pOffice.get() );
 #endif
@@ -184,38 +182,6 @@ void TiledRenderingTest::testCalcSheetNames( Office* pOffice )
     CPPUNIT_ASSERT( strcmp( pDocument->getPartName( 2 ), "Sheet3" ) == 0 );
 }
 
-void TiledRenderingTest::testGetStyles( Office* pOffice )
-{
-    const string sDocPath = m_sSrcRoot + "/libreofficekit/qa/data/blank_text.odt";
-    const string sLockFile = m_sSrcRoot +"/libreofficekit/qa/data/.~lock.blank_text.odt#";
-
-    // FIXME: LOK will fail when trying to open a locked file
-    remove( sLockFile.c_str() );
-
-    scoped_ptr< Document> pDocument( pOffice->documentLoad( sDocPath.c_str() ) );
-
-    boost::property_tree::ptree aTree;
-    char* pJSON = pDocument->getStyles();
-    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);
-        }
-    }
-}
-
 #if 0
 static void dumpRGBABitmap( const OUString& rPath, const unsigned char* pBuffer,
                             const int nWidth, const int nHeight )


More information about the Libreoffice-commits mailing list