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