[gparted] Add 1 MiB ASCII PipeCapture test (#777973)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Add 1 MiB ASCII PipeCapture test (#777973)
- Date: Sat, 3 Jun 2017 15:42:17 +0000 (UTC)
commit eb2d571a6c5c8d5108e5dd2a7e7bf3f1c913cb35
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Sun May 21 10:52:01 2017 +0100
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
tests/test_PipeCapture.cc | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/tests/test_PipeCapture.cc b/tests/test_PipeCapture.cc
index 05ede91..7b49649 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]