LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sd/qa/unit - import-tests.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 98 98 100.0 %
Date: 2013-07-09 Functions: 14 15 93.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  */
       9             : 
      10             : #include "sdmodeltestbase.hxx"
      11             : 
      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>
      17             : 
      18             : #include <svx/svdotext.hxx>
      19             : #include <animations/animationnodehelper.hxx>
      20             : 
      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>
      27             : 
      28             : using namespace ::com::sun::star;
      29             : 
      30             : /// Impress import filters tests.
      31          15 : class SdFiltersTest : public SdModelTestBase
      32             : {
      33             : public:
      34             :     void testDocumentLayout();
      35             :     void testSmoketest();
      36             :     void testN759180();
      37             :     void testN778859();
      38             :     void testFdo64512();
      39             : 
      40           2 :     CPPUNIT_TEST_SUITE(SdFiltersTest);
      41           1 :     CPPUNIT_TEST(testDocumentLayout);
      42           1 :     CPPUNIT_TEST(testSmoketest);
      43           1 :     CPPUNIT_TEST(testN759180);
      44           1 :     CPPUNIT_TEST(testN778859);
      45           1 :     CPPUNIT_TEST(testFdo64512);
      46           2 :     CPPUNIT_TEST_SUITE_END();
      47             : };
      48             : 
      49             : /** Test document against a reference XML dump of shapes.
      50             : 
      51             : If you want to update one of these tests, or add a new one, set the nUpdateMe
      52             : to the index of the test, and the dump XML's will be created (or rewritten)
      53             : instead of checking. Use with care - when the test is failing, first find out
      54             : why, instead of just updating .xml's blindly.
      55             : 
      56             : Example: Let's say you are adding a test called fdoABCD.pptx.  You'll place it
      57             : to the data/ subdirectory, and will add an entry to aFilesToCompare below,
      58             : like:
      59             : 
      60             :         { "fdoABCD.pptx", "xml/fdoABCD_" },
      61             : 
      62             : and will count the index in the aFilesToCompare structure (1st is 0, 2nd is 1,
      63             : etc.)  Temporarily you'll set nUpdateMe to this index (instead of -1), and run
      64             : 
      65             : make sd
      66             : 
      67             : This will generate the sd/qa/unit/data/xml/fdoABCD_*.xml for you.  Now you
      68             : will change nUpdateMe back to -1, and commit your fdoABCD.pptx test, the
      69             : xml/fdoABCD_*.xml dumps, and the aFilesToCompare addition in one commit.
      70             : 
      71             : As the last step, you will revert your fix and do 'make sd' again, to check
      72             : that without your fix, the unit test breaks.  Then clean up, and push :-)
      73             : 
      74             : NOTE: This approach is suitable only for tests of fixes that actually change
      75             : the layout - best to check by reverting your fix locally after having added
      76             : the test, and re-running; it should break.
      77             : */
      78           1 : void SdFiltersTest::testDocumentLayout()
      79             : {
      80             :     struct { const char *pInput, *pDump; } aFilesToCompare[] =
      81             :     {
      82             :         { "odp/shapes-test.odp", "xml/shapes-test_page" },
      83             :         { "pptx/fdo47434-all.pptx", "pptx/xml/fdo47434_page" },
      84             :         { "n758621.ppt", "xml/n758621_" },
      85             :         { "fdo64586.ppt", "xml/fdo64586_" },
      86             :         // FIXME re-enable again when a better fix is found { "n819614.pptx", "xml/n819614_" },
      87             :         { "n820786.pptx", "xml/n820786_" },
      88             :         { "n762695.pptx", "xml/n762695_" },
      89             :         { "n593612.pptx", "xml/n593612_" },
      90           1 :     };
      91             : 
      92           8 :     for ( int i = 0; i < static_cast< int >( SAL_N_ELEMENTS( aFilesToCompare ) ); ++i )
      93             :     {
      94           7 :         int nUpdateMe = -1; // index of test we want to update; supposedly only when the test is created
      95             : 
      96           7 :         ::sd::DrawDocShellRef xDocShRef = loadURL( getURLFromSrc( "/sd/qa/unit/data/" ) + OUString::createFromAscii( aFilesToCompare[i].pInput ) );
      97             :         compareWithShapesDump( xDocShRef,
      98          14 :                 getPathFromSrc( "/sd/qa/unit/data/" ) + OUString::createFromAscii( aFilesToCompare[i].pDump ),
      99          14 :                 i == nUpdateMe );
     100           7 :     }
     101           1 : }
     102             : 
     103           1 : void SdFiltersTest::testSmoketest()
     104             : {
     105           1 :     ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/smoketest.pptx"));
     106           1 :     CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef.Is() );
     107           1 :     CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef->IsInDestruction() );
     108             : 
     109           1 :     SdDrawDocument *pDoc = xDocShRef->GetDoc();
     110           1 :     CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != NULL );
     111             : 
     112             :     // cf. SdrModel svx/svdmodel.hxx ...
     113             : 
     114           1 :     CPPUNIT_ASSERT_MESSAGE( "wrong page count", pDoc->GetPageCount() == 3);
     115             : 
     116           1 :     const SdrPage *pPage = pDoc->GetPage (1);
     117           1 :     CPPUNIT_ASSERT_MESSAGE( "no page", pPage != NULL );
     118             : 
     119           1 :     sal_uIntPtr nObjs = pPage->GetObjCount();
     120           4 :     for (sal_uIntPtr i = 0; i < nObjs; i++)
     121             :     {
     122           3 :         SdrObject *pObj = pPage->GetObj(i);
     123           3 :         SdrObjKind eKind = (SdrObjKind) pObj->GetObjIdentifier();
     124           3 :         SdrTextObj *pTxt = dynamic_cast<SdrTextObj *>( pObj );
     125             :         (void)pTxt; (void)eKind;
     126             :     }
     127             : 
     128           1 :     CPPUNIT_ASSERT_MESSAGE( "changed", !pDoc->IsChanged() );
     129           1 :     xDocShRef->DoClose();
     130           1 : }
     131             : 
     132           1 : void SdFiltersTest::testN759180()
     133             : {
     134           1 :     ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/n759180.pptx"));
     135           1 :     CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef.Is() );
     136           1 :     CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef->IsInDestruction() );
     137             : 
     138           1 :     SdDrawDocument *pDoc = xDocShRef->GetDoc();
     139           1 :     CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != NULL );
     140           1 :     const SdrPage *pPage = pDoc->GetPage (1);
     141           1 :     CPPUNIT_ASSERT_MESSAGE( "no page", pPage != NULL );
     142             : 
     143             :     //sal_uIntPtr nObjs = pPage->GetObjCount();
     144             :     //for (sal_uIntPtr i = 0; i < nObjs; i++)
     145             :     {
     146             :         // Get the object
     147           1 :         SdrObject *pObj = pPage->GetObj(0);
     148           1 :         SdrTextObj *pTxtObj = dynamic_cast<SdrTextObj *>( pObj );
     149           1 :         CPPUNIT_ASSERT(pTxtObj);
     150           1 :         std::vector<EECharAttrib> rLst;
     151           1 :         const EditTextObject& aEdit = pTxtObj->GetOutlinerParaObject()->GetTextObject();
     152           1 :         const SvxULSpaceItem *pULSpace = dynamic_cast<const SvxULSpaceItem *>(aEdit.GetParaAttribs(0).GetItem(EE_PARA_ULSPACE));
     153           1 :         CPPUNIT_ASSERT(pULSpace);
     154           1 :         CPPUNIT_ASSERT_MESSAGE( "Para bottom spacing is wrong!", pULSpace->GetLower() == 0 );
     155           1 :         aEdit.GetCharAttribs(1, rLst);
     156           2 :         for( std::vector<EECharAttrib>::reverse_iterator it = rLst.rbegin(); it!=rLst.rend(); ++it)
     157             :         {
     158           2 :             const SvxFontHeightItem * pFontHeight = dynamic_cast<const SvxFontHeightItem *>((*it).pAttr);
     159           2 :             if(pFontHeight)
     160             :             {
     161             :                 // nStart == 9
     162             :                 // font height = 5 => 5*2540/72
     163           1 :                 CPPUNIT_ASSERT_MESSAGE( "Font height is wrong", pFontHeight->GetHeight() == 176 );
     164           1 :                 break;
     165             :             }
     166           1 :         }
     167           1 :     }
     168           1 : }
     169             : 
     170           1 : void SdFiltersTest::testN778859()
     171             : {
     172           1 :     ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/pptx/n778859.pptx"));
     173           1 :     CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef.Is() );
     174           1 :     CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef->IsInDestruction() );
     175             : 
     176           1 :     SdDrawDocument *pDoc = xDocShRef->GetDoc();
     177           1 :     CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != NULL );
     178           1 :     const SdrPage *pPage = pDoc->GetPage(1);
     179           1 :     CPPUNIT_ASSERT_MESSAGE( "no page", pPage != NULL );
     180             :     {
     181             :         // Get the object
     182           1 :         SdrObject *pObj = pPage->GetObj(1);
     183           1 :         SdrTextObj *pTxtObj = dynamic_cast<SdrTextObj *>( pObj );
     184           1 :         CPPUNIT_ASSERT(!pTxtObj->IsAutoFit());
     185           1 :     }
     186           1 : }
     187             : 
     188           1 : void SdFiltersTest::testFdo64512()
     189             : {
     190           1 :     ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/fdo64512.odp"));
     191           1 :     CPPUNIT_ASSERT_MESSAGE( "failed to load", xDocShRef.Is() );
     192           1 :     CPPUNIT_ASSERT_MESSAGE( "not in destruction", !xDocShRef->IsInDestruction() );
     193             : 
     194             :     uno::Reference< drawing::XDrawPagesSupplier > xDoc(
     195           2 :         xDocShRef->GetDoc()->getUnoModel(), uno::UNO_QUERY_THROW );
     196           1 :     CPPUNIT_ASSERT_MESSAGE( "not exactly one page", xDoc->getDrawPages()->getCount() == 1 );
     197             : 
     198             :     uno::Reference< drawing::XDrawPage > xPage(
     199           2 :         xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW );
     200           1 :     CPPUNIT_ASSERT_MESSAGE( "no exactly three shapes", xPage->getCount() == 3 );
     201             : 
     202             :     uno::Reference< beans::XPropertySet > xConnectorShape(
     203           2 :         xPage->getByIndex(2), uno::UNO_QUERY );
     204           1 :     CPPUNIT_ASSERT_MESSAGE( "no connector shape", xConnectorShape.is() );
     205             : 
     206             :     uno::Reference< beans::XPropertySet > xSvgShape(
     207           2 :         xConnectorShape->getPropertyValue("StartShape"), uno::UNO_QUERY );
     208           1 :     CPPUNIT_ASSERT_MESSAGE( "no start shape", xSvgShape.is() );
     209             : 
     210             :     uno::Reference< beans::XPropertySet > xCustomShape(
     211           2 :         xConnectorShape->getPropertyValue("EndShape"), uno::UNO_QUERY );
     212           1 :     CPPUNIT_ASSERT_MESSAGE( "no end shape", xCustomShape.is() );
     213             : 
     214             :     uno::Reference< animations::XAnimationNodeSupplier > xAnimNodeSupplier(
     215           2 :         xPage, uno::UNO_QUERY_THROW );
     216             :     uno::Reference< animations::XAnimationNode > xRootNode(
     217           2 :         xAnimNodeSupplier->getAnimationNode() );
     218           2 :     std::vector< uno::Reference< animations::XAnimationNode > > aAnimVector;
     219           1 :     anim::create_deep_vector(xRootNode, aAnimVector);
     220           1 :     CPPUNIT_ASSERT_MESSAGE( "not 8 animation nodes", aAnimVector.size() == 8 );
     221             : 
     222             :     uno::Reference< animations::XAnimate > xNode(
     223           2 :         aAnimVector[7], uno::UNO_QUERY_THROW );
     224             :     uno::Reference< drawing::XShape > xTargetShape(
     225           2 :         xNode->getTarget(), uno::UNO_QUERY_THROW );
     226           2 :     CPPUNIT_ASSERT_MESSAGE( "inner node not referencing svg shape",
     227           2 :                             xTargetShape != xSvgShape );
     228           1 : }
     229             : 
     230           1 : CPPUNIT_TEST_SUITE_REGISTRATION(SdFiltersTest);
     231             : 
     232           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     233             : 
     234             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10