From 6f223177f995d3c9347226356e96c67a62a7ec51 Mon Sep 17 00:00:00 2001 From: David Tardon Date: Sat, 25 Feb 2012 13:43:14 +0100 Subject: convert pdfimport test --- sdext/CppunitTest_pdfimport.mk | 90 ++++++++++++++++++++ sdext/Module_sdext.mk | 4 + sdext/source/pdfimport/test/makefile.mk | 141 -------------------------------- sdext/source/pdfimport/test/tests.cxx | 101 ++++++++++++++++++++++- 4 files changed, 192 insertions(+), 144 deletions(-) create mode 100644 sdext/CppunitTest_pdfimport.mk delete mode 100755 sdext/source/pdfimport/test/makefile.mk diff --git a/sdext/CppunitTest_pdfimport.mk b/sdext/CppunitTest_pdfimport.mk new file mode 100644 index 000000000000..bbda2d544960 --- /dev/null +++ b/sdext/CppunitTest_pdfimport.mk @@ -0,0 +1,90 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# Version: MPL 1.1 / GPLv3+ / LGPLv3+ +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License or as specified alternatively below. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# Major Contributor(s): +# Copyright (C) 2012 Red Hat, Inc., David Tardon +# (initial developer) +# +# All Rights Reserved. +# +# For minor contributions see the git repository. +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 3 or later (the "GPLv3+"), or +# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), +# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable +# instead of those above. + +$(eval $(call gb_CppunitTest_CppunitTest,sdext_pdfimport)) + +$(eval $(call gb_CppunitTest_add_defs,sdext_pdfimport,\ + -DPDFIMPORT_EXECUTABLE_LOCATION=\"file://$(dir $(call gb_Executable_get_target,xpdfimport))\" \ +)) + +$(eval $(call gb_CppunitTest_add_api,sdext_pdfimport,\ + offapi \ + udkapi \ +)) + +$(eval $(call gb_CppunitTest_set_include,sdext_pdfimport,\ + -I$(SRCDIR)/sdext/source/pdfimport/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_CppunitTest_use_externals,sdext_pdfimport,\ + zlib \ +)) + +$(eval $(call gb_CppunitTest_add_linked_libs,sdext_pdfimport,\ + comphelper \ + cppu \ + cppuhelper \ + sal \ + test \ + unotest \ + $(gb_STDLIBS) \ +)) + +$(eval $(call gb_CppunitTest_add_linked_static_libs,sdext_pdfimport,\ + basegfx_s \ +)) + +$(eval $(call gb_CppunitTest_add_library_objects,sdext_pdfimport,\ + pdfimport \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sdext_pdfimport,\ + sdext/source/pdfimport/test/tests \ +)) + +$(eval $(call gb_CppunitTest_uses_ure,sdext_pdfimport)) + +$(eval $(call gb_CppunitTest_add_type_rdbs,sdext_pdfimport,\ + types \ +)) + +$(eval $(call gb_CppunitTest_add_components,sdext_pdfimport,\ + comphelper/util/comphelp \ + configmgr/source/configmgr \ + i18npool/util/i18npool \ + ucb/source/core/ucb1 \ + ucb/source/ucp/file/ucpfile1 \ +)) + +$(eval $(call gb_CppunitTest_set_args,sdext_pdfimport,\ + --headless \ + --protector unoexceptionprotector$(gb_Library_DLLEXT) unoexceptionprotector \ + "-env:CONFIGURATION_LAYERS=xcsxcu:$(call gb_CppunitTarget__make_url,$(OUTDIR)/xml/registry)" \ +)) + +# vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sdext/Module_sdext.mk b/sdext/Module_sdext.mk index a8fef26590e4..8f496905f175 100644 --- a/sdext/Module_sdext.mk +++ b/sdext/Module_sdext.mk @@ -45,6 +45,10 @@ $(eval $(call gb_Module_add_targets,sdext,\ Library_pdfimport \ Package_pdfimport_keywords \ )) + +$(eval $(call gb_Module_add_check_targets,sdext,\ + CppunitTest_pdfimport \ +)) endif ifeq ($(ENABLE_PRESENTER_SCREEN),YES) diff --git a/sdext/source/pdfimport/test/makefile.mk b/sdext/source/pdfimport/test/makefile.mk deleted file mode 100755 index fdc3966c702f..000000000000 --- a/sdext/source/pdfimport/test/makefile.mk +++ /dev/null @@ -1,141 +0,0 @@ -#************************************************************************* -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# Copyright 2000, 2010 Oracle and/or its affiliates. -# -# OpenOffice.org - a multi-platform office productivity suite -# -# This file is part of OpenOffice.org. -# -# OpenOffice.org is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License version 3 -# only, as published by the Free Software Foundation. -# -# OpenOffice.org is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License version 3 for more details -# (a copy is included in the LICENSE file that accompanied this code). -# -# You should have received a copy of the GNU Lesser General Public License -# version 3 along with OpenOffice.org. If not, see -# -# for a copy of the LGPLv3 License. -# -#************************************************************************* - -PRJ=..$/..$/.. -PRJNAME=sdext -TARGET=tests -TARGETTYPE=CUI -ENABLE_EXCEPTIONS=TRUE - -# --- Settings ----------------------------------------------------- - -.INCLUDE: settings.mk - -# --- test lib ------------------------------------------------------ - -.IF "$(ENABLE_PDFIMPORT)" == "NO" -@all: - @echo "PDF Import extension disabled." -.ENDIF - -CFLAGSCXX += $(CPPUNIT_CFLAGS) - -.IF "$(SYSTEM_ZLIB)" == "YES" -CFLAGS+=-DSYSTEM_ZLIB -.ENDIF - -SHL1OBJS= \ - $(SLO)$/tests.obj - -SHL1LIBS=\ - $(SLB)$/pdfmisc.lib \ - $(SLB)$/pdfparse.lib \ - $(SLB)$/pdfsax.lib \ - $(SLB)$/pdfparsetree.lib \ - $(SLB)$/pdfodf.lib \ - $(SLB)$/xpdfwrapper.lib \ - $(SLB)$/pdfimport.lib - -SHL1TARGET=$(TARGET) -SHL1STDLIBS=\ - $(BASEGFXLIB) \ - $(UNOTOOLSLIB) \ - $(CANVASTOOLSLIB) \ - $(COMPHELPERLIB) \ - $(CPPUHELPERLIB) \ - $(CPPUNITLIB) \ - $(ZLIB3RDLIB) \ - $(CPPULIB) \ - $(UNOTESTLIB) \ - $(TESTLIB) \ - $(SALLIB) - - -SHL1IMPLIB= i$(SHL1TARGET) -DEF1NAME =$(SHL1TARGET) -SHL1VERSIONMAP = export.map - -# --- pdf2xml binary ------------------------------------------------------ - -TARGET2=pdf2xml - -APP1TARGET=$(TARGET2) -APP1LIBSALCPPRT= -APP1OBJS=$(SLO)$/pdf2xml.obj - -APP1LIBS=\ - $(SLB)$/pdfmisc.lib \ - $(SLB)$/pdfparse.lib \ - $(SLB)$/pdfsax.lib \ - $(SLB)$/pdfparsetree.lib \ - $(SLB)$/pdfodf.lib \ - $(SLB)$/xpdfwrapper.lib \ - $(SLB)$/pdfimport.lib - -APP1STDLIBS=\ - $(BASEGFXLIB) \ - $(UNOTOOLSLIB) \ - $(CANVASTOOLSLIB) \ - $(COMPHELPERLIB) \ - $(CPPUHELPERLIB) \ - $(CPPUNITLIB) \ - $(ZLIB3RDLIB) \ - $(CPPULIB) \ - $(SALLIB) - -# --- pdfunzip binary ------------------------------------------------------ - -TARGET3=pdfunzip - -APP2TARGET=$(TARGET3) -APP2LIBSALCPPRT= -APP2OBJS=$(SLO)$/pdfunzip.obj - -APP2LIBS=\ - $(SLB)$/pdfmisc.lib \ - $(SLB)$/pdfparse.lib \ - $(SLB)$/pdfsax.lib \ - $(SLB)$/pdfparsetree.lib \ - $(SLB)$/pdfodf.lib \ - $(SLB)$/xpdfwrapper.lib \ - $(SLB)$/pdfimport.lib - -APP2STDLIBS=\ - $(BASEGFXLIB) \ - $(UNOTOOLSLIB) \ - $(CANVASTOOLSLIB) \ - $(COMPHELPERLIB) \ - $(CPPUHELPERLIB) \ - $(CPPUNITLIB) \ - $(ZLIB3RDLIB) \ - $(CPPULIB) \ - $(SALLIB) - -# --- Targets ------------------------------------------------------ - -.INCLUDE : target.mk -.INCLUDE : _cppunit.mk diff --git a/sdext/source/pdfimport/test/tests.cxx b/sdext/source/pdfimport/test/tests.cxx index 0fd470e26c44..78d0a5ea8026 100644 --- a/sdext/source/pdfimport/test/tests.cxx +++ b/sdext/source/pdfimport/test/tests.cxx @@ -60,6 +60,7 @@ #include "cppunit/plugin/TestPlugIn.h" #include +#include #include #include #include @@ -79,6 +80,7 @@ #include #include +#include using namespace ::pdfparse; using namespace ::pdfi; @@ -477,6 +479,92 @@ namespace bool m_bDashedLineSeen; }; + /* + This is a (hackish) way to set correct path to the xpdfimport executable + during build. Because $OUTDIR/bin is not in $PATH, it will not be found + directly. We also know that xpdf_ImportFromFile() tries to get the path + through the extension mechanism, but there are no registered extensions + available when this test is run. So we create a phony + PackageInformationProvider that pretends such extension exists and passes + out the path we need .-) + */ + + typedef cppu::WeakComponentImplHelper1 PackageInformationProvider_Base; + + class PackageInformationProvider + : private cppu::BaseMutex + , public PackageInformationProvider_Base + { + public: + PackageInformationProvider() + : PackageInformationProvider_Base(m_aMutex) + { + } + + private: + virtual rtl::OUString SAL_CALL getPackageLocation(rtl::OUString const&) + throw() + { + rtl::OUString const aLocation(RTL_CONSTASCII_USTRINGPARAM(PDFIMPORT_EXECUTABLE_LOCATION)); + return aLocation; + } + + virtual uno::Sequence > SAL_CALL isUpdateAvailable(rtl::OUString const&) + throw() + { + // dummy impl. + uno::Sequence > const aSeq; + return aSeq; + } + + virtual uno::Sequence > SAL_CALL getExtensionList() + throw() + { + // dummy impl. + uno::Sequence > const aSeq; + return aSeq; + } + }; + + typedef cppu::WeakComponentImplHelper1 ComponentContext_Base; + + class ComponentContext + : private cppu::BaseMutex + , public ComponentContext_Base + { + public: + explicit ComponentContext(uno::Reference const& xParent) + : ComponentContext_Base(m_aMutex) + , m_xParent(xParent) + { + assert(m_xParent.is()); + } + + private: + virtual uno::Any SAL_CALL getValueByName(rtl::OUString const& rName) + throw() + { + if (rName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("/singletons/com.sun.star.deployment.PackageInformationProvider"))) + { + uno::Reference const xProvider(new PackageInformationProvider()); + uno::Any aComponent; + aComponent <<= xProvider; + return aComponent; + } + + return m_xParent->getValueByName(rName); + } + + virtual uno::Reference SAL_CALL getServiceManager() + throw() + { + return m_xParent->getServiceManager(); + } + + private: + uno::Reference m_xParent; + }; + class PDFITest : public test::BootstrapFixture { public: @@ -487,7 +575,7 @@ namespace pSink, uno::Reference< task::XInteractionHandler >(), rtl::OUString(), - getComponentContext() ); + impl_getComponentContext() ); // make destruction explicit, a bunch of things are // checked in the destructor @@ -496,7 +584,7 @@ namespace void testOdfDrawExport() { - pdfi::PDFIRawAdaptor aAdaptor( getComponentContext() ); + pdfi::PDFIRawAdaptor aAdaptor( impl_getComponentContext() ); aAdaptor.setTreeVisitorFactory( createDrawTreeVisitorFactory() ); ::rtl::OUString aURL, aAbsURL, aBaseURL; @@ -512,7 +600,7 @@ namespace void testOdfWriterExport() { - pdfi::PDFIRawAdaptor aAdaptor( getComponentContext() ); + pdfi::PDFIRawAdaptor aAdaptor( impl_getComponentContext() ); aAdaptor.setTreeVisitorFactory( createWriterTreeVisitorFactory() ); ::rtl::OUString aURL, aAbsURL, aBaseURL; @@ -531,6 +619,13 @@ namespace CPPUNIT_TEST(testOdfWriterExport); CPPUNIT_TEST(testOdfDrawExport); CPPUNIT_TEST_SUITE_END(); + + private: + uno::Reference impl_getComponentContext() + { + uno::Reference const xCtxt(new ComponentContext(getComponentContext())); + return xCtxt; + } }; } -- cgit