From a1b214effc2d6c3c579a9e822cf04db888cb408d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Wed, 6 Jul 2011 13:08:02 +0100 Subject: [PATCH] add regression testing infrastructure for wmf/emf --- svtools/CppunitTest_svtools_filters_test.mk | 75 ++++++ svtools/Module_svtools.mk | 4 + svtools/prj/build.lst | 2 +- svtools/qa/cppunit/data/emf/fail/.gitignore | 0 .../cppunit/data/emf/indeterminate/.gitignore | 0 svtools/qa/cppunit/data/emf/pass/.gitignore | 0 svtools/qa/cppunit/data/wmf/fail/.gitignore | 0 .../cppunit/data/wmf/indeterminate/.gitignore | 0 svtools/qa/cppunit/data/wmf/pass/.gitignore | 0 svtools/qa/cppunit/filters-test.cxx | 214 ++++++++++++++++++ 10 files changed, 294 insertions(+), 1 deletion(-) create mode 100755 svtools/CppunitTest_svtools_filters_test.mk create mode 100644 svtools/qa/cppunit/data/emf/fail/.gitignore create mode 100644 svtools/qa/cppunit/data/emf/indeterminate/.gitignore create mode 100644 svtools/qa/cppunit/data/emf/pass/.gitignore create mode 100644 svtools/qa/cppunit/data/wmf/fail/.gitignore create mode 100644 svtools/qa/cppunit/data/wmf/indeterminate/.gitignore create mode 100644 svtools/qa/cppunit/data/wmf/pass/.gitignore create mode 100644 svtools/qa/cppunit/filters-test.cxx diff --git a/svtools/CppunitTest_svtools_filters_test.mk b/svtools/CppunitTest_svtools_filters_test.mk new file mode 100755 index 000000000000..952ec02cbecc --- /dev/null +++ b/svtools/CppunitTest_svtools_filters_test.mk @@ -0,0 +1,75 @@ +#************************************************************************* +# 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. +# 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,svtools_filters_test)) + +$(eval $(call gb_CppunitTest_add_exception_objects,svtools_filters_test, \ + svtools/qa/cppunit/filters-test \ +)) + +$(eval $(call gb_CppunitTest_add_linked_libs,svtools_filters_test, \ + comphelper \ + cppu \ + cppuhelper \ + sal \ + svt \ + tl \ + vcl \ + $(gb_STDLIBS) \ +)) + +$(eval $(call gb_CppunitTest_set_include,svtools_filters_test,\ + $$(INCLUDE) \ + -I$(OUTDIR)/inc \ +)) + +$(eval $(call gb_CppunitTest_add_api,svtools_filters_test,\ + udkapi \ + offapi \ +)) + +$(eval $(call gb_CppunitTest_uses_ure,svtools_filters_test)) + +$(eval $(call gb_CppunitTest_add_type_rdbs,svtools_filters_test,\ + types \ +)) + +$(eval $(call gb_CppunitTest_add_service_rdbs,svtools_filters_test,\ + svtools_filters_test \ +)) + +$(eval $(call gb_CppunitTest_set_args,svtools_filters_test,\ + --headless \ + --invisible \ + --protector unoexceptionprotector$(gb_Library_DLLEXT) unoexceptionprotector \ +)) + +$(eval $(call gb_RdbTarget_RdbTarget,svtools_filters_test)) + +# vim: set noet sw=4 ts=4: diff --git a/svtools/Module_svtools.mk b/svtools/Module_svtools.mk index 0b669d9dee1b..ac2fff8623a3 100644 --- a/svtools/Module_svtools.mk +++ b/svtools/Module_svtools.mk @@ -39,6 +39,10 @@ $(eval $(call gb_Module_add_targets,svtools,\ Package_inc \ )) +$(eval $(call gb_Module_add_check_targets,svtools,\ + CppunitTest_svtools_filters_test \ +)) + $(eval $(call gb_Module_add_subsequentcheck_targets,svtools,\ JunitTest_svtools_unoapi \ )) diff --git a/svtools/prj/build.lst b/svtools/prj/build.lst index a438456220a0..d18c9f9df2a2 100644 --- a/svtools/prj/build.lst +++ b/svtools/prj/build.lst @@ -1,2 +1,2 @@ -st svtools : TRANSLATIONS:translations svl offapi toolkit ucbhelper unotools JPEG:jpeg cppu cppuhelper comphelper sal salhelper sot jvmfwk LIBXSLT:libxslt NULL +st svtools : TRANSLATIONS:translations svl offapi toolkit ucbhelper unotools JPEG:jpeg cppu cppuhelper comphelper sal salhelper sot jvmfwk LIBXSLT:libxslt ure test NULL st svtools\prj nmake - all st_prj NULL diff --git a/svtools/qa/cppunit/data/emf/fail/.gitignore b/svtools/qa/cppunit/data/emf/fail/.gitignore new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/svtools/qa/cppunit/data/emf/indeterminate/.gitignore b/svtools/qa/cppunit/data/emf/indeterminate/.gitignore new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/svtools/qa/cppunit/data/emf/pass/.gitignore b/svtools/qa/cppunit/data/emf/pass/.gitignore new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/svtools/qa/cppunit/data/wmf/fail/.gitignore b/svtools/qa/cppunit/data/wmf/fail/.gitignore new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/svtools/qa/cppunit/data/wmf/indeterminate/.gitignore b/svtools/qa/cppunit/data/wmf/indeterminate/.gitignore new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/svtools/qa/cppunit/data/wmf/pass/.gitignore b/svtools/qa/cppunit/data/wmf/pass/.gitignore new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/svtools/qa/cppunit/filters-test.cxx b/svtools/qa/cppunit/filters-test.cxx new file mode 100644 index 000000000000..c5d43af4bb9b --- /dev/null +++ b/svtools/qa/cppunit/filters-test.cxx @@ -0,0 +1,214 @@ +/* -*- 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 + * Portions created by the Initial Developer are Copyright (C) 2011 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Caolán McNamara + * + * 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 +#include + +#include +#include + +#include + +#include + +#include + +#include +#include + +#include + +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 &rURL, int nExpected); + bool load(const rtl::OUString &rURL); + + /** + * Ensure CVEs remain unbroken + */ + void testCVEs(); + + CPPUNIT_TEST_SUITE(FiltersTest); + CPPUNIT_TEST(testCVEs); + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xContext; + uno::Reference m_xFactory; + ::rtl::OUString m_aSrcRoot; +}; + +bool FiltersTest::load(const rtl::OUString &rURL) +{ + GraphicFilter aGraphicFilter(false); + SvFileStream aFileStream(rURL, STREAM_READ); + Graphic aGraphic; + return aGraphicFilter.ImportGraphic(aGraphic, rURL, aFileStream) == 0; +} + +void FiltersTest::recursiveScan(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(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()); + } + sal_uInt32 nStartTime = osl_getGlobalTimer(); + bool bRes = load(sURL); + 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(m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/clone/libs-gui/svtools/qa/cppunit/data/wmf/pass")), true); + recursiveScan(m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/clone/libs-gui/svtools/qa/cppunit/data/wmf/fail")), false); + recursiveScan(m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/clone/libs-gui/svtools/qa/cppunit/data/wmf/indeterminate")), 2); + + recursiveScan(m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/clone/libs-gui/svtools/qa/cppunit/data/emf/pass")), true); + recursiveScan(m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/clone/libs-gui/svtools/qa/cppunit/data/emf/fail")), false); + recursiveScan(m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/clone/libs-gui/svtools/qa/cppunit/data/emf/indeterminate")), 2); +} + +FiltersTest::FiltersTest() + : m_aSrcRoot(RTL_CONSTASCII_USTRINGPARAM("file://")) +{ + m_xContext = cppu::defaultBootstrap_InitialComponentContext(); + m_xFactory = m_xContext->getServiceManager(); + + uno::Reference 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); +#if 0 + // initialise UCB-Broker + uno::Sequence 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 xUcb = + ucbhelper::ContentBroker::get()->getContentProviderManagerInterface(); + uno::Reference 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 ) ); +#endif + + InitVCL(xSM); + + 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: */