Commit 2878b863c15323d7d4eb8456cf1af176a6665a57
- Diff rendering mode:
- inline
- side by side
test/unit/fstream_test.cpp
(65 / 1)
|   | |||
| 1 | // -*- C++ -*- Time-stamp: <09/10/23 08:28:43 ptr> | ||
| 1 | // -*- C++ -*- Time-stamp: <10/01/28 11:11:55 ptr> | ||
| 2 | 2 | ||
| 3 | 3 | /* | |
| 4 | 4 | * Copyright (c) 2004-2008 | |
| … | … | ||
| 409 | 409 | ||
| 410 | 410 | EXAM_CHECK( s.rdbuf()->sgetn( b2, 10 ) == 10 ); | |
| 411 | 411 | EXAM_CHECK( b2[9] == '0' ); | |
| 412 | |||
| 413 | return EXAM_RESULT; | ||
| 414 | } | ||
| 415 | |||
| 416 | int 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' ); | ||
| 412 | 476 | ||
| 413 | 477 | return EXAM_RESULT; | |
| 414 | 478 | } |
test/unit/stream_test.h
(2 / 1)
|   | |||
| 1 | // -*- C++ -*- Time-stamp: <09/10/16 22:15:32 ptr> | ||
| 1 | // -*- C++ -*- Time-stamp: <10/01/28 11:08:52 ptr> | ||
| 2 | 2 | ||
| 3 | 3 | /* | |
| 4 | 4 | * Copyright (c) 2004-2008 | |
| … | … | ||
| 71 | 71 | int EXAM_DECL(offset); | |
| 72 | 72 | int EXAM_DECL(big_file); | |
| 73 | 73 | int EXAM_DECL(custom_facet); | |
| 74 | int EXAM_DECL(tell_binary_wce); | ||
| 74 | 75 | }; | |
| 75 | 76 | ||
| 76 | 77 | class strstream_buffer_test |
test/unit/suite.cc
(3 / 2)
|   | |||
| 1 | // -*- C++ -*- Time-stamp: <10/01/23 02:25:50 ptr> | ||
| 1 | // -*- C++ -*- Time-stamp: <10/01/28 11:11:01 ptr> | ||
| 2 | 2 | ||
| 3 | 3 | /* | |
| 4 | 4 | * Copyright (c) 2008, 2009 | |
| … | … | ||
| 401 | 401 | t.add( &fstream_test::input, fstrm_test, "fstream input", | |
| 402 | 402 | t.add( &fstream_test::output, fstrm_test, "fstream output" ) ) ) ) ); | |
| 403 | 403 | ||
| 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] ) ); | ||
| 405 | 406 | t.add( &fstream_test::tellp, fstrm_test, "fstream tellp", fstream_tc[0] ); | |
| 406 | 407 | ||
| 407 | 408 | t.add( &fstream_test::seek_wide_stream, fstrm_test, "wfstream seek", |

