diff options
author | Jan Holesovsky <kendy@suse.cz> | 2013-05-14 11:47:34 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@suse.cz> | 2013-05-14 16:50:47 +0200 |
commit | ab0189b2b881ee6bb324876be3311ec1942bd235 (patch) | |
tree | 3f411b834a481a319cb4a65abd1a84a893d6740a /sd/qa | |
parent | 77b14c46aae4240226ef16ae3842e3ca35aaee73 (diff) |
sd unittests: Reorganize the Impress tests to be a bit more focused.
Change-Id: I222c824681fc7bcc25c6f591f09c69fae8c812ec
Diffstat (limited to 'sd/qa')
-rw-r--r-- | sd/qa/unit/import-tests.cxx | 211 | ||||
-rw-r--r-- | sd/qa/unit/sdmodeltestbase.hxx | 162 |
2 files changed, 179 insertions, 194 deletions
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx index 66d436295c2b..73da840273d3 100644 --- a/sd/qa/unit/import-tests.cxx +++ b/sd/qa/unit/import-tests.cxx @@ -7,139 +7,48 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <sal/config.h> -#include <unotest/filters-test.hxx> -#include <test/bootstrapfixture.hxx> -#include <test/xmldiff.hxx> -#include <rtl/strbuf.hxx> -#include <osl/file.hxx> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/document/XFilter.hpp> -#include <com/sun/star/frame/XStorable.hpp> +#include "sdmodeltestbase.hxx" -#include <sfx2/app.hxx> -#include <sfx2/docfilt.hxx> -#include <sfx2/docfile.hxx> -#include <sfx2/sfxmodelfactory.hxx> #include <svl/stritem.hxx> - -#include <svx/svdtext.hxx> -#include <svx/svdotext.hxx> - -#include "drawdoc.hxx" -#include "../source/ui/inc/DrawDocShell.hxx" - -#include <osl/process.h> -#include <osl/thread.h> - -#include <string> -#include <iostream> - -#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> -#include <drawinglayer/XShapeDumper.hxx> - #include <editeng/editobj.hxx> #include <editeng/outlobj.hxx> #include <editeng/ulspitem.hxx> #include <editeng/fhgtitem.hxx> -/* Implementation of Filters test */ +#include <svx/svdotext.hxx> using namespace ::com::sun::star; -class SdFiltersTest - : public test::FiltersTest - , public test::BootstrapFixture +/// Impress import filters tests. +class SdFiltersTest : public SdModelTestBase { public: - SdFiltersTest(); - - ::sd::DrawDocShellRef loadURL( const OUString &rURL ); - virtual bool load( const OUString &rFilter, - const OUString &rURL, const OUString &rUserData, - unsigned int nFilterFlags, unsigned int nClipboardID, - unsigned int nFilterVersion); - - virtual void setUp(); - virtual void tearDown(); - - void test(); + void testDocumentLayout(); void testN759180(); - void testFdo47434(); CPPUNIT_TEST_SUITE(SdFiltersTest); - CPPUNIT_TEST(test); + CPPUNIT_TEST(testDocumentLayout); CPPUNIT_TEST(testN759180); - CPPUNIT_TEST(testFdo47434); CPPUNIT_TEST_SUITE_END(); - -private: - uno::Reference<document::XFilter> m_xFilter; - uno::Reference<uno::XInterface> m_xDrawComponent; - void testStuff(::sd::DrawDocShellRef xDocShRef, const OString& fileNameBase); }; -#define PPTX_FORMAT_TYPE 268959811 -#define ODP_FORMAT_TYPE 285212967 - -struct FileFormat { - const char* pName; const char* pFilterName; const char* pTypeName; sal_uLong nFormatType; -}; +/** Test document against a reference XML dump of shapes. -// cf. sc/qa/unit/filters-test.cxx and filters/...*.xcu to fill out. -FileFormat aFileFormats[] = { - { "pptx" , "Impress MS PowerPoint 2007 XML", "MS PowerPoint 2007 XML", PPTX_FORMAT_TYPE }, - { "odp" , "impress8", "impress8", ODP_FORMAT_TYPE }, - { 0, 0, 0, 0 } -}; - -::sd::DrawDocShellRef SdFiltersTest::loadURL( const OUString &rURL ) +TODO: add info how to create the reference XML dump. +*/ +void SdFiltersTest::testDocumentLayout() { - FileFormat *pFmt(0); - - for (size_t i = 0; i < SAL_N_ELEMENTS (aFileFormats); i++) + struct { const char *pInput, *pDump; } aFilesToCompare[] = { - pFmt = aFileFormats + i; - if (pFmt->pName && rURL.endsWithIgnoreAsciiCaseAsciiL (pFmt->pName, strlen (pFmt->pName))) - break; - } - CPPUNIT_ASSERT_MESSAGE( "missing filter info", pFmt->pName != NULL ); + { "odp/shapes-test.odp", "xml/shapes-test_page" }, + { "pptx/fdo47434-all.pptx", "pptx/xml/fdo47434_page" } + }; - sal_uInt32 nFormat = 0; - if (pFmt->nFormatType) - nFormat = SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS; - SfxFilter* aFilter = new SfxFilter( - OUString::createFromAscii( pFmt->pFilterName ), - OUString(), pFmt->nFormatType, nFormat, - OUString::createFromAscii( pFmt->pTypeName ), - 0, OUString(), OUString(), /* userdata */ - OUString("private:factory/simpress*") ); - aFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT); - - ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell(); - SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ); - pSrcMed->SetFilter(aFilter); - if ( !xDocShRef->DoLoad(pSrcMed) ) + for ( unsigned int i = 0; i < SAL_N_ELEMENTS( aFilesToCompare ); ++i ) { - if (xDocShRef.Is()) - xDocShRef->DoClose(); - CPPUNIT_ASSERT_MESSAGE( "failed to load", false ); + ::sd::DrawDocShellRef xDocShRef = loadURL( getURLFromSrc( "/sd/qa/unit/data/" ) + OUString::createFromAscii( aFilesToCompare[i].pInput ) ); + compareWithShapesDump( xDocShRef, getPathFromSrc( "/sd/qa/unit/data/" ) + OUString::createFromAscii( aFilesToCompare[i].pDump ) ); } - - return xDocShRef; -} - -void SdFiltersTest::test() -{ - { - ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/odp/shapes-test.odp")); - testStuff(xDocShRef, OUStringToOString(getPathFromSrc("/sd/qa/unit/data/xml/shapes-test_page"), RTL_TEXTENCODING_UTF8)); - } - /* - { - ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/odp/text-test.odp")); - testStuff(xDocShRef); - }*/ } void SdFiltersTest::testN759180() @@ -180,92 +89,6 @@ void SdFiltersTest::testN759180() } } -void SdFiltersTest::testFdo47434() -{ - // The problem was the arrow that has cy < 180 and flipH = 0 is rendered incorrectly. - // Its height should be 1, not negative. - ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/pptx/fdo47434-all.pptx")); - testStuff(xDocShRef, OUStringToOString(getPathFromSrc("/sd/qa/unit/data/pptx/xml/fdo47434_page"), RTL_TEXTENCODING_UTF8)); -} - -void SdFiltersTest::testStuff(::sd::DrawDocShellRef xDocShRef, const OString& fileNameBase) -{ - CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef.Is() ); - CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef->IsInDestruction() ); - - uno::Reference<frame::XModel> xTempModel(xDocShRef->GetDoc()->getUnoModel(), uno::UNO_QUERY_THROW); - CPPUNIT_ASSERT(xTempModel.is()); - uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier (xTempModel, uno::UNO_QUERY_THROW); - CPPUNIT_ASSERT(xDrawPagesSupplier.is()); - uno::Reference< drawing::XDrawPages > xDrawPages = xDrawPagesSupplier->getDrawPages(); - CPPUNIT_ASSERT(xDrawPages.is()); - - XShapeDumper xShapeDumper; - sal_Int32 nLength = xDrawPages->getCount(); - OString aFileNameExt(".xml"); - for (sal_Int32 i = 0; i < nLength; ++i) - { - uno::Reference<drawing::XDrawPage> xDrawPage; - uno::Any aAny = xDrawPages->getByIndex(i); - aAny >>= xDrawPage; - uno::Reference< drawing::XShapes > xShapes(xDrawPage, uno::UNO_QUERY_THROW); - OUString aString = xShapeDumper.dump(xShapes); - OStringBuffer aFileNameBuf(fileNameBase); - aFileNameBuf.append(i); - aFileNameBuf.append(aFileNameExt); - - OString aFileName = aFileNameBuf.makeStringAndClear(); - - std::cout << aString << std::endl; - doXMLDiff(aFileName.getStr(), - OUStringToOString(aString, RTL_TEXTENCODING_UTF8).getStr(), - static_cast<int>(aString.getLength()), - OUStringToOString( - getPathFromSrc("/sd/qa/unit/data/tolerance.xml"), - RTL_TEXTENCODING_UTF8).getStr()); - } - xDocShRef->DoClose(); -} - -bool SdFiltersTest::load(const OUString &rFilter, const OUString &rURL, - const OUString &rUserData, unsigned int nFilterFlags, unsigned int nClipboardID, - unsigned int nFilterVersion) -{ - SfxFilter aFilter( - rFilter, - OUString(), nFilterFlags, nClipboardID, OUString(), 0, OUString(), - rUserData, OUString() ); - aFilter.SetVersion(nFilterVersion); - - ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell(); - SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ); - pSrcMed->SetFilter(&aFilter); - bool bLoaded = xDocShRef->DoLoad(pSrcMed); - xDocShRef->DoClose(); - return bLoaded; -} - -SdFiltersTest::SdFiltersTest() -{ -} - -void SdFiltersTest::setUp() -{ - test::BootstrapFixture::setUp(); - - // 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_xDrawComponent = - getMultiServiceFactory()->createInstance(OUString("com.sun.star.comp.Draw.PresentationDocument")); - CPPUNIT_ASSERT_MESSAGE("no impress component!", m_xDrawComponent.is()); -} - -void SdFiltersTest::tearDown() -{ - uno::Reference< lang::XComponent >( m_xDrawComponent, uno::UNO_QUERY_THROW )->dispose(); - test::BootstrapFixture::tearDown(); -} - CPPUNIT_TEST_SUITE_REGISTRATION(SdFiltersTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sd/qa/unit/sdmodeltestbase.hxx b/sd/qa/unit/sdmodeltestbase.hxx new file mode 100644 index 000000000000..9852338a4c21 --- /dev/null +++ b/sd/qa/unit/sdmodeltestbase.hxx @@ -0,0 +1,162 @@ +/* -*- 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/. + */ + +#ifndef SD_QA_UNIT_SDMODELTESTBASE_HXX +#define SD_QA_UNIT_SDMODELTESTBASE_HXX + +#include <test/bootstrapfixture.hxx> +#include <test/xmldiff.hxx> + +#include <unotest/filters-test.hxx> +#include <unotest/macros_test.hxx> + +#include "drawdoc.hxx" +#include "../source/ui/inc/DrawDocShell.hxx" + +#include <rtl/strbuf.hxx> +#include <sfx2/docfile.hxx> +#include <sfx2/docfilt.hxx> + +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <drawinglayer/XShapeDumper.hxx> + +using namespace ::com::sun::star; + +struct FileFormat { + const char* pName; const char* pFilterName; const char* pTypeName; sal_uLong nFormatType; +}; + +// These values are taken from "Flags" in filter/source/config/fragments/filters/* +#define ODP_FORMAT_TYPE ( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_TEMPLATE | SFX_FILTER_OWN | SFX_FILTER_DEFAULT | SFX_FILTER_ENCRYPTION | SFX_FILTER_PREFERED ) +#define PPT_FORMAT_TYPE ( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN ) +#define PPTX_FORMAT_TYPE ( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN | SFX_FILTER_STARONEFILTER | SFX_FILTER_PREFERED ) + +/** List of file formats we support in Impress unit tests. + +Taken from filter/source/config/fragments/filters/ too: +pName: The file extension. +pFilterName: <node oor:Name="..."> +pTypeName: <prop oor:Name="UIName">...</prop> +nFormatType: <prop oor:name="Flags">...</prop> +*/ +FileFormat aFileFormats[] = { + { "odp", "impress8", "impress8", ODP_FORMAT_TYPE }, + { "ppt", "MS PowerPoint 97", "Microsoft PowerPoint 97/2000/XP/2003", PPT_FORMAT_TYPE }, + { "pptx", "Impress MS PowerPoint 2007 XML", "MS PowerPoint 2007 XML", PPTX_FORMAT_TYPE }, + { 0, 0, 0, 0 } +}; + +/// Base class for filter tests loading or roundtriping a document, and asserting the document model. +class SdModelTestBase : public test::BootstrapFixture, public unotest::MacrosTest +{ +public: + SdModelTestBase() + { + } + + virtual void setUp() + { + test::BootstrapFixture::setUp(); + + // 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_xDrawComponent = getMultiServiceFactory()->createInstance(OUString("com.sun.star.comp.Draw.PresentationDocument")); + CPPUNIT_ASSERT_MESSAGE("no impress component!", m_xDrawComponent.is()); + } + + virtual void tearDown() + { + uno::Reference< lang::XComponent >( m_xDrawComponent, uno::UNO_QUERY_THROW )->dispose(); + test::BootstrapFixture::tearDown(); + } + +protected: + /// Load the document. + ::sd::DrawDocShellRef loadURL( const OUString &rURL ) + { + FileFormat *pFmt(0); + + for (size_t i = 0; i < SAL_N_ELEMENTS (aFileFormats); i++) + { + pFmt = aFileFormats + i; + if (pFmt->pName && rURL.endsWithIgnoreAsciiCaseAsciiL (pFmt->pName, strlen (pFmt->pName))) + break; + } + CPPUNIT_ASSERT_MESSAGE( "missing filter info", pFmt->pName != NULL ); + + sal_uInt32 nFormat = 0; + if (pFmt->nFormatType) + nFormat = SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS; + SfxFilter* aFilter = new SfxFilter( + OUString::createFromAscii( pFmt->pFilterName ), + OUString(), pFmt->nFormatType, nFormat, + OUString::createFromAscii( pFmt->pTypeName ), + 0, OUString(), OUString(), /* userdata */ + OUString("private:factory/simpress*") ); + aFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT); + + ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell(); + SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ); + pSrcMed->SetFilter(aFilter); + if ( !xDocShRef->DoLoad(pSrcMed) ) + { + if (xDocShRef.Is()) + xDocShRef->DoClose(); + CPPUNIT_ASSERT_MESSAGE( "failed to load", false ); + } + + return xDocShRef; + } + + /// Dump shapes in xDocShRef, and compare the dump against content of pShapesDumpFileNameBase<number>.xml. + void compareWithShapesDump( ::sd::DrawDocShellRef xDocShRef, const OUString &rShapesDumpFileNameBase ) + { + CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef.Is() ); + CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef->IsInDestruction() ); + + uno::Reference<frame::XModel> xTempModel(xDocShRef->GetDoc()->getUnoModel(), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xTempModel.is()); + uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier (xTempModel, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xDrawPagesSupplier.is()); + uno::Reference< drawing::XDrawPages > xDrawPages = xDrawPagesSupplier->getDrawPages(); + CPPUNIT_ASSERT(xDrawPages.is()); + + XShapeDumper xShapeDumper; + sal_Int32 nLength = xDrawPages->getCount(); + for (sal_Int32 i = 0; i < nLength; ++i) + { + uno::Reference<drawing::XDrawPage> xDrawPage; + uno::Any aAny = xDrawPages->getByIndex(i); + aAny >>= xDrawPage; + uno::Reference< drawing::XShapes > xShapes(xDrawPage, uno::UNO_QUERY_THROW); + OUString aString = xShapeDumper.dump(xShapes); + + OStringBuffer aFileNameBuf( OUStringToOString( rShapesDumpFileNameBase, RTL_TEXTENCODING_UTF8 ) ); + aFileNameBuf.append(i); + aFileNameBuf.append(".xml"); + + OString aFileName = aFileNameBuf.makeStringAndClear(); + + std::cout << aString << std::endl; + doXMLDiff(aFileName.getStr(), + OUStringToOString(aString, RTL_TEXTENCODING_UTF8).getStr(), + static_cast<int>(aString.getLength()), + OUStringToOString( + getPathFromSrc("/sd/qa/unit/data/tolerance.xml"), + RTL_TEXTENCODING_UTF8).getStr()); + } + xDocShRef->DoClose(); + } + + +private: + uno::Reference<uno::XInterface> m_xDrawComponent; +}; + +#endif |