Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
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/
9 : : *
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.
14 : : *
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.
19 : : *
20 : : * Contributor(s):
21 : : * Caolán McNamara <caolanm@redhat.com>
22 : : *
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.
28 : : */
29 : :
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>
37 : :
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>
43 : :
44 : : #include <svx/svdtext.hxx>
45 : : #include <svx/svdotext.hxx>
46 : :
47 : : #include "drawdoc.hxx"
48 : : #include "../source/ui/inc/DrawDocShell.hxx"
49 : :
50 : : #include <osl/process.h>
51 : : #include <osl/thread.h>
52 : :
53 : : /* Implementation of Filters test */
54 : :
55 : : using namespace ::com::sun::star;
56 : :
57 [ + - ][ - + ]: 12 : class SdFiltersTest
58 : : : public test::FiltersTest
59 : : , public test::BootstrapFixture
60 : : {
61 : : public:
62 : : SdFiltersTest();
63 : :
64 : : ::sd::DrawDocShellRef loadURL( const rtl::OUString &rURL );
65 : : virtual bool load( const rtl::OUString &rFilter, const rtl::OUString &rURL, const rtl::OUString &rUserData);
66 : :
67 : : virtual void setUp();
68 : : virtual void tearDown();
69 : :
70 : : void test();
71 : : // Ensure CVEs remain unbroken
72 : : void testCVEs();
73 : :
74 [ + - ][ + - ]: 6 : CPPUNIT_TEST_SUITE(SdFiltersTest);
[ + - ][ + - ]
[ # # ]
75 [ + - ][ + - ]: 3 : CPPUNIT_TEST(test);
[ + - ][ + - ]
[ + - ][ + - ]
76 [ + - ][ + - ]: 3 : CPPUNIT_TEST(testCVEs);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
77 [ + - ][ + - ]: 6 : CPPUNIT_TEST_SUITE_END();
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
78 : :
79 : : private:
80 : : uno::Reference<document::XFilter> m_xFilter;
81 : : uno::Reference<uno::XInterface> m_xDrawComponent;
82 : : };
83 : :
84 : : #define PPTX_FORMAT_TYPE 268959811
85 : :
86 : : struct FileFormat {
87 : : const char* pName; const char* pFilterName; const char* pTypeName; sal_uLong nFormatType;
88 : : };
89 : :
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 }
94 : : };
95 : :
96 : 3 : ::sd::DrawDocShellRef SdFiltersTest::loadURL( const rtl::OUString &rURL )
97 : : {
98 : 3 : FileFormat *pFmt = NULL;
99 : :
100 [ + - ]: 3 : for (size_t i = 0; i < SAL_N_ELEMENTS (aFileFormats); i++)
101 : : {
102 : 3 : pFmt = aFileFormats + i;
103 [ + - ][ + - ]: 3 : if (pFmt->pName && rURL.endsWithIgnoreAsciiCaseAsciiL (pFmt->pName, strlen (pFmt->pName)))
[ + - ]
104 : 3 : break;
105 : : }
106 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE( "missing filter info", pFmt && pFmt->pName != NULL );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ - + ]
[ + - ][ + - ]
[ + - ]
107 : :
108 : 3 : sal_uInt32 nFormat = 0;
109 [ + - ]: 3 : if (pFmt->nFormatType)
110 : 3 : 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 [ + - ][ + - ]: 3 : rtl::OUString("private:factory/sdraw*") );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
117 : 3 : aFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT);
118 : :
119 [ + - ]: 3 : ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell();
120 [ + - ][ + - ]: 3 : SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
[ + - ][ + - ]
121 [ + - ]: 3 : pSrcMed->SetFilter(aFilter);
122 [ + - ][ - + ]: 3 : if ( !xDocShRef->DoLoad(pSrcMed) )
123 : : {
124 [ # # ]: 0 : if (xDocShRef.Is())
125 [ # # ]: 0 : xDocShRef->DoClose();
126 [ # # ][ # # ]: 0 : CPPUNIT_ASSERT_MESSAGE( "failed to load", false );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
127 : : }
128 : :
129 : 3 : return xDocShRef;
130 : : }
131 : :
132 : 3 : void SdFiltersTest::test()
133 : : {
134 [ + - ][ + - ]: 3 : ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/a.pptx"));
135 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef.Is() );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
136 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef->IsInDestruction() );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
137 : :
138 [ + - ]: 3 : SdDrawDocument *pDoc = xDocShRef->GetDoc();
139 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != NULL );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
140 : :
141 : : // cf. SdrModel svx/svdmodel.hxx ...
142 : :
143 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE( "wrong page count", pDoc->GetPageCount() == 3);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
144 : :
145 [ + - ]: 3 : const SdrPage *pPage = pDoc->GetPage (1);
146 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE( "no page", pPage != NULL );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
147 : :
148 [ + - ]: 3 : sal_uIntPtr nObjs = pPage->GetObjCount();
149 [ + + ]: 12 : for (sal_uIntPtr i = 0; i < nObjs; i++)
150 : : {
151 [ + - ]: 9 : SdrObject *pObj = pPage->GetObj(i);
152 [ + - ]: 9 : SdrObjKind eKind = (SdrObjKind) pObj->GetObjIdentifier();
153 [ - + ]: 9 : SdrTextObj *pTxt = dynamic_cast<SdrTextObj *>( pObj );
154 : : (void)pTxt; (void)eKind;
155 : : }
156 : :
157 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE( "changed", !pDoc->IsChanged() );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
158 [ + - ][ + - ]: 3 : xDocShRef->DoClose();
159 : 3 : }
160 : :
161 : 15 : bool SdFiltersTest::load(const rtl::OUString &rFilter, const rtl::OUString &rURL,
162 : : const rtl::OUString &rUserData)
163 : : {
164 : : SfxFilter aFilter(
165 : : rFilter,
166 : : rtl::OUString(), 0, 0, rtl::OUString(), 0, rtl::OUString(),
167 [ + - ][ + - ]: 15 : rUserData, rtl::OUString() );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
168 : :
169 [ + - ][ + - ]: 15 : ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell();
170 [ + - ][ + - ]: 15 : SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
[ + - ][ + - ]
171 [ + - ]: 15 : pSrcMed->SetFilter(&aFilter);
172 [ + - ]: 15 : bool bLoaded = xDocShRef->DoLoad(pSrcMed);
173 [ + - ]: 15 : xDocShRef->DoClose();
174 [ + - ][ + - ]: 15 : return bLoaded;
175 : : }
176 : :
177 : 3 : void SdFiltersTest::testCVEs()
178 : : {
179 : : testDir(rtl::OUString("MS PowerPoint 97"),
180 : : getURLFromSrc("/sd/qa/unit/data/ppt/"),
181 [ + - ][ + - ]: 3 : rtl::OUString("sdfilt"));
182 : 3 : }
183 : :
184 [ + - ]: 6 : SdFiltersTest::SdFiltersTest()
185 : : {
186 : 6 : }
187 : :
188 : 6 : void SdFiltersTest::setUp()
189 : : {
190 : 6 : test::BootstrapFixture::setUp();
191 : :
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 [ + - ][ + - ]: 6 : getMultiServiceFactory()->createInstance("com.sun.star.comp.Draw.PresentationDocument");
[ + - ]
196 [ + - ][ + - ]: 6 : CPPUNIT_ASSERT_MESSAGE("no impress component!", m_xDrawComponent.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
197 : 6 : }
198 : :
199 : 6 : void SdFiltersTest::tearDown()
200 : : {
201 [ + - ][ + - ]: 6 : uno::Reference< lang::XComponent >( m_xDrawComponent, uno::UNO_QUERY_THROW )->dispose();
202 : 6 : test::BootstrapFixture::tearDown();
203 : 6 : }
204 : :
205 : 3 : CPPUNIT_TEST_SUITE_REGISTRATION(SdFiltersTest);
206 : :
207 [ + - ][ + - ]: 12 : CPPUNIT_PLUGIN_IMPLEMENT();
[ + - ][ + - ]
[ + - ][ # # ]
208 : :
209 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|