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 : : * Markus Mohrhard <markus.mohrhard@googlemail.com>
17 : : * Portions created by the Initial Developer are Copyright (C) 2012 the
18 : : * Initial Developer. All Rights Reserved.
19 : : *
20 : : * Contributor(s):
21 : : * Michael Meeks <michael.meeks@suse.com>
22 : : * Caolán McNamara <caolanm@redhat.com>
23 : : *
24 : : * Alternatively, the contents of this file may be used under the terms of
25 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
26 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
27 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
28 : : * instead of those above.
29 : : */
30 : :
31 : : #include <sal/config.h>
32 : : #include <unotest/filters-test.hxx>
33 : : #include <test/bootstrapfixture.hxx>
34 : : #include <test/xmldiff.hxx>
35 : : #include <rtl/strbuf.hxx>
36 : : #include <osl/file.hxx>
37 : : #include <com/sun/star/lang/XComponent.hpp>
38 : : #include <com/sun/star/document/XFilter.hpp>
39 : : #include <com/sun/star/frame/XStorable.hpp>
40 : :
41 : : #include <sfx2/app.hxx>
42 : : #include <sfx2/docfilt.hxx>
43 : : #include <sfx2/docfile.hxx>
44 : : #include <sfx2/sfxmodelfactory.hxx>
45 : : #include <svl/stritem.hxx>
46 : :
47 : : #include <svx/svdtext.hxx>
48 : : #include <svx/svdotext.hxx>
49 : :
50 : : #include "drawdoc.hxx"
51 : : #include "../source/ui/inc/DrawDocShell.hxx"
52 : :
53 : : #include <osl/process.h>
54 : : #include <osl/thread.h>
55 : :
56 : : #include <string>
57 : : #include <iostream>
58 : : #include <rtl/oustringostreaminserter.hxx>
59 : :
60 : : #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
61 : : #include <drawinglayer/XShapeDumper.hxx>
62 : :
63 : : #include <editeng/editobj.hxx>
64 : : #include <editeng/outlobj.hxx>
65 : : #include <editeng/ulspitem.hxx>
66 : : #include <editeng/fhgtitem.hxx>
67 : :
68 : : /* Implementation of Filters test */
69 : :
70 : : using namespace ::com::sun::star;
71 : :
72 [ + - ][ - + ]: 18 : class SdFiltersTest
73 : : : public test::FiltersTest
74 : : , public test::BootstrapFixture
75 : : {
76 : : public:
77 : : SdFiltersTest();
78 : :
79 : : ::sd::DrawDocShellRef loadURL( const rtl::OUString &rURL );
80 : : virtual bool load( const rtl::OUString &rFilter, const rtl::OUString &rURL, const rtl::OUString &rUserData);
81 : :
82 : : virtual void setUp();
83 : : virtual void tearDown();
84 : :
85 : : void test();
86 : : void testN759180();
87 : : void testFdo47434();
88 : :
89 [ + - ][ + - ]: 6 : CPPUNIT_TEST_SUITE(SdFiltersTest);
[ + - ][ + - ]
[ # # ]
90 [ + - ][ + - ]: 3 : CPPUNIT_TEST(test);
[ + - ][ + - ]
[ + - ][ + - ]
91 [ + - ][ + - ]: 3 : CPPUNIT_TEST(testN759180);
[ + - ][ + - ]
[ + - ][ + - ]
92 [ + - ][ + - ]: 3 : CPPUNIT_TEST(testFdo47434);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
93 [ + - ][ + - ]: 6 : CPPUNIT_TEST_SUITE_END();
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
94 : :
95 : : private:
96 : : uno::Reference<document::XFilter> m_xFilter;
97 : : uno::Reference<uno::XInterface> m_xDrawComponent;
98 : : void testStuff(::sd::DrawDocShellRef xDocShRef, const rtl::OString& fileNameBase);
99 : : };
100 : :
101 : : #define PPTX_FORMAT_TYPE 268959811
102 : : #define ODP_FORMAT_TYPE 285212967
103 : :
104 : : struct FileFormat {
105 : : const char* pName; const char* pFilterName; const char* pTypeName; sal_uLong nFormatType;
106 : : };
107 : :
108 : : // cf. sc/qa/unit/filters-test.cxx and filters/...*.xcu to fill out.
109 : : FileFormat aFileFormats[] = {
110 : : { "pptx" , "Impress MS PowerPoint 2007 XML", "MS PowerPoint 2007 XML", PPTX_FORMAT_TYPE },
111 : : { "odp" , "impress8", "impress8", ODP_FORMAT_TYPE },
112 : : { 0, 0, 0, 0 }
113 : : };
114 : :
115 : 9 : ::sd::DrawDocShellRef SdFiltersTest::loadURL( const rtl::OUString &rURL )
116 : : {
117 : 9 : FileFormat *pFmt(0);
118 : :
119 [ + - ]: 12 : for (size_t i = 0; i < SAL_N_ELEMENTS (aFileFormats); i++)
120 : : {
121 : 12 : pFmt = aFileFormats + i;
122 [ + - ][ + + ]: 12 : if (pFmt->pName && rURL.endsWithIgnoreAsciiCaseAsciiL (pFmt->pName, strlen (pFmt->pName)))
[ + + ]
123 : 9 : break;
124 : : }
125 [ + - ][ + - ]: 9 : CPPUNIT_ASSERT_MESSAGE( "missing filter info", pFmt->pName != NULL );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
126 : :
127 : 9 : sal_uInt32 nFormat = 0;
128 [ + - ]: 9 : if (pFmt->nFormatType)
129 : 9 : nFormat = SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS;
130 : : SfxFilter* aFilter = new SfxFilter(
131 : : rtl::OUString::createFromAscii( pFmt->pFilterName ),
132 : : rtl::OUString(), pFmt->nFormatType, nFormat,
133 : : rtl::OUString::createFromAscii( pFmt->pTypeName ),
134 : : 0, rtl::OUString(), rtl::OUString(), /* userdata */
135 [ + - ][ + - ]: 9 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/simpress*")) );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
136 : 9 : aFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT);
137 : :
138 [ + - ]: 9 : ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell();
139 [ + - ][ + - ]: 9 : SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
[ + - ][ + - ]
140 [ + - ]: 9 : pSrcMed->SetFilter(aFilter);
141 [ + - ][ - + ]: 9 : if ( !xDocShRef->DoLoad(pSrcMed) )
142 : : {
143 [ # # ]: 0 : if (xDocShRef.Is())
144 [ # # ]: 0 : xDocShRef->DoClose();
145 [ # # ][ # # ]: 0 : CPPUNIT_ASSERT_MESSAGE( "failed to load", false );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
146 : : }
147 : :
148 : 9 : return xDocShRef;
149 : : }
150 : :
151 : 3 : void SdFiltersTest::test()
152 : : {
153 : : {
154 [ + - ][ + - ]: 3 : ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/odp/shapes-test.odp"));
155 [ + - ][ + - ]: 3 : testStuff(xDocShRef, rtl::OUStringToOString(getPathFromSrc("/sd/qa/unit/data/xml/shapes-test_page"), RTL_TEXTENCODING_UTF8));
[ + - ][ + - ]
[ + - ]
156 : : }
157 : : /*
158 : : {
159 : : ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/odp/text-test.odp"));
160 : : testStuff(xDocShRef);
161 : : }*/
162 : 3 : }
163 : :
164 : 3 : void SdFiltersTest::testN759180()
165 : : {
166 [ + - ][ + - ]: 3 : ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/n759180.pptx"));
167 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef.Is() );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
168 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef->IsInDestruction() );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
169 : :
170 [ + - ]: 3 : SdDrawDocument *pDoc = xDocShRef->GetDoc();
171 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != NULL );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
172 [ + - ]: 3 : const SdrPage *pPage = pDoc->GetPage (1);
173 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE( "no page", pPage != NULL );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
174 : :
175 : : //sal_uIntPtr nObjs = pPage->GetObjCount();
176 : : //for (sal_uIntPtr i = 0; i < nObjs; i++)
177 : : {
178 : : // Get the object
179 [ + - ]: 3 : SdrObject *pObj = pPage->GetObj(0);
180 [ - + ]: 3 : SdrTextObj *pTxtObj = dynamic_cast<SdrTextObj *>( pObj );
181 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT(pTxtObj);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
182 [ + - ]: 3 : std::vector<EECharAttrib> rLst;
183 [ + - ][ + - ]: 3 : const EditTextObject& aEdit = pTxtObj->GetOutlinerParaObject()->GetTextObject();
184 [ + - ][ + - ]: 3 : const SvxULSpaceItem *pULSpace = dynamic_cast<const SvxULSpaceItem *>(aEdit.GetParaAttribs(0).GetItem(EE_PARA_ULSPACE));
[ - + ][ + - ]
185 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT(pULSpace);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
186 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE( "Para bottom spacing is wrong!", pULSpace->GetLower() == 0 );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
187 [ + - ]: 3 : aEdit.GetCharAttribs(1, rLst);
188 [ + - ][ + - ]: 6 : for( std::vector<EECharAttrib>::reverse_iterator it = rLst.rbegin(); it!=rLst.rend(); it++)
[ + - ]
189 : : {
190 [ + - ][ - + ]: 6 : const SvxFontHeightItem * pFontHeight = dynamic_cast<const SvxFontHeightItem *>((*it).pAttr);
191 [ + + ]: 6 : if(pFontHeight)
192 : : {
193 : : // nStart == 9
194 : : // font height = 5 => 5*2540/72
195 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_MESSAGE( "Font height is wrong", pFontHeight->GetHeight() == 176 );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
196 : 3 : break;
197 : : }
198 : 3 : }
199 [ + - ]: 3 : }
200 : 3 : }
201 : :
202 : 3 : void SdFiltersTest::testFdo47434()
203 : : {
204 : : // The problem was the arrow that has cy < 180 and flipH = 0 is rendered incorrectly.
205 : : // Its height should be 1, not negative.
206 [ + - ][ + - ]: 3 : ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/pptx/fdo47434-all.pptx"));
207 [ + - ][ + - ]: 3 : testStuff(xDocShRef, rtl::OUStringToOString(getPathFromSrc("/sd/qa/unit/data/pptx/xml/fdo47434_page"), RTL_TEXTENCODING_UTF8));
[ + - ][ + - ]
[ + - ]
208 : 3 : }
209 : :
210 : 6 : void SdFiltersTest::testStuff(::sd::DrawDocShellRef xDocShRef, const rtl::OString& fileNameBase)
211 : : {
212 [ + - ][ + - ]: 6 : CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef.Is() );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
213 [ + - ][ + - ]: 6 : CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef->IsInDestruction() );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
214 : :
215 [ + - ][ + - ]: 6 : uno::Reference<frame::XModel> xTempModel(xDocShRef->GetDoc()->getUnoModel(), uno::UNO_QUERY_THROW);
[ + - ]
216 [ + - ][ + - ]: 6 : CPPUNIT_ASSERT(xTempModel.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
217 [ + - ]: 6 : uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier (xTempModel, uno::UNO_QUERY_THROW);
218 [ + - ][ + - ]: 6 : CPPUNIT_ASSERT(xDrawPagesSupplier.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
219 [ + - ][ + - ]: 6 : uno::Reference< drawing::XDrawPages > xDrawPages = xDrawPagesSupplier->getDrawPages();
220 [ + - ][ + - ]: 6 : CPPUNIT_ASSERT(xDrawPages.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
221 : :
222 [ + - ]: 6 : XShapeDumper xShapeDumper;
223 [ + - ][ + - ]: 6 : sal_Int32 nLength = xDrawPages->getCount();
224 : 6 : rtl::OString aFileNameExt(".xml");
225 [ + + ]: 33 : for (sal_Int32 i = 0; i < nLength; ++i)
226 : : {
227 : 27 : uno::Reference<drawing::XDrawPage> xDrawPage;
228 [ + - ][ + - ]: 27 : uno::Any aAny = xDrawPages->getByIndex(i);
229 [ + - ]: 27 : aAny >>= xDrawPage;
230 [ + - ]: 27 : uno::Reference< drawing::XShapes > xShapes(xDrawPage, uno::UNO_QUERY_THROW);
231 [ + - ]: 27 : rtl::OUString aString = xShapeDumper.dump(xShapes);
232 [ + - ]: 27 : rtl::OStringBuffer aFileNameBuf(fileNameBase);
233 [ + - ]: 27 : aFileNameBuf.append(i);
234 [ + - ]: 27 : aFileNameBuf.append(aFileNameExt);
235 : :
236 : 27 : rtl::OString aFileName = aFileNameBuf.makeStringAndClear();
237 : :
238 [ + - ][ + - ]: 27 : std::cout << aString << std::endl;
239 : : doXMLDiff(aFileName.getStr(),
240 : : rtl::OUStringToOString(aString, RTL_TEXTENCODING_UTF8).getStr(),
241 : 27 : static_cast<int>(aString.getLength()),
242 : : rtl::OUStringToOString(
243 : : getPathFromSrc("/sd/qa/unit/data/tolerance.xml"),
244 [ + - ][ + - ]: 54 : RTL_TEXTENCODING_UTF8).getStr());
[ + - ][ + - ]
245 : 27 : }
246 [ + - ]: 6 : xDocShRef->DoClose();
247 : 6 : }
248 : :
249 : 0 : bool SdFiltersTest::load(const rtl::OUString &rFilter, const rtl::OUString &rURL,
250 : : const rtl::OUString &rUserData)
251 : : {
252 : : SfxFilter aFilter(
253 : : rFilter,
254 : : rtl::OUString(), 0, 0, rtl::OUString(), 0, rtl::OUString(),
255 [ # # ][ # # ]: 0 : rUserData, rtl::OUString() );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
256 : :
257 [ # # ][ # # ]: 0 : ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell();
258 [ # # ][ # # ]: 0 : SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
[ # # ][ # # ]
259 [ # # ]: 0 : pSrcMed->SetFilter(&aFilter);
260 [ # # ]: 0 : bool bLoaded = xDocShRef->DoLoad(pSrcMed);
261 [ # # ]: 0 : xDocShRef->DoClose();
262 [ # # ][ # # ]: 0 : return bLoaded;
263 : : }
264 : :
265 [ + - ]: 9 : SdFiltersTest::SdFiltersTest()
266 : : {
267 : 9 : }
268 : :
269 : 9 : void SdFiltersTest::setUp()
270 : : {
271 : 9 : test::BootstrapFixture::setUp();
272 : :
273 : : // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
274 : : // which is a private symbol to us, gets called
275 : : m_xDrawComponent =
276 [ + - ]: 18 : getMultiServiceFactory()->createInstance(rtl::OUString(
277 [ + - ][ + - ]: 9 : RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Draw.PresentationDocument")));
[ + - ]
278 [ + - ][ + - ]: 9 : CPPUNIT_ASSERT_MESSAGE("no impress component!", m_xDrawComponent.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
279 : 9 : }
280 : :
281 : 9 : void SdFiltersTest::tearDown()
282 : : {
283 [ + - ][ + - ]: 9 : uno::Reference< lang::XComponent >( m_xDrawComponent, uno::UNO_QUERY_THROW )->dispose();
284 : 9 : test::BootstrapFixture::tearDown();
285 : 9 : }
286 : :
287 : 3 : CPPUNIT_TEST_SUITE_REGISTRATION(SdFiltersTest);
288 : :
289 [ + - ][ + - ]: 12 : CPPUNIT_PLUGIN_IMPLEMENT();
[ + - ][ + - ]
[ + - ][ # # ]
290 : :
291 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|