mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-07 03:30:44 +00:00
Add regression tests for Viatom loader.
Also enable the native file dialog box for importing Viatom files.
This commit is contained in:
parent
3fbc1777c5
commit
9cb7de950b
@ -39,11 +39,21 @@ ViatomLoader::OpenFile( const QString & filename )
|
|||||||
{
|
{
|
||||||
qDebug() << "ViatomLoader::OpenFile(" << filename << ")";
|
qDebug() << "ViatomLoader::OpenFile(" << filename << ")";
|
||||||
|
|
||||||
|
Session* sess = ParseFile(filename);
|
||||||
|
if (sess != nullptr) {
|
||||||
|
SaveSessionToDatabase(sess);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Session* ViatomLoader::ParseFile(const QString & filename)
|
||||||
|
{
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
|
|
||||||
if (!file.open( QFile::ReadOnly )) {
|
if (!file.open( QFile::ReadOnly )) {
|
||||||
qDebug() << "Couldn't open Viatom data file" << filename;
|
qDebug() << "Couldn't open Viatom data file" << filename;
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
@ -68,7 +78,7 @@ ViatomLoader::OpenFile( const QString & filename )
|
|||||||
( M > 60) ||
|
( M > 60) ||
|
||||||
( S > 61)) {
|
( S > 61)) {
|
||||||
qDebug( ) << filename << "does not appear to be a Viatom data file";
|
qDebug( ) << filename << "does not appear to be a Viatom data file";
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
char dchr[32];
|
char dchr[32];
|
||||||
@ -137,11 +147,17 @@ ViatomLoader::OpenFile( const QString & filename )
|
|||||||
sess->setMax( POS_Motion, ev_mv->Max( ) );
|
sess->setMax( POS_Motion, ev_mv->Max( ) );
|
||||||
|
|
||||||
sess->really_set_last( time_ms );
|
sess->really_set_last( time_ms );
|
||||||
|
|
||||||
|
return sess;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ViatomLoader::SaveSessionToDatabase(Session* sess)
|
||||||
|
{
|
||||||
|
Machine* mach = sess->machine();
|
||||||
|
|
||||||
sess->SetChanged( true );
|
sess->SetChanged( true );
|
||||||
mach->AddSession( sess );
|
mach->AddSession( sess );
|
||||||
mach->Save( );
|
mach->Save( );
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool viatom_initialized = false;
|
static bool viatom_initialized = false;
|
||||||
|
@ -28,6 +28,8 @@ class ViatomLoader : public MachineLoader
|
|||||||
|
|
||||||
virtual int Open(const QString & path);
|
virtual int Open(const QString & path);
|
||||||
virtual int OpenFile(const QString & filename);
|
virtual int OpenFile(const QString & filename);
|
||||||
|
Session* ParseFile(const QString & filename);
|
||||||
|
void SaveSessionToDatabase(Session* session);
|
||||||
|
|
||||||
static void Register();
|
static void Register();
|
||||||
|
|
||||||
|
@ -2403,7 +2403,6 @@ void MainWindow::on_actionImport_Viatom_Data_triggered()
|
|||||||
w.setFileMode(QFileDialog::ExistingFiles);
|
w.setFileMode(QFileDialog::ExistingFiles);
|
||||||
w.setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
w.setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||||
w.setOption(QFileDialog::ShowDirsOnly, false);
|
w.setOption(QFileDialog::ShowDirsOnly, false);
|
||||||
w.setOption(QFileDialog::DontUseNativeDialog, true);
|
|
||||||
w.setNameFilters(QStringList("Viatom Data File (20[0-5][0-9][01][0-9][0-3][0-9][012][0-9][0-5][0-9][0-5][0-9])"));
|
w.setNameFilters(QStringList("Viatom Data File (20[0-5][0-9][01][0-9][0-3][0-9][012][0-9][0-5][0-9][0-5][0-9])"));
|
||||||
|
|
||||||
ViatomLoader viatom;
|
ViatomLoader viatom;
|
||||||
|
@ -516,14 +516,16 @@ test {
|
|||||||
tests/prs1tests.cpp \
|
tests/prs1tests.cpp \
|
||||||
tests/resmedtests.cpp \
|
tests/resmedtests.cpp \
|
||||||
tests/sessiontests.cpp \
|
tests/sessiontests.cpp \
|
||||||
tests/versiontests.cpp
|
tests/versiontests.cpp \
|
||||||
|
tests/viatomtests.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
tests/AutoTest.h \
|
tests/AutoTest.h \
|
||||||
tests/prs1tests.h \
|
tests/prs1tests.h \
|
||||||
tests/resmedtests.h \
|
tests/resmedtests.h \
|
||||||
tests/sessiontests.h \
|
tests/sessiontests.h \
|
||||||
tests/versiontests.h
|
tests/versiontests.h \
|
||||||
|
tests/viatomtests.h
|
||||||
}
|
}
|
||||||
|
|
||||||
macx {
|
macx {
|
||||||
|
@ -136,6 +136,7 @@ static QString eventChannel(ChannelID i)
|
|||||||
CHANNELNAME(CPAP_PressureSet);
|
CHANNELNAME(CPAP_PressureSet);
|
||||||
CHANNELNAME(CPAP_IPAPSet);
|
CHANNELNAME(CPAP_IPAPSet);
|
||||||
CHANNELNAME(CPAP_EPAPSet);
|
CHANNELNAME(CPAP_EPAPSet);
|
||||||
|
CHANNELNAME(POS_Motion);
|
||||||
s = hex(i);
|
s = hex(i);
|
||||||
qDebug() << "event channel" << qPrintable(s);
|
qDebug() << "event channel" << qPrintable(s);
|
||||||
} while(false);
|
} while(false);
|
||||||
|
80
oscar/tests/viatomtests.cpp
Normal file
80
oscar/tests/viatomtests.cpp
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/* Viatom Unit Tests
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 The OSCAR Team
|
||||||
|
*
|
||||||
|
* This file is subject to the terms and conditions of the GNU General Public
|
||||||
|
* License. See the file COPYING in the main directory of the source code
|
||||||
|
* for more details. */
|
||||||
|
|
||||||
|
#include "viatomtests.h"
|
||||||
|
#include "sessiontests.h"
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
#define TESTDATA_PATH "./testdata/"
|
||||||
|
|
||||||
|
static ViatomLoader* s_loader = nullptr;
|
||||||
|
static QString viatomOutputPath(const QString & inpath, const QString & suffix);
|
||||||
|
|
||||||
|
void ViatomTests::initTestCase(void)
|
||||||
|
{
|
||||||
|
QString profile_path = TESTDATA_PATH "profile/";
|
||||||
|
Profiles::Create("test", &profile_path);
|
||||||
|
|
||||||
|
schema::init();
|
||||||
|
ViatomLoader::Register();
|
||||||
|
s_loader = dynamic_cast<ViatomLoader*>(lookupLoader(viatom_class_name));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ViatomTests::cleanupTestCase(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ====================================================================================================
|
||||||
|
|
||||||
|
static void parseAndEmitSessionYaml(const QString & path)
|
||||||
|
{
|
||||||
|
qDebug() << path;
|
||||||
|
|
||||||
|
Session* session = s_loader->ParseFile(path);
|
||||||
|
if (session != nullptr) {
|
||||||
|
QString outpath = viatomOutputPath(path, "-session.yml");
|
||||||
|
SessionToYaml(outpath, session, true);
|
||||||
|
delete session;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ViatomTests::testSessionsToYaml()
|
||||||
|
{
|
||||||
|
static const QString root = TESTDATA_PATH "viatom/input/";
|
||||||
|
static const QRegularExpression re("(20[0-5][0-9][01][0-9][0-3][0-9][012][0-9][0-5][0-9][0-5][0-9])");
|
||||||
|
|
||||||
|
QDir dir(root);
|
||||||
|
dir.setFilter(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks);
|
||||||
|
dir.setSorting(QDir::Name);
|
||||||
|
|
||||||
|
for (auto & fi : dir.entryInfoList()) {
|
||||||
|
QRegularExpressionMatch match = re.match(fi.fileName());
|
||||||
|
if (match.hasMatch()) {
|
||||||
|
parseAndEmitSessionYaml(fi.canonicalFilePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ====================================================================================================
|
||||||
|
|
||||||
|
QString viatomOutputPath(const QString & inpath, const QString & suffix)
|
||||||
|
{
|
||||||
|
// Output to viatom/output/FILENAME(-session.yml, etc.)
|
||||||
|
QFileInfo path(inpath);
|
||||||
|
QString basename = path.fileName();
|
||||||
|
|
||||||
|
QDir outdir(TESTDATA_PATH "viatom/output");
|
||||||
|
outdir.mkpath(".");
|
||||||
|
|
||||||
|
QString filename = QString("%1%2")
|
||||||
|
.arg(basename)
|
||||||
|
.arg(suffix);
|
||||||
|
return outdir.path() + QDir::separator() + filename;
|
||||||
|
}
|
28
oscar/tests/viatomtests.h
Normal file
28
oscar/tests/viatomtests.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/* Viatom Unit Tests
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 The OSCAR Team
|
||||||
|
*
|
||||||
|
* This file is subject to the terms and conditions of the GNU General Public
|
||||||
|
* License. See the file COPYING in the main directory of the source code
|
||||||
|
* for more details. */
|
||||||
|
|
||||||
|
#ifndef VIATOMTESTS_H
|
||||||
|
#define VIATOMTESTS_H
|
||||||
|
|
||||||
|
#include "AutoTest.h"
|
||||||
|
#include "../SleepLib/loader_plugins/viatom_loader.h"
|
||||||
|
|
||||||
|
class ViatomTests : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void initTestCase();
|
||||||
|
void testSessionsToYaml();
|
||||||
|
void cleanupTestCase();
|
||||||
|
};
|
||||||
|
|
||||||
|
DECLARE_TEST(ViatomTests)
|
||||||
|
|
||||||
|
#endif // VIATOMTESTS_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user