Organize Linux and macOS as separate applications
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
#include "../src/UartReplay.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QElapsedTimer>
|
||||
#include <QEventLoop>
|
||||
#include <QTemporaryFile>
|
||||
#include <QTimer>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
QTemporaryFile log;
|
||||
assert(log.open());
|
||||
log.write(
|
||||
"[2026-08-12 10:00:00.000] [SESSION START] port=/dev/test baud=460800\n"
|
||||
"[2026-08-12 10:00:00.001] [LOCATION] source=gps lat=40.0 lon=29.0\n"
|
||||
"diagnostic line without timestamp\n"
|
||||
"[LOCATION] source=imu_corrected lat=40.1 lon=29.1\n"
|
||||
"[FUSION] lat=40.2 lon=29.2 height=10\n"
|
||||
"[LOCATION] source=gps lat=40.3 lon=29.3\n"
|
||||
"[2026-08-12 10:00:00.999] [SESSION END]\n");
|
||||
log.flush();
|
||||
|
||||
UartReplay replay;
|
||||
QStringList received;
|
||||
QVector<qint64> receivedAt;
|
||||
QElapsedTimer elapsed;
|
||||
QEventLoop loop;
|
||||
QObject::connect(&replay, &UartReplay::lineReady, &loop, [&](const QString &line) {
|
||||
received.push_back(line);
|
||||
receivedAt.push_back(elapsed.elapsed());
|
||||
});
|
||||
QObject::connect(&replay, &UartReplay::replayFinished, &loop, &QEventLoop::quit);
|
||||
QTimer::singleShot(2000, &loop, &QEventLoop::quit);
|
||||
|
||||
elapsed.start();
|
||||
assert(replay.start(log.fileName(), 20, 10));
|
||||
assert(replay.locationCount() == 4);
|
||||
loop.exec();
|
||||
|
||||
assert(!replay.isRunning());
|
||||
assert(received.size() == 5);
|
||||
assert(received.first().startsWith(QStringLiteral("[LOCATION] source=gps")));
|
||||
assert(received.at(1) == QStringLiteral("diagnostic line without timestamp"));
|
||||
assert(received.at(3).startsWith(QStringLiteral("[FUSION]")));
|
||||
assert(receivedAt.last() >= 15);
|
||||
|
||||
QTemporaryFile splitLog;
|
||||
assert(splitLog.open());
|
||||
splitLog.write("latitude: 40.25\nlongitude: 29.50\n");
|
||||
splitLog.flush();
|
||||
received.clear();
|
||||
receivedAt.clear();
|
||||
elapsed.restart();
|
||||
assert(replay.start(splitLog.fileName(), 1, 1));
|
||||
assert(replay.locationCount() == 1);
|
||||
loop.exec();
|
||||
assert(received.size() == 2);
|
||||
|
||||
QTemporaryFile invalidLog;
|
||||
assert(invalidLog.open());
|
||||
invalidLog.write("only diagnostics\n");
|
||||
invalidLog.flush();
|
||||
assert(!replay.start(invalidLog.fileName(), 200, 50));
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user