Add test that PipeCapture can read NUL byte in middle of UTF-8 char (#777973)
Test that binary data that happens to be the start of a multi-byte UTF-8 character but then contains a NUL byte is successfully read. The test currently detects failure thus: $ ./test_PipeCapture ... [ RUN ] PipeCaptureTest.ReadNULByteInMiddleOfMultiByteUTF8Character test_PipeCapture.cc:346: Failure Expected: expectedstr Of length: 7 To be equal to: capturedstr.raw() Of length: 0 With first binary difference: < 0x00000000 "._45678" 00 5F 34 35 36 37 38 -- > 0x00000000 "" [ FAILED ] PipeCaptureTest.ReadNULByteInMiddleOfMultiByteUTF8Character (0 ms) ... Bug 777973 - Segmentation fault on bad disk
This commit is contained in:
parent
3a6a304c64
commit
6b82616d2e
|
@ -337,6 +337,23 @@ TEST_F( PipeCaptureTest, ReadEmbeddedNULCharacter )
|
|||
EXPECT_TRUE( eof_signalled );
|
||||
}
|
||||
|
||||
TEST_F( PipeCaptureTest, ReadNULByteInMiddleOfMultiByteUTF8Character )
|
||||
{
|
||||
// Test NUL byte in the middle of reading a multi-byte UTF-8 character.
|
||||
const char * buf = "\xC0\x00_45678";
|
||||
inputstr = std::string( buf, 8 );
|
||||
PipeCapture pc( pipefds[ReaderFD], capturedstr );
|
||||
pc.signal_eof.connect( sigc::mem_fun( *this, &PipeCaptureTest::eof_callback ) );
|
||||
pc.connect_signal();
|
||||
run_writer_thread();
|
||||
// Initial \xC0 byte is part of an incomplete UTF-8 characters so will be skipped
|
||||
// by PipeCapture.
|
||||
buf = "\x00_45678";
|
||||
expectedstr = std::string( buf, 7 );
|
||||
EXPECT_BINARYSTRINGEQ( expectedstr, capturedstr.raw() );
|
||||
EXPECT_TRUE( eof_signalled );
|
||||
}
|
||||
|
||||
} // namespace GParted
|
||||
|
||||
// Custom Google Test main() which also initialises the Glib threading system for
|
||||
|
|
Loading…
Reference in New Issue