summaryrefslogtreecommitdiff
path: root/tests/unit/jtty/test_jtty_waterfall.cpp
blob: 0611a2f8122ecccc71bde178816bd6a208c74c18 (plain)
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
#include <QtTest>
#include <QMouseEvent>
#include <QSignalSpy>

#include "commons.h"
#include "widgets/plotter.h"

namespace {
dec_data_t storage;
}
dec_data_t& dec_data = storage;
QVector<QColor> g_ColorTbl (256, Qt::black);

class TestablePlotter final : public CPlotter
{
public:
  using CPlotter::mouseDoubleClickEvent;

  TestablePlotter ()
  {
    setMode ("JTTY");
    setNsps (0, 6912);
    setCurrent (false);
    setPlot2dGain (0);
    setPlot2dZero (0);
    setCumulative (true);
    setLinearAvg (false);
    setReference (false);
    setQ65_Sync (false);
    setVHF (false);
    setSingleDecode (false);
    setFlatten (false, false);
    setWaterfallAvg (2);
    setBars (false);
    setTimestamp (1);
    setDiskUTC (-1);
    setDataFromDisk (false);
    setTol (100);
    resize (700, 350);
    show ();
    QCoreApplication::processEvents ();
  }

  void push (JttyWaterfallRow const& row)
  {
    std::array<float, 2048> values {};
    if (row.gap) values.fill (1.e30f);
    setJttyRow (row);
    draw (values.data (), true, false);
  }

  void clickRow (int row)
  {
    QMouseEvent event {QEvent::MouseButtonDblClick, QPointF (100, 30 + row),
                       Qt::LeftButton, Qt::LeftButton, Qt::NoModifier};
    mouseDoubleClickEvent (&event);
  }
};

class TestJttyWaterfall final : public QObject
{
  Q_OBJECT
private slots:
  void rowIdentitySurvivesAverageResizeAndReplot ()
  {
    TestablePlotter plotter;
    QSignalSpy selected (&plotter, &CPlotter::jttyDecodeAgainAtSample);
    qint64 const start = qint64 (1) << 34;
    plotter.push ({12, start, start + 6912, 180000, false});
    plotter.setWaterfallAvg (11);
    plotter.push ({12, start + 6912, start + 6912 + 38016, 183168, false});
    plotter.resize (1000, 450);
    QCoreApplication::processEvents ();
    plotter.replot ();
    plotter.clickRow (1);
    QCOMPARE (selected.size (), 1);
    QCOMPARE (selected[0][0].toULongLong (), quint64 (12));
    QCOMPARE (selected[0][1].toLongLong (), start + 6912);
    plotter.clickRow (0);
    QCOMPARE (selected.size (), 2);
    QCOMPARE (selected[1][1].toLongLong (), start + 6912 + 38016);
  }

  void gapsAndUnpopulatedRowsDoNotSelectUnrelatedAudio ()
  {
    TestablePlotter plotter;
    QSignalSpy selected (&plotter, &CPlotter::jttyDecodeAgainAtSample);
    plotter.push ({4, 0, 3456, 288, false});
    plotter.push ({4, 3456, 3456, 288, true});
    plotter.push ({5, 0, 3456, 190000, false});
    plotter.clickRow (1);
    plotter.clickRow (10);
    QCOMPARE (selected.size (), 0);
    plotter.clickRow (2);
    QCOMPARE (selected.size (), 1);
    QCOMPARE (selected[0][0].toULongLong (), quint64 (4));
    plotter.clickRow (0);
    QCOMPARE (selected.size (), 2);
    QCOMPARE (selected[1][0].toULongLong (), quint64 (5));
  }
};

QTEST_MAIN (TestJttyWaterfall)
#include "test_jtty_waterfall.moc"