summaryrefslogtreecommitdiff
path: root/tests/unit/audio/test_sound_input.cpp
diff options
context:
space:
mode:
authorDave Hibberd <hibby@debian.org>2026-10-20 22:35:06 +0100
committerDave Hibberd <hibby@debian.org>2026-10-20 22:35:06 +0100
commit82ebb1ed1af30cee4dfbb1c628431d32885a00e0 (patch)
tree1a1f782d3e576b758be0bc61171574a7cd8f2376 /tests/unit/audio/test_sound_input.cpp
parent061658210acb6425517733ea012dda803a7f72a1 (diff)
parent61d684922b0f1c8455cc60eb3d123df058c9e1f5 (diff)
Merge tag 'debian/3.3.0_beta2+dfsg-1' into hibbian/trixie-backports
tagging wsjtx 3.3.0~beta2+dfsg-1
Diffstat (limited to 'tests/unit/audio/test_sound_input.cpp')
-rw-r--r--tests/unit/audio/test_sound_input.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/unit/audio/test_sound_input.cpp b/tests/unit/audio/test_sound_input.cpp
new file mode 100644
index 00000000..8002c03a
--- /dev/null
+++ b/tests/unit/audio/test_sound_input.cpp
@@ -0,0 +1,85 @@
+#include <QtTest>
+
+#include "Audio/soundin.h"
+
+namespace
+{
+ class TestAudioSink final : public AudioDevice
+ {
+ public:
+ void inputInterrupted () override {++interruptions;}
+ int interruptions {0};
+
+ protected:
+ qint64 readData (char *, qint64) override {return -1;}
+ qint64 writeData (char const *, qint64 size) override {return size;}
+ };
+}
+
+class TestSoundInput : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void sticky_underrun_does_not_interrupt_recovered_input ()
+ {
+ TestAudioSink sink;
+ SoundInput input;
+ input.m_sink = &sink;
+ input.updateStreamInterruption (QAudio::ActiveState, QAudio::NoError);
+ input.updateStreamInterruption (QAudio::IdleState, QAudio::UnderrunError);
+ input.updateStreamInterruption (QAudio::IdleState, QAudio::UnderrunError);
+ QCOMPARE (sink.interruptions, 1);
+
+ input.updateStreamInterruption (QAudio::ActiveState, QAudio::UnderrunError);
+ for (int notification = 0; notification < 5; ++notification)
+ input.updateStreamInterruption (QAudio::ActiveState, QAudio::UnderrunError);
+ QCOMPARE (sink.interruptions, 1);
+
+ input.updateStreamInterruption (QAudio::IdleState, QAudio::UnderrunError);
+ QCOMPARE (sink.interruptions, 2);
+ input.updateStreamInterruption (QAudio::ActiveState, QAudio::UnderrunError);
+ input.updateStreamInterruption (QAudio::ActiveState, QAudio::NoError);
+ input.updateStreamInterruption (QAudio::ActiveState, QAudio::UnderrunError);
+ QCOMPARE (sink.interruptions, 3);
+ }
+
+ void interruption_states_rearm_after_recovery ()
+ {
+ TestAudioSink sink;
+ SoundInput input;
+ input.m_sink = &sink;
+ QList<QAudio::State> states {QAudio::IdleState, QAudio::SuspendedState};
+#if QT_VERSION >= QT_VERSION_CHECK (5, 10, 0)
+ states.append (QAudio::InterruptedState);
+#endif
+ int expected = 0;
+ for (auto state : states)
+ {
+ input.updateStreamInterruption (QAudio::ActiveState, QAudio::NoError);
+ input.updateStreamInterruption (state, QAudio::NoError);
+ input.updateStreamInterruption (state, QAudio::NoError);
+ QCOMPARE (sink.interruptions, ++expected);
+ }
+ }
+
+ void hard_errors_and_stream_replacement_remain_observable ()
+ {
+ TestAudioSink sink;
+ SoundInput input;
+ input.m_sink = &sink;
+ int expected = 0;
+ for (auto error : {QAudio::OpenError, QAudio::IOError, QAudio::FatalError})
+ {
+ input.updateStreamInterruption (QAudio::StoppedState, error);
+ input.updateStreamInterruption (QAudio::StoppedState, error);
+ QCOMPARE (sink.interruptions, ++expected);
+ input.stop ();
+ }
+ input.updateStreamInterruption (QAudio::StoppedState, QAudio::FatalError);
+ QCOMPARE (sink.interruptions, ++expected);
+ }
+};
+
+QTEST_GUILESS_MAIN (TestSoundInput)
+#include "test_sound_input.moc"