1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
/***************************************************************************
* Copyright (C) 2007 by Dominik Seichter *
* domseichter@web.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "FilterTest.h"
#include <cppunit/Asserter.h>
#include <stdlib.h>
using namespace PoDoFo;
CPPUNIT_TEST_SUITE_REGISTRATION( FilterTest );
static const char s_pTestBuffer1[] = "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.";
// We treat the buffer as _excluding_ the trailing \0
static const long s_lTestLength1 = strlen(s_pTestBuffer1);
const char s_pTestBuffer2[] = {
0x01, 0x64, 0x65, 0xFE, 0x6B, 0x80, 0x45, 0x32, 0x88, 0x12, 0x71, 0xEA, 0x01,
0x01, 0x64, 0x65, 0xFE, 0x6B, 0x80, 0x45, 0x32, 0x88, 0x12, 0x71, 0xEA, 0x03,
0x01, 0x64, 0x65, 0xFE, 0x6B, 0x80, 0x45, 0x32, 0x88, 0x12, 0x71, 0xEA, 0x02,
0x01, 0x64, 0x65, 0xFE, 0x6B, 0x80, 0x45, 0x32, 0x88, 0x12, 0x71, 0xEA, 0x00,
0x01, 0x64, 0x65, 0xFE, 0x6B, 0x80, 0x45, 0x32, 0x88, 0x12, 0x71, 0xEA, 0x00,
0x00, 0x00, 0x00, 0x00, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
const long s_lTestLength2 = 6*13;
void FilterTest::setUp()
{
}
void FilterTest::tearDown()
{
}
void FilterTest::TestFilter( EPdfFilter eFilter, const char * pTestBuffer, const long lTestLength )
{
char* pEncoded;
char* pDecoded;
pdf_long lEncoded;
pdf_long lDecoded;
std::auto_ptr<PdfFilter> pFilter = PdfFilterFactory::Create( eFilter );
if( !pFilter.get() )
{
printf("!!! Filter %i not implemented.\n", eFilter);
return;
}
printf("Testing Algorithm %i:\n", eFilter);
printf("\t-> Testing Encoding\n");
try {
pFilter->Encode( pTestBuffer, lTestLength, &pEncoded, &lEncoded );
} catch( PdfError & e ) {
if( e == ePdfError_UnsupportedFilter )
{
printf("\t-> Encoding not supported for filter %i.\n", eFilter );
return;
}
else
{
e.AddToCallstack( __FILE__, __LINE__ );
throw e;
}
}
printf("\t-> Testing Decoding\n");
try {
pFilter->Decode( pEncoded, lEncoded, &pDecoded, &lDecoded );
} catch( PdfError & e ) {
if( e == ePdfError_UnsupportedFilter )
{
printf("\t-> Decoding not supported for filter %i.\n", eFilter);
return;
}
else
{
e.AddToCallstack( __FILE__, __LINE__ );
throw e;
}
}
printf("\t-> Original Data Length: %li\n", lTestLength );
printf("\t-> Encoded Data Length: %li\n", lEncoded );
printf("\t-> Decoded Data Length: %li\n", lDecoded );
CPPUNIT_ASSERT_EQUAL( static_cast<long>(lTestLength), static_cast<long>(lDecoded) );
CPPUNIT_ASSERT_EQUAL( memcmp( pTestBuffer, pDecoded, lTestLength ), 0 );
free( pEncoded );
free( pDecoded );
printf("\t-> Test succeeded!\n");
}
void FilterTest::testFilters()
{
for( int i =0; i<=ePdfFilter_Crypt; i++ )
{
TestFilter( static_cast<EPdfFilter>(i), s_pTestBuffer1, s_lTestLength1 );
TestFilter( static_cast<EPdfFilter>(i), s_pTestBuffer2, s_lTestLength2 );
}
}
void FilterTest::testCCITT()
{
std::auto_ptr<PdfFilter> pFilter = PdfFilterFactory::Create( ePdfFilter_CCITTFaxDecode );
if( !pFilter.get() )
{
printf("!!! ePdfFilter_CCITTFaxDecode not implemented skipping test!\n");
return;
}
}
|