Add 1 MiB ASCII PipeCapture test (#777973)
Add test sending 1 MiB of ASCII test into PipeCapture to read. This requires multiple reads and rewites through the pipe. This is as much a check of the threading in the PipeCaptureTest class as it is of PipeCapture itself. This is because a single thread might block reading from a pipe waiting for itself to write to the pipe. Deadlock. Hence the requirement to use a separate thread for reading and writing. Bug 777973 - Segmentation fault on bad disk
This commit is contained in:
parent
d90702d526
commit
eb2d571a6c
|
@ -37,6 +37,15 @@
|
||||||
namespace GParted
|
namespace GParted
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Repeat a C++ string count times, where count >= 0.
|
||||||
|
static std::string repeat( const std::string & str, size_t count )
|
||||||
|
{
|
||||||
|
std::string result = "";
|
||||||
|
while ( count -- > 0 )
|
||||||
|
result += str;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// Explicit test fixture class with common variables and methods used in each test.
|
// Explicit test fixture class with common variables and methods used in each test.
|
||||||
// Reference:
|
// Reference:
|
||||||
// Google Test, Primer, Test Fixtures: Using the Same Data Configuration for Multiple Tests
|
// Google Test, Primer, Test Fixtures: Using the Same Data Configuration for Multiple Tests
|
||||||
|
@ -159,6 +168,18 @@ TEST_F( PipeCaptureTest, ShortASCIIText )
|
||||||
EXPECT_TRUE( eof_signalled );
|
EXPECT_TRUE( eof_signalled );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F( PipeCaptureTest, LongASCIIText )
|
||||||
|
{
|
||||||
|
// Test capturing 1 MiB of ASCII text (requiring multiple reads in PipeCapture).
|
||||||
|
inputstr = repeat( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_\n", 16384 );
|
||||||
|
PipeCapture pc( pipefds[ReaderFD], capturedstr );
|
||||||
|
pc.signal_eof.connect( sigc::mem_fun( *this, &PipeCaptureTest::eof_callback ) );
|
||||||
|
pc.connect_signal();
|
||||||
|
run_writer_thread();
|
||||||
|
EXPECT_STREQ( inputstr.c_str(), capturedstr.c_str() );
|
||||||
|
EXPECT_TRUE( eof_signalled );
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace GParted
|
} // namespace GParted
|
||||||
|
|
||||||
// Custom Google Test main() which also initialises the Glib threading system for
|
// Custom Google Test main() which also initialises the Glib threading system for
|
||||||
|
|
Loading…
Reference in New Issue