1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
|
#include <memory>
#include <QtTest>
#include <QThread>
#include "Transceiver/TransceiverBase.hpp"
#include "Transceiver/TransceiverFactory.hpp"
#include "Transceiver/TxInhibitTransceiver.hpp"
class FakeInhibitTransceiver final
: public Transceiver
{
Q_OBJECT
public:
FakeInhibitTransceiver ()
: Transceiver {nullptr, nullptr}
{
}
void set (TransceiverState const& state, unsigned sequence_number) noexcept override
{
++set_calls;
last_set_thread = QThread::currentThread ();
last_state = state;
last_sequence_number = sequence_number;
}
void start (unsigned sequence_number) noexcept override
{
started = true;
last_sequence_number = sequence_number;
}
void stop () noexcept override
{
stopped = true;
}
void send_update (TransceiverState const& state, unsigned sequence_number)
{
Q_EMIT update (state, sequence_number);
}
void send_receive_audio (ReceiveAudio audio) { Q_EMIT receiveAudio (audio); }
TransceiverState last_state;
unsigned last_sequence_number {0};
bool stopped {false};
bool started {false};
int set_calls {0};
QThread * last_set_thread {nullptr};
};
class RecordingTransceiverBase final
: public TransceiverBase
{
public:
explicit RecordingTransceiverBase (logger_type * logger)
: TransceiverBase {logger, nullptr}
{
}
QStringList operations;
private:
int do_start () override {return 0;}
void do_stop () override {}
void do_frequency (Frequency, MODE, bool) override {}
void do_tx_frequency (Frequency, MODE, bool) override {}
void do_mode (MODE) override {}
void do_ptt (bool on) override
{
operations.append (QStringLiteral ("ptt:%1").arg (on));
update_PTT (on);
}
void do_tune (bool on) override
{
operations.append (QStringLiteral ("tune:%1").arg (on));
}
};
class TestTxInhibitTransceiver : public QObject
{
Q_OBJECT
private:
Q_SIGNAL void command (QString controller, quint32 ttl, QString station);
Q_SLOT void forwardsReceiveAudio ()
{
auto * fake = new FakeInhibitTransceiver;
TxInhibitTransceiver transceiver {nullptr, std::unique_ptr<Transceiver> {fake}};
ReceiveAudio observed;
connect (&transceiver, &Transceiver::receiveAudio,
this, [&observed] (ReceiveAudio audio) { observed = std::move (audio); });
auto block = std::make_shared<ReceiveAudioBlock> ();
fake->send_receive_audio (block);
QCOMPARE (observed, ReceiveAudio {block});
}
Q_SLOT void holdFiltersPttAndTuneWithoutChangingReportedRigState ()
{
auto * fake = new FakeInhibitTransceiver;
TxInhibitTransceiver transceiver {nullptr, std::unique_ptr<Transceiver> {fake}};
QSignalSpy status {&transceiver, &TxInhibitTransceiver::statusChanged};
QSignalSpy updates {&transceiver, &Transceiver::update};
transceiver.start (10);
QVERIFY (!status.isEmpty ());
Transceiver::TransceiverState requested;
requested.online (true);
requested.ptt (true);
requested.tune (true);
transceiver.set (requested, 11);
QVERIFY (fake->last_state.ptt ());
QVERIFY (fake->last_state.tune ());
transceiver.tx_inhibit_command (QStringLiteral ("W1AW"), 600, QStringLiteral ("W1AW"));
QTRY_VERIFY (!fake->last_state.ptt ());
QVERIFY (!fake->last_state.tune ());
Transceiver::TransceiverState physical;
physical.online (true);
physical.ptt (false);
physical.tune (false);
fake->send_update (physical, 11);
QCOMPARE (updates.size (), 1);
auto const reported = qvariant_cast<Transceiver::TransceiverState> (updates.takeFirst ().at (0));
QVERIFY (!reported.ptt ());
QVERIFY (!reported.tune ());
}
Q_SLOT void pttAndTuneTransitionsReachTransceiverBaseInSafeOrder ()
{
Transceiver::logger_type logger;
auto * recorder = new RecordingTransceiverBase {&logger};
TxInhibitTransceiver transceiver {
&logger, std::unique_ptr<Transceiver> {recorder}};
QSignalSpy status {&transceiver, &TxInhibitTransceiver::statusChanged};
transceiver.start (12);
Transceiver::TransceiverState requested;
requested.online (true);
requested.ptt (true);
requested.tune (true);
transceiver.set (requested, 13);
QCOMPARE (recorder->operations.mid (recorder->operations.size () - 2),
QStringList ({QStringLiteral ("tune:1"), QStringLiteral ("ptt:1")}));
transceiver.tx_inhibit_command (QStringLiteral ("W1AW"), 600, QStringLiteral ("W1AW"));
QTRY_COMPARE (recorder->operations.mid (recorder->operations.size () - 2),
QStringList ({QStringLiteral ("ptt:0"), QStringLiteral ("tune:0")}));
transceiver.tx_inhibit_command (QStringLiteral ("W1AW"), 0, QStringLiteral ("W1AW"));
QTRY_COMPARE (recorder->operations.mid (recorder->operations.size () - 2),
QStringList ({QStringLiteral ("tune:1"), QStringLiteral ("ptt:1")}));
}
Q_SLOT void holdBeforeFirstRequestDoesNotForwardAnOfflineState ()
{
auto * fake = new FakeInhibitTransceiver;
TxInhibitTransceiver transceiver {nullptr, std::unique_ptr<Transceiver> {fake}};
QSignalSpy status {&transceiver, &TxInhibitTransceiver::statusChanged};
transceiver.start (15);
transceiver.tx_inhibit_command (QStringLiteral ("W1AW"), 600, QStringLiteral ("W1AW"));
QTRY_VERIFY (status.last ().at (1).toBool ());
QCOMPARE (fake->set_calls, 0);
Transceiver::TransceiverState requested;
requested.online (true);
requested.ptt (true);
transceiver.set (requested, 16);
QVERIFY (fake->last_state.online ());
QVERIFY (!fake->last_state.ptt ());
}
Q_SLOT void releasesAreScopedToControllerIdentity ()
{
auto * fake = new FakeInhibitTransceiver;
TxInhibitTransceiver transceiver {nullptr, std::unique_ptr<Transceiver> {fake}};
QSignalSpy status {&transceiver, &TxInhibitTransceiver::statusChanged};
transceiver.start (20);
Transceiver::TransceiverState requested;
requested.online (true);
requested.ptt (true);
transceiver.set (requested, 21);
transceiver.tx_inhibit_command (QStringLiteral ("OWNER"), 600, QStringLiteral ("OWNER"));
QTRY_VERIFY (!fake->last_state.ptt ());
transceiver.tx_inhibit_command (QStringLiteral ("OTHER"), 0, QStringLiteral ("OTHER"));
QTest::qWait (30);
QVERIFY (!fake->last_state.ptt ());
transceiver.tx_inhibit_command (QStringLiteral ("OTHER"), 600, QStringLiteral ("OWNER"));
QTRY_COMPARE (status.last ().at (3).toUInt (), 2u);
transceiver.tx_inhibit_command (QStringLiteral ("OWNER"), 0, QStringLiteral ("OWNER"));
QTest::qWait (30);
QVERIFY (!fake->last_state.ptt ());
transceiver.tx_inhibit_command (QStringLiteral ("OTHER"), 0, QStringLiteral ("OTHER"));
QTRY_VERIFY (fake->last_state.ptt ());
}
Q_SLOT void excessHoldersRemainBoundedAndFailClosed ()
{
auto * fake = new FakeInhibitTransceiver;
TxInhibitTransceiver transceiver {nullptr, std::unique_ptr<Transceiver> {fake}};
QSignalSpy status {&transceiver, &TxInhibitTransceiver::statusChanged};
transceiver.start (22);
Transceiver::TransceiverState requested;
requested.online (true);
requested.ptt (true);
transceiver.set (requested, 23);
for (auto i = 0; i < TxInhibitTransceiver::maximum_tracked_holds; ++i)
{
transceiver.tx_inhibit_command (QStringLiteral ("HOLDER_%1").arg (i), 1200, QStringLiteral ("HOLDER_%1").arg (i));
}
QTRY_COMPARE (status.last ().at (2).toString ().split (QStringLiteral (", ")).size (),
TxInhibitTransceiver::maximum_tracked_holds);
transceiver.tx_inhibit_command (QStringLiteral ("HOLDER_0"), 2400, QStringLiteral ("HOLDER_0"));
transceiver.tx_inhibit_command (QStringLiteral ("OVERFLOW"), 1800, QStringLiteral ("OVERFLOW"));
transceiver.tx_inhibit_command (QStringLiteral ("OVERFLOW"), 0, QStringLiteral ("OVERFLOW"));
QTRY_COMPARE_WITH_TIMEOUT (status.last ().at (2).toString (),
QStringLiteral ("HOLDER_0"), 1800);
transceiver.tx_inhibit_command (QStringLiteral ("HOLDER_0"), 0, QStringLiteral ("HOLDER_0"));
QTRY_VERIFY (status.last ().at (2).toString ().isEmpty ());
QVERIFY (status.last ().at (1).toBool ());
QVERIFY (!fake->last_state.ptt ());
QTRY_VERIFY_WITH_TIMEOUT (fake->last_state.ptt (), 1200);
}
Q_SLOT void leaseExpiresAndClearedIntentDoesNotRekey ()
{
auto * fake = new FakeInhibitTransceiver;
TxInhibitTransceiver transceiver {nullptr, std::unique_ptr<Transceiver> {fake}};
QSignalSpy status {&transceiver, &TxInhibitTransceiver::statusChanged};
transceiver.start (30);
Transceiver::TransceiverState requested;
requested.online (true);
requested.ptt (true);
transceiver.set (requested, 31);
transceiver.tx_inhibit_command (QStringLiteral ("W2SZ"), 100, QStringLiteral ("W2SZ"));
QTRY_VERIFY (!fake->last_state.ptt ());
QTRY_VERIFY_WITH_TIMEOUT (fake->last_state.ptt (), 300);
QCOMPARE (status.last ().at (5).toUInt (), 1u);
transceiver.tx_inhibit_command (QStringLiteral ("W2SZ"), 600, QStringLiteral ("W2SZ"));
QTRY_VERIFY (!fake->last_state.ptt ());
requested.ptt (false);
transceiver.set (requested, 32);
transceiver.tx_inhibit_command (QStringLiteral ("W2SZ"), 0, QStringLiteral ("W2SZ"));
QTest::qWait (30);
QVERIFY (!fake->last_state.ptt ());
}
Q_SLOT void refreshedHoldExtendsItsDeadline ()
{
auto * fake = new FakeInhibitTransceiver;
TxInhibitTransceiver transceiver {nullptr, std::unique_ptr<Transceiver> {fake}};
QSignalSpy status {&transceiver, &TxInhibitTransceiver::statusChanged};
transceiver.start (35);
Transceiver::TransceiverState requested;
requested.online (true);
requested.ptt (true);
transceiver.set (requested, 36);
transceiver.tx_inhibit_command (QStringLiteral ("W2SZ"), 800, QStringLiteral ("W2SZ"));
QTRY_VERIFY (!fake->last_state.ptt ());
QTest::qWait (450);
transceiver.tx_inhibit_command (QStringLiteral ("W2SZ"), 800, QStringLiteral ("W2SZ"));
QTest::qWait (450);
QVERIFY (!fake->last_state.ptt ());
QTRY_VERIFY_WITH_TIMEOUT (fake->last_state.ptt (), 600);
QCOMPARE (status.last ().at (3).toUInt (), 2u);
QCOMPARE (status.last ().at (5).toUInt (), 1u);
}
Q_SLOT void stopDoesNotRestorePttFromAnActiveHold ()
{
auto * fake = new FakeInhibitTransceiver;
TxInhibitTransceiver transceiver {nullptr, std::unique_ptr<Transceiver> {fake}};
QSignalSpy status {&transceiver, &TxInhibitTransceiver::statusChanged};
transceiver.start (37);
Transceiver::TransceiverState requested;
requested.online (true);
requested.ptt (true);
transceiver.set (requested, 38);
transceiver.tx_inhibit_command (QStringLiteral ("W2SZ"), 100, QStringLiteral ("W2SZ"));
QTRY_VERIFY (!fake->last_state.ptt ());
auto const set_calls = fake->set_calls;
transceiver.stop ();
QVERIFY (fake->stopped);
QVERIFY (!status.last ().at (0).toBool ());
QVERIFY (!status.last ().at (1).toBool ());
QTest::qWait (200);
QCOMPARE (fake->set_calls, set_calls);
QVERIFY (!fake->last_state.ptt ());
}
Q_SLOT void counterOnlyChangesEmitStatus ()
{
auto * fake = new FakeInhibitTransceiver;
TxInhibitTransceiver transceiver {nullptr, std::unique_ptr<Transceiver> {fake}};
QSignalSpy status {&transceiver, &TxInhibitTransceiver::statusChanged};
transceiver.start (39);
auto status_count = status.size ();
transceiver.tx_inhibit_invalid (3);
QCOMPARE (status.size (), ++status_count);
QCOMPARE (status.last ().at (6).toUInt (), 3u);
transceiver.tx_inhibit_command (QStringLiteral ("COUNTER"), 0, {});
QCOMPARE (status.size (), ++status_count);
QCOMPARE (status.last ().at (4).toUInt (), 1u);
transceiver.tx_inhibit_command (QStringLiteral ("COUNTER"), 600, {});
QCOMPARE (status.size (), ++status_count);
transceiver.tx_inhibit_command (QStringLiteral ("COUNTER"), 600, {});
QCOMPARE (status.size (), ++status_count);
QCOMPARE (status.last ().at (3).toUInt (), 2u);
}
Q_SLOT void pttOffWithChangedTxRequestForwardsFinalState ()
{
auto * fake = new FakeInhibitTransceiver;
TxInhibitTransceiver transceiver {nullptr, std::unique_ptr<Transceiver> {fake}};
QSignalSpy status {&transceiver, &TxInhibitTransceiver::statusChanged};
transceiver.start (41);
Transceiver::TransceiverState requested;
requested.online (true);
requested.ptt (true);
transceiver.set (requested, 42);
auto next_request = requested.tx_request ();
next_request.mode = QStringLiteral ("JT9");
next_request.fast_mode = true;
requested.ptt (false);
requested.tx_request (next_request);
transceiver.set (requested, 43);
QVERIFY (!fake->last_state.ptt ());
QCOMPARE (fake->last_state.tx_request ().mode, QStringLiteral ("JT9"));
QVERIFY (fake->last_state.tx_request ().fast_mode);
}
Q_SLOT void txRequestEqualityIncludesAllFields ()
{
TxEvidence::TxRequest lhs;
auto rhs = lhs;
QVERIFY (lhs == rhs);
rhs.mode = QStringLiteral ("JT9");
QVERIFY (lhs != rhs);
rhs = lhs;
rhs.fast_mode = true;
QVERIFY (lhs != rhs);
rhs = lhs;
rhs.channel = AudioDevice::Right;
QVERIFY (lhs != rhs);
rhs = lhs;
rhs.queue_epoch = TxAudioQueueEpoch {1};
QVERIFY (lhs != rhs);
rhs = lhs;
rhs.start_window_open_ms = 1;
QVERIFY (lhs != rhs);
}
Q_SLOT void txInhibitCapabilityMatchesPttMethod ()
{
QVERIFY (TransceiverFactory::supports_tx_inhibit (TransceiverFactory::PTT_method_DTR));
QVERIFY (TransceiverFactory::supports_tx_inhibit (TransceiverFactory::PTT_method_RTS));
QVERIFY (!TransceiverFactory::supports_tx_inhibit (TransceiverFactory::PTT_method_CAT));
QVERIFY (!TransceiverFactory::supports_tx_inhibit (TransceiverFactory::PTT_method_VOX));
}
Q_SLOT void queuedCommandsApplyOnTransceiverThread ()
{
auto * fake = new FakeInhibitTransceiver;
TxInhibitTransceiver transceiver {nullptr, std::unique_ptr<Transceiver> {fake}};
QThread worker;
auto * gui_thread = QThread::currentThread ();
fake->moveToThread (&worker);
transceiver.moveToThread (&worker);
connect (this, &TestTxInhibitTransceiver::command,
&transceiver, &TxInhibitTransceiver::tx_inhibit_command, Qt::QueuedConnection);
worker.start ();
QMetaObject::invokeMethod (&transceiver, [&] {
transceiver.start (70);
Transceiver::TransceiverState requested;
requested.online (true);
requested.ptt (true);
transceiver.set (requested, 71);
}, Qt::BlockingQueuedConnection);
Q_EMIT command (QStringLiteral ("KEY"), 600, {});
bool held_on_worker {false};
QMetaObject::invokeMethod (&transceiver, [&] {
held_on_worker = !fake->last_state.ptt () && fake->last_set_thread == &worker;
}, Qt::BlockingQueuedConnection);
Q_EMIT command (QStringLiteral ("KEY"), 0, {});
bool released_on_worker {false};
QMetaObject::invokeMethod (&transceiver, [&] {
released_on_worker = fake->last_state.ptt () && fake->last_set_thread == &worker;
transceiver.stop ();
fake->moveToThread (gui_thread);
transceiver.moveToThread (gui_thread);
}, Qt::BlockingQueuedConnection);
worker.quit ();
worker.wait ();
QVERIFY (held_on_worker);
QVERIFY (released_on_worker);
}
Q_SLOT void noHoldAllowsPttAndTune ()
{
auto * fake = new FakeInhibitTransceiver;
TxInhibitTransceiver transceiver {nullptr, std::unique_ptr<Transceiver> {fake}};
QSignalSpy status {&transceiver, &TxInhibitTransceiver::statusChanged};
transceiver.start (50);
QVERIFY (fake->started);
QVERIFY (status.last ().at (0).toBool ());
QVERIFY (!status.last ().at (1).toBool ());
Transceiver::TransceiverState requested;
requested.online (true);
requested.ptt (true);
requested.tune (true);
transceiver.set (requested, 51);
QVERIFY (fake->last_state.ptt ());
QVERIFY (fake->last_state.tune ());
requested.ptt (false);
requested.tune (false);
transceiver.set (requested, 52);
QVERIFY (!fake->last_state.ptt ());
QVERIFY (!fake->last_state.tune ());
}
Q_SLOT void endedTuneAndUpdatedMetadataDoNotRestartAfterRelease ()
{
auto * fake = new FakeInhibitTransceiver;
TxInhibitTransceiver transceiver {nullptr, std::unique_ptr<Transceiver> {fake}};
transceiver.start (60);
Transceiver::TransceiverState requested;
requested.online (true);
requested.ptt (true);
requested.tune (true);
transceiver.set (requested, 61);
transceiver.tx_inhibit_command (QStringLiteral ("KEY"), 600, {});
requested.ptt (false);
requested.tune (false);
auto request = requested.tx_request ();
request.mode = QStringLiteral ("JT9");
request.fast_mode = true;
requested.tx_request (request);
transceiver.set (requested, 62);
transceiver.tx_inhibit_command (QStringLiteral ("KEY"), 0, {});
QVERIFY (!fake->last_state.ptt ());
QVERIFY (!fake->last_state.tune ());
QVERIFY (fake->last_state.tx_request () == request);
}
};
QTEST_MAIN (TestTxInhibitTransceiver)
#include "test_tx_inhibit_transceiver.moc"
|