diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-07-05 15:04:08 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-07-05 15:04:08 +0100 |
commit | c79da65498963caf32d7931627c7781cce04bcea (patch) | |
tree | da2258c8c8b20fde3232dd390d013e2c3b48543f /sc | |
parent | 6cfa32e2ff651fb2678980a9fff149628379db93 (diff) |
make filters test a seperate test lib, otherwise conflicts on internal dlopen
Diffstat (limited to 'sc')
-rw-r--r-- | sc/CppunitTest_sc_test_filters.mk | 106 | ||||
-rw-r--r-- | sc/Module_sc.mk | 1 | ||||
-rw-r--r-- | sc/qa/unit/filters-test.cxx | 243 | ||||
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 81 |
4 files changed, 350 insertions, 81 deletions
diff --git a/sc/CppunitTest_sc_test_filters.mk b/sc/CppunitTest_sc_test_filters.mk new file mode 100644 index 000000000000..578d2b74ed6f --- /dev/null +++ b/sc/CppunitTest_sc_test_filters.mk @@ -0,0 +1,106 @@ +#************************************************************************* +# 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. +# +# The Initial Developer of the Original Code is +# Caolán McNamara, Red Hat, Inc. <caolanm@redhat.com> +# Portions created by the Initial Developer are Copyright (C) 2011 the +# Initial Developer. All Rights Reserved. +# +# Major Contributor(s): +# +# 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,sc_filters_test)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sc_filters_test, \ + sc/qa/unit/filters-test \ +)) + +$(call gb_CxxObject_get_target,sc/qa/unit/filters-test): $(WORKDIR)/AllLangRes/sc + +$(eval $(call gb_CppunitTest_add_linked_libs,sc_filters_test, \ + sc \ + sfx \ + svl \ + svt \ + vcl \ + tl \ + ucbhelper \ + utl \ + i18nisolang1 \ + comphelper \ + cppu \ + cppuhelper \ + sal \ + $(gb_STDLIBS) \ +)) + +$(eval $(call gb_CppunitTest_set_include,sc_filters_test,\ + -I$(realpath $(SRCDIR)/sc/inc/pch) \ + -I$(realpath $(SRCDIR)/sc/source/ui/inc) \ + -I$(realpath $(SRCDIR)/sc/inc) \ + $$(INCLUDE) \ + -I$(OUTDIR)/inc \ +)) + +$(eval $(call gb_CppunitTest_add_api,sc_filters_test,\ + offapi \ + udkapi \ +)) + +$(eval $(call gb_CppunitTest_uses_ure,sc_filters_test)) + +$(eval $(call gb_CppunitTest_add_type_rdbs,sc_filters_test,\ + types \ +)) + +$(eval $(call gb_CppunitTest_add_service_rdbs,sc_filters_test,\ + sc_filters_test \ +)) + +$(eval $(call gb_CppunitTest_set_args,sc_filters_test,\ + --headless \ + --invisible \ + --protector unoexceptionprotector$(gb_Library_DLLEXT) unoexceptionprotector \ +)) + +$(eval $(call gb_RdbTarget_RdbTarget,sc_filters_test)) + +$(eval $(call gb_RdbTarget_add_components,sc_filters_test,\ + sc/util/sc \ + sc/util/scfilt \ + forms/util/frm \ + dbaccess/util/dba \ + sfx2/util/sfx \ + framework/util/fwk \ + toolkit/util/tk \ + unoxml/source/service/unoxml \ + fileaccess/source/fileacc \ + comphelper/util/comphelp \ +)) + +$(eval $(call gb_RdbTarget_add_old_components,sc_filters_test,\ + i18npool \ + package2 \ + ucb1 \ + ucpfile1 \ +)) + +# vim: set noet sw=4: diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk index 0b91eee26d80..d07a2c51b4d3 100644 --- a/sc/Module_sc.mk +++ b/sc/Module_sc.mk @@ -35,6 +35,7 @@ $(eval $(call gb_Module_add_targets,sc,\ $(eval $(call gb_Module_add_check_targets,sc,\ CppunitTest_sc_ucalc \ + CppunitTest_sc_test_filters \ )) diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx new file mode 100644 index 000000000000..efe93aa1dbac --- /dev/null +++ b/sc/qa/unit/filters-test.cxx @@ -0,0 +1,243 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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. 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. + * + * The Initial Developer of the Original Code is + * Caolán McNamara <caolanm@redhat.com> + * Portions created by the Initial Developer are Copyright (C) 2011 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Caolán McNamara <caolanm@redhat.com> + * + * 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. + */ + +#include <sal/cppunit.h> + +#include <sal/config.h> +#include <osl/file.hxx> +#include <osl/process.h> + +#include <cppuhelper/compbase1.hxx> +#include <cppuhelper/bootstrap.hxx> +#include <cppuhelper/basemutex.hxx> + +#include <comphelper/processfactory.hxx> + +#include <i18npool/mslangid.hxx> + +#include <tools/urlobj.hxx> + +#include <unotools/tempfile.hxx> +#include <unotools/syslocaleoptions.hxx> + +#include <vcl/svapp.hxx> + +#include <ucbhelper/contentbroker.hxx> + +#include <sfx2/app.hxx> +#include <sfx2/docfilt.hxx> +#include <sfx2/docfile.hxx> +#include <sfx2/sfxmodelfactory.hxx> + +#include "docsh.hxx" + +const int indeterminate = 2; + +using namespace ::com::sun::star; + +/* Implementation of Filters test */ + +class FiltersTest : public CppUnit::TestFixture +{ +public: + FiltersTest(); + ~FiltersTest(); + + virtual void setUp(); + virtual void tearDown(); + + void recursiveScan(const rtl::OUString &rFilter, const rtl::OUString &rURL, const rtl::OUString &rUserData, int nExpected); + bool load(const rtl::OUString &rFilter, const rtl::OUString &rURL, const rtl::OUString &rUserData); + + /** + * Ensure CVEs remain unbroken + */ + void testCVEs(); + + CPPUNIT_TEST_SUITE(FiltersTest); +#if !defined(__OpenBSD__) + CPPUNIT_TEST(testCVEs); +#endif + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<uno::XComponentContext> m_xContext; + uno::Reference<lang::XMultiComponentFactory> m_xFactory; + uno::Reference<uno::XInterface> m_xWriterComponent; + ::rtl::OUString m_aSrcRoot; +}; + +bool FiltersTest::load(const rtl::OUString &rFilter, const rtl::OUString &rURL, + const rtl::OUString &rUserData) +{ + SfxFilter aFilter( + rFilter, + rtl::OUString(), 0, 0, rtl::OUString(), 0, rtl::OUString(), + rUserData, rtl::OUString() ); + + ScDocShellRef xDocShRef = new ScDocShell; + SfxMedium aSrcMed(rURL, STREAM_STD_READ, true); + aSrcMed.SetFilter(&aFilter); + return xDocShRef->DoLoad(&aSrcMed); +} + +void FiltersTest::recursiveScan(const rtl::OUString &rFilter, const rtl::OUString &rURL, const rtl::OUString &rUserData, int nExpected) +{ + osl::Directory aDir(rURL); + + CPPUNIT_ASSERT(osl::FileBase::E_None == aDir.open()); + osl::DirectoryItem aItem; + osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL|osl_FileStatus_Mask_Type); + while (aDir.getNextItem(aItem) == osl::FileBase::E_None) + { + aItem.getFileStatus(aFileStatus); + rtl::OUString sURL = aFileStatus.getFileURL(); + if (aFileStatus.getFileType() == osl::FileStatus::Directory) + recursiveScan(rFilter, sURL, rUserData, nExpected); + else + { + sal_Int32 nLastSlash = sURL.lastIndexOf('/'); + + //ignore .files + if ( + (nLastSlash != -1) && (nLastSlash+1 < sURL.getLength()) && + (sURL.getStr()[nLastSlash+1] == '.') + ) + { + continue; + } + + rtl::OString aRes(rtl::OUStringToOString(sURL, + osl_getThreadTextEncoding())); + if (nExpected == indeterminate) + { + fprintf(stderr, "loading %s\n", aRes.getStr()); + } + sal_uInt32 nStartTime = osl_getGlobalTimer(); + bool bRes = load(rFilter, sURL, rUserData); + sal_uInt32 nEndTime = osl_getGlobalTimer(); + if (nExpected == indeterminate) + { + fprintf(stderr, "pass/fail was %d (%"SAL_PRIuUINT32" ms)\n", + bRes, nEndTime-nStartTime); + continue; + } + CPPUNIT_ASSERT_MESSAGE(aRes.getStr(), bRes == nExpected); + } + } + CPPUNIT_ASSERT(osl::FileBase::E_None == aDir.close()); +} + +void FiltersTest::testCVEs() +{ + recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Quattro Pro 6.0")), + m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/clone/calc/sc/qa/unit/data/qpro/pass")), rtl::OUString(), true); + + recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Quattro Pro 6.0")), + m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/clone/calc/sc/qa/unit/data/qpro/fail")), rtl::OUString(), false); + + recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Quattro Pro 6.0")), + m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/clone/calc/sc/qa/unit/data/qpro/indeterminate")), rtl::OUString(), indeterminate); +} + +FiltersTest::FiltersTest() + : m_aSrcRoot(RTL_CONSTASCII_USTRINGPARAM("file://")) +{ + m_xContext = cppu::defaultBootstrap_InitialComponentContext(); + m_xFactory = m_xContext->getServiceManager(); + + uno::Reference<lang::XMultiServiceFactory> xSM(m_xFactory, uno::UNO_QUERY_THROW); + + //Without this we're crashing because callees are using + //getProcessServiceFactory. In general those should be removed in favour + //of retaining references to the root ServiceFactory as its passed around + comphelper::setProcessServiceFactory(xSM); + + // initialise UCB-Broker + uno::Sequence<uno::Any> aUcbInitSequence(2); + aUcbInitSequence[0] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local")); + aUcbInitSequence[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office")); + bool bInitUcb = ucbhelper::ContentBroker::initialize(xSM, aUcbInitSequence); + CPPUNIT_ASSERT_MESSAGE("Should be able to initialize UCB", bInitUcb); + + uno::Reference<ucb::XContentProviderManager> xUcb = + ucbhelper::ContentBroker::get()->getContentProviderManagerInterface(); + uno::Reference<ucb::XContentProvider> xFileProvider(xSM->createInstance( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.FileContentProvider"))), uno::UNO_QUERY); + xUcb->registerContentProvider(xFileProvider, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file")), sal_True); + + // force locale (and resource files loaded) to en-US + const LanguageType eLang=LANGUAGE_ENGLISH_US; + + rtl::OUString aLang, aCountry; + MsLangId::convertLanguageToIsoNames(eLang, aLang, aCountry); + lang::Locale aLocale(aLang, aCountry, rtl::OUString()); + ResMgr::SetDefaultLocale( aLocale ); + + SvtSysLocaleOptions aLocalOptions; + aLocalOptions.SetUILocaleConfigString( + MsLangId::convertLanguageToIsoString( eLang ) ); + + InitVCL(xSM); + + //This is a bit of a fudge, we do this to ensure that ScGlobals::ensure, + //which is a private symbol to us, gets called + m_xWriterComponent = + xSM->createInstance(rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Calc.SpreadsheetDocument"))); + CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xWriterComponent.is()); + + const char* pSrcRoot = getenv( "SRC_ROOT" ); + CPPUNIT_ASSERT_MESSAGE("SRC_ROOT env variable not set", pSrcRoot != NULL && pSrcRoot[0] != 0); + +#ifdef WNT + if (pSrcRoot[1] == ':') + m_aSrcRoot += rtl::OUString::createFromAscii( "/" ); +#endif + m_aSrcRoot += rtl::OUString::createFromAscii( pSrcRoot ); +} + +void FiltersTest::setUp() +{ +} + +FiltersTest::~FiltersTest() +{ + uno::Reference< lang::XComponent >(m_xContext, uno::UNO_QUERY_THROW)->dispose(); +} + +void FiltersTest::tearDown() +{ +} + +CPPUNIT_TEST_SUITE_REGISTRATION(FiltersTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 2345555f3348..8899b5e24590 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -77,7 +77,6 @@ #include <svx/svdograf.hxx> #include <svx/svdpage.hxx> -#include <sfx2/docfilt.hxx> #include <sfx2/docfile.hxx> #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> @@ -225,9 +224,6 @@ public: virtual void setUp(); virtual void tearDown(); - void recursiveScan(const rtl::OUString &rFilter, const rtl::OUString &rURL, int nExpected); - bool load(const rtl::OUString &rFilter, const rtl::OUString &rURL); - void testCollator(); void testInput(); void testCellFunctions(); @@ -257,11 +253,6 @@ public: void testGraphicsInGroup(); /** - * Ensure CVEs remain unbroken - */ - void testCVEs(); - - /** * Test toggling relative/absolute flag of cell and cell range references. * This corresponds with hitting Shift-F4 while the cursor is on a formula * cell. @@ -286,9 +277,6 @@ public: CPPUNIT_TEST(testGraphicsInGroup); CPPUNIT_TEST(testStreamValid); CPPUNIT_TEST(testFunctionLists); -#if !defined(__OpenBSD__) - CPPUNIT_TEST(testCVEs); -#endif CPPUNIT_TEST(testToggleRefFlag); CPPUNIT_TEST_SUITE_END(); @@ -615,75 +603,6 @@ void Test::testCSV() } } -bool Test::load(const rtl::OUString &rFilter, const rtl::OUString &rURL) -{ - SfxFilter aFilter( - rFilter, - rtl::OUString(), 0, 0, rtl::OUString(), 0, rtl::OUString(), - rtl::OUString(), rtl::OUString() ); - - ScDocShellRef xDocShRef = new ScDocShell; - SfxMedium aSrcMed(rURL, STREAM_STD_READ, true); - aSrcMed.SetFilter(&aFilter); - return xDocShRef->DoLoad(&aSrcMed); -} - -void Test::recursiveScan(const rtl::OUString &rFilter, const rtl::OUString &rURL, int nExpected) -{ - osl::Directory aDir(rURL); - - CPPUNIT_ASSERT(osl::FileBase::E_None == aDir.open()); - osl::DirectoryItem aItem; - osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL|osl_FileStatus_Mask_Type); - while (aDir.getNextItem(aItem) == osl::FileBase::E_None) - { - aItem.getFileStatus(aFileStatus); - rtl::OUString sURL = aFileStatus.getFileURL(); - if (aFileStatus.getFileType() == osl::FileStatus::Directory) - recursiveScan(rFilter, sURL, nExpected); - else - { - sal_Int32 nLastSlash = sURL.lastIndexOf('/'); - - //ignore .files - if ( - (nLastSlash != -1) && (nLastSlash+1 < sURL.getLength()) && - (sURL.getStr()[nLastSlash+1] == '.') - ) - { - continue; - } - - rtl::OString aRes(rtl::OUStringToOString(sURL, - osl_getThreadTextEncoding())); - if (nExpected == indeterminate) - { - fprintf(stderr, "loading %s\n", aRes.getStr()); - } - bool bRes = load(rFilter, sURL); - if (nExpected == indeterminate) - { - fprintf(stderr, "pass/fail was %d\n", bRes); - continue; - } - CPPUNIT_ASSERT_MESSAGE(aRes.getStr(), bRes == nExpected); - } - } - CPPUNIT_ASSERT(osl::FileBase::E_None == aDir.close()); -} - -void Test::testCVEs() -{ - recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Quattro Pro 6.0")), - m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/clone/calc/sc/qa/unit/data/qpro/pass")), true); - - recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Quattro Pro 6.0")), - m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/clone/calc/sc/qa/unit/data/qpro/fail")), false); - - recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Quattro Pro 6.0")), - m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/clone/calc/sc/qa/unit/data/qpro/indeterminate")), indeterminate); -} - template<typename Evaluator> void checkMatrixElements(const ScMatrix& rMat) { |