diff --git a/tests/test_PipeCapture.cc b/tests/test_PipeCapture.cc index 05ede913..7b496491 100644 --- a/tests/test_PipeCapture.cc +++ b/tests/test_PipeCapture.cc @@ -37,6 +37,15 @@ 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. // Reference: // 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 ); } +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 // Custom Google Test main() which also initialises the Glib threading system for