LCOV - code coverage report
Current view: top level - sdext/source/pdfimport/test - tests.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 203 268 75.7 %
Date: 2014-04-11 Functions: 39 47 83.0 %
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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <zlib.h>
      21             : 
      22             : #include "outputwrap.hxx"
      23             : #include "contentsink.hxx"
      24             : #include "pdfihelper.hxx"
      25             : #include "wrapper.hxx"
      26             : #include "pdfparse.hxx"
      27             : #include "../pdfiadaptor.hxx"
      28             : 
      29             : #include <rtl/math.hxx>
      30             : #include <osl/file.hxx>
      31             : #include <comphelper/sequence.hxx>
      32             : 
      33             : #include "cppunit/TestAssert.h"
      34             : #include "cppunit/TestFixture.h"
      35             : #include "cppunit/extensions/HelperMacros.h"
      36             : #include "cppunit/plugin/TestPlugIn.h"
      37             : #include <test/bootstrapfixture.hxx>
      38             : 
      39             : #include <com/sun/star/rendering/XCanvas.hpp>
      40             : #include <com/sun/star/rendering/XColorSpace.hpp>
      41             : #include <com/sun/star/rendering/PathJoinType.hpp>
      42             : #include <com/sun/star/rendering/PathCapType.hpp>
      43             : #include <com/sun/star/rendering/BlendMode.hpp>
      44             : 
      45             : #include <basegfx/matrix/b2dhommatrix.hxx>
      46             : #include <basegfx/tools/canvastools.hxx>
      47             : #include <basegfx/polygon/b2dpolygon.hxx>
      48             : #include <basegfx/polygon/b2dpolypolygon.hxx>
      49             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      50             : #include <basegfx/polygon/b2dpolygonclipper.hxx>
      51             : 
      52             : #include <vector>
      53             : #include <boost/unordered_map.hpp>
      54             : 
      55             : #include <cassert>
      56             : #include <rtl/ustring.hxx>
      57             : 
      58             : using namespace ::pdfparse;
      59             : using namespace ::pdfi;
      60             : using namespace ::com::sun::star;
      61             : 
      62             : namespace
      63             : {
      64             : 
      65             :     class TestSink : public ContentSink
      66             :     {
      67             :     public:
      68           1 :         TestSink() :
      69             :             m_nNextFontId( 1 ),
      70             :             m_aIdToFont(),
      71             :             m_aFontToId(),
      72             :             m_aGCStack(1),
      73             :             m_aPageSize(),
      74             :             m_aHyperlinkBounds(),
      75             :             m_aURI(),
      76             :             m_aTextOut(),
      77             :             m_nNumPages(0),
      78             :             m_bPageEnded(false),
      79             :             m_bRedCircleSeen(false),
      80             :             m_bGreenStrokeSeen(false),
      81             :             m_bDashedLineSeen(false),
      82           1 :             m_bImageSeen(false)
      83           1 :         {}
      84             : 
      85           2 :         virtual ~TestSink()
      86           2 :         {
      87           1 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "A4 page size (in 100th of points): Width", m_aPageSize.Width, 79400, 0.00000001);
      88           1 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "A4 page size (in 100th of points): Height" , m_aPageSize.Height, 59500, 0.0000001 );
      89           1 :             CPPUNIT_ASSERT_MESSAGE( "endPage() called", m_bPageEnded );
      90           1 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "Num pages equal one", m_nNumPages, (sal_Int32) 1 );
      91           2 :             CPPUNIT_ASSERT_MESSAGE( "Correct hyperlink bounding box",
      92             :                                     rtl::math::approxEqual(m_aHyperlinkBounds.X1,34.7 ) &&
      93             :                                     rtl::math::approxEqual(m_aHyperlinkBounds.Y1,386.0) &&
      94             :                                     rtl::math::approxEqual(m_aHyperlinkBounds.X2,166.7) &&
      95           1 :                                     rtl::math::approxEqual(m_aHyperlinkBounds.Y2,406.2) );
      96           1 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "Correct hyperlink URI", m_aURI, OUString("http://download.openoffice.org/") );
      97             : 
      98             :             const char* sText = " \n \nThis is a testtext\nNew paragraph,\nnew line\n"
      99           1 :                 "Hyperlink, this is\n?\nThis is more text\noutline mode\n?\nNew paragraph\n";
     100           1 :             OString aTmp;
     101             :             m_aTextOut.makeStringAndClear().convertToString( &aTmp,
     102             :                                                              RTL_TEXTENCODING_ASCII_US,
     103           1 :                                                              OUSTRING_TO_OSTRING_CVTFLAGS );
     104           2 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "Imported text is \"This is a testtext New paragraph, new line"
     105             :                                     " Hyperlink, this is * This is more text outline mode * New paragraph\"",
     106           1 :                                     OString(sText), aTmp );
     107             : 
     108           1 :             CPPUNIT_ASSERT_MESSAGE( "red circle seen in input", m_bRedCircleSeen );
     109           1 :             CPPUNIT_ASSERT_MESSAGE( "green stroke seen in input", m_bGreenStrokeSeen );
     110           1 :             CPPUNIT_ASSERT_MESSAGE( "dashed line seen in input", m_bDashedLineSeen );
     111           1 :             CPPUNIT_ASSERT_MESSAGE( "image seen in input", m_bImageSeen );
     112           2 :         }
     113             : 
     114             :     private:
     115          52 :         GraphicsContext& getCurrentContext() { return m_aGCStack.back(); }
     116             : 
     117             :         // ContentSink interface implementation
     118           1 :         virtual void setPageNum( sal_Int32 nNumPages ) SAL_OVERRIDE
     119             :         {
     120           1 :             m_nNumPages = nNumPages;
     121           1 :         }
     122             : 
     123           1 :         virtual void startPage( const geometry::RealSize2D& rSize ) SAL_OVERRIDE
     124             :         {
     125           1 :             m_aPageSize = rSize;
     126           1 :         }
     127             : 
     128           1 :         virtual void endPage() SAL_OVERRIDE
     129             :         {
     130           1 :             m_bPageEnded = true;
     131           1 :         }
     132             : 
     133           1 :         virtual void hyperLink( const geometry::RealRectangle2D& rBounds,
     134             :                                 const OUString&             rURI ) SAL_OVERRIDE
     135             :         {
     136           1 :             m_aHyperlinkBounds = rBounds;
     137           1 :             m_aURI = rURI;
     138           1 :         }
     139             : 
     140          16 :         virtual void pushState() SAL_OVERRIDE
     141             :         {
     142          16 :             GraphicsContextStack::value_type const a(m_aGCStack.back());
     143          16 :             m_aGCStack.push_back(a);
     144          16 :         }
     145             : 
     146          16 :         virtual void popState() SAL_OVERRIDE
     147             :         {
     148          16 :             m_aGCStack.pop_back();
     149          16 :         }
     150             : 
     151           2 :         virtual void setTransformation( const geometry::AffineMatrix2D& rMatrix ) SAL_OVERRIDE
     152             :         {
     153             :             basegfx::unotools::homMatrixFromAffineMatrix(
     154           2 :                 getCurrentContext().Transformation,
     155           2 :                 rMatrix );
     156           2 :         }
     157             : 
     158           2 :         virtual void setLineDash( const uno::Sequence<double>& dashes,
     159             :                                   double                       start ) SAL_OVERRIDE
     160             :         {
     161           2 :             GraphicsContext& rContext( getCurrentContext() );
     162           2 :             if( dashes.getLength() )
     163           1 :                 comphelper::sequenceToContainer(rContext.DashArray,dashes);
     164           2 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "line dashing start offset", start, 0.0, 0.000000001 );
     165           2 :         }
     166             : 
     167           1 :         virtual void setFlatness( double nFlatness ) SAL_OVERRIDE
     168             :         {
     169           1 :             getCurrentContext().Flatness = nFlatness;
     170           1 :         }
     171             : 
     172           3 :         virtual void setLineJoin(sal_Int8 nJoin) SAL_OVERRIDE
     173             :         {
     174           3 :             getCurrentContext().LineJoin = nJoin;
     175           3 :         }
     176             : 
     177           3 :         virtual void setLineCap(sal_Int8 nCap) SAL_OVERRIDE
     178             :         {
     179           3 :             getCurrentContext().LineCap = nCap;
     180           3 :         }
     181             : 
     182           1 :         virtual void setMiterLimit(double nVal) SAL_OVERRIDE
     183             :         {
     184           1 :             getCurrentContext().MiterLimit = nVal;
     185           1 :         }
     186             : 
     187           4 :         virtual void setLineWidth(double nVal) SAL_OVERRIDE
     188             :         {
     189           4 :             getCurrentContext().LineWidth = nVal;
     190           4 :         }
     191             : 
     192          14 :         virtual void setFillColor( const rendering::ARGBColor& rColor ) SAL_OVERRIDE
     193             :         {
     194          14 :             getCurrentContext().FillColor = rColor;
     195          14 :         }
     196             : 
     197           4 :         virtual void setStrokeColor( const rendering::ARGBColor& rColor ) SAL_OVERRIDE
     198             :         {
     199           4 :             getCurrentContext().LineColor = rColor;
     200           4 :         }
     201             : 
     202           0 :         virtual void setBlendMode(sal_Int8 nMode) SAL_OVERRIDE
     203             :         {
     204           0 :             getCurrentContext().BlendMode = nMode;
     205           0 :         }
     206             : 
     207          11 :         virtual void setFont( const FontAttributes& rFont ) SAL_OVERRIDE
     208             :         {
     209          11 :             FontToIdMap::const_iterator it = m_aFontToId.find( rFont );
     210          11 :             if( it != m_aFontToId.end() )
     211           7 :                 getCurrentContext().FontId = it->second;
     212             :             else
     213             :             {
     214           4 :                 m_aFontToId[ rFont ] = m_nNextFontId;
     215           4 :                 m_aIdToFont[ m_nNextFontId ] = rFont;
     216           4 :                 getCurrentContext().FontId = m_nNextFontId;
     217           4 :                 m_nNextFontId++;
     218             :             }
     219          11 :         }
     220             : 
     221           2 :         virtual void strokePath( const uno::Reference<rendering::XPolyPolygon2D>& rPath ) SAL_OVERRIDE
     222             :         {
     223           2 :             GraphicsContext& rContext( getCurrentContext() );
     224           2 :             basegfx::B2DPolyPolygon aPath = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
     225           2 :             aPath.transform( rContext.Transformation );
     226             : 
     227           2 :             if( rContext.DashArray.empty() )
     228             :             {
     229           1 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is green", rContext.LineColor.Alpha, 1.0, 0.00000001);
     230           1 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is green", rContext.LineColor.Blue, 0.0, 0.00000001);
     231           1 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is green", rContext.LineColor.Green, 1.0, 0.00000001);
     232           1 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is green", rContext.LineColor.Red, 0.0, 0.00000001);
     233             : 
     234           2 :                 CPPUNIT_ASSERT_MESSAGE( "Line width is 0",
     235           1 :                                         rtl::math::approxEqual(rContext.LineWidth, 28.3) );
     236             : 
     237           1 :                 const char* sExportString = "m53570 7650-35430 24100";
     238           2 :                 CPPUNIT_ASSERT_MESSAGE( "Stroke is m535.7 518.5-354.3-241",
     239           1 :                                         basegfx::tools::exportToSvgD( aPath, true, true, false ).equalsAscii(sExportString) );
     240             : 
     241           1 :                 m_bGreenStrokeSeen = true;
     242             :             }
     243             :             else
     244             :             {
     245           2 :                 CPPUNIT_ASSERT_MESSAGE( "Dash array consists of four entries",
     246             :                                         rContext.DashArray.size() == 4 &&
     247             :                                         rtl::math::approxEqual(rContext.DashArray[0],14.3764) &&
     248             :                                         rContext.DashArray[0] == rContext.DashArray[1] &&
     249             :                                         rContext.DashArray[1] == rContext.DashArray[2] &&
     250           1 :                                         rContext.DashArray[2] == rContext.DashArray[3] );
     251             : 
     252           1 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Alpha, 1.0, 0.00000001);
     253           1 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Blue, 0.0, 0.00000001);
     254           1 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Green, 0.0, 0.00000001);
     255           1 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Red, 0.0, 0.00000001);
     256             : 
     257           2 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line width is 0",
     258           1 :                                         rContext.LineWidth, 0, 0.0000001 );
     259             : 
     260           1 :                 const char* sExportString = "m49890 5670.00000000001-35430 24090";
     261           2 :                 CPPUNIT_ASSERT_MESSAGE( "Stroke is m49890 5670.00000000001-35430 24090",
     262           1 :                                         basegfx::tools::exportToSvgD( aPath, true, true, false ).equalsAscii(sExportString) );
     263             : 
     264           1 :                 m_bDashedLineSeen = true;
     265             :             }
     266           4 :             CPPUNIT_ASSERT_MESSAGE( "Blend mode is normal",
     267           2 :                                     rContext.BlendMode == rendering::BlendMode::NORMAL );
     268           4 :             CPPUNIT_ASSERT_MESSAGE( "Join type is round",
     269           2 :                                     rContext.LineJoin == rendering::PathJoinType::ROUND );
     270           4 :             CPPUNIT_ASSERT_MESSAGE( "Cap type is butt",
     271           2 :                                     rContext.LineCap == rendering::PathCapType::BUTT );
     272           4 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line miter limit is 10",
     273           2 :                                     rContext.MiterLimit, 10, 0.0000001 );
     274           4 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Flatness is 0",
     275           2 :                                     rContext.Flatness, 1, 0.00000001 );
     276           4 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font id is 0",
     277           4 :                                     rContext.FontId, (sal_Int32) 0 );
     278           2 :         }
     279             : 
     280           0 :         virtual void fillPath( const uno::Reference<rendering::XPolyPolygon2D>& rPath ) SAL_OVERRIDE
     281             :         {
     282           0 :             GraphicsContext& rContext( getCurrentContext() );
     283           0 :             basegfx::B2DPolyPolygon aPath = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
     284           0 :             aPath.transform( rContext.Transformation );
     285             : 
     286           0 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Alpha, 1.0, 0.00000001);
     287           0 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Blue, 0.0, 0.00000001);
     288           0 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Green, 0.0, 0.00000001);
     289           0 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Red, 0.0, 0.00000001);
     290             : 
     291           0 :             CPPUNIT_ASSERT_MESSAGE( "Blend mode is normal",
     292           0 :                                     rContext.BlendMode == rendering::BlendMode::NORMAL );
     293           0 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Flatness is 10",
     294           0 :                                     rContext.Flatness, 10, 0.00000001 );
     295           0 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font id is 0",
     296           0 :                                     rContext.FontId, (sal_Int32) 0 );
     297           0 :         }
     298             : 
     299           1 :         virtual void eoFillPath( const uno::Reference<rendering::XPolyPolygon2D>& rPath ) SAL_OVERRIDE
     300             :         {
     301           1 :             GraphicsContext& rContext( getCurrentContext() );
     302           1 :             basegfx::B2DPolyPolygon aPath = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
     303           1 :             aPath.transform( rContext.Transformation );
     304             : 
     305           1 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Alpha, 1.0, 0.00000001);
     306           1 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Blue, 0.0, 0.00000001);
     307           1 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Green, 0.0, 0.00000001);
     308           1 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Red, 0.0, 0.00000001);
     309             : 
     310           2 :             CPPUNIT_ASSERT_MESSAGE( "Blend mode is normal",
     311           1 :                                     rContext.BlendMode == rendering::BlendMode::NORMAL );
     312           2 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Flatness is 0",
     313           1 :                                     rContext.Flatness, 1, 0.00000001 );
     314           2 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font id is 0",
     315           1 :                                     rContext.FontId, (sal_Int32) 0 );
     316             : 
     317             :             const char* sExportString = "m12050 49610c-4310 0-7800-3490-7800-7800 0-4300 "
     318           1 :                 "3490-7790 7800-7790 4300 0 7790 3490 7790 7790 0 4310-3490 7800-7790 7800z";
     319           2 :             CPPUNIT_ASSERT_MESSAGE( "Stroke is a 4-bezier circle",
     320           1 :                                     basegfx::tools::exportToSvgD( aPath, true, true, false ).equalsAscii(sExportString) );
     321             : 
     322           1 :             m_bRedCircleSeen = true;
     323           1 :         }
     324             : 
     325           1 :         virtual void intersectClip(const uno::Reference<rendering::XPolyPolygon2D>& rPath) SAL_OVERRIDE
     326             :         {
     327           1 :             basegfx::B2DPolyPolygon aNewClip = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
     328           2 :             basegfx::B2DPolyPolygon aCurClip = getCurrentContext().Clip;
     329             : 
     330           1 :             if( aCurClip.count() )  // #i92985# adapted API from (..., false, false) to (..., true, false)
     331           0 :                 aNewClip = basegfx::tools::clipPolyPolygonOnPolyPolygon( aCurClip, aNewClip, true, false );
     332             : 
     333           2 :             getCurrentContext().Clip = aNewClip;
     334           1 :         }
     335             : 
     336           1 :         virtual void intersectEoClip(const uno::Reference<rendering::XPolyPolygon2D>& rPath) SAL_OVERRIDE
     337             :         {
     338           1 :             basegfx::B2DPolyPolygon aNewClip = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
     339           2 :             basegfx::B2DPolyPolygon aCurClip = getCurrentContext().Clip;
     340             : 
     341           1 :             if( aCurClip.count() )  // #i92985# adapted API from (..., false, false) to (..., true, false)
     342           1 :                 aNewClip = basegfx::tools::clipPolyPolygonOnPolyPolygon( aCurClip, aNewClip, true, false );
     343             : 
     344           2 :             getCurrentContext().Clip = aNewClip;
     345           1 :         }
     346             : 
     347         104 :         virtual void drawGlyphs( const OUString&             rGlyphs,
     348             :                                  const geometry::RealRectangle2D& /*rRect*/,
     349             :                                  const geometry::Matrix2D&        /*rFontMatrix*/ ) SAL_OVERRIDE
     350             :         {
     351         104 :             m_aTextOut.append(rGlyphs);
     352         104 :         }
     353             : 
     354          11 :         virtual void endText() SAL_OVERRIDE
     355             :         {
     356          11 :             m_aTextOut.append( "\n" );
     357          11 :         }
     358             : 
     359           0 :         virtual void drawMask(const uno::Sequence<beans::PropertyValue>& xBitmap,
     360             :                               bool                                       /*bInvert*/ ) SAL_OVERRIDE
     361             :         {
     362           0 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMask received two properties",
     363           0 :                                     xBitmap.getLength(), (sal_Int32) 3 );
     364           0 :             CPPUNIT_ASSERT_MESSAGE( "drawMask got URL param",
     365           0 :                                     xBitmap[0].Name.equalsAscii( "URL" ) );
     366           0 :             CPPUNIT_ASSERT_MESSAGE( "drawMask got InputStream param",
     367           0 :                                     xBitmap[1].Name.equalsAscii( "InputStream" ) );
     368           0 :         }
     369             : 
     370           1 :         virtual void drawImage(const uno::Sequence<beans::PropertyValue>& xBitmap ) SAL_OVERRIDE
     371             :         {
     372           2 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawImage received two properties",
     373           1 :                                     xBitmap.getLength(), (sal_Int32) 3 );
     374           2 :             CPPUNIT_ASSERT_MESSAGE( "drawImage got URL param",
     375           1 :                                     xBitmap[0].Name.equalsAscii( "URL" ) );
     376           2 :             CPPUNIT_ASSERT_MESSAGE( "drawImage got InputStream param",
     377           1 :                                     xBitmap[1].Name.equalsAscii( "InputStream" ) );
     378           1 :             m_bImageSeen = true;
     379           1 :         }
     380             : 
     381           0 :         virtual void drawColorMaskedImage(const uno::Sequence<beans::PropertyValue>& xBitmap,
     382             :                                           const uno::Sequence<uno::Any>&             /*xMaskColors*/ ) SAL_OVERRIDE
     383             :         {
     384           0 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawColorMaskedImage received two properties",
     385           0 :                                     xBitmap.getLength(), (sal_Int32) 3 );
     386           0 :             CPPUNIT_ASSERT_MESSAGE( "drawColorMaskedImage got URL param",
     387           0 :                                     xBitmap[0].Name.equalsAscii( "URL" ) );
     388           0 :             CPPUNIT_ASSERT_MESSAGE( "drawColorMaskedImage got InputStream param",
     389           0 :                                     xBitmap[1].Name.equalsAscii( "InputStream" ) );
     390           0 :         }
     391             : 
     392           0 :         virtual void drawMaskedImage(const uno::Sequence<beans::PropertyValue>& xBitmap,
     393             :                                      const uno::Sequence<beans::PropertyValue>& xMask,
     394             :                                      bool                                       /*bInvertMask*/) SAL_OVERRIDE
     395             :         {
     396           0 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMaskedImage received two properties #1",
     397           0 :                                     xBitmap.getLength(), (sal_Int32) 3 );
     398           0 :             CPPUNIT_ASSERT_MESSAGE( "drawMaskedImage got URL param #1",
     399           0 :                                     xBitmap[0].Name.equalsAscii( "URL" ) );
     400           0 :             CPPUNIT_ASSERT_MESSAGE( "drawMaskedImage got InputStream param #1",
     401           0 :                                     xBitmap[1].Name.equalsAscii( "InputStream" ) );
     402             : 
     403           0 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMaskedImage received two properties #2",
     404           0 :                                     xMask.getLength(), (sal_Int32) 3 );
     405           0 :             CPPUNIT_ASSERT_MESSAGE( "drawMaskedImage got URL param #2",
     406           0 :                                     xMask[0].Name.equalsAscii( "URL" ) );
     407           0 :             CPPUNIT_ASSERT_MESSAGE( "drawMaskedImage got InputStream param #2",
     408           0 :                                     xMask[1].Name.equalsAscii( "InputStream" ) );
     409           0 :         }
     410             : 
     411           0 :         virtual void drawAlphaMaskedImage(const uno::Sequence<beans::PropertyValue>& xBitmap,
     412             :                                           const uno::Sequence<beans::PropertyValue>& xMask) SAL_OVERRIDE
     413             :         {
     414           0 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawAlphaMaskedImage received two properties #1",
     415           0 :                                     xBitmap.getLength(), (sal_Int32) 3 );
     416           0 :             CPPUNIT_ASSERT_MESSAGE( "drawAlphaMaskedImage got URL param #1",
     417           0 :                                     xBitmap[0].Name.equalsAscii( "URL" ) );
     418           0 :             CPPUNIT_ASSERT_MESSAGE( "drawAlphaMaskedImage got InputStream param #1",
     419           0 :                                     xBitmap[1].Name.equalsAscii( "InputStream" ) );
     420             : 
     421           0 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawAlphaMaskedImage received two properties #2",
     422           0 :                                     xMask.getLength(), (sal_Int32) 3 );
     423           0 :             CPPUNIT_ASSERT_MESSAGE( "drawAlphaMaskedImage got URL param #2",
     424           0 :                                     xMask[0].Name.equalsAscii( "URL" ) );
     425           0 :             CPPUNIT_ASSERT_MESSAGE( "drawAlphaMaskedImage got InputStream param #2",
     426           0 :                                     xMask[1].Name.equalsAscii( "InputStream" ) );
     427           0 :         }
     428             : 
     429           0 :         virtual void setTextRenderMode( sal_Int32 ) SAL_OVERRIDE
     430             :         {
     431           0 :         }
     432             : 
     433             :         typedef boost::unordered_map<sal_Int32,FontAttributes> IdToFontMap;
     434             :         typedef boost::unordered_map<FontAttributes,sal_Int32,FontAttrHash> FontToIdMap;
     435             : 
     436             :         typedef std::vector<GraphicsContext> GraphicsContextStack;
     437             : 
     438             :         sal_Int32                 m_nNextFontId;
     439             :         IdToFontMap               m_aIdToFont;
     440             :         FontToIdMap               m_aFontToId;
     441             : 
     442             :         GraphicsContextStack      m_aGCStack;
     443             :         geometry::RealSize2D      m_aPageSize;
     444             :         geometry::RealRectangle2D m_aHyperlinkBounds;
     445             :         OUString           m_aURI;
     446             :         OUStringBuffer     m_aTextOut;
     447             :         sal_Int32                 m_nNumPages;
     448             :         bool                      m_bPageEnded;
     449             :         bool                      m_bRedCircleSeen;
     450             :         bool                      m_bGreenStrokeSeen;
     451             :         bool                      m_bDashedLineSeen;
     452             :         bool                      m_bImageSeen;
     453             :     };
     454             : 
     455           9 :     class PDFITest : public test::BootstrapFixture
     456             :     {
     457             :     public:
     458           1 :         void testXPDFParser()
     459             :         {
     460           1 :             pdfi::ContentSinkSharedPtr pSink( new TestSink() );
     461             :             pdfi::xpdf_ImportFromFile( getURLFromSrc("/sdext/source/pdfimport/test/testinput.pdf"),
     462             :                                        pSink,
     463             :                                        uno::Reference< task::XInteractionHandler >(),
     464             :                                        OUString(),
     465           1 :                                        getComponentContext() );
     466             : 
     467             :             // make destruction explicit, a bunch of things are
     468             :             // checked in the destructor
     469           1 :             pSink.reset();
     470           1 :         }
     471             : 
     472           1 :         void testOdfDrawExport()
     473             :         {
     474           1 :             pdfi::PDFIRawAdaptor aAdaptor( getComponentContext() );
     475           1 :             aAdaptor.setTreeVisitorFactory( createDrawTreeVisitorFactory() );
     476             : 
     477           2 :             OUString tempFileURL;
     478           1 :             CPPUNIT_ASSERT( osl::File::createTempFile( NULL, NULL, &tempFileURL ) == osl::File::E_None );
     479           1 :             osl::File::remove( tempFileURL ); // FIXME the below apparently fails silently if the file already exists
     480           2 :             CPPUNIT_ASSERT_MESSAGE("Exporting to ODF",
     481             :                                    aAdaptor.odfConvert( getURLFromSrc("/sdext/source/pdfimport/test/testinput.pdf"),
     482             :                                                         new OutputWrap(tempFileURL),
     483           1 :                                                         NULL ));
     484           2 :             osl::File::remove( tempFileURL );
     485           1 :         }
     486             : 
     487           1 :         void testOdfWriterExport()
     488             :         {
     489           1 :             pdfi::PDFIRawAdaptor aAdaptor( getComponentContext() );
     490           1 :             aAdaptor.setTreeVisitorFactory( createWriterTreeVisitorFactory() );
     491             : 
     492           2 :             OUString tempFileURL;
     493           1 :             CPPUNIT_ASSERT( osl::File::createTempFile( NULL, NULL, &tempFileURL ) == osl::File::E_None );
     494           1 :             osl::File::remove( tempFileURL ); // FIXME the below apparently fails silently if the file already exists
     495           2 :             CPPUNIT_ASSERT_MESSAGE("Exporting to ODF",
     496             :                                    aAdaptor.odfConvert( getURLFromSrc("/sdext/source/pdfimport/test/testinput.pdf"),
     497             :                                                         new OutputWrap(tempFileURL),
     498           1 :                                                         NULL ));
     499           2 :             osl::File::remove( tempFileURL );
     500           1 :         }
     501             : 
     502           2 :         CPPUNIT_TEST_SUITE(PDFITest);
     503           1 :         CPPUNIT_TEST(testXPDFParser);
     504           1 :         CPPUNIT_TEST(testOdfWriterExport);
     505           1 :         CPPUNIT_TEST(testOdfDrawExport);
     506           2 :         CPPUNIT_TEST_SUITE_END();
     507             :     };
     508             : 
     509             : }
     510             : 
     511           1 : CPPUNIT_TEST_SUITE_REGISTRATION(PDFITest);
     512             : 
     513           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     514             : 
     515             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10