1 /***************************************************************************
2 * Copyright (C) 2016 by Dominik Seichter *
3 * domseichter@web.de *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21 #include "DeviceTest.h"
22 #include <podofo.h>
23
24 #include <stdio.h>
25 #include <string.h>
26 #define BUFFER_SIZE 4096
27
28 using namespace PoDoFo;
29
30 // Registers the fixture into the 'registry'
31 CPPUNIT_TEST_SUITE_REGISTRATION( DeviceTest );
32
setUp()33 void DeviceTest::setUp()
34 {
35 }
36
tearDown()37 void DeviceTest::tearDown()
38 {
39 }
40
41
testDevices()42 void DeviceTest::testDevices()
43 {
44 const char* pszTestString = "Hello World Buffer!";
45 long lLen = strlen( pszTestString );
46
47 PdfRefCountedBuffer buffer1;
48 PdfRefCountedBuffer buffer2;
49
50 printf("-> Testing PdfRefCountedBuffer...\n");
51
52 // test simple append
53 printf("\t -> Appending\n");
54 PdfBufferOutputStream stream1( &buffer1 );
55 stream1.Write( pszTestString, lLen );
56 stream1.Close();
57 if( static_cast<long>(buffer1.GetSize()) != lLen )
58 {
59 fprintf( stderr, "Buffer size does not match! Size=%li should be %li\n", buffer1.GetSize(), lLen );
60 PODOFO_RAISE_ERROR( ePdfError_TestFailed );
61 }
62
63 if( strcmp( buffer1.GetBuffer(), pszTestString ) != 0 )
64 {
65 fprintf( stderr, "Buffer contents do not match!\n" );
66 PODOFO_RAISE_ERROR( ePdfError_TestFailed );
67 }
68
69 // test assignment
70 printf("\t -> Assignment\n");
71 buffer2 = buffer1;
72 if( buffer1.GetSize() != buffer2.GetSize() )
73 {
74 fprintf( stderr, "Buffer sizes does not match! Size1=%li Size2=%li\n", buffer1.GetSize(), buffer2.GetSize() );
75 PODOFO_RAISE_ERROR( ePdfError_TestFailed );
76 }
77
78 if( strcmp( buffer1.GetBuffer(), buffer2.GetBuffer() ) != 0 )
79 {
80 fprintf( stderr, "Buffer contents do not match after assignment!\n" );
81 PODOFO_RAISE_ERROR( ePdfError_TestFailed );
82 }
83
84 // test detach
85 printf("\t -> Detaching\n");
86 PdfBufferOutputStream stream( &buffer2 );
87 stream.Write( pszTestString, lLen );
88 stream.Close();
89 if( static_cast<long>(buffer2.GetSize()) != lLen * 2 )
90 {
91 fprintf( stderr, "Buffer size after detach does not match! Size=%li should be %li\n", buffer2.GetSize(), lLen * 2 );
92 PODOFO_RAISE_ERROR( ePdfError_TestFailed );
93 }
94
95 if( static_cast<long>(buffer1.GetSize()) != lLen )
96 {
97 fprintf( stderr, "Buffer1 size seems to be modified\n");
98 PODOFO_RAISE_ERROR( ePdfError_TestFailed );
99 }
100
101 if( strcmp( buffer1.GetBuffer(), pszTestString ) != 0 )
102 {
103 fprintf( stderr, "Buffer1 contents seem to be modified!\n" );
104 PODOFO_RAISE_ERROR( ePdfError_TestFailed );
105 }
106
107 // large appends
108 PdfBufferOutputStream streamLarge( &buffer1 );
109 for( int i=0;i<100;i++ )
110 {
111 streamLarge.Write( pszTestString, lLen );
112 }
113 streamLarge.Close();
114
115 if( static_cast<long>(buffer1.GetSize()) != (lLen * 100 + lLen) )
116 {
117 fprintf( stderr, "Buffer1 size is wrong after 100 attaches: %li\n", buffer1.GetSize() );
118 PODOFO_RAISE_ERROR( ePdfError_TestFailed );
119 }
120
121 }
122
123