GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / sd / qa / unit / sdmodeltestbase.hxx
blob00b589284a5eee70dc5549e281a5b1e9831feae1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef INCLUDED_SD_QA_UNIT_SDMODELTESTBASE_HXX
11 #define INCLUDED_SD_QA_UNIT_SDMODELTESTBASE_HXX
13 #include <test/bootstrapfixture.hxx>
14 #include <test/xmldiff.hxx>
16 #include <unotest/filters-test.hxx>
17 #include <unotest/macros_test.hxx>
19 #include "drawdoc.hxx"
20 #include "../source/ui/inc/DrawDocShell.hxx"
21 #include "unotools/tempfile.hxx"
23 #include <rtl/strbuf.hxx>
24 #include <sfx2/docfile.hxx>
25 #include <sfx2/docfilt.hxx>
27 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
28 #include <drawinglayer/XShapeDumper.hxx>
30 using namespace ::com::sun::star;
32 struct FileFormat {
33 const char* pName; const char* pFilterName; const char* pTypeName; const char* pUserData; sal_uLong nFormatType;
36 // These values are taken from "Flags" in filter/source/config/fragments/filters/*
37 #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 )
38 #define PPT_FORMAT_TYPE ( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN )
39 #define PPTX_FORMAT_TYPE ( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN | SFX_FILTER_STARONEFILTER | SFX_FILTER_PREFERED )
41 /** List of file formats we support in Impress unit tests.
43 Taken from filter/source/config/fragments/filters/ too:
44 pName: The file extension.
45 pFilterName: <node oor:Name="...">
46 pTypeName: <prop oor:Name="UIName">...</prop>
47 nFormatType: <prop oor:name="Flags">...</prop>
49 FileFormat aFileFormats[] = {
50 { "odp", "impress8", "impress8", "", ODP_FORMAT_TYPE },
51 { "ppt", "MS PowerPoint 97", "Microsoft PowerPoint 97/2000/XP/2003", "sdfilt", PPT_FORMAT_TYPE },
52 { "pptx", "Impress MS PowerPoint 2007 XML", "MS PowerPoint 2007 XML", "", PPTX_FORMAT_TYPE },
53 { 0, 0, 0, 0, 0 }
56 #define ODP 0
57 #define PPT 1
58 #define PPTX 2
60 /// Base class for filter tests loading or roundtriping a document, and asserting the document model.
61 class SdModelTestBase : public test::BootstrapFixture, public unotest::MacrosTest
63 public:
64 SdModelTestBase()
68 virtual void setUp()
70 test::BootstrapFixture::setUp();
72 // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
73 // which is a private symbol to us, gets called
74 m_xDrawComponent = getMultiServiceFactory()->createInstance("com.sun.star.comp.Draw.PresentationDocument");
75 CPPUNIT_ASSERT_MESSAGE("no impress component!", m_xDrawComponent.is());
78 virtual void tearDown()
80 uno::Reference< lang::XComponent >( m_xDrawComponent, uno::UNO_QUERY_THROW )->dispose();
81 test::BootstrapFixture::tearDown();
84 protected:
85 /// Load the document.
86 ::sd::DrawDocShellRef loadURL( const OUString &rURL )
88 FileFormat *pFmt(0);
90 for (size_t i = 0; i < SAL_N_ELEMENTS (aFileFormats); i++)
92 pFmt = aFileFormats + i;
93 if (pFmt->pName && rURL.endsWithIgnoreAsciiCaseAsciiL (pFmt->pName, strlen (pFmt->pName)))
94 break;
96 CPPUNIT_ASSERT_MESSAGE( "missing filter info", pFmt->pName != NULL );
98 sal_uInt32 nFormat = 0;
99 if (pFmt->nFormatType)
100 nFormat = SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS;
101 SfxFilter* aFilter = new SfxFilter(
102 OUString::createFromAscii( pFmt->pFilterName ),
103 OUString(), pFmt->nFormatType, nFormat,
104 OUString::createFromAscii( pFmt->pTypeName ),
105 0, OUString(),
106 OUString::createFromAscii( pFmt->pUserData ),
107 OUString("private:factory/simpress*") );
108 aFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT);
110 ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell();
111 SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
112 pSrcMed->SetFilter(aFilter);
113 if ( !xDocShRef->DoLoad(pSrcMed) )
115 if (xDocShRef.Is())
116 xDocShRef->DoClose();
117 CPPUNIT_ASSERT_MESSAGE( OUStringToOString( "failed to load " + rURL, RTL_TEXTENCODING_UTF8 ).getStr(), false );
120 return xDocShRef;
123 ::sd::DrawDocShellRef saveAndReload( ::sd::DrawDocShell *pShell, sal_Int32 nExportType )
125 FileFormat *pFmt = &aFileFormats[0];
126 if( ( (sal_uInt32) nExportType ) < SAL_N_ELEMENTS( aFileFormats ) )
127 pFmt = &aFileFormats[ nExportType ];
128 OUString aExt = OUString( "." ) + OUString::createFromAscii( pFmt->pName );
129 utl::TempFile aTempFile( OUString(), &aExt );
130 aTempFile.EnableKillingFile();
131 SfxMedium aStoreMedium( aTempFile.GetURL(), STREAM_STD_WRITE );
132 sal_uInt32 nExportFormat = 0;
133 if( pFmt->nFormatType == ODP_FORMAT_TYPE )
134 nExportFormat = SFX_FILTER_EXPORT | SFX_FILTER_USESOPTIONS;
135 SfxFilter* pExportFilter = new SfxFilter(
136 OUString::createFromAscii( pFmt->pFilterName ),
137 OUString(), pFmt->nFormatType, nExportFormat,
138 OUString::createFromAscii( pFmt->pTypeName ),
139 0, OUString(),
140 OUString::createFromAscii( pFmt->pUserData ),
141 OUString("private:factory/simpress*") );
142 pExportFilter->SetVersion( SOFFICE_FILEFORMAT_CURRENT );
143 aStoreMedium.SetFilter( pExportFilter );
144 pShell->DoSaveAs( aStoreMedium );
145 pShell->DoClose();
147 return loadURL( aTempFile.GetURL() );
150 /** Dump shapes in xDocShRef, and compare the dump against content of pShapesDumpFileNameBase<number>.xml.
152 @param bCreate Instead of comparing to the reference file(s), create it/them.
154 void compareWithShapesDump( ::sd::DrawDocShellRef xDocShRef, const OUString &rShapesDumpFileNameBase, bool bCreate = false )
156 CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef.Is() );
157 CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef->IsInDestruction() );
159 uno::Reference<frame::XModel> xTempModel(xDocShRef->GetDoc()->getUnoModel(), uno::UNO_QUERY_THROW);
160 CPPUNIT_ASSERT(xTempModel.is());
161 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier (xTempModel, uno::UNO_QUERY_THROW);
162 CPPUNIT_ASSERT(xDrawPagesSupplier.is());
163 uno::Reference< drawing::XDrawPages > xDrawPages = xDrawPagesSupplier->getDrawPages();
164 CPPUNIT_ASSERT(xDrawPages.is());
166 XShapeDumper xShapeDumper;
167 sal_Int32 nLength = xDrawPages->getCount();
168 for (sal_Int32 i = 0; i < nLength; ++i)
170 uno::Reference<drawing::XDrawPage> xDrawPage;
171 uno::Any aAny = xDrawPages->getByIndex(i);
172 aAny >>= xDrawPage;
173 uno::Reference< drawing::XShapes > xShapes(xDrawPage, uno::UNO_QUERY_THROW);
174 OUString aString = xShapeDumper.dump(xShapes);
176 OStringBuffer aFileNameBuf( OUStringToOString( rShapesDumpFileNameBase, RTL_TEXTENCODING_UTF8 ) );
177 aFileNameBuf.append(i);
178 aFileNameBuf.append(".xml");
180 OString aFileName = aFileNameBuf.makeStringAndClear();
182 if ( bCreate )
184 std::ofstream aStream( aFileName.getStr(), std::ofstream::out );
185 aStream << aString;
186 aStream.close();
188 else
190 doXMLDiff(aFileName.getStr(),
191 OUStringToOString(aString, RTL_TEXTENCODING_UTF8).getStr(),
192 static_cast<int>(aString.getLength()),
193 OUStringToOString(
194 getPathFromSrc("/sd/qa/unit/data/tolerance.xml"),
195 RTL_TEXTENCODING_UTF8).getStr());
198 xDocShRef->DoClose();
202 private:
203 uno::Reference<uno::XInterface> m_xDrawComponent;
206 #endif
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */