2012-01-13 04:30:48 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
2013-04-19 21:10:42 +01:00
|
|
|
* This file is part of the LibreOffice project.
|
2012-01-13 04:30:48 +01:00
|
|
|
*
|
2013-04-19 21:10:42 +01:00
|
|
|
* 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/.
|
2012-01-13 04:30:48 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sal/config.h>
|
|
|
|
#include <unotest/filters-test.hxx>
|
|
|
|
#include <test/bootstrapfixture.hxx>
|
2012-07-12 03:02:00 +02:00
|
|
|
#include <test/xmldiff.hxx>
|
2012-01-13 04:30:48 +01:00
|
|
|
#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 <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>
|
|
|
|
|
2012-01-19 21:01:05 +01:00
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
|
2012-06-13 01:30:59 +02:00
|
|
|
#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
|
|
|
|
#include <drawinglayer/XShapeDumper.hxx>
|
|
|
|
|
2012-08-14 17:04:40 +05:30
|
|
|
#include <editeng/editobj.hxx>
|
|
|
|
#include <editeng/outlobj.hxx>
|
|
|
|
#include <editeng/ulspitem.hxx>
|
|
|
|
#include <editeng/fhgtitem.hxx>
|
|
|
|
|
2012-01-13 04:30:48 +01:00
|
|
|
/* Implementation of Filters test */
|
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
|
|
|
class SdFiltersTest
|
|
|
|
: public test::FiltersTest
|
|
|
|
, public test::BootstrapFixture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SdFiltersTest();
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
::sd::DrawDocShellRef loadURL( const OUString &rURL );
|
|
|
|
virtual bool load( const OUString &rFilter,
|
|
|
|
const OUString &rURL, const OUString &rUserData,
|
2012-11-01 13:12:21 +00:00
|
|
|
unsigned int nFilterFlags, unsigned int nClipboardID,
|
|
|
|
unsigned int nFilterVersion);
|
2012-01-13 04:30:48 +01:00
|
|
|
|
|
|
|
virtual void setUp();
|
|
|
|
virtual void tearDown();
|
|
|
|
|
|
|
|
void test();
|
2012-08-14 17:04:40 +05:30
|
|
|
void testN759180();
|
2012-08-21 20:08:40 +05:30
|
|
|
void testFdo47434();
|
2012-01-13 04:30:48 +01:00
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(SdFiltersTest);
|
|
|
|
CPPUNIT_TEST(test);
|
2012-08-14 17:04:40 +05:30
|
|
|
CPPUNIT_TEST(testN759180);
|
2012-08-21 20:08:40 +05:30
|
|
|
CPPUNIT_TEST(testFdo47434);
|
2012-01-13 04:30:48 +01:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
private:
|
|
|
|
uno::Reference<document::XFilter> m_xFilter;
|
|
|
|
uno::Reference<uno::XInterface> m_xDrawComponent;
|
2013-04-07 12:06:47 +02:00
|
|
|
void testStuff(::sd::DrawDocShellRef xDocShRef, const OString& fileNameBase);
|
2012-01-13 04:30:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#define PPTX_FORMAT_TYPE 268959811
|
2012-06-13 05:42:28 +02:00
|
|
|
#define ODP_FORMAT_TYPE 285212967
|
2012-01-13 04:30:48 +01:00
|
|
|
|
|
|
|
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 },
|
2012-06-13 05:42:28 +02:00
|
|
|
{ "odp" , "impress8", "impress8", ODP_FORMAT_TYPE },
|
2012-01-13 04:30:48 +01:00
|
|
|
{ 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
::sd::DrawDocShellRef SdFiltersTest::loadURL( const OUString &rURL )
|
2012-01-13 04:30:48 +01:00
|
|
|
{
|
2012-07-16 10:23:46 +02:00
|
|
|
FileFormat *pFmt(0);
|
2012-01-13 04:30:48 +01:00
|
|
|
|
|
|
|
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(
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString::createFromAscii( pFmt->pFilterName ),
|
|
|
|
OUString(), pFmt->nFormatType, nFormat,
|
|
|
|
OUString::createFromAscii( pFmt->pTypeName ),
|
|
|
|
0, OUString(), OUString(), /* userdata */
|
|
|
|
OUString("private:factory/simpress*") );
|
2012-01-13 04:30:48 +01:00
|
|
|
aFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT);
|
|
|
|
|
|
|
|
::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell();
|
2012-07-02 22:47:41 +02:00
|
|
|
SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
|
2012-01-13 04:30:48 +01:00
|
|
|
pSrcMed->SetFilter(aFilter);
|
|
|
|
if ( !xDocShRef->DoLoad(pSrcMed) )
|
|
|
|
{
|
|
|
|
if (xDocShRef.Is())
|
|
|
|
xDocShRef->DoClose();
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "failed to load", false );
|
|
|
|
}
|
|
|
|
|
|
|
|
return xDocShRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SdFiltersTest::test()
|
|
|
|
{
|
2012-06-15 16:12:52 +02:00
|
|
|
{
|
2012-07-12 03:02:00 +02:00
|
|
|
::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/odp/shapes-test.odp"));
|
2013-04-07 12:06:47 +02:00
|
|
|
testStuff(xDocShRef, OUStringToOString(getPathFromSrc("/sd/qa/unit/data/xml/shapes-test_page"), RTL_TEXTENCODING_UTF8));
|
2012-06-15 16:12:52 +02:00
|
|
|
}
|
2012-07-04 19:55:28 +02:00
|
|
|
/*
|
2012-06-15 16:12:52 +02:00
|
|
|
{
|
|
|
|
::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/odp/text-test.odp"));
|
|
|
|
testStuff(xDocShRef);
|
2012-07-04 19:55:28 +02:00
|
|
|
}*/
|
2012-06-15 16:12:52 +02:00
|
|
|
}
|
|
|
|
|
2012-08-14 17:04:40 +05:30
|
|
|
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<SdrTextObj *>( pObj );
|
|
|
|
CPPUNIT_ASSERT(pTxtObj);
|
|
|
|
std::vector<EECharAttrib> rLst;
|
|
|
|
const EditTextObject& aEdit = pTxtObj->GetOutlinerParaObject()->GetTextObject();
|
|
|
|
const SvxULSpaceItem *pULSpace = dynamic_cast<const SvxULSpaceItem *>(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);
|
2012-09-16 00:48:05 +02:00
|
|
|
for( std::vector<EECharAttrib>::reverse_iterator it = rLst.rbegin(); it!=rLst.rend(); ++it)
|
2012-08-14 17:04:40 +05:30
|
|
|
{
|
|
|
|
const SvxFontHeightItem * pFontHeight = dynamic_cast<const SvxFontHeightItem *>((*it).pAttr);
|
|
|
|
if(pFontHeight)
|
|
|
|
{
|
|
|
|
// nStart == 9
|
|
|
|
// font height = 5 => 5*2540/72
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "Font height is wrong", pFontHeight->GetHeight() == 176 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-21 20:08:40 +05:30
|
|
|
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"));
|
2013-04-07 12:06:47 +02:00
|
|
|
testStuff(xDocShRef, OUStringToOString(getPathFromSrc("/sd/qa/unit/data/pptx/xml/fdo47434_page"), RTL_TEXTENCODING_UTF8));
|
2012-08-21 20:08:40 +05:30
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void SdFiltersTest::testStuff(::sd::DrawDocShellRef xDocShRef, const OString& fileNameBase)
|
2012-06-15 16:12:52 +02:00
|
|
|
{
|
2012-01-13 04:30:48 +01:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef.Is() );
|
|
|
|
CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef->IsInDestruction() );
|
|
|
|
|
2012-06-13 01:30:59 +02:00
|
|
|
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());
|
2012-01-19 21:01:05 +01:00
|
|
|
|
2012-06-13 01:30:59 +02:00
|
|
|
XShapeDumper xShapeDumper;
|
|
|
|
sal_Int32 nLength = xDrawPages->getCount();
|
2013-04-07 12:06:47 +02:00
|
|
|
OString aFileNameExt(".xml");
|
2012-06-13 01:30:59 +02:00
|
|
|
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);
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString aString = xShapeDumper.dump(xShapes);
|
|
|
|
OStringBuffer aFileNameBuf(fileNameBase);
|
2012-07-12 03:02:00 +02:00
|
|
|
aFileNameBuf.append(i);
|
|
|
|
aFileNameBuf.append(aFileNameExt);
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OString aFileName = aFileNameBuf.makeStringAndClear();
|
2012-07-12 03:02:00 +02:00
|
|
|
|
2012-06-13 01:30:59 +02:00
|
|
|
std::cout << aString << std::endl;
|
2012-07-13 12:29:03 +02:00
|
|
|
doXMLDiff(aFileName.getStr(),
|
2013-04-07 12:06:47 +02:00
|
|
|
OUStringToOString(aString, RTL_TEXTENCODING_UTF8).getStr(),
|
2012-07-13 12:29:03 +02:00
|
|
|
static_cast<int>(aString.getLength()),
|
2013-04-07 12:06:47 +02:00
|
|
|
OUStringToOString(
|
2012-07-13 12:29:03 +02:00
|
|
|
getPathFromSrc("/sd/qa/unit/data/tolerance.xml"),
|
|
|
|
RTL_TEXTENCODING_UTF8).getStr());
|
2012-06-13 01:30:59 +02:00
|
|
|
}
|
2012-01-13 04:30:48 +01:00
|
|
|
xDocShRef->DoClose();
|
|
|
|
}
|
2012-07-12 00:59:24 +02:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
bool SdFiltersTest::load(const OUString &rFilter, const OUString &rURL,
|
|
|
|
const OUString &rUserData, unsigned int nFilterFlags, unsigned int nClipboardID,
|
2012-11-01 13:12:21 +00:00
|
|
|
unsigned int nFilterVersion)
|
2012-01-13 04:30:48 +01:00
|
|
|
{
|
|
|
|
SfxFilter aFilter(
|
|
|
|
rFilter,
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString(), nFilterFlags, nClipboardID, OUString(), 0, OUString(),
|
|
|
|
rUserData, OUString() );
|
2012-11-01 13:12:21 +00:00
|
|
|
aFilter.SetVersion(nFilterVersion);
|
2012-01-13 04:30:48 +01:00
|
|
|
|
|
|
|
::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell();
|
2012-07-02 22:47:41 +02:00
|
|
|
SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
|
2012-01-13 04:30:48 +01:00
|
|
|
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 =
|
2013-04-07 12:06:47 +02:00
|
|
|
getMultiServiceFactory()->createInstance(OUString("com.sun.star.comp.Draw.PresentationDocument"));
|
2012-01-13 04:30:48 +01:00
|
|
|
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: */
|