Skip to content

Commit

Permalink
Add TrainingSession::LapNames tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pcolby committed Sep 5, 2014
1 parent 587f407 commit 49ac9b0
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 38 deletions.
8 changes: 0 additions & 8 deletions test/polar/v2/testdata/training-sessions-19401412.hrm
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,6 @@ Pedaling Index
Max Incline
Degrees 90 0

[LapNames]
1 1
2 1
3 1
4 1
5 2
6 1

[Summary-123]
5239 0 0 2760 2479 0
0 0 0 0 0 0
Expand Down
8 changes: 0 additions & 8 deletions test/polar/v2/testdata/training-sessions-19401412.rr.hrm
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,6 @@ Pedaling Index
Max Incline
Degrees 90 0

[LapNames]
1 1
2 1
3 1
4 1
5 2
6 1

[Summary-123]
5239 0 0 2760 2479 0
0 0 0 0 0 0
Expand Down
11 changes: 0 additions & 11 deletions test/polar/v2/testdata/training-sessions-22165267.hrm
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,6 @@ Pedaling Index
Max Incline
Degrees 90 0

[LapNames]
1 2
2 2
3 2
4 2
5 2
6 2
7 2
8 2
9 2

[Summary-123]
2131 127 0 1957 47 0
0 0 0 0 0 0
Expand Down
11 changes: 0 additions & 11 deletions test/polar/v2/testdata/training-sessions-22165267.rr.hrm
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,6 @@ Pedaling Index
Max Incline
Degrees 90 0

[LapNames]
1 2
2 2
3 2
4 2
5 2
6 2
7 2
8 2
9 2

[Summary-123]
2131 127 0 1957 47 0
0 0 0 0 0 0
Expand Down
130 changes: 130 additions & 0 deletions test/polar/v2/testtrainingsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ void TestTrainingSession::toHRM()
// Parse the route (protobuf) message.
polar::v2::TrainingSession session(baseName);
QVERIFY(session.parse());
session.setHrmOption(polar::v2::TrainingSession::LapNames, false);
const QStringList hrm = session.toHRM(false);

// Write the result to a text file for optional post-mortem investigations.
Expand All @@ -858,6 +859,134 @@ void TestTrainingSession::toHRM()
QCOMPARE(hrm, expected);
}

void TestTrainingSession::toHRM_LapNames_data()
{
QTest::addColumn<QString>("baseName");
QTest::addColumn<QStringList>("expected");

#define LOAD_TEST_DATA(name, expectedCount) { \
QString baseName; \
QStringList expected; \
for (int count = 0; count < expectedCount; ++count) { \
QFile expectedFile(QFINDTESTDATA((expectedCount == 1) \
? QString::fromLatin1("testdata/" name ".LapNames.hrm") \
: QString::fromLatin1("testdata/" name ".%1.LapNames.hrm").arg(count) \
)); \
expectedFile.open(QIODevice::ReadOnly); \
expected.append(QString::fromLatin1(expectedFile.readAll())); \
if (baseName.isEmpty()) { \
baseName = expectedFile.fileName(); \
baseName.chop((expectedCount == 1) ? 13 : 15); \
} \
} \
QTest::newRow(name) << baseName << expected; \
}

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

#undef LOAD_TEST_DATA
}

void TestTrainingSession::toHRM_LapNames()
{
QFETCH(QString, baseName);
QFETCH(QStringList, expected);
qDebug() << baseName;

// Parse the route (protobuf) message.
polar::v2::TrainingSession session(baseName);
QVERIFY(session.parse());
session.setHrmOption(polar::v2::TrainingSession::LapNames);
const QStringList hrm = session.toHRM(false);

// Write the result to a text file for optional post-mortem investigations.
for (int index = 0; index < hrm.length(); ++index) {
QString fileName;
#ifndef Q_OS_WIN
fileName = QLatin1String("../");
#endif
fileName += QString::fromLatin1("polar/v2/testdata/%1.result")
.arg(QLatin1String(QTest::currentDataTag()));
if (hrm.length() != 1) {
fileName += QString::fromLatin1(".%1").arg(index);
}
fileName += QString::fromLatin1(".hrm");
QFile file(fileName);
if (file.open(QIODevice::WriteOnly|QIODevice::Truncate)) {
file.write(hrm.at(index).toLatin1());
}
}

// Compare the generated HRM string against the expected result.
QCOMPARE(hrm, expected);
}

void TestTrainingSession::toHRM_LapNames_RR_data()
{
QTest::addColumn<QString>("baseName");
QTest::addColumn<QStringList>("expected");

#define LOAD_TEST_DATA(name, expectedCount) { \
QString baseName; \
QStringList expected; \
for (int count = 0; count < expectedCount; ++count) { \
QFile expectedFile(QFINDTESTDATA((expectedCount == 1) \
? QString::fromLatin1("testdata/" name ".rr.LapNames.hrm") \
: QString::fromLatin1("testdata/" name ".%1.rr.LapNames.hrm").arg(count) \
)); \
expectedFile.open(QIODevice::ReadOnly); \
expected.append(QString::fromLatin1(expectedFile.readAll())); \
if (baseName.isEmpty()) { \
baseName = expectedFile.fileName(); \
baseName.chop((expectedCount == 1) ? 16 : 18); \
} \
} \
QTest::newRow(name) << baseName << expected; \
}

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

#undef LOAD_TEST_DATA
}

void TestTrainingSession::toHRM_LapNames_RR()
{
QFETCH(QString, baseName);
QFETCH(QStringList, expected);
qDebug() << baseName;

// Parse the route (protobuf) message.
polar::v2::TrainingSession session(baseName);
QVERIFY(session.parse());
session.setHrmOption(polar::v2::TrainingSession::LapNames);
const QStringList hrm = session.toHRM(true);

// Write the result to a text file for optional post-mortem investigations.
for (int index = 0; index < hrm.length(); ++index) {
QString fileName;
#ifndef Q_OS_WIN
fileName = QLatin1String("../");
#endif
fileName += QString::fromLatin1("polar/v2/testdata/%1.result")
.arg(QLatin1String(QTest::currentDataTag()));
if (hrm.length() != 1) {
fileName += QString::fromLatin1(".%1").arg(index);
}
fileName += QString::fromLatin1(".rr.hrm");
QFile file(fileName);
if (file.open(QIODevice::WriteOnly|QIODevice::Truncate)) {
file.write(hrm.at(index).toLatin1());
}
}

// Compare the generated HRM string against the expected result.
QCOMPARE(hrm, expected);
}

void TestTrainingSession::toHRM_RR_data()
{
QTest::addColumn<QString>("baseName");
Expand Down Expand Up @@ -897,6 +1026,7 @@ void TestTrainingSession::toHRM_RR()
// Parse the route (protobuf) message.
polar::v2::TrainingSession session(baseName);
QVERIFY(session.parse());
session.setHrmOption(polar::v2::TrainingSession::LapNames, false);
const QStringList hrm = session.toHRM(true);

// Write the result to a text file for optional post-mortem investigations.
Expand Down
6 changes: 6 additions & 0 deletions test/polar/v2/testtrainingsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ private slots:
void toHRM_data();
void toHRM();

void toHRM_LapNames_data();
void toHRM_LapNames();

void toHRM_LapNames_RR_data();
void toHRM_LapNames_RR();

void toHRM_RR_data();
void toHRM_RR();

Expand Down

0 comments on commit 49ac9b0

Please sign in to comment.