Bump for 3.6-28
[LibreOffice.git] / sd / qa / unit / filters-test.cxx
blob2b474bc442c6e8c81078adbf3b45ad6183a40668
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Initial Developer of the Original Code is
16 * Michael Meeks <michael.meeks@suse.com>
17 * Portions created by the Initial Developer are Copyright (C) 2011 the
18 * Initial Developer. All Rights Reserved.
20 * Contributor(s):
21 * Caolán McNamara <caolanm@redhat.com>
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
25 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
26 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
27 * instead of those above.
30 #include <sal/config.h>
31 #include <unotest/filters-test.hxx>
32 #include <test/bootstrapfixture.hxx>
33 #include <rtl/strbuf.hxx>
34 #include <osl/file.hxx>
35 #include <com/sun/star/lang/XComponent.hpp>
36 #include <com/sun/star/document/XFilter.hpp>
38 #include <sfx2/app.hxx>
39 #include <sfx2/docfilt.hxx>
40 #include <sfx2/docfile.hxx>
41 #include <sfx2/sfxmodelfactory.hxx>
42 #include <svl/stritem.hxx>
44 #include <svx/svdtext.hxx>
45 #include <svx/svdotext.hxx>
47 #include "drawdoc.hxx"
48 #include "../source/ui/inc/DrawDocShell.hxx"
50 #include <osl/process.h>
51 #include <osl/thread.h>
53 /* Implementation of Filters test */
55 using namespace ::com::sun::star;
57 class SdFiltersTest
58 : public test::FiltersTest
59 , public test::BootstrapFixture
61 public:
62 SdFiltersTest();
64 ::sd::DrawDocShellRef loadURL( const rtl::OUString &rURL );
65 virtual bool load( const rtl::OUString &rFilter, const rtl::OUString &rURL, const rtl::OUString &rUserData);
67 virtual void setUp();
68 virtual void tearDown();
70 void test();
71 // Ensure CVEs remain unbroken
72 void testCVEs();
74 CPPUNIT_TEST_SUITE(SdFiltersTest);
75 CPPUNIT_TEST(test);
76 CPPUNIT_TEST(testCVEs);
77 CPPUNIT_TEST_SUITE_END();
79 private:
80 uno::Reference<document::XFilter> m_xFilter;
81 uno::Reference<uno::XInterface> m_xDrawComponent;
84 #define PPTX_FORMAT_TYPE 268959811
86 struct FileFormat {
87 const char* pName; const char* pFilterName; const char* pTypeName; sal_uLong nFormatType;
90 // cf. sc/qa/unit/filters-test.cxx and filters/...*.xcu to fill out.
91 FileFormat aFileFormats[] = {
92 { "pptx" , "Impress MS PowerPoint 2007 XML", "MS PowerPoint 2007 XML", PPTX_FORMAT_TYPE },
93 { 0, 0, 0, 0 }
96 ::sd::DrawDocShellRef SdFiltersTest::loadURL( const rtl::OUString &rURL )
98 FileFormat *pFmt = NULL;
100 for (size_t i = 0; i < SAL_N_ELEMENTS (aFileFormats); i++)
102 pFmt = aFileFormats + i;
103 if (pFmt->pName && rURL.endsWithIgnoreAsciiCaseAsciiL (pFmt->pName, strlen (pFmt->pName)))
104 break;
106 CPPUNIT_ASSERT_MESSAGE( "missing filter info", pFmt && pFmt->pName != NULL );
108 sal_uInt32 nFormat = 0;
109 if (pFmt->nFormatType)
110 nFormat = SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS;
111 SfxFilter* aFilter = new SfxFilter(
112 rtl::OUString::createFromAscii( pFmt->pFilterName ),
113 rtl::OUString(), pFmt->nFormatType, nFormat,
114 rtl::OUString::createFromAscii( pFmt->pTypeName ),
115 0, rtl::OUString(), rtl::OUString(), /* userdata */
116 rtl::OUString("private:factory/sdraw*") );
117 aFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT);
119 ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell();
120 SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
121 pSrcMed->SetFilter(aFilter);
122 if ( !xDocShRef->DoLoad(pSrcMed) )
124 if (xDocShRef.Is())
125 xDocShRef->DoClose();
126 CPPUNIT_ASSERT_MESSAGE( "failed to load", false );
129 return xDocShRef;
132 void SdFiltersTest::test()
134 ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/a.pptx"));
135 CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef.Is() );
136 CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef->IsInDestruction() );
138 SdDrawDocument *pDoc = xDocShRef->GetDoc();
139 CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != NULL );
141 // cf. SdrModel svx/svdmodel.hxx ...
143 CPPUNIT_ASSERT_MESSAGE( "wrong page count", pDoc->GetPageCount() == 3);
145 const SdrPage *pPage = pDoc->GetPage (1);
146 CPPUNIT_ASSERT_MESSAGE( "no page", pPage != NULL );
148 sal_uIntPtr nObjs = pPage->GetObjCount();
149 for (sal_uIntPtr i = 0; i < nObjs; i++)
151 SdrObject *pObj = pPage->GetObj(i);
152 SdrObjKind eKind = (SdrObjKind) pObj->GetObjIdentifier();
153 SdrTextObj *pTxt = dynamic_cast<SdrTextObj *>( pObj );
154 (void)pTxt; (void)eKind;
157 CPPUNIT_ASSERT_MESSAGE( "changed", !pDoc->IsChanged() );
158 xDocShRef->DoClose();
161 bool SdFiltersTest::load(const rtl::OUString &rFilter, const rtl::OUString &rURL,
162 const rtl::OUString &rUserData)
164 SfxFilter aFilter(
165 rFilter,
166 rtl::OUString(), 0, 0, rtl::OUString(), 0, rtl::OUString(),
167 rUserData, rtl::OUString() );
169 ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell();
170 SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
171 pSrcMed->SetFilter(&aFilter);
172 bool bLoaded = xDocShRef->DoLoad(pSrcMed);
173 xDocShRef->DoClose();
174 return bLoaded;
177 void SdFiltersTest::testCVEs()
179 testDir(rtl::OUString("MS PowerPoint 97"),
180 getURLFromSrc("/sd/qa/unit/data/ppt/"),
181 rtl::OUString("sdfilt"));
184 SdFiltersTest::SdFiltersTest()
188 void SdFiltersTest::setUp()
190 test::BootstrapFixture::setUp();
192 // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
193 // which is a private symbol to us, gets called
194 m_xDrawComponent =
195 getMultiServiceFactory()->createInstance("com.sun.star.comp.Draw.PresentationDocument");
196 CPPUNIT_ASSERT_MESSAGE("no impress component!", m_xDrawComponent.is());
199 void SdFiltersTest::tearDown()
201 uno::Reference< lang::XComponent >( m_xDrawComponent, uno::UNO_QUERY_THROW )->dispose();
202 test::BootstrapFixture::tearDown();
205 CPPUNIT_TEST_SUITE_REGISTRATION(SdFiltersTest);
207 CPPUNIT_PLUGIN_IMPLEMENT();
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */