diff --git a/src/polar/v2/trainingsession.h b/src/polar/v2/trainingsession.h index 096dc591..7df000c9 100644 --- a/src/polar/v2/trainingsession.h +++ b/src/polar/v2/trainingsession.h @@ -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) @@ -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) diff --git a/test/polar/v2/testtrainingsession.cpp b/test/polar/v2/testtrainingsession.cpp index ee2576ca..ad7b99bd 100644 --- a/test/polar/v2/testtrainingsession.cpp +++ b/test/polar/v2/testtrainingsession.cpp @@ -795,6 +795,190 @@ void TestTrainingSession::toGPX() QVERIFY(validator.validate(gpx.toByteArray())); } +void TestTrainingSession::toGPX_AllExtensions_data() +{ + QTest::addColumn("baseName"); + QTest::addColumn("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("baseName"); + QTest::addColumn("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("baseName"); + QTest::addColumn("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("baseName"); @@ -1110,6 +1294,126 @@ void TestTrainingSession::toTCX() QVERIFY(validator.validate(tcx.toByteArray())); } +void TestTrainingSession::toTCX_AllExtensions_data() +{ + QTest::addColumn("baseName"); + QTest::addColumn("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("baseName"); + QTest::addColumn("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("baseName"); diff --git a/test/polar/v2/testtrainingsession.h b/test/polar/v2/testtrainingsession.h index 14c7c0bd..82efb90e 100644 --- a/test/polar/v2/testtrainingsession.h +++ b/test/polar/v2/testtrainingsession.h @@ -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(); @@ -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();