Unit tests update

This commit is contained in:
Markus Gans 2018-03-23 00:26:30 +01:00
parent 3716e48045
commit 0ba27ce365
2 changed files with 83 additions and 2 deletions

View File

@ -708,10 +708,10 @@ void FMouseSGR::setRawData (char fifo_buf[], int fifo_buf_size)
for (n = len; n < fifo_buf_size; n++) // Remove founded entry for (n = len; n < fifo_buf_size; n++) // Remove founded entry
fifo_buf[n - len] = fifo_buf[n]; fifo_buf[n - len] = fifo_buf[n];
n = fifo_buf_size - len - 1; n = fifo_buf_size - len;
for (; n < fifo_buf_size; n++) // Fill rest with '\0' for (; n < fifo_buf_size; n++) // Fill rest with '\0'
fifo_buf[n - len] = '\0'; fifo_buf[n] = '\0';
input_data_pending = bool(fifo_buf[0] != '\0'); input_data_pending = bool(fifo_buf[0] != '\0');
} }

View File

@ -100,6 +100,7 @@ class FMouseTest : public CPPUNIT_NS::TestFixture
void gpmMouseTest(); void gpmMouseTest();
#endif #endif
void x11MouseTest(); void x11MouseTest();
void sgrMouseTest();
private: private:
// Adds code needed to register the test suite // Adds code needed to register the test suite
@ -114,6 +115,7 @@ class FMouseTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST (gpmMouseTest); CPPUNIT_TEST (gpmMouseTest);
#endif #endif
CPPUNIT_TEST (x11MouseTest); CPPUNIT_TEST (x11MouseTest);
CPPUNIT_TEST (sgrMouseTest);
// End of test suite definition // End of test suite definition
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
@ -285,6 +287,12 @@ void FMouseTest::x11MouseTest()
CPPUNIT_ASSERT ( ! x11_mouse.isWheelDown() ); CPPUNIT_ASSERT ( ! x11_mouse.isWheelDown() );
CPPUNIT_ASSERT ( ! x11_mouse.isMoved() ); CPPUNIT_ASSERT ( ! x11_mouse.isMoved() );
// The same input again
char raw[] = { 0x1b, '[', 'M', 0x23, 0x50, 0x32 };
x11_mouse.setRawData ( raw, sizeof(raw));
x11_mouse.processEvent (&tv);
CPPUNIT_ASSERT ( ! x11_mouse.hasEvent() );
// Left mouse button pressed // Left mouse button pressed
char rawdata2[] = { 0x1b, '[', 'M', 0x20, 0x21, 0x21 }; char rawdata2[] = { 0x1b, '[', 'M', 0x20, 0x21, 0x21 };
x11_mouse.setRawData (rawdata2, sizeof(rawdata2)); x11_mouse.setRawData (rawdata2, sizeof(rawdata2));
@ -539,6 +547,79 @@ void FMouseTest::x11MouseTest()
CPPUNIT_ASSERT ( x11_mouse.isShiftKeyPressed() ); CPPUNIT_ASSERT ( x11_mouse.isShiftKeyPressed() );
CPPUNIT_ASSERT ( x11_mouse.isControlKeyPressed() ); CPPUNIT_ASSERT ( x11_mouse.isControlKeyPressed() );
CPPUNIT_ASSERT ( x11_mouse.isMetaKeyPressed() ); CPPUNIT_ASSERT ( x11_mouse.isMetaKeyPressed() );
char rawdata10[] = { 0x1b, '[', 'M', 0x20, 0x7f, 0x3f };
x11_mouse.setRawData (rawdata10, sizeof(rawdata9));
CPPUNIT_ASSERT ( x11_mouse.hasData() );
x11_mouse.processEvent (&tv);
CPPUNIT_ASSERT ( x11_mouse.hasEvent() );
x11_mouse.clearEvent();
CPPUNIT_ASSERT ( ! x11_mouse.hasEvent() );
}
//----------------------------------------------------------------------
void FMouseTest::sgrMouseTest()
{
FMouseSGR sgr_mouse;
CPPUNIT_ASSERT ( ! sgr_mouse.hasData() );
char rawdata1[] = { 0x1b, '[', '<', '0', ';', '7'
, '3', ';', '4', 'm', '@', '@' };
sgr_mouse.setRawData (rawdata1, sizeof(rawdata1));
CPPUNIT_ASSERT ( sgr_mouse.hasData() );
CPPUNIT_ASSERT ( sgr_mouse.isInputDataPending() );
CPPUNIT_ASSERT ( strcmp(rawdata1, "@@") == 0 );
timeval tv;
FObject::getCurrentTime(&tv);
sgr_mouse.processEvent (&tv);
CPPUNIT_ASSERT ( sgr_mouse.getPos() == FPoint(73, 4) );
CPPUNIT_ASSERT ( sgr_mouse.hasEvent() );
CPPUNIT_ASSERT ( ! sgr_mouse.isLeftButtonPressed() );
CPPUNIT_ASSERT ( sgr_mouse.isLeftButtonReleased() );
CPPUNIT_ASSERT ( ! sgr_mouse.isLeftButtonDoubleClick() );
CPPUNIT_ASSERT ( ! sgr_mouse.isRightButtonPressed() );
CPPUNIT_ASSERT ( ! sgr_mouse.isRightButtonReleased() );
CPPUNIT_ASSERT ( ! sgr_mouse.isMiddleButtonPressed() );
CPPUNIT_ASSERT ( ! sgr_mouse.isMiddleButtonReleased() );
CPPUNIT_ASSERT ( ! sgr_mouse.isShiftKeyPressed() );
CPPUNIT_ASSERT ( ! sgr_mouse.isControlKeyPressed() );
CPPUNIT_ASSERT ( ! sgr_mouse.isMetaKeyPressed() );
CPPUNIT_ASSERT ( ! sgr_mouse.isWheelUp() );
CPPUNIT_ASSERT ( ! sgr_mouse.isWheelDown() );
CPPUNIT_ASSERT ( ! sgr_mouse.isMoved() );
// The same input again
char raw[] = { 0x1b, '[', '<', '0', ';', '7', '3', ';', '4', 'm' };
sgr_mouse.setRawData ( raw, sizeof(raw));
sgr_mouse.processEvent (&tv);
CPPUNIT_ASSERT ( ! sgr_mouse.hasEvent() );
// Left mouse button pressed
char rawdata2[] = { 0x1b, '[', '<', '0', ';', '1', ';', '1', 'M' };
sgr_mouse.setRawData (rawdata2, sizeof(rawdata2));
CPPUNIT_ASSERT ( sgr_mouse.hasData() );
CPPUNIT_ASSERT ( ! sgr_mouse.isInputDataPending() );
sgr_mouse.processEvent (&tv);
CPPUNIT_ASSERT ( ! sgr_mouse.hasData() );
CPPUNIT_ASSERT ( sgr_mouse.getPos() == FPoint(1, 1) );
CPPUNIT_ASSERT ( sgr_mouse.hasEvent() );
CPPUNIT_ASSERT ( sgr_mouse.isLeftButtonPressed() );
CPPUNIT_ASSERT ( ! sgr_mouse.isLeftButtonReleased() );
CPPUNIT_ASSERT ( ! sgr_mouse.isLeftButtonDoubleClick() );
CPPUNIT_ASSERT ( ! sgr_mouse.isRightButtonPressed() );
CPPUNIT_ASSERT ( ! sgr_mouse.isRightButtonReleased() );
CPPUNIT_ASSERT ( ! sgr_mouse.isMiddleButtonPressed() );
CPPUNIT_ASSERT ( ! sgr_mouse.isMiddleButtonReleased() );
CPPUNIT_ASSERT ( ! sgr_mouse.isShiftKeyPressed() );
CPPUNIT_ASSERT ( ! sgr_mouse.isControlKeyPressed() );
CPPUNIT_ASSERT ( ! sgr_mouse.isMetaKeyPressed() );
CPPUNIT_ASSERT ( ! sgr_mouse.isWheelUp() );
CPPUNIT_ASSERT ( ! sgr_mouse.isWheelDown() );
CPPUNIT_ASSERT ( ! sgr_mouse.isMoved() );
} }