~ubuntu-branches/ubuntu/lucid/libwpd/lucid

« back to all changes in this revision

Viewing changes to src/test/test.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Rene Engelhard
  • Date: 2007-06-15 13:28:41 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20070615132841-00nybwftc708w96n
Tags: 0.8.10-1
* New upstream release
* bump shlibs for libwpd-stream8c2a 

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include <gsf/gsf-input-stdio.h>
34
34
#include "libwpd_internal.h"
35
35
#include "GSFStream.h"
 
36
#include "WPXStreamImplementation.h"
36
37
#include "WPXMemoryStream.h"
37
38
 
38
39
 
152
153
        g_object_unref (pGsfInput);
153
154
        gsf_shutdown();
154
155
 
 
156
        /********************** 
 
157
         * Test WPXFileStream *
 
158
         **********************/
 
159
        input = new WPXFileStream(TMP_FILENAME);
 
160
 
 
161
        CPPUNIT_ASSERT_EQUAL ( false, input->isOLEStream() );
 
162
        CPPUNIT_ASSERT_EQUAL ( (WPXInputStream*) NULL, input->getDocumentOLEStream() );
 
163
 
 
164
        // test read()
 
165
        input->seek(0, WPX_SEEK_SET);
 
166
        CPPUNIT_ASSERT ( NULL != input->read(0, numBytesRead)  );
 
167
        CPPUNIT_ASSERT_EQUAL ( (size_t) 0, numBytesRead );
 
168
        CPPUNIT_ASSERT_EQUAL ( (long int) 0 , input->tell() );
 
169
        CPPUNIT_ASSERT ( NULL != input->read(1, numBytesRead)  );
 
170
        CPPUNIT_ASSERT_EQUAL ( (long int) 1 , input->tell() );
 
171
 
 
172
        input->seek(0, WPX_SEEK_SET);
 
173
        CPPUNIT_ASSERT ( NULL != input->read(50, numBytesRead)  );
 
174
        CPPUNIT_ASSERT_EQUAL ( (long int) 8 , input->tell() );
 
175
 
 
176
        // test readU*()
 
177
        input->seek(0, WPX_SEEK_SET);
 
178
        CPPUNIT_ASSERT_EQUAL( (uint8_t) 1 , readU8(input) );
 
179
        CPPUNIT_ASSERT_EQUAL( (uint8_t) 2 , readU8(input) );
 
180
        CPPUNIT_ASSERT_EQUAL( (uint8_t) 3 , readU8(input) );
 
181
        CPPUNIT_ASSERT_EQUAL( (uint8_t) 4 , readU8(input) );
 
182
 
 
183
        input->seek(0, WPX_SEEK_SET);
 
184
        CPPUNIT_ASSERT_EQUAL( (uint16_t) 0x0201 , readU16(input) );
 
185
        CPPUNIT_ASSERT_EQUAL( (uint16_t) 0x0403 , readU16(input) );
 
186
 
 
187
        input->seek(0, WPX_SEEK_SET);
 
188
        u32 = readU32(input);
 
189
        CPPUNIT_ASSERT_EQUAL( (uint32_t) 0x04030201 , u32 );
 
190
        u32 = readU32(input);
 
191
        CPPUNIT_ASSERT_EQUAL( (uint32_t) 0x07060500 , u32 );
 
192
 
 
193
        // test seek(), tell(), atEOS()
 
194
        input->seek(1, WPX_SEEK_SET);
 
195
        CPPUNIT_ASSERT_EQUAL ( (long int) 1 , input->tell() );
 
196
 
 
197
        input->seek(0, WPX_SEEK_SET);
 
198
        CPPUNIT_ASSERT_EQUAL ( (long int) 0 , input->tell() );
 
199
 
 
200
        input->seek(8, WPX_SEEK_SET);
 
201
        CPPUNIT_ASSERT_EQUAL ( (long int) 8 , input->tell() );
 
202
 
 
203
        input->seek(0, WPX_SEEK_SET);
 
204
        for (int i = 0; i < 8; i++)
 
205
                readU8(input);
 
206
        CPPUNIT_ASSERT_EQUAL ( true, input->atEOS() );
 
207
 
 
208
        CPPUNIT_ASSERT_THROW ( readU8(input), FileException );
 
209
 
 
210
        input->seek(-1, WPX_SEEK_SET);
 
211
        CPPUNIT_ASSERT_EQUAL ( (long int) 0, input->tell() );
 
212
 
 
213
        input->seek(8, WPX_SEEK_SET);
 
214
        CPPUNIT_ASSERT_EQUAL ( true, input->atEOS() );
 
215
        
 
216
        input->seek(10000, WPX_SEEK_SET);
 
217
        CPPUNIT_ASSERT( 10000 != input->tell() );
 
218
        CPPUNIT_ASSERT( input->atEOS() );
 
219
 
 
220
        delete input;
 
221
 
 
222
        /************************ 
 
223
         * Test WPXStringStream *
 
224
         ************************/
 
225
        input = new WPXStringStream("\1\2\3\4\0\5\6\7", 8);
 
226
 
 
227
        CPPUNIT_ASSERT_EQUAL ( false, input->isOLEStream() );
 
228
        CPPUNIT_ASSERT_EQUAL ( (WPXInputStream*) NULL, input->getDocumentOLEStream() );
 
229
 
 
230
        // test read()
 
231
        input->seek(0, WPX_SEEK_SET);
 
232
        CPPUNIT_ASSERT ( NULL != input->read(0, numBytesRead)  );
 
233
        CPPUNIT_ASSERT_EQUAL ( (size_t) 0, numBytesRead );
 
234
        CPPUNIT_ASSERT_EQUAL ( (long int) 0 , input->tell() );
 
235
        CPPUNIT_ASSERT ( NULL != input->read(1, numBytesRead)  );
 
236
        CPPUNIT_ASSERT_EQUAL ( (long int) 1 , input->tell() );
 
237
 
 
238
        input->seek(0, WPX_SEEK_SET);
 
239
        CPPUNIT_ASSERT ( NULL != input->read(50, numBytesRead)  );
 
240
        CPPUNIT_ASSERT_EQUAL ( (long int) 8 , input->tell() );
 
241
 
 
242
        // test readU*()
 
243
        input->seek(0, WPX_SEEK_SET);
 
244
        CPPUNIT_ASSERT_EQUAL( (uint8_t) 1 , readU8(input) );
 
245
        CPPUNIT_ASSERT_EQUAL( (uint8_t) 2 , readU8(input) );
 
246
        CPPUNIT_ASSERT_EQUAL( (uint8_t) 3 , readU8(input) );
 
247
        CPPUNIT_ASSERT_EQUAL( (uint8_t) 4 , readU8(input) );
 
248
 
 
249
        input->seek(0, WPX_SEEK_SET);
 
250
        CPPUNIT_ASSERT_EQUAL( (uint16_t) 0x0201 , readU16(input) );
 
251
        CPPUNIT_ASSERT_EQUAL( (uint16_t) 0x0403 , readU16(input) );
 
252
 
 
253
        input->seek(0, WPX_SEEK_SET);
 
254
        u32 = readU32(input);
 
255
        CPPUNIT_ASSERT_EQUAL( (uint32_t) 0x04030201 , u32 );
 
256
        u32 = readU32(input);
 
257
        CPPUNIT_ASSERT_EQUAL( (uint32_t) 0x07060500 , u32 );
 
258
 
 
259
        // test seek(), tell(), atEOS()
 
260
        input->seek(1, WPX_SEEK_SET);
 
261
        CPPUNIT_ASSERT_EQUAL ( (long int) 1 , input->tell() );
 
262
 
 
263
        input->seek(0, WPX_SEEK_SET);
 
264
        CPPUNIT_ASSERT_EQUAL ( (long int) 0 , input->tell() );
 
265
 
 
266
        input->seek(8, WPX_SEEK_SET);
 
267
        CPPUNIT_ASSERT_EQUAL ( (long int) 8 , input->tell() );
 
268
 
 
269
        input->seek(0, WPX_SEEK_SET);
 
270
        for (int i = 0; i < 8; i++)
 
271
                readU8(input);
 
272
        CPPUNIT_ASSERT_EQUAL ( true, input->atEOS() );
 
273
 
 
274
        CPPUNIT_ASSERT_THROW ( readU8(input), FileException );
 
275
 
 
276
        input->seek(-1, WPX_SEEK_SET);
 
277
        CPPUNIT_ASSERT_EQUAL ( (long int) 0, input->tell() );
 
278
 
 
279
        input->seek(8, WPX_SEEK_SET);
 
280
        CPPUNIT_ASSERT_EQUAL ( true, input->atEOS() );
 
281
        
 
282
        input->seek(10000, WPX_SEEK_SET);
 
283
        CPPUNIT_ASSERT( 10000 != input->tell() );
 
284
        CPPUNIT_ASSERT( input->atEOS() );
 
285
 
 
286
        delete input;
 
287
 
155
288
 
156
289
        /************************ 
157
290
         * Test WPXMemoryInputStream *