From 77b14c46aae4240226ef16ae3842e3ca35aaee73 Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Tue, 14 May 2013 12:00:51 +0200 Subject: sd unittests: Better name for the import tests. Change-Id: I62c47cbfd71e7606770552368e97e1c92fadf211 --- sd/qa/unit/import-tests.cxx | 273 +++++++++++++++++++++++++++++++++++++++++ sd/qa/unit/regression-test.cxx | 273 ----------------------------------------- 2 files changed, 273 insertions(+), 273 deletions(-) create mode 100644 sd/qa/unit/import-tests.cxx delete mode 100644 sd/qa/unit/regression-test.cxx (limited to 'sd/qa') diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx new file mode 100644 index 000000000000..66d436295c2b --- /dev/null +++ b/sd/qa/unit/import-tests.cxx @@ -0,0 +1,273 @@ +/* -*- 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/. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include "drawdoc.hxx" +#include "../source/ui/inc/DrawDocShell.hxx" + +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include + +/* Implementation of Filters test */ + +using namespace ::com::sun::star; + +class SdFiltersTest + : public test::FiltersTest + , public test::BootstrapFixture +{ +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 testN759180(); + void testFdo47434(); + + CPPUNIT_TEST_SUITE(SdFiltersTest); + CPPUNIT_TEST(test); + CPPUNIT_TEST(testN759180); + CPPUNIT_TEST(testFdo47434); + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference m_xFilter; + uno::Reference 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; +}; + +// 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 ) +{ + 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; +} + +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() +{ + ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/n759180.pptx")); + CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef.Is() ); + CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef->IsInDestruction() ); + + SdDrawDocument *pDoc = xDocShRef->GetDoc(); + CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != NULL ); + const SdrPage *pPage = pDoc->GetPage (1); + CPPUNIT_ASSERT_MESSAGE( "no page", pPage != NULL ); + + //sal_uIntPtr nObjs = pPage->GetObjCount(); + //for (sal_uIntPtr i = 0; i < nObjs; i++) + { + // Get the object + SdrObject *pObj = pPage->GetObj(0); + SdrTextObj *pTxtObj = dynamic_cast( pObj ); + CPPUNIT_ASSERT(pTxtObj); + std::vector rLst; + const EditTextObject& aEdit = pTxtObj->GetOutlinerParaObject()->GetTextObject(); + const SvxULSpaceItem *pULSpace = dynamic_cast(aEdit.GetParaAttribs(0).GetItem(EE_PARA_ULSPACE)); + CPPUNIT_ASSERT(pULSpace); + CPPUNIT_ASSERT_MESSAGE( "Para bottom spacing is wrong!", pULSpace->GetLower() == 0 ); + aEdit.GetCharAttribs(1, rLst); + for( std::vector::reverse_iterator it = rLst.rbegin(); it!=rLst.rend(); ++it) + { + const SvxFontHeightItem * pFontHeight = dynamic_cast((*it).pAttr); + if(pFontHeight) + { + // nStart == 9 + // font height = 5 => 5*2540/72 + CPPUNIT_ASSERT_MESSAGE( "Font height is wrong", pFontHeight->GetHeight() == 176 ); + break; + } + } + } +} + +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 xTempModel(xDocShRef->GetDoc()->getUnoModel(), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xTempModel.is()); + uno::Reference 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 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(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(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/qa/unit/regression-test.cxx b/sd/qa/unit/regression-test.cxx deleted file mode 100644 index 66d436295c2b..000000000000 --- a/sd/qa/unit/regression-test.cxx +++ /dev/null @@ -1,273 +0,0 @@ -/* -*- 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/. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include - -#include "drawdoc.hxx" -#include "../source/ui/inc/DrawDocShell.hxx" - -#include -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include - -/* Implementation of Filters test */ - -using namespace ::com::sun::star; - -class SdFiltersTest - : public test::FiltersTest - , public test::BootstrapFixture -{ -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 testN759180(); - void testFdo47434(); - - CPPUNIT_TEST_SUITE(SdFiltersTest); - CPPUNIT_TEST(test); - CPPUNIT_TEST(testN759180); - CPPUNIT_TEST(testFdo47434); - CPPUNIT_TEST_SUITE_END(); - -private: - uno::Reference m_xFilter; - uno::Reference 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; -}; - -// 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 ) -{ - 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; -} - -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() -{ - ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/n759180.pptx")); - CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef.Is() ); - CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef->IsInDestruction() ); - - SdDrawDocument *pDoc = xDocShRef->GetDoc(); - CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != NULL ); - const SdrPage *pPage = pDoc->GetPage (1); - CPPUNIT_ASSERT_MESSAGE( "no page", pPage != NULL ); - - //sal_uIntPtr nObjs = pPage->GetObjCount(); - //for (sal_uIntPtr i = 0; i < nObjs; i++) - { - // Get the object - SdrObject *pObj = pPage->GetObj(0); - SdrTextObj *pTxtObj = dynamic_cast( pObj ); - CPPUNIT_ASSERT(pTxtObj); - std::vector rLst; - const EditTextObject& aEdit = pTxtObj->GetOutlinerParaObject()->GetTextObject(); - const SvxULSpaceItem *pULSpace = dynamic_cast(aEdit.GetParaAttribs(0).GetItem(EE_PARA_ULSPACE)); - CPPUNIT_ASSERT(pULSpace); - CPPUNIT_ASSERT_MESSAGE( "Para bottom spacing is wrong!", pULSpace->GetLower() == 0 ); - aEdit.GetCharAttribs(1, rLst); - for( std::vector::reverse_iterator it = rLst.rbegin(); it!=rLst.rend(); ++it) - { - const SvxFontHeightItem * pFontHeight = dynamic_cast((*it).pAttr); - if(pFontHeight) - { - // nStart == 9 - // font height = 5 => 5*2540/72 - CPPUNIT_ASSERT_MESSAGE( "Font height is wrong", pFontHeight->GetHeight() == 176 ); - break; - } - } - } -} - -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 xTempModel(xDocShRef->GetDoc()->getUnoModel(), uno::UNO_QUERY_THROW); - CPPUNIT_ASSERT(xTempModel.is()); - uno::Reference 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 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(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(); - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit