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
|
#include <QtTest>
#include "widgets/JttyLiveEntry.hpp"
class TestJttyLiveEntry final
: public QObject
{
Q_OBJECT
private slots:
void emptyTextCommitsNothing ()
{
auto const plan = Jtty::planIncrementalCommit (QString {});
QVERIFY (plan.text.isEmpty ());
QCOMPARE (plan.length, 0);
}
void fewerThanHoldbackWordsCommitsNothing ()
{
// Exactly maxCompactAtomWords complete words: still all held back.
auto const plan = Jtty::planIncrementalCommit (QStringLiteral ("CQ K1ABC CQ "));
QVERIFY (plan.text.isEmpty ());
QCOMPARE (plan.length, 0);
}
void callSplitAcrossHoldbackNeverCommitsPartway ()
{
// The motivating case: TEXT5's fixed 5-char windows would slice "CQ K1ABC" mid-callsign if released early.
for (auto const& text : {QStringLiteral ("CQ "), QStringLiteral ("CQ K1ABC ")}) {
auto const plan = Jtty::planIncrementalCommit (text);
QVERIFY2 (plan.text.isEmpty (), qPrintable (text));
}
}
void wordBeyondHoldbackReleasesOnlyTheEarlierWords ()
{
// A 4th word pushes the first word out past the 3-word holdback.
auto const plan = Jtty::planIncrementalCommit (
QStringLiteral ("CQ K1ABC CQ DE "));
QCOMPARE (plan.text, QStringLiteral ("CQ "));
QCOMPARE (plan.length, 3);
}
void releasedPrefixExactlyMatchesOriginalText ()
{
QString const text = QStringLiteral ("FIRST SECOND THIRD FOURTH FIFTH ");
auto const plan = Jtty::planIncrementalCommit (text);
QCOMPARE (text.left (plan.length), plan.text);
// 5 complete words, holdback 3: releases the first 2.
QCOMPARE (plan.text, QStringLiteral ("FIRST SECOND "));
}
void trailingPartialWordIsNeverReleased ()
{
// Same words as the previous case, but the 5th is still mid-typing (no trailing space), so only 4 are complete.
auto const plan = Jtty::planIncrementalCommit (
QStringLiteral ("FIRST SECOND THIRD FOURTH FIF"));
QCOMPARE (plan.text, QStringLiteral ("FIRST "));
}
void forceFlushReleasesEverythingRegardlessOfHoldback ()
{
QString const text = QStringLiteral ("CQ K1ABC");
auto const plan = Jtty::planIncrementalCommit (text, true);
QCOMPARE (plan.text, text);
QCOMPARE (plan.length, text.size ());
}
void forceFlushOnEmptyTextCommitsNothing ()
{
auto const plan = Jtty::planIncrementalCommit (QString {}, true);
QVERIFY (plan.text.isEmpty ());
QCOMPARE (plan.length, 0);
}
void customHoldbackIsHonoured ()
{
auto const plan = Jtty::planIncrementalCommit (
QStringLiteral ("ONE TWO THREE "), false, 1);
QCOMPARE (plan.text, QStringLiteral ("ONE TWO "));
}
};
QTEST_GUILESS_MAIN (TestJttyLiveEntry)
#include "test_jtty_live_entry.moc"
|