LCOV - code coverage report
Current view: top level - libreoffice/sdext/source/pdfimport/test - tests.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 193 266 72.6 %
Date: 2012-12-27 Functions: 38 47 80.9 %
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             : #ifdef SYSTEM_ZLIB
      21             : #include "zlib.h"
      22             : #else
      23             : #include <zlib/zlib.h>
      24             : #endif
      25             : 
      26             : #include "outputwrap.hxx"
      27             : #include "contentsink.hxx"
      28             : #include "pdfihelper.hxx"
      29             : #include "wrapper.hxx"
      30             : #include "pdfparse.hxx"
      31             : #include "../pdfiadaptor.hxx"
      32             : 
      33             : #include <rtl/math.hxx>
      34             : #include <osl/file.hxx>
      35             : #include <comphelper/sequence.hxx>
      36             : 
      37             : #include "cppunit/TestAssert.h"
      38             : #include "cppunit/TestFixture.h"
      39             : #include "cppunit/extensions/HelperMacros.h"
      40             : #include "cppunit/plugin/TestPlugIn.h"
      41             : #include <test/bootstrapfixture.hxx>
      42             : 
      43             : #include <com/sun/star/rendering/XCanvas.hpp>
      44             : #include <com/sun/star/rendering/XColorSpace.hpp>
      45             : #include <com/sun/star/rendering/PathJoinType.hpp>
      46             : #include <com/sun/star/rendering/PathCapType.hpp>
      47             : #include <com/sun/star/rendering/BlendMode.hpp>
      48             : 
      49             : #include <basegfx/matrix/b2dhommatrix.hxx>
      50             : #include <basegfx/tools/canvastools.hxx>
      51             : #include <basegfx/polygon/b2dpolygon.hxx>
      52             : #include <basegfx/polygon/b2dpolypolygon.hxx>
      53             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      54             : #include <basegfx/polygon/b2dpolygonclipper.hxx>
      55             : 
      56             : #include <vector>
      57             : #include <boost/unordered_map.hpp>
      58             : 
      59             : #include <cassert>
      60             : #include <rtl/ustring.hxx>
      61             : 
      62             : using namespace ::pdfparse;
      63             : using namespace ::pdfi;
      64             : using namespace ::com::sun::star;
      65             : 
      66             : namespace
      67             : {
      68             : 
      69             :     class TestSink : public ContentSink
      70             :     {
      71             :     public:
      72           1 :         TestSink() :
      73             :             m_nNextFontId( 1 ),
      74             :             m_aIdToFont(),
      75             :             m_aFontToId(),
      76             :             m_aGCStack(1),
      77             :             m_aPageSize(),
      78             :             m_aHyperlinkBounds(),
      79             :             m_aURI(),
      80             :             m_aTextOut(),
      81             :             m_nNumPages(0),
      82             :             m_bPageEnded(false),
      83             :             m_bRedCircleSeen(false),
      84             :             m_bGreenStrokeSeen(false),
      85           1 :             m_bDashedLineSeen(false)
      86           1 :         {}
      87             : 
      88           2 :         ~TestSink()
      89           2 :         {
      90           1 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "A4 page size (in 100th of points): Width", m_aPageSize.Width, 79400, 0.00000001);
      91           1 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "A4 page size (in 100th of points): Height" , m_aPageSize.Height, 59500, 0.0000001 );
      92           1 :             CPPUNIT_ASSERT_MESSAGE( "endPage() called", m_bPageEnded );
      93           1 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "Num pages equal one", m_nNumPages, (sal_Int32) 1 );
      94           2 :             CPPUNIT_ASSERT_MESSAGE( "Correct hyperlink bounding box",
      95             :                                     rtl::math::approxEqual(m_aHyperlinkBounds.X1,34.7 ) &&
      96             :                                     rtl::math::approxEqual(m_aHyperlinkBounds.Y1,386.0) &&
      97             :                                     rtl::math::approxEqual(m_aHyperlinkBounds.X2,166.7) &&
      98           1 :                                     rtl::math::approxEqual(m_aHyperlinkBounds.Y2,406.2) );
      99           1 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "Correct hyperlink URI", m_aURI, ::rtl::OUString("http://download.openoffice.org/") );
     100             : 
     101             :             const char* sText = " \n \nThis is a testtext\nNew paragraph,\nnew line\n"
     102           1 :                 "Hyperlink, this is\n?\nThis is more text\noutline mode\n?\nNew paragraph\n";
     103           1 :             ::rtl::OString aTmp;
     104             :             m_aTextOut.makeStringAndClear().convertToString( &aTmp,
     105             :                                                              RTL_TEXTENCODING_ASCII_US,
     106           1 :                                                              OUSTRING_TO_OSTRING_CVTFLAGS );
     107           2 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "Imported text is \"This is a testtext New paragraph, new line"
     108             :                                     " Hyperlink, this is * This is more text outline mode * New paragraph\"",
     109           1 :                                     rtl::OString(sText), aTmp );
     110             : 
     111           1 :             CPPUNIT_ASSERT_MESSAGE( "red circle seen in input", m_bRedCircleSeen );
     112           1 :             CPPUNIT_ASSERT_MESSAGE( "green stroke seen in input", m_bGreenStrokeSeen );
     113           1 :             CPPUNIT_ASSERT_MESSAGE( "dashed line seen in input", m_bDashedLineSeen );
     114           2 :         }
     115             : 
     116             :     private:
     117          52 :         GraphicsContext& getCurrentContext() { return m_aGCStack.back(); }
     118             : 
     119             :         // ContentSink interface implementation
     120           1 :         virtual void setPageNum( sal_Int32 nNumPages )
     121             :         {
     122           1 :             m_nNumPages = nNumPages;
     123           1 :         }
     124             : 
     125           1 :         virtual void startPage( const geometry::RealSize2D& rSize )
     126             :         {
     127           1 :             m_aPageSize = rSize;
     128           1 :         }
     129             : 
     130           1 :         virtual void endPage()
     131             :         {
     132           1 :             m_bPageEnded = true;
     133           1 :         }
     134             : 
     135           1 :         virtual void hyperLink( const geometry::RealRectangle2D& rBounds,
     136             :                                 const ::rtl::OUString&             rURI )
     137             :         {
     138           1 :             m_aHyperlinkBounds = rBounds;
     139           1 :             m_aURI = rURI;
     140           1 :         }
     141             : 
     142          16 :         virtual void pushState()
     143             :         {
     144          16 :             GraphicsContextStack::value_type const a(m_aGCStack.back());
     145          16 :             m_aGCStack.push_back(a);
     146          16 :         }
     147             : 
     148          16 :         virtual void popState()
     149             :         {
     150          16 :             m_aGCStack.pop_back();
     151          16 :         }
     152             : 
     153           2 :         virtual void setTransformation( const geometry::AffineMatrix2D& rMatrix )
     154             :         {
     155             :             basegfx::unotools::homMatrixFromAffineMatrix(
     156           2 :                 getCurrentContext().Transformation,
     157           2 :                 rMatrix );
     158           2 :         }
     159             : 
     160           2 :         virtual void setLineDash( const uno::Sequence<double>& dashes,
     161             :                                   double                       start )
     162             :         {
     163           2 :             GraphicsContext& rContext( getCurrentContext() );
     164           2 :             if( dashes.getLength() )
     165           1 :                 comphelper::sequenceToContainer(rContext.DashArray,dashes);
     166           2 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "line dashing start offset", start, 0.0, 0.000000001 );
     167           2 :         }
     168             : 
     169           1 :         virtual void setFlatness( double nFlatness )
     170             :         {
     171           1 :             getCurrentContext().Flatness = nFlatness;
     172           1 :         }
     173             : 
     174           3 :         virtual void setLineJoin(sal_Int8 nJoin)
     175             :         {
     176           3 :             getCurrentContext().LineJoin = nJoin;
     177           3 :         }
     178             : 
     179           3 :         virtual void setLineCap(sal_Int8 nCap)
     180             :         {
     181           3 :             getCurrentContext().LineCap = nCap;
     182           3 :         }
     183             : 
     184           1 :         virtual void setMiterLimit(double nVal)
     185             :         {
     186           1 :             getCurrentContext().MiterLimit = nVal;
     187           1 :         }
     188             : 
     189           4 :         virtual void setLineWidth(double nVal)
     190             :         {
     191           4 :             getCurrentContext().LineWidth = nVal;
     192           4 :         }
     193             : 
     194          14 :         virtual void setFillColor( const rendering::ARGBColor& rColor )
     195             :         {
     196          14 :             getCurrentContext().FillColor = rColor;
     197          14 :         }
     198             : 
     199           4 :         virtual void setStrokeColor( const rendering::ARGBColor& rColor )
     200             :         {
     201           4 :             getCurrentContext().LineColor = rColor;
     202           4 :         }
     203             : 
     204           0 :         virtual void setBlendMode(sal_Int8 nMode)
     205             :         {
     206           0 :             getCurrentContext().BlendMode = nMode;
     207           0 :         }
     208             : 
     209          11 :         virtual void setFont( const FontAttributes& rFont )
     210             :         {
     211          11 :             FontToIdMap::const_iterator it = m_aFontToId.find( rFont );
     212          11 :             if( it != m_aFontToId.end() )
     213           7 :                 getCurrentContext().FontId = it->second;
     214             :             else
     215             :             {
     216           4 :                 m_aFontToId[ rFont ] = m_nNextFontId;
     217           4 :                 m_aIdToFont[ m_nNextFontId ] = rFont;
     218           4 :                 getCurrentContext().FontId = m_nNextFontId;
     219           4 :                 m_nNextFontId++;
     220             :             }
     221          11 :         }
     222             : 
     223           2 :         virtual void strokePath( const uno::Reference<rendering::XPolyPolygon2D>& rPath )
     224             :         {
     225           2 :             GraphicsContext& rContext( getCurrentContext() );
     226           2 :             basegfx::B2DPolyPolygon aPath = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
     227           2 :             aPath.transform( rContext.Transformation );
     228             : 
     229           2 :             if( rContext.DashArray.empty() )
     230             :             {
     231           1 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is green", rContext.LineColor.Alpha, 1.0, 0.00000001);
     232           1 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is green", rContext.LineColor.Blue, 0.0, 0.00000001);
     233           1 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is green", rContext.LineColor.Green, 1.0, 0.00000001);
     234           1 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is green", rContext.LineColor.Red, 0.0, 0.00000001);
     235             : 
     236           2 :                 CPPUNIT_ASSERT_MESSAGE( "Line width is 0",
     237           1 :                                         rtl::math::approxEqual(rContext.LineWidth, 28.3) );
     238             : 
     239           1 :                 const char* sExportString = "m53570 7650-35430 24100";
     240           2 :                 CPPUNIT_ASSERT_MESSAGE( "Stroke is m535.7 518.5-354.3-241",
     241           1 :                                         basegfx::tools::exportToSvgD( aPath ).compareToAscii(sExportString) == 0 );
     242             : 
     243           1 :                 m_bGreenStrokeSeen = true;
     244             :             }
     245             :             else
     246             :             {
     247           2 :                 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           1 :                                         rContext.DashArray[2] == rContext.DashArray[3] );
     253             : 
     254           1 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Alpha, 1.0, 0.00000001);
     255           1 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Blue, 0.0, 0.00000001);
     256           1 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Green, 0.0, 0.00000001);
     257           1 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Red, 0.0, 0.00000001);
     258             : 
     259           2 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line width is 0",
     260           1 :                                         rContext.LineWidth, 0, 0.0000001 );
     261             : 
     262           1 :                 const char* sExportString = "m49890 5670.00000000001-35430 24090";
     263           2 :                 CPPUNIT_ASSERT_MESSAGE( "Stroke is m49890 5670.00000000001-35430 24090",
     264           1 :                                         basegfx::tools::exportToSvgD( aPath ).compareToAscii(sExportString) == 0 );
     265             : 
     266           1 :                 m_bDashedLineSeen = true;
     267             :             }
     268           4 :             CPPUNIT_ASSERT_MESSAGE( "Blend mode is normal",
     269           2 :                                     rContext.BlendMode == rendering::BlendMode::NORMAL );
     270           4 :             CPPUNIT_ASSERT_MESSAGE( "Join type is round",
     271           2 :                                     rContext.LineJoin == rendering::PathJoinType::ROUND );
     272           4 :             CPPUNIT_ASSERT_MESSAGE( "Cap type is butt",
     273           2 :                                     rContext.LineCap == rendering::PathCapType::BUTT );
     274           4 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line miter limit is 10",
     275           2 :                                     rContext.MiterLimit, 10, 0.0000001 );
     276           4 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Flatness is 0",
     277           2 :                                     rContext.Flatness, 1, 0.00000001 );
     278           4 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font id is 0",
     279           4 :                                     rContext.FontId, (sal_Int32) 0 );
     280           2 :         }
     281             : 
     282           0 :         virtual void fillPath( const uno::Reference<rendering::XPolyPolygon2D>& rPath )
     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", rContext.LineColor.Alpha, 1.0, 0.00000001);
     289           0 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Blue, 0.0, 0.00000001);
     290           0 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Green, 0.0, 0.00000001);
     291           0 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Red, 0.0, 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 :                                     rContext.Flatness, 10, 0.00000001 );
     297           0 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font id is 0",
     298           0 :                                     rContext.FontId, (sal_Int32) 0 );
     299           0 :         }
     300             : 
     301           1 :         virtual void eoFillPath( const uno::Reference<rendering::XPolyPolygon2D>& rPath )
     302             :         {
     303           1 :             GraphicsContext& rContext( getCurrentContext() );
     304           1 :             basegfx::B2DPolyPolygon aPath = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
     305           1 :             aPath.transform( rContext.Transformation );
     306             : 
     307           1 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Alpha, 1.0, 0.00000001);
     308           1 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Blue, 0.0, 0.00000001);
     309           1 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Green, 0.0, 0.00000001);
     310           1 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Line color is black", rContext.LineColor.Red, 0.0, 0.00000001);
     311             : 
     312           2 :             CPPUNIT_ASSERT_MESSAGE( "Blend mode is normal",
     313           1 :                                     rContext.BlendMode == rendering::BlendMode::NORMAL );
     314           2 :             CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Flatness is 0",
     315           1 :                                     rContext.Flatness, 1, 0.00000001 );
     316           2 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "Font id is 0",
     317           1 :                                     rContext.FontId, (sal_Int32) 0 );
     318             : 
     319             :             const char* sExportString = "m12050 49610c-4310 0-7800-3490-7800-7800 0-4300 "
     320           1 :                 "3490-7790 7800-7790 4300 0 7790 3490 7790 7790 0 4310-3490 7800-7790 7800z";
     321           2 :             CPPUNIT_ASSERT_MESSAGE( "Stroke is a 4-bezier circle",
     322           1 :                                     basegfx::tools::exportToSvgD( aPath ).compareToAscii(sExportString) == 0 );
     323             : 
     324           1 :             m_bRedCircleSeen = true;
     325           1 :         }
     326             : 
     327           1 :         virtual void intersectClip(const uno::Reference<rendering::XPolyPolygon2D>& rPath)
     328             :         {
     329           1 :             basegfx::B2DPolyPolygon aNewClip = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
     330           1 :             basegfx::B2DPolyPolygon aCurClip = getCurrentContext().Clip;
     331             : 
     332           1 :             if( aCurClip.count() )  // #i92985# adapted API from (..., false, false) to (..., true, false)
     333           0 :                 aNewClip = basegfx::tools::clipPolyPolygonOnPolyPolygon( aCurClip, aNewClip, true, false );
     334             : 
     335           1 :             getCurrentContext().Clip = aNewClip;
     336           1 :         }
     337             : 
     338           1 :         virtual void intersectEoClip(const uno::Reference<rendering::XPolyPolygon2D>& rPath)
     339             :         {
     340           1 :             basegfx::B2DPolyPolygon aNewClip = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
     341           1 :             basegfx::B2DPolyPolygon aCurClip = getCurrentContext().Clip;
     342             : 
     343           1 :             if( aCurClip.count() )  // #i92985# adapted API from (..., false, false) to (..., true, false)
     344           1 :                 aNewClip = basegfx::tools::clipPolyPolygonOnPolyPolygon( aCurClip, aNewClip, true, false );
     345             : 
     346           1 :             getCurrentContext().Clip = aNewClip;
     347           1 :         }
     348             : 
     349         104 :         virtual void drawGlyphs( const rtl::OUString&             rGlyphs,
     350             :                                  const geometry::RealRectangle2D& /*rRect*/,
     351             :                                  const geometry::Matrix2D&        /*rFontMatrix*/ )
     352             :         {
     353         104 :             m_aTextOut.append(rGlyphs);
     354         104 :         }
     355             : 
     356          11 :         virtual void endText()
     357             :         {
     358          11 :             m_aTextOut.append( ::rtl::OUString("\n") );
     359          11 :         }
     360             : 
     361           0 :         virtual void drawMask(const uno::Sequence<beans::PropertyValue>& xBitmap,
     362             :                               bool                                       /*bInvert*/ )
     363             :         {
     364           0 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMask received two properties",
     365           0 :                                     xBitmap.getLength(), (sal_Int32) 3 );
     366           0 :             CPPUNIT_ASSERT_MESSAGE( "drawMask got URL param",
     367           0 :                                     xBitmap[0].Name.compareToAscii( "URL" ) == 0 );
     368           0 :             CPPUNIT_ASSERT_MESSAGE( "drawMask got InputStream param",
     369           0 :                                     xBitmap[1].Name.compareToAscii( "InputStream" ) == 0 );
     370           0 :         }
     371             : 
     372           0 :         virtual void drawImage(const uno::Sequence<beans::PropertyValue>& xBitmap )
     373             :         {
     374           0 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawImage received two properties",
     375           0 :                                     xBitmap.getLength(), (sal_Int32) 3 );
     376           0 :             CPPUNIT_ASSERT_MESSAGE( "drawImage got URL param",
     377           0 :                                     xBitmap[0].Name.compareToAscii( "URL" ) == 0 );
     378           0 :             CPPUNIT_ASSERT_MESSAGE( "drawImage got InputStream param",
     379           0 :                                     xBitmap[1].Name.compareToAscii( "InputStream" ) == 0 );
     380           0 :         }
     381             : 
     382           0 :         virtual void drawColorMaskedImage(const uno::Sequence<beans::PropertyValue>& xBitmap,
     383             :                                           const uno::Sequence<uno::Any>&             /*xMaskColors*/ )
     384             :         {
     385           0 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawColorMaskedImage received two properties",
     386           0 :                                     xBitmap.getLength(), (sal_Int32) 3 );
     387           0 :             CPPUNIT_ASSERT_MESSAGE( "drawColorMaskedImage got URL param",
     388           0 :                                     xBitmap[0].Name.compareToAscii( "URL" ) == 0 );
     389           0 :             CPPUNIT_ASSERT_MESSAGE( "drawColorMaskedImage got InputStream param",
     390           0 :                                     xBitmap[1].Name.compareToAscii( "InputStream" ) == 0 );
     391           0 :         }
     392             : 
     393           0 :         virtual void drawMaskedImage(const uno::Sequence<beans::PropertyValue>& xBitmap,
     394             :                                      const uno::Sequence<beans::PropertyValue>& xMask,
     395             :                                      bool                                       /*bInvertMask*/)
     396             :         {
     397           0 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMaskedImage received two properties #1",
     398           0 :                                     xBitmap.getLength(), (sal_Int32) 3 );
     399           0 :             CPPUNIT_ASSERT_MESSAGE( "drawMaskedImage got URL param #1",
     400           0 :                                     xBitmap[0].Name.compareToAscii( "URL" ) == 0 );
     401           0 :             CPPUNIT_ASSERT_MESSAGE( "drawMaskedImage got InputStream param #1",
     402           0 :                                     xBitmap[1].Name.compareToAscii( "InputStream" ) == 0 );
     403             : 
     404           0 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawMaskedImage received two properties #2",
     405           0 :                                     xMask.getLength(), (sal_Int32) 3 );
     406           0 :             CPPUNIT_ASSERT_MESSAGE( "drawMaskedImage got URL param #2",
     407           0 :                                     xMask[0].Name.compareToAscii( "URL" ) == 0 );
     408           0 :             CPPUNIT_ASSERT_MESSAGE( "drawMaskedImage got InputStream param #2",
     409           0 :                                     xMask[1].Name.compareToAscii( "InputStream" ) == 0 );
     410           0 :         }
     411             : 
     412           0 :         virtual void drawAlphaMaskedImage(const uno::Sequence<beans::PropertyValue>& xBitmap,
     413             :                                           const uno::Sequence<beans::PropertyValue>& xMask)
     414             :         {
     415           0 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawAlphaMaskedImage received two properties #1",
     416           0 :                                     xBitmap.getLength(), (sal_Int32) 3 );
     417           0 :             CPPUNIT_ASSERT_MESSAGE( "drawAlphaMaskedImage got URL param #1",
     418           0 :                                     xBitmap[0].Name.compareToAscii( "URL" ) == 0 );
     419           0 :             CPPUNIT_ASSERT_MESSAGE( "drawAlphaMaskedImage got InputStream param #1",
     420           0 :                                     xBitmap[1].Name.compareToAscii( "InputStream" ) == 0 );
     421             : 
     422           0 :             CPPUNIT_ASSERT_EQUAL_MESSAGE( "drawAlphaMaskedImage received two properties #2",
     423           0 :                                     xMask.getLength(), (sal_Int32) 3 );
     424           0 :             CPPUNIT_ASSERT_MESSAGE( "drawAlphaMaskedImage got URL param #2",
     425           0 :                                     xMask[0].Name.compareToAscii( "URL" ) == 0 );
     426           0 :             CPPUNIT_ASSERT_MESSAGE( "drawAlphaMaskedImage got InputStream param #2",
     427           0 :                                     xMask[1].Name.compareToAscii( "InputStream" ) == 0 );
     428           0 :         }
     429             : 
     430           0 :         virtual void setTextRenderMode( sal_Int32 )
     431             :         {
     432           0 :         }
     433             : 
     434             :         typedef boost::unordered_map<sal_Int32,FontAttributes> IdToFontMap;
     435             :         typedef boost::unordered_map<FontAttributes,sal_Int32,FontAttrHash> FontToIdMap;
     436             : 
     437             :         typedef std::vector<GraphicsContext> GraphicsContextStack;
     438             : 
     439             :         sal_Int32                 m_nNextFontId;
     440             :         IdToFontMap               m_aIdToFont;
     441             :         FontToIdMap               m_aFontToId;
     442             : 
     443             :         GraphicsContextStack      m_aGCStack;
     444             :         geometry::RealSize2D      m_aPageSize;
     445             :         geometry::RealRectangle2D m_aHyperlinkBounds;
     446             :         ::rtl::OUString           m_aURI;
     447             :         ::rtl::OUStringBuffer     m_aTextOut;
     448             :         sal_Int32                 m_nNumPages;
     449             :         bool                      m_bPageEnded;
     450             :         bool                      m_bRedCircleSeen;
     451             :         bool                      m_bGreenStrokeSeen;
     452             :         bool                      m_bDashedLineSeen;
     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             :                                        rtl::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           1 :             ::rtl::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           1 :             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           1 :             ::rtl::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           1 :             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