1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include "sdmodeltestbase.hxx"
12 #include <svl/stritem.hxx>
13 #include <editeng/editobj.hxx>
14 #include <editeng/outlobj.hxx>
15 #include <editeng/ulspitem.hxx>
16 #include <editeng/fhgtitem.hxx>
18 #include <svx/svdotext.hxx>
19 #include <animations/animationnodehelper.hxx>
21 #include <com/sun/star/drawing/XDrawPage.hpp>
22 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
23 #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
24 #include <com/sun/star/animations/XAnimationNode.hpp>
25 #include <com/sun/star/animations/XAnimate.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
28 using namespace ::com::sun::star
;
30 /// Impress import filters tests.
31 class SdFiltersTest
: public SdModelTestBase
34 void testDocumentLayout();
40 CPPUNIT_TEST_SUITE(SdFiltersTest
);
41 CPPUNIT_TEST(testDocumentLayout
);
42 CPPUNIT_TEST(testSmoketest
);
43 CPPUNIT_TEST(testN759180
);
44 CPPUNIT_TEST(testN778859
);
45 CPPUNIT_TEST(testFdo64512
);
46 CPPUNIT_TEST_SUITE_END();
49 /** Test document against a reference XML dump of shapes.
51 If you want to update one of these tests, set the nUpdateMe to the index of
52 the test, the dump XML's will be created (or rewritten) instead of checking.
53 Use with care - when the test is failing, first find out why, instead of just
54 updating .xml's blindly.
56 NOTE: This approach is suitable only for tests of fixes that actually change
57 the layout - best to check by reverting your fix locally after having added
58 the test, and re-running; it should break.
60 void SdFiltersTest::testDocumentLayout()
62 struct { const char *pInput
, *pDump
; } aFilesToCompare
[] =
64 { "odp/shapes-test.odp", "xml/shapes-test_page" },
65 { "pptx/fdo47434-all.pptx", "pptx/xml/fdo47434_page" },
66 { "n758621.ppt", "xml/n758621_" },
67 { "fdo64586.ppt", "xml/fdo64586_" },
68 // FIXME re-enable again when a better fix is found { "n819614.pptx", "xml/n819614_" },
69 { "n820786.pptx", "xml/n820786_" },
72 for ( int i
= 0; i
< static_cast< int >( SAL_N_ELEMENTS( aFilesToCompare
) ); ++i
)
74 int nUpdateMe
= -1; // index of test we want to update; supposedly only when the test is created
76 ::sd::DrawDocShellRef xDocShRef
= loadURL( getURLFromSrc( "/sd/qa/unit/data/" ) + OUString::createFromAscii( aFilesToCompare
[i
].pInput
) );
77 compareWithShapesDump( xDocShRef
,
78 getPathFromSrc( "/sd/qa/unit/data/" ) + OUString::createFromAscii( aFilesToCompare
[i
].pDump
),
83 void SdFiltersTest::testSmoketest()
85 ::sd::DrawDocShellRef xDocShRef
= loadURL(getURLFromSrc("/sd/qa/unit/data/smoketest.pptx"));
86 CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef
.Is() );
87 CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef
->IsInDestruction() );
89 SdDrawDocument
*pDoc
= xDocShRef
->GetDoc();
90 CPPUNIT_ASSERT_MESSAGE( "no document", pDoc
!= NULL
);
92 // cf. SdrModel svx/svdmodel.hxx ...
94 CPPUNIT_ASSERT_MESSAGE( "wrong page count", pDoc
->GetPageCount() == 3);
96 const SdrPage
*pPage
= pDoc
->GetPage (1);
97 CPPUNIT_ASSERT_MESSAGE( "no page", pPage
!= NULL
);
99 sal_uIntPtr nObjs
= pPage
->GetObjCount();
100 for (sal_uIntPtr i
= 0; i
< nObjs
; i
++)
102 SdrObject
*pObj
= pPage
->GetObj(i
);
103 SdrObjKind eKind
= (SdrObjKind
) pObj
->GetObjIdentifier();
104 SdrTextObj
*pTxt
= dynamic_cast<SdrTextObj
*>( pObj
);
105 (void)pTxt
; (void)eKind
;
108 CPPUNIT_ASSERT_MESSAGE( "changed", !pDoc
->IsChanged() );
109 xDocShRef
->DoClose();
112 void SdFiltersTest::testN759180()
114 ::sd::DrawDocShellRef xDocShRef
= loadURL(getURLFromSrc("/sd/qa/unit/data/n759180.pptx"));
115 CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef
.Is() );
116 CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef
->IsInDestruction() );
118 SdDrawDocument
*pDoc
= xDocShRef
->GetDoc();
119 CPPUNIT_ASSERT_MESSAGE( "no document", pDoc
!= NULL
);
120 const SdrPage
*pPage
= pDoc
->GetPage (1);
121 CPPUNIT_ASSERT_MESSAGE( "no page", pPage
!= NULL
);
123 //sal_uIntPtr nObjs = pPage->GetObjCount();
124 //for (sal_uIntPtr i = 0; i < nObjs; i++)
127 SdrObject
*pObj
= pPage
->GetObj(0);
128 SdrTextObj
*pTxtObj
= dynamic_cast<SdrTextObj
*>( pObj
);
129 CPPUNIT_ASSERT(pTxtObj
);
130 std::vector
<EECharAttrib
> rLst
;
131 const EditTextObject
& aEdit
= pTxtObj
->GetOutlinerParaObject()->GetTextObject();
132 const SvxULSpaceItem
*pULSpace
= dynamic_cast<const SvxULSpaceItem
*>(aEdit
.GetParaAttribs(0).GetItem(EE_PARA_ULSPACE
));
133 CPPUNIT_ASSERT(pULSpace
);
134 CPPUNIT_ASSERT_MESSAGE( "Para bottom spacing is wrong!", pULSpace
->GetLower() == 0 );
135 aEdit
.GetCharAttribs(1, rLst
);
136 for( std::vector
<EECharAttrib
>::reverse_iterator it
= rLst
.rbegin(); it
!=rLst
.rend(); ++it
)
138 const SvxFontHeightItem
* pFontHeight
= dynamic_cast<const SvxFontHeightItem
*>((*it
).pAttr
);
142 // font height = 5 => 5*2540/72
143 CPPUNIT_ASSERT_MESSAGE( "Font height is wrong", pFontHeight
->GetHeight() == 176 );
150 void SdFiltersTest::testN778859()
152 ::sd::DrawDocShellRef xDocShRef
= loadURL(getURLFromSrc("/sd/qa/unit/data/pptx/n778859.pptx"));
153 CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef
.Is() );
154 CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef
->IsInDestruction() );
156 SdDrawDocument
*pDoc
= xDocShRef
->GetDoc();
157 CPPUNIT_ASSERT_MESSAGE( "no document", pDoc
!= NULL
);
158 const SdrPage
*pPage
= pDoc
->GetPage(1);
159 CPPUNIT_ASSERT_MESSAGE( "no page", pPage
!= NULL
);
162 SdrObject
*pObj
= pPage
->GetObj(1);
163 SdrTextObj
*pTxtObj
= dynamic_cast<SdrTextObj
*>( pObj
);
164 CPPUNIT_ASSERT(!pTxtObj
->IsAutoFit());
168 void SdFiltersTest::testFdo64512()
170 ::sd::DrawDocShellRef xDocShRef
= loadURL(getURLFromSrc("/sd/qa/unit/data/fdo64512.odp"));
171 CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef
.Is() );
172 CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef
->IsInDestruction() );
174 uno::Reference
< drawing::XDrawPagesSupplier
> xDoc(
175 xDocShRef
->GetDoc()->getUnoModel(), uno::UNO_QUERY_THROW
);
176 CPPUNIT_ASSERT_MESSAGE( "not exactly one page", xDoc
->getDrawPages()->getCount() == 1 );
178 uno::Reference
< drawing::XDrawPage
> xPage(
179 xDoc
->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW
);
180 CPPUNIT_ASSERT_MESSAGE( "no exactly three shapes", xPage
->getCount() == 3 );
182 uno::Reference
< beans::XPropertySet
> xConnectorShape(
183 xPage
->getByIndex(2), uno::UNO_QUERY
);
184 CPPUNIT_ASSERT_MESSAGE( "no connector shape", xConnectorShape
.is() );
186 uno::Reference
< beans::XPropertySet
> xSvgShape(
187 xConnectorShape
->getPropertyValue("StartShape"), uno::UNO_QUERY
);
188 CPPUNIT_ASSERT_MESSAGE( "no start shape", xSvgShape
.is() );
190 uno::Reference
< beans::XPropertySet
> xCustomShape(
191 xConnectorShape
->getPropertyValue("EndShape"), uno::UNO_QUERY
);
192 CPPUNIT_ASSERT_MESSAGE( "no end shape", xCustomShape
.is() );
194 uno::Reference
< animations::XAnimationNodeSupplier
> xAnimNodeSupplier(
195 xPage
, uno::UNO_QUERY_THROW
);
196 uno::Reference
< animations::XAnimationNode
> xRootNode(
197 xAnimNodeSupplier
->getAnimationNode() );
198 std::vector
< uno::Reference
< animations::XAnimationNode
> > aAnimVector
;
199 anim::create_deep_vector(xRootNode
, aAnimVector
);
200 CPPUNIT_ASSERT_MESSAGE( "not 8 animation nodes", aAnimVector
.size() == 8 );
202 uno::Reference
< animations::XAnimate
> xNode(
203 aAnimVector
[7], uno::UNO_QUERY_THROW
);
204 uno::Reference
< drawing::XShape
> xTargetShape(
205 xNode
->getTarget(), uno::UNO_QUERY_THROW
);
206 CPPUNIT_ASSERT_MESSAGE( "inner node not referencing svg shape",
207 xTargetShape
!= xSvgShape
);
210 CPPUNIT_TEST_SUITE_REGISTRATION(SdFiltersTest
);
212 CPPUNIT_PLUGIN_IMPLEMENT();
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */