[gparted] Add check of PipeCapture update callback (#777973)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Add check of PipeCapture update callback (#777973)
- Date: Sat, 3 Jun 2017 15:42:27 +0000 (UTC)
commit 8b47de88728419daae4f249ec0f1e2f1c516d2ba
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Tue May 23 19:23:37 2017 +0100
Add check of PipeCapture update callback (#777973)
Also ensure that the PipeCapture calls registered update callbacks and
that the data so far captured matches the leading portion of the input.
Bug 777973 - Segmentation fault on bad disk
tests/test_PipeCapture.cc | 36 +++++++++++++++++++++++++++++++++++-
1 files changed, 35 insertions(+), 1 deletions(-)
---
diff --git a/tests/test_PipeCapture.cc b/tests/test_PipeCapture.cc
index 4e90956..49b5630 100644
--- a/tests/test_PipeCapture.cc
+++ b/tests/test_PipeCapture.cc
@@ -142,7 +142,7 @@ std::string BinaryStringToPrint( size_t offset, const char * s, size_t len )
class PipeCaptureTest : public ::testing::Test
{
protected:
- PipeCaptureTest() : eof_signalled( false ) {};
+ PipeCaptureTest() : eof_signalled( false ), update_signalled( 0U ) {};
virtual void SetUp();
virtual void TearDown();
@@ -157,11 +157,13 @@ protected:
std::string inputstr;
Glib::ustring capturedstr;
bool eof_signalled;
+ unsigned update_signalled;
int pipefds[2];
Glib::RefPtr<Glib::MainLoop> glib_main_loop;
public:
void eof_callback() { eof_signalled = true; };
+ void update_callback_leading_match();
};
// Further setup PipeCaptureTest fixture before running each test. Create pipe and Glib
@@ -223,6 +225,23 @@ void PipeCaptureTest::run_writer_thread()
glib_main_loop->run();
}
+// Callback fired from CapturePipe counting calls and ensuring captured string matches
+// leading portion of input string.
+void PipeCaptureTest::update_callback_leading_match()
+{
+ update_signalled ++;
+ EXPECT_BINARYSTRINGEQ( inputstr.substr( 0, capturedstr.raw().length() ),
+ capturedstr.raw() );
+ if ( HasFailure() )
+ // No point trying to PipeCapture the rest of the input and report
+ // hundreds of further failures in the same test, so end the currently
+ // running Glib main loop immediately.
+ // References:
+ // * Google Test, AdvancedGuide, Propagating Fatal Failures
+ // * Google Test, AdvancedGuide, Checking for Failures in the Current Test
+ glib_main_loop->quit();
+}
+
TEST_F( PipeCaptureTest, EmptyPipe )
{
// Test capturing 0 bytes with no on EOF callback registered.
@@ -270,6 +289,21 @@ TEST_F( PipeCaptureTest, LongASCIIText )
EXPECT_TRUE( eof_signalled );
}
+TEST_F( PipeCaptureTest, LongASCIITextWithUpdate )
+{
+ // Test capturing 1 MiB of ASCII text, that registered update callback occurs and
+ // intermediate captured string is a leading match for the input string.
+ inputstr = repeat( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_\n", 16384 );
+ PipeCapture pc( pipefds[ReaderFD], capturedstr );
+ pc.signal_eof.connect( sigc::mem_fun( *this, &PipeCaptureTest::eof_callback ) );
+ pc.signal_update.connect( sigc::mem_fun( *this, &PipeCaptureTest::update_callback_leading_match ) );
+ pc.connect_signal();
+ run_writer_thread();
+ EXPECT_BINARYSTRINGEQ( inputstr, capturedstr.raw() );
+ EXPECT_GT( update_signalled, 0U );
+ 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]