From 7a852953be6b813e510168a06a24b35859cea127 Mon Sep 17 00:00:00 2001 From: sawinglogz <3787776-sawinglogz@users.noreply.gitlab.com> Date: Sun, 23 May 2021 15:48:20 -0400 Subject: [PATCH] Move raw data signal tests into a separate class. Otherwise QTest treats the signal handlers as separate tests. --- oscar/tests/rawdatatests.cpp | 36 ++++++++++++++++++++---------------- oscar/tests/rawdatatests.h | 12 ++++++++++-- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/oscar/tests/rawdatatests.cpp b/oscar/tests/rawdatatests.cpp index ef29cdc4..d9d60951 100644 --- a/oscar/tests/rawdatatests.cpp +++ b/oscar/tests/rawdatatests.cpp @@ -29,14 +29,11 @@ void RawDataTests::testQIODeviceInterface() // Connect signals for testing. - m_channelReadyRead = -1; - m_readyRead = false; - m_readChannelFinished = false; - m_aboutToClose = false; - connect(&raw, SIGNAL(channelReadyRead(int)), this, SLOT(onChannelReadyRead(int))); - connect(&raw, SIGNAL(readyRead()), this, SLOT(onReadyRead())); - connect(&raw, SIGNAL(readChannelFinished()), this, SLOT(onReadChannelFinished())); - connect(&raw, SIGNAL(aboutToClose()), this, SLOT(onAboutToClose())); + _RawDataTestSignalSink sink; + connect(&raw, SIGNAL(channelReadyRead(int)), &sink, SLOT(onChannelReadyRead(int))); + connect(&raw, SIGNAL(readyRead()), &sink, SLOT(onReadyRead())); + connect(&raw, SIGNAL(readChannelFinished()), &sink, SLOT(onReadChannelFinished())); + connect(&raw, SIGNAL(aboutToClose()), &sink, SLOT(onAboutToClose())); // Open @@ -59,8 +56,8 @@ void RawDataTests::testQIODeviceInterface() // waitForReadyRead and ready signals Q_ASSERT(raw.waitForReadyRead(10000) == false); - //Q_ASSERT(m_channelReadyRead != -1); - //Q_ASSERT(m_readyRead == true); + //Q_ASSERT(sink.m_channelReadyRead != -1); + //Q_ASSERT(sink.m_readyRead == true); // Channels @@ -190,8 +187,8 @@ void RawDataTests::testQIODeviceInterface() // Close raw.close(); Q_ASSERT(raw.isOpen() == qio.isOpen()); - Q_ASSERT(m_aboutToClose); - //Q_ASSERT(m_readChannelFinished); + Q_ASSERT(sink.m_aboutToClose); + //Q_ASSERT(sink.m_readChannelFinished); // Unimplemented/untested: @@ -206,22 +203,29 @@ void RawDataTests::testQIODeviceInterface() // channelBytesWritten signal } -void RawDataTests::onAboutToClose() +_RawDataTestSignalSink::_RawDataTestSignalSink() : QObject() { + m_channelReadyRead = -1; + m_readyRead = false; + m_readChannelFinished = false; + m_aboutToClose = false; +} + +void _RawDataTestSignalSink::onAboutToClose() { m_aboutToClose = true; } -void RawDataTests::onChannelReadyRead(int channel) +void _RawDataTestSignalSink::onChannelReadyRead(int channel) { m_channelReadyRead = channel; } -void RawDataTests::onReadChannelFinished() +void _RawDataTestSignalSink::onReadChannelFinished() { m_readChannelFinished = true; } -void RawDataTests::onReadyRead() +void _RawDataTestSignalSink::onReadyRead() { m_readyRead = true; } diff --git a/oscar/tests/rawdatatests.h b/oscar/tests/rawdatatests.h index 8b62b0e1..b3124339 100644 --- a/oscar/tests/rawdatatests.h +++ b/oscar/tests/rawdatatests.h @@ -13,15 +13,23 @@ class RawDataTests : public QObject Q_OBJECT private slots: void testQIODeviceInterface(); +}; +DECLARE_TEST(RawDataTests) +class _RawDataTestSignalSink : public QObject +{ + Q_OBJECT + friend RawDataTests; + private slots: void onAboutToClose(); void onChannelReadyRead(int); void onReadChannelFinished(); void onReadyRead(); -private: + private: + _RawDataTestSignalSink(); bool m_aboutToClose; int m_channelReadyRead; bool m_readChannelFinished; bool m_readyRead; }; -DECLARE_TEST(RawDataTests) +// Do not declare this as a test to be executed.