Files
@ 22c28fc64310
Branch filter:
Location: tempo-plotter/tests/test_recorder.cpp
22c28fc64310
3.3 KiB
text/x-c++hdr
removed ledwidget external dependency by copying files to project
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 | /*
Copyright © 2018 Hasan Yavuz Özderya
This file is part of serialplot.
serialplot is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
serialplot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with serialplot. If not, see <http://www.gnu.org/licenses/>.
*/
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
#include <QDir>
#include "datarecorder.h"
#include "test_helpers.h"
#define TEST_FILE_NAME "sp_test_recording.csv"
TEST_CASE("test recording single channel", "[recorder]")
{
DataRecorder rec;
TestSource source(1, false);
// temporary file, remove if exists
auto fileName = QDir::tempPath() + QString("/" TEST_FILE_NAME);
if (QFile::exists(fileName)) QFile::remove(fileName);
// connect source → sink
source.connectSink(&rec);
// prepare data
QStringList channelNames({"Channel 1"});
SamplePack samples(5, 1);
for (int i = 0; i < 5; i++)
{
samples.data(0)[i] = i+1;
}
// test
rec.startRecording(fileName, ",", channelNames, false);
source._feed(samples);
rec.stopRecording();
// read file contents back
QFile recordFile(fileName);
REQUIRE(recordFile.open(QIODevice::ReadOnly | QIODevice::Text));
// NOTE: mind the extra parantheses, otherwise 'catch' macros fail to compile
REQUIRE((recordFile.readLine() == "Channel 1\n"));
for (int i = 0; i < 5; i++)
REQUIRE((recordFile.readLine() == QString("%1\n").arg(i+1)));
// cleanup
if (QFile::exists(fileName)) QFile::remove(fileName);
}
TEST_CASE("test recording multiple channels", "[recorder]")
{
DataRecorder rec;
TestSource source(3, false);
// temporary file, remove if exists
auto fileName = QDir::tempPath() + QString("/" TEST_FILE_NAME);
if (QFile::exists(fileName)) QFile::remove(fileName);
// connect source → sink
source.connectSink(&rec);
// prepare data
QStringList channelNames({"Channel 1", "Channel 2", "Channel 3"});
SamplePack samples(5, 3);
for (int ci = 0; ci < 3; ci++)
{
for (int i = 0; i < 5; i++)
{
samples.data(ci)[i] = (ci+1)*(i+1);
}
}
// test
rec.startRecording(fileName, ",", channelNames, false);
source._feed(samples);
rec.stopRecording();
// read file contents back
QFile recordFile(fileName);
REQUIRE(recordFile.open(QIODevice::ReadOnly | QIODevice::Text));
// NOTE: mind the extra parantheses, otherwise 'catch' macros fail to compile
REQUIRE((recordFile.readLine() == "Channel 1,Channel 2,Channel 3\n"));
REQUIRE((recordFile.readLine() == "1,2,3\n"));
REQUIRE((recordFile.readLine() == "2,4,6\n"));
REQUIRE((recordFile.readLine() == "3,6,9\n"));
REQUIRE((recordFile.readLine() == "4,8,12\n"));
REQUIRE((recordFile.readLine() == "5,10,15\n"));
// cleanup
if (QFile::exists(fileName)) QFile::remove(fileName);
}
|