summaryrefslogtreecommitdiff
path: root/tests/unit/jtty/test_jtty_replay_ownership.cpp
diff options
context:
space:
mode:
authorhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
committerhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
commitc25cbdf6fb6d946175f4335fab77bfea601b56db (patch)
tree6f7a94b7b81f999e434f61b73d47e337dfd26bf2 /tests/unit/jtty/test_jtty_replay_ownership.cpp
parent71f5689252c9f13e70e1c24856904475b2307809 (diff)
parent0685fcada9f95fe90f70b387cd7d757da8209624 (diff)
Merge tag 'debian/3.2.0_rc1+dfsg-2' into debian/trixie-backportsdebian/trixie-backports
tagging wsjtx 3.2.0~rc1+dfsg-2
Diffstat (limited to 'tests/unit/jtty/test_jtty_replay_ownership.cpp')
-rw-r--r--tests/unit/jtty/test_jtty_replay_ownership.cpp107
1 files changed, 107 insertions, 0 deletions
diff --git a/tests/unit/jtty/test_jtty_replay_ownership.cpp b/tests/unit/jtty/test_jtty_replay_ownership.cpp
new file mode 100644
index 00000000..36876033
--- /dev/null
+++ b/tests/unit/jtty/test_jtty_replay_ownership.cpp
@@ -0,0 +1,107 @@
+#include <QtTest>
+#include <atomic>
+#include <chrono>
+#include <condition_variable>
+#include <mutex>
+#include <thread>
+
+#include "JttyReplay.hpp"
+
+namespace
+{
+constexpr int step = 3456;
+}
+
+class TestJttyReplayOwnership : public QObject
+{
+ Q_OBJECT
+
+ void verifyReplayBoundWithLiveInput ()
+ {
+ std::atomic<int> liveFrames {3 * step};
+ std::mutex mutex;
+ std::condition_variable changed;
+ bool ready = false, released = false, done = false;
+ bool producerReleased = false, producerReady = false, appendFinished = false;
+ std::thread writer {[&] {
+ {
+ std::unique_lock<std::mutex> lock {mutex};
+ ready = true;
+ changed.notify_all ();
+ producerReleased = changed.wait_for (lock, std::chrono::seconds {5},
+ [&] { return released; });
+ }
+ if (producerReleased)
+ liveFrames.store (4 * step);
+ {
+ std::lock_guard<std::mutex> lock {mutex};
+ done = true;
+ changed.notify_all ();
+ }
+ }};
+ {
+ std::unique_lock<std::mutex> lock {mutex};
+ producerReady = changed.wait_for (lock, std::chrono::seconds {5}, [&] { return ready; });
+ }
+ QVector<int> visited;
+ int const replayFrames = liveFrames.load ();
+ replayJttyFrames (replayFrames, [&] (int k) {
+ visited.append (k);
+ if (k == step)
+ {
+ std::unique_lock<std::mutex> lock {mutex};
+ released = true;
+ changed.notify_all ();
+ appendFinished = changed.wait_for (lock, std::chrono::seconds {5},
+ [&] { return done; });
+ }
+ return false;
+ });
+ writer.join ();
+ QVERIFY (producerReady);
+ QVERIFY (producerReleased);
+ QCOMPARE (liveFrames.load (), 4 * step);
+ QVERIFY (appendFinished);
+ // Manual replay is a finite request over its starting receive range;
+ // audio arriving during a decode belongs to subsequent processing.
+ QCOMPARE (visited, QVector<int> ({step, 2 * step}));
+ }
+
+private Q_SLOTS:
+ void fixed_range_data ()
+ {
+ QTest::addColumn<int> ("frames");
+ QTest::addColumn<QVector<int>> ("expected");
+ QTest::newRow ("empty") << 0 << QVector<int> {};
+ QTest::newRow ("short") << step - 1 << QVector<int> {};
+ QTest::newRow ("boundary") << step << QVector<int> {};
+ QTest::newRow ("past-boundary") << step + 1 << QVector<int> {step};
+ QTest::newRow ("multiple") << 3 * step << QVector<int> {step, 2 * step};
+ }
+
+ void fixed_range ()
+ {
+ QFETCH (int, frames);
+ QFETCH (QVector<int>, expected);
+ QVector<int> visited;
+ replayJttyFrames (frames, [&] (int k) { visited.append (k); return false; });
+ QCOMPARE (visited, expected);
+ }
+
+ void picked_stop_processed_once ()
+ {
+ int frames = 8 * step;
+ int stop = 5000;
+ QVector<int> visited;
+ replayJttyFrames (frames, [&] (int k) {
+ visited.append (k);
+ return k >= stop;
+ });
+ QCOMPARE (visited, QVector<int> ({step, 2 * step}));
+ }
+
+ void replay_is_bounded_at_start () { verifyReplayBoundWithLiveInput (); }
+};
+
+QTEST_GUILESS_MAIN (TestJttyReplayOwnership)
+#include "test_jtty_replay_ownership.moc"