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

Generated by: LCOV version 1.10