Skip to content

Commit

Permalink
Add placeholder test code for GPX / TCX extensions
Browse files Browse the repository at this point in the history
These test functions will cover the following extensions:
* Cluetrust GPX Extension (#29)
* Garmin (GPX) TrackPoint Extension (#30)
* Garmin (TCX) Activity Extension (#31)
  • Loading branch information
pcolby committed Sep 10, 2014
1 parent 0c80b43 commit bd69c12
Show file tree
Hide file tree
Showing 3 changed files with 326 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/polar/v2/trainingsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ class TrainingSession : public QObject {

public:
enum OutputFormat {
GpxOutput = 0x01,
HrmOutput = 0x02,
TcxOutput = 0x04,
GpxOutput = 0x0001,
HrmOutput = 0x0002,
TcxOutput = 0x0004,
AllOutputs = GpxOutput|HrmOutput|TcxOutput
};
Q_DECLARE_FLAGS(OutputFormats, OutputFormat)

enum GpxOption {
CluetrustGpxExtension = 0x1001,
GarminTrackPointExtension = 0x1002,
CluetrustGpxExtension = 0x0100,
GarminTrackPointExtension = 0x0200,
};
Q_DECLARE_FLAGS(GpxOptions, GpxOption)

Expand All @@ -65,8 +65,8 @@ class TrainingSession : public QObject {

enum TcxOption {
ForceTcxUTC = 0x0001,
GarminActivityExtension = 0x1001,
GarminCourseExtension = 0x1002,
GarminActivityExtension = 0x0100,
//GarminCourseExtension = 0x0200, //< Needs power support.
};
Q_DECLARE_FLAGS(TcxOptions, TcxOption)

Expand Down
304 changes: 304 additions & 0 deletions test/polar/v2/testtrainingsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,190 @@ void TestTrainingSession::toGPX()
QVERIFY(validator.validate(gpx.toByteArray()));
}

void TestTrainingSession::toGPX_AllExtensions_data()
{
QTest::addColumn<QString>("baseName");
QTest::addColumn<QByteArray>("expected");

#define LOAD_TEST_DATA(name) { \
QFile expectedFile(QFINDTESTDATA("testdata/" name ".all-extensions.gpx")); \
QString baseName(expectedFile.fileName()); \
baseName.chop(19); \
expectedFile.open(QIODevice::ReadOnly); \
QTest::newRow(name) << baseName << expectedFile.readAll(); \
}

LOAD_TEST_DATA("training-sessions-1");
LOAD_TEST_DATA("training-sessions-2");
LOAD_TEST_DATA("training-sessions-19401412");
LOAD_TEST_DATA("training-sessions-19946380");
LOAD_TEST_DATA("training-sessions-22165267");

#undef LOAD_TEST_DATA
}

void TestTrainingSession::toGPX_AllExtensions()
{
QFETCH(QString, baseName);
QFETCH(QByteArray, expected);

// Parse the route (protobuf) message.
polar::v2::TrainingSession session(baseName);
QVERIFY(session.parse());
session.setGpxOption(polar::v2::TrainingSession::CluetrustGpxExtension);
session.setGpxOption(polar::v2::TrainingSession::GarminTrackPointExtension);
QDomDocument gpx = session.toGPX(QDateTime::fromString(
QLatin1String("2014-07-15T12:34:56Z"), Qt::ISODate));

// Write the result to an XML file for optional post-mortem investigations.
#ifdef Q_OS_WIN
QFile file(QString::fromLatin1("polar/v2/testdata/%1.result.gpx")
#else
QFile file(QString::fromLatin1("../polar/v2/testdata/%1.result.gpx")
#endif
.arg(QString::fromLatin1(QTest::currentDataTag())));
if (file.open(QIODevice::WriteOnly|QIODevice::Truncate)) {
file.write(gpx.toByteArray(2));
}
file.close();

// Compare the generated document against the expected result.
QDomDocument expectedDoc;
expectedDoc.setContent(expected);
compare(gpx, expectedDoc);

// Validate the generated document against the relevant XML schema.
gpx.documentElement().removeAttribute(QLatin1String("xsi:schemaLocation"));
QFile xsd(QFINDTESTDATA("schemata/gpx.xsd"));
QVERIFY(xsd.open(QIODevice::ReadOnly));
QXmlSchema schema;
QVERIFY(schema.load(&xsd, QUrl::fromLocalFile(xsd.fileName())));
QXmlSchemaValidator validator(schema);
QVERIFY(validator.validate(gpx.toByteArray()));
}

void TestTrainingSession::toGPX_Cluetrust_data()
{
QTest::addColumn<QString>("baseName");
QTest::addColumn<QByteArray>("expected");

#define LOAD_TEST_DATA(name) { \
QFile expectedFile(QFINDTESTDATA("testdata/" name ".cluetrust.gpx")); \
QString baseName(expectedFile.fileName()); \
baseName.chop(14); \
expectedFile.open(QIODevice::ReadOnly); \
QTest::newRow(name) << baseName << expectedFile.readAll(); \
}

LOAD_TEST_DATA("training-sessions-1");
LOAD_TEST_DATA("training-sessions-2");
LOAD_TEST_DATA("training-sessions-19401412");
LOAD_TEST_DATA("training-sessions-19946380");
LOAD_TEST_DATA("training-sessions-22165267");

#undef LOAD_TEST_DATA
}

void TestTrainingSession::toGPX_Cluetrust()
{
QFETCH(QString, baseName);
QFETCH(QByteArray, expected);

// Parse the route (protobuf) message.
polar::v2::TrainingSession session(baseName);
QVERIFY(session.parse());
session.setGpxOption(polar::v2::TrainingSession::CluetrustGpxExtension);
QDomDocument gpx = session.toGPX(QDateTime::fromString(
QLatin1String("2014-07-15T12:34:56Z"), Qt::ISODate));

// Write the result to an XML file for optional post-mortem investigations.
#ifdef Q_OS_WIN
QFile file(QString::fromLatin1("polar/v2/testdata/%1.result.gpx")
#else
QFile file(QString::fromLatin1("../polar/v2/testdata/%1.result.gpx")
#endif
.arg(QString::fromLatin1(QTest::currentDataTag())));
if (file.open(QIODevice::WriteOnly|QIODevice::Truncate)) {
file.write(gpx.toByteArray(2));
}
file.close();

// Compare the generated document against the expected result.
QDomDocument expectedDoc;
expectedDoc.setContent(expected);
compare(gpx, expectedDoc);

// Validate the generated document against the relevant XML schema.
gpx.documentElement().removeAttribute(QLatin1String("xsi:schemaLocation"));
QFile xsd(QFINDTESTDATA("schemata/gpx.xsd"));
QVERIFY(xsd.open(QIODevice::ReadOnly));
QXmlSchema schema;
QVERIFY(schema.load(&xsd, QUrl::fromLocalFile(xsd.fileName())));
QXmlSchemaValidator validator(schema);
QVERIFY(validator.validate(gpx.toByteArray()));
}

void TestTrainingSession::toGPX_GarminTrackPoint_data()
{
QTest::addColumn<QString>("baseName");
QTest::addColumn<QByteArray>("expected");

#define LOAD_TEST_DATA(name) { \
QFile expectedFile(QFINDTESTDATA("testdata/" name ".garmin-trackpoint.gpx")); \
QString baseName(expectedFile.fileName()); \
baseName.chop(22); \
expectedFile.open(QIODevice::ReadOnly); \
QTest::newRow(name) << baseName << expectedFile.readAll(); \
}

LOAD_TEST_DATA("training-sessions-1");
LOAD_TEST_DATA("training-sessions-2");
LOAD_TEST_DATA("training-sessions-19401412");
LOAD_TEST_DATA("training-sessions-19946380");
LOAD_TEST_DATA("training-sessions-22165267");

#undef LOAD_TEST_DATA
}

void TestTrainingSession::toGPX_GarminTrackPoint()
{
QFETCH(QString, baseName);
QFETCH(QByteArray, expected);

// Parse the route (protobuf) message.
polar::v2::TrainingSession session(baseName);
QVERIFY(session.parse());
session.setGpxOption(polar::v2::TrainingSession::GarminTrackPointExtension);
QDomDocument gpx = session.toGPX(QDateTime::fromString(
QLatin1String("2014-07-15T12:34:56Z"), Qt::ISODate));

// Write the result to an XML file for optional post-mortem investigations.
#ifdef Q_OS_WIN
QFile file(QString::fromLatin1("polar/v2/testdata/%1.result.gpx")
#else
QFile file(QString::fromLatin1("../polar/v2/testdata/%1.result.gpx")
#endif
.arg(QString::fromLatin1(QTest::currentDataTag())));
if (file.open(QIODevice::WriteOnly|QIODevice::Truncate)) {
file.write(gpx.toByteArray(2));
}
file.close();

// Compare the generated document against the expected result.
QDomDocument expectedDoc;
expectedDoc.setContent(expected);
compare(gpx, expectedDoc);

// Validate the generated document against the relevant XML schema.
gpx.documentElement().removeAttribute(QLatin1String("xsi:schemaLocation"));
QFile xsd(QFINDTESTDATA("schemata/gpx.xsd"));
QVERIFY(xsd.open(QIODevice::ReadOnly));
QXmlSchema schema;
QVERIFY(schema.load(&xsd, QUrl::fromLocalFile(xsd.fileName())));
QXmlSchemaValidator validator(schema);
QVERIFY(validator.validate(gpx.toByteArray()));
}

void TestTrainingSession::toHRM_data()
{
QTest::addColumn<QString>("baseName");
Expand Down Expand Up @@ -1110,6 +1294,126 @@ void TestTrainingSession::toTCX()
QVERIFY(validator.validate(tcx.toByteArray()));
}

void TestTrainingSession::toTCX_AllExtensions_data()
{
QTest::addColumn<QString>("baseName");
QTest::addColumn<QByteArray>("expected");

#define LOAD_TEST_DATA(name) { \
QFile expectedFile(QFINDTESTDATA("testdata/" name ".all-extensions.tcx")); \
QString baseName(expectedFile.fileName()); \
baseName.chop(19); \
expectedFile.open(QIODevice::ReadOnly); \
QTest::newRow(name) << baseName << expectedFile.readAll(); \
}

LOAD_TEST_DATA("training-sessions-1");
LOAD_TEST_DATA("training-sessions-2");
LOAD_TEST_DATA("training-sessions-19401412");
LOAD_TEST_DATA("training-sessions-19946380");
LOAD_TEST_DATA("training-sessions-22165267");

#undef LOAD_TEST_DATA
}

void TestTrainingSession::toTCX_AllExtensions()
{
QFETCH(QString, baseName);
QFETCH(QByteArray, expected);

// Parse the route (protobuf) message.
polar::v2::TrainingSession session(baseName);
QVERIFY(session.parse());
session.setTcxOption(polar::v2::TrainingSession::GarminActivityExtension);
QDomDocument tcx = session.toTCX(QLatin1String("Jul 17 2014 21:02:38"));

// Write the result to an XML file for optional post-mortem investigations.
#ifdef Q_OS_WIN
QFile file(QString::fromLatin1("polar/v2/testdata/%1.result.tcx")
#else
QFile file(QString::fromLatin1("../polar/v2/testdata/%1.result.tcx")
#endif
.arg(QString::fromLatin1(QTest::currentDataTag())));
if (file.open(QIODevice::WriteOnly|QIODevice::Truncate)) {
file.write(tcx.toByteArray(2));
}
file.close();

// Compare the generated document against the expected result.
QDomDocument expectedDoc;
expectedDoc.setContent(expected);
compare(tcx, expectedDoc);

// Validate the generated document against the relevant XML schema.
tcx.documentElement().removeAttribute(QLatin1String("xsi:schemaLocation"));
QFile xsd(QFINDTESTDATA("schemata/TrainingCenterDatabasev2.xsd"));
QVERIFY(xsd.open(QIODevice::ReadOnly));
QXmlSchema schema;
QVERIFY(schema.load(&xsd, QUrl::fromLocalFile(xsd.fileName())));
QXmlSchemaValidator validator(schema);
QVERIFY(validator.validate(tcx.toByteArray()));
}

void TestTrainingSession::toTCX_GarminActivity_data()
{
QTest::addColumn<QString>("baseName");
QTest::addColumn<QByteArray>("expected");

#define LOAD_TEST_DATA(name) { \
QFile expectedFile(QFINDTESTDATA("testdata/" name ".garmin-activity.tcx")); \
QString baseName(expectedFile.fileName()); \
baseName.chop(20); \
expectedFile.open(QIODevice::ReadOnly); \
QTest::newRow(name) << baseName << expectedFile.readAll(); \
}

LOAD_TEST_DATA("training-sessions-1");
LOAD_TEST_DATA("training-sessions-2");
LOAD_TEST_DATA("training-sessions-19401412");
LOAD_TEST_DATA("training-sessions-19946380");
LOAD_TEST_DATA("training-sessions-22165267");

#undef LOAD_TEST_DATA
}

void TestTrainingSession::toTCX_GarminActivity()
{
QFETCH(QString, baseName);
QFETCH(QByteArray, expected);

// Parse the route (protobuf) message.
polar::v2::TrainingSession session(baseName);
QVERIFY(session.parse());
session.setTcxOption(polar::v2::TrainingSession::GarminActivityExtension);
QDomDocument tcx = session.toTCX(QLatin1String("Jul 17 2014 21:02:38"));

// Write the result to an XML file for optional post-mortem investigations.
#ifdef Q_OS_WIN
QFile file(QString::fromLatin1("polar/v2/testdata/%1.result.tcx")
#else
QFile file(QString::fromLatin1("../polar/v2/testdata/%1.result.tcx")
#endif
.arg(QString::fromLatin1(QTest::currentDataTag())));
if (file.open(QIODevice::WriteOnly|QIODevice::Truncate)) {
file.write(tcx.toByteArray(2));
}
file.close();

// Compare the generated document against the expected result.
QDomDocument expectedDoc;
expectedDoc.setContent(expected);
compare(tcx, expectedDoc);

// Validate the generated document against the relevant XML schema.
tcx.documentElement().removeAttribute(QLatin1String("xsi:schemaLocation"));
QFile xsd(QFINDTESTDATA("schemata/TrainingCenterDatabasev2.xsd"));
QVERIFY(xsd.open(QIODevice::ReadOnly));
QXmlSchema schema;
QVERIFY(schema.load(&xsd, QUrl::fromLocalFile(xsd.fileName())));
QXmlSchemaValidator validator(schema);
QVERIFY(validator.validate(tcx.toByteArray()));
}

void TestTrainingSession::toTCX_UTC_data()
{
QTest::addColumn<QString>("baseName");
Expand Down
15 changes: 15 additions & 0 deletions test/polar/v2/testtrainingsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ private slots:
void toGPX_data();
void toGPX();

void toGPX_AllExtensions_data();
void toGPX_AllExtensions();

void toGPX_Cluetrust_data();
void toGPX_Cluetrust();

void toGPX_GarminTrackPoint_data();
void toGPX_GarminTrackPoint();

void toHRM_data();
void toHRM();

Expand All @@ -77,6 +86,12 @@ private slots:
void toTCX_data();
void toTCX();

void toTCX_AllExtensions_data();
void toTCX_AllExtensions();

void toTCX_GarminActivity_data();
void toTCX_GarminActivity();

void toTCX_UTC_data();
void toTCX_UTC();

Expand Down

0 comments on commit bd69c12

Please sign in to comment.