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
|
/***************************************************************************
* Copyright (C) 2005 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 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 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 "../PdfTest.h"
#include <stdio.h>
#include <string.h>
#define BUFFER_SIZE 4096
using namespace PoDoFo;
void RefCountedBufferTest()
{
const char* pszTestString = "Hello World Buffer!";
long lLen = strlen( pszTestString );
PdfRefCountedBuffer buffer1;
PdfRefCountedBuffer buffer2;
// test simple append
printf("\t -> Appending\n");
PdfBufferOutputStream stream1( &buffer1 );
stream1.Write( pszTestString, lLen );
stream1.Close();
if( static_cast<long>(buffer1.GetSize()) != lLen )
{
fprintf( stderr, "Buffer size does not match! Size=%li should be %li\n", buffer1.GetSize(), lLen );
PODOFO_RAISE_ERROR( ePdfError_TestFailed );
}
if( strcmp( buffer1.GetBuffer(), pszTestString ) != 0 )
{
fprintf( stderr, "Buffer contents do not match!\n" );
PODOFO_RAISE_ERROR( ePdfError_TestFailed );
}
// test assignment
printf("\t -> Assignment\n");
buffer2 = buffer1;
if( buffer1.GetSize() != buffer2.GetSize() )
{
fprintf( stderr, "Buffer sizes does not match! Size1=%li Size2=%li\n", buffer1.GetSize(), buffer2.GetSize() );
PODOFO_RAISE_ERROR( ePdfError_TestFailed );
}
if( strcmp( buffer1.GetBuffer(), buffer2.GetBuffer() ) != 0 )
{
fprintf( stderr, "Buffer contents do not match after assignment!\n" );
PODOFO_RAISE_ERROR( ePdfError_TestFailed );
}
// test detach
printf("\t -> Detaching\n");
PdfBufferOutputStream stream( &buffer2 );
stream.Write( pszTestString, lLen );
stream.Close();
if( static_cast<long>(buffer2.GetSize()) != lLen * 2 )
{
fprintf( stderr, "Buffer size after detach does not match! Size=%li should be %li\n", buffer2.GetSize(), lLen * 2 );
PODOFO_RAISE_ERROR( ePdfError_TestFailed );
}
if( static_cast<long>(buffer1.GetSize()) != lLen )
{
fprintf( stderr, "Buffer1 size seems to be modified\n");
PODOFO_RAISE_ERROR( ePdfError_TestFailed );
}
if( strcmp( buffer1.GetBuffer(), pszTestString ) != 0 )
{
fprintf( stderr, "Buffer1 contents seem to be modified!\n" );
PODOFO_RAISE_ERROR( ePdfError_TestFailed );
}
// large appends
PdfBufferOutputStream streamLarge( &buffer1 );
for( int i=0;i<100;i++ )
{
streamLarge.Write( pszTestString, lLen );
}
streamLarge.Close();
if( static_cast<long>(buffer1.GetSize()) != (lLen * 100 + lLen) )
{
fprintf( stderr, "Buffer1 size is wrong after 100 attaches: %li\n", buffer1.GetSize() );
PODOFO_RAISE_ERROR( ePdfError_TestFailed );
}
}
int main( int argc, char** )
{
printf("Device Test\n");
printf("==============\n");
if( argc != 1 )
{
printf("Usage: DeviceTest\n");
return 0;
}
try {
printf("-> Testing PdfRefCountedBuffer...\n");
RefCountedBufferTest();
} catch( const PdfError & e ) {
e.PrintErrorMsg();
return e.GetError();
}
printf("All tests successfull!\n");
return 0;
}
|