From f8783d69bc848866265910bf1a2de814a4cba821 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Fri, 26 May 2017 09:34:08 +0100 Subject: [PATCH] Add PipeCapture line discipline tests Test that backspace and carriage return are processed correctly and Ctrl-A and Ctrl-B are skipped by PipeCapture. --- tests/test_PipeCapture.cc | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/test_PipeCapture.cc b/tests/test_PipeCapture.cc index 608d171f..3a8882fe 100644 --- a/tests/test_PipeCapture.cc +++ b/tests/test_PipeCapture.cc @@ -354,6 +354,62 @@ TEST_F( PipeCaptureTest, ReadNULByteInMiddleOfMultiByteUTF8Character ) EXPECT_TRUE( eof_signalled ); } +TEST_F( PipeCaptureTest, LineDisciplineCarriageReturn ) +{ + // Test PipeCapture line discipline processes carriage return character. + inputstr = "1111\n2222\r33"; + PipeCapture pc( pipefds[ReaderFD], capturedstr ); + pc.connect_signal(); + run_writer_thread(); + expectedstr = "1111\n3322"; + EXPECT_BINARYSTRINGEQ( expectedstr, capturedstr.raw() ); +} + +TEST_F( PipeCaptureTest, LineDisciplineCarriageReturn2 ) +{ + // Test PipeCapture line discipline processes multiple carriage return characters. + inputstr = "1111\n2222\r33\r\r4"; + PipeCapture pc( pipefds[ReaderFD], capturedstr ); + pc.connect_signal(); + run_writer_thread(); + expectedstr = "1111\n4322"; + EXPECT_BINARYSTRINGEQ( expectedstr, capturedstr.raw() ); +} + +TEST_F( PipeCaptureTest, LineDisciplineBackspace ) +{ + // Test PipeCapture line discipline processes backspace character. + inputstr = "1111\n2222\b33"; + PipeCapture pc( pipefds[ReaderFD], capturedstr ); + pc.connect_signal(); + run_writer_thread(); + expectedstr = "1111\n22233"; + EXPECT_BINARYSTRINGEQ( expectedstr, capturedstr.raw() ); +} + +TEST_F( PipeCaptureTest, LineDisciplineBackspace2 ) +{ + // Test PipeCapture line discipline processes too many backspace characters moving + // the cursor back only to the beginning of the current line. + inputstr = "1111\n2222\b\b\b\b\b\b33\b4"; + PipeCapture pc( pipefds[ReaderFD], capturedstr ); + pc.connect_signal(); + run_writer_thread(); + expectedstr = "1111\n3422"; + EXPECT_BINARYSTRINGEQ( expectedstr, capturedstr.raw() ); +} + +TEST_F( PipeCaptureTest, LineDisciplineSkipCtrlAB ) +{ + // Test PipeCapture line discipline skips Ctrl-A and Ctrl-B. + inputstr = "ij\x01kl\x02mn"; + PipeCapture pc( pipefds[ReaderFD], capturedstr ); + pc.connect_signal(); + run_writer_thread(); + expectedstr = "ijklmn"; + EXPECT_BINARYSTRINGEQ( expectedstr, capturedstr.raw() ); +} + } // namespace GParted // Custom Google Test main() which also initialises the Glib threading system for