Commit 2878b863c15323d7d4eb8456cf1af176a6665a57

Unit test for Workaround for Windows CE seek issue

See e3144513c; patch tracker ID: 2941143.
  
1// -*- C++ -*- Time-stamp: <09/10/23 08:28:43 ptr>
1// -*- C++ -*- Time-stamp: <10/01/28 11:11:55 ptr>
22
33/*
44 * Copyright (c) 2004-2008
409409
410410 EXAM_CHECK( s.rdbuf()->sgetn( b2, 10 ) == 10 );
411411 EXAM_CHECK( b2[9] == '0' );
412
413 return EXAM_RESULT;
414}
415
416int EXAM_IMPL(fstream_test::tell_binary_wce)
417{
418 // Test in binary mode:
419 {
420 fstream s( "test_file.txt", ios_base::in | ios_base::out | ios_base::binary | ios_base::trunc );
421 EXAM_REQUIRE( s );
422
423 /*
424 Patch tracker issue ID 2941143
425
426 Platform: Windows CE 5 (Windows Mobile 5.x & 6.x)
427 Compiler: Visual Studio 2008; the issue is not compiler-related
428
429 Problem: on files larger than 4K opened in binary mode, ifstream::tellg()
430 does not return correct values. Short snippet demonstrates the issue:
431 =================================
432 std::ifstream in( filename, std::ios_base::in | std::ios_base::binary );
433 in.get();
434 std::streampos pos = in.tellg();
435 assert( pos == 1 );
436 =================================
437
438 Underlying problem: the sequence
439
440 - create mapping
441 - SetFilePosition( file, pos, FILE_BEGIN ) // pos == file size
442 - first access to mapped page
443 - SetFilePosition( file, 0, FILE_CURRENT )
444
445 does not work as expected: last SetFilePosition() returns 4096 instead of
446 file size. If the first access to mapped page happens before the call to
447 SetFilePosition() that sets file pointer to EOF, everything works fine.
448
449 Workaround: in fstream_win32io.cpp, method
450 _Filebuf_base::_M_mmap() explicitly accesses the first page of the
451 mapping before calling _M_seek(). Note that with full & global
452 optimizations enabled, the optimizer is very aggressive and tends to cut
453 away expressions producing unused values (hence the assignment to a static
454 variable)
455 */
456
457 for ( int i = 0; i < 4096 /* PAGE_SIZE */; ++i ) {
458 s << '0';
459 }
460
461 for ( int i = 0; i < 100 /* PAGE_SIZE + 100 */; ++i ) {
462 s << '1';
463 }
464 }
465
466 fstream s( "test_file.txt", ios_base::in | ios_base::binary );
467 EXAM_CHECK( s );
468 s.get();
469 EXAM_CHECK( s );
470 EXAM_CHECK( s.tellg() == static_cast<streampos>(1) );
471 s.seekg( 4195 );
472 char c = 'a';
473 s >> c;
474 EXAM_CHECK( s );
475 EXAM_CHECK( c == '1' );
412476
413477 return EXAM_RESULT;
414478}
  
1// -*- C++ -*- Time-stamp: <09/10/16 22:15:32 ptr>
1// -*- C++ -*- Time-stamp: <10/01/28 11:08:52 ptr>
22
33/*
44 * Copyright (c) 2004-2008
7171 int EXAM_DECL(offset);
7272 int EXAM_DECL(big_file);
7373 int EXAM_DECL(custom_facet);
74 int EXAM_DECL(tell_binary_wce);
7475};
7576
7677class strstream_buffer_test
  
1// -*- C++ -*- Time-stamp: <10/01/23 02:25:50 ptr>
1// -*- C++ -*- Time-stamp: <10/01/28 11:11:01 ptr>
22
33/*
44 * Copyright (c) 2008, 2009
401401 t.add( &fstream_test::input, fstrm_test, "fstream input",
402402 t.add( &fstream_test::output, fstrm_test, "fstream output" ) ) ) ) );
403403
404 t.add( &fstream_test::tellg, fstrm_test, "fstream tellg", fstream_tc[0] );
404 t.add( &fstream_test::tell_binary_wce, fstrm_test, "fstream tellg binary WCE workaround",
405 t.add( &fstream_test::tellg, fstrm_test, "fstream tellg", fstream_tc[0] ) );
405406 t.add( &fstream_test::tellp, fstrm_test, "fstream tellp", fstream_tc[0] );
406407
407408 t.add( &fstream_test::seek_wide_stream, fstrm_test, "wfstream seek",