Kaydet (Commit) 37fd0d98 authored tarafından Michael Meeks's avatar Michael Meeks

sw: switch filters-test to the new shared unit test code

üst 4b7cc85c
...@@ -58,6 +58,7 @@ $(eval $(call gb_CppunitTest_add_linked_libs,sw_swdoc_test, \ ...@@ -58,6 +58,7 @@ $(eval $(call gb_CppunitTest_add_linked_libs,sw_swdoc_test, \
svx \ svx \
svxcore \ svxcore \
swd \ swd \
test \
tk \ tk \
tl \ tl \
ucbhelper \ ucbhelper \
......
...@@ -43,6 +43,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sw_filters_test, \ ...@@ -43,6 +43,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sw_filters_test, \
$(call gb_CxxObject_get_target,sw/qa/core/filters-test): $(WORKDIR)/AllLangRes/sw $(call gb_CxxObject_get_target,sw/qa/core/filters-test): $(WORKDIR)/AllLangRes/sw
$(eval $(call gb_CppunitTest_add_linked_libs,sw_filters_test, \ $(eval $(call gb_CppunitTest_add_linked_libs,sw_filters_test, \
test \
sw \ sw \
sfx \ sfx \
svl \ svl \
......
...@@ -27,34 +27,14 @@ ...@@ -27,34 +27,14 @@
* instead of those above. * instead of those above.
*/ */
#include "sal/config.h" #include <sal/config.h>
#include "sal/precppunit.hxx" #include <test/bootstrapfixture.hxx>
#include "cppunit/TestAssert.h"
#include "cppunit/TestFixture.h"
#include "cppunit/extensions/HelperMacros.h"
#include "cppunit/plugin/TestPlugIn.h"
#include <osl/file.hxx> #include <osl/file.hxx>
#include <osl/process.h> #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 <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/app.hxx>
#include <sfx2/docfilt.hxx> #include <sfx2/docfilt.hxx>
#include <sfx2/docfile.hxx> #include <sfx2/docfile.hxx>
...@@ -76,11 +56,10 @@ using namespace ::com::sun::star; ...@@ -76,11 +56,10 @@ using namespace ::com::sun::star;
/* Implementation of Filters test */ /* Implementation of Filters test */
class FiltersTest : public CppUnit::TestFixture class FiltersTest : public test::BootstrapFixture
{ {
public: public:
FiltersTest(); FiltersTest();
~FiltersTest();
virtual void setUp(); virtual void setUp();
virtual void tearDown(); virtual void tearDown();
...@@ -88,9 +67,7 @@ public: ...@@ -88,9 +67,7 @@ public:
void recursiveScan(const rtl::OUString &rFilter, const rtl::OUString &rURL, const rtl::OUString &rUserData, int nExpected); 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); bool load(const rtl::OUString &rFilter, const rtl::OUString &rURL, const rtl::OUString &rUserData);
/** // Ensure CVEs remain unbroken
* Ensure CVEs remain unbroken
*/
void testCVEs(); void testCVEs();
CPPUNIT_TEST_SUITE(FiltersTest); CPPUNIT_TEST_SUITE(FiltersTest);
...@@ -98,8 +75,6 @@ public: ...@@ -98,8 +75,6 @@ public:
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
uno::Reference<uno::XComponentContext> m_xContext;
uno::Reference<lang::XMultiComponentFactory> m_xFactory;
uno::Reference<uno::XInterface> m_xWriterComponent; uno::Reference<uno::XInterface> m_xWriterComponent;
::rtl::OUString m_aSrcRoot; ::rtl::OUString m_aSrcRoot;
int m_nLoadedDocs; int m_nLoadedDocs;
...@@ -172,86 +147,44 @@ void FiltersTest::recursiveScan(const rtl::OUString &rFilter, const rtl::OUStrin ...@@ -172,86 +147,44 @@ void FiltersTest::recursiveScan(const rtl::OUString &rFilter, const rtl::OUStrin
void FiltersTest::testCVEs() void FiltersTest::testCVEs()
{ {
recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Staroffice XML (Writer)")), m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/sw/qa/core/data/xml/pass")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CXML")), true); recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Staroffice XML (Writer)")),
getURLFromSrc("/sw/qa/core/data/xml/pass"),
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CXML")), true);
recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Staroffice XML (Writer)")), m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/sw/qa/core/data/xml/fail")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CXML")), false); recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Staroffice XML (Writer)")),
getURLFromSrc("/sw/qa/core/data/xml/fail"),
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CXML")), false);
recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MS Word 97")), m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/sw/qa/core/data/ww8/pass")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CWW8")), true); recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MS Word 97")),
getURLFromSrc("/sw/qa/core/data/ww8/pass"),
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CWW8")), true);
recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MS Word 97")), m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/sw/qa/core/data/ww8/fail")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CWW8")), false); recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MS Word 97")),
getURLFromSrc("/sw/qa/core/data/ww8/fail"),
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CWW8")), false);
recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MS Word 97")), m_aSrcRoot + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/sw/qa/core/data/ww8/indeterminate")), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CWW8")), indeterminate); recursiveScan(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MS Word 97")),
getURLFromSrc("/sw/qa/core/data/ww8/indeterminate"),
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CWW8")), indeterminate);
printf("Writer: tested %d files\n", m_nLoadedDocs); printf("Writer: tested %d files\n", m_nLoadedDocs);
} }
FiltersTest::FiltersTest() FiltersTest::FiltersTest()
: m_aSrcRoot(RTL_CONSTASCII_USTRINGPARAM("file://")) : m_nLoadedDocs(0)
, m_nLoadedDocs(0)
{ {
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 SwGlobals::ensure, //This is a bit of a fudge, we do this to ensure that SwGlobals::ensure,
//which is a private symbol to us, gets called //which is a private symbol to us, gets called
m_xWriterComponent = m_xWriterComponent =
xSM->createInstance(rtl::OUString( getMultiServiceFactory()->createInstance(rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.TextDocument"))); RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.TextDocument")));
CPPUNIT_ASSERT_MESSAGE("no writer component!", m_xWriterComponent.is()); CPPUNIT_ASSERT_MESSAGE("no writer 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() void FiltersTest::setUp()
{ {
} }
FiltersTest::~FiltersTest()
{
uno::Reference< lang::XComponent >(m_xContext, uno::UNO_QUERY_THROW)->dispose();
}
void FiltersTest::tearDown() void FiltersTest::tearDown()
{ {
} }
......
...@@ -28,31 +28,15 @@ ...@@ -28,31 +28,15 @@
* instead of those above. * instead of those above.
*/ */
#include "sal/config.h" #include <sal/config.h>
#include "sal/precppunit.hxx" #include <test/bootstrapfixture.hxx>
#include "cppunit/TestAssert.h"
#include "cppunit/TestFixture.h"
#include "cppunit/extensions/HelperMacros.h"
#include "cppunit/plugin/TestPlugIn.h"
#include <osl/file.hxx> #include <osl/file.hxx>
#include <osl/process.h> #include <osl/process.h>
#include <cppuhelper/compbase1.hxx>
#include <cppuhelper/bootstrap.hxx>
#include <cppuhelper/basemutex.hxx>
#include <comphelper/processfactory.hxx>
#include <tools/urlobj.hxx> #include <tools/urlobj.hxx>
#include <unotools/tempfile.hxx> #include <unotools/tempfile.hxx>
#include <ucbhelper/contentbroker.hxx>
#include <vcl/svapp.hxx>
#include <sfx2/app.hxx> #include <sfx2/app.hxx>
#include <sfx2/docfilt.hxx> #include <sfx2/docfilt.hxx>
#include <sfx2/docfile.hxx> #include <sfx2/docfile.hxx>
...@@ -79,7 +63,7 @@ using namespace ::com::sun::star; ...@@ -79,7 +63,7 @@ using namespace ::com::sun::star;
/* Implementation of Swdoc-Test class */ /* Implementation of Swdoc-Test class */
class SwDocTest : public CppUnit::TestFixture class SwDocTest : public test::BootstrapFixture
{ {
public: public:
SwDocTest(); SwDocTest();
...@@ -105,8 +89,6 @@ public: ...@@ -105,8 +89,6 @@ public:
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
uno::Reference<uno::XComponentContext> m_xContext;
uno::Reference<lang::XMultiComponentFactory> m_xFactory;
SwDoc *m_pDoc; SwDoc *m_pDoc;
SwDocShellRef m_xDocShRef; SwDocShellRef m_xDocShRef;
}; };
...@@ -462,32 +444,6 @@ void SwDocTest::randomTest() ...@@ -462,32 +444,6 @@ void SwDocTest::randomTest()
SwDocTest::SwDocTest() SwDocTest::SwDocTest()
{ {
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);
InitVCL(xSM);
SwGlobals::ensure(); SwGlobals::ensure();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment