Here you go. I didn't actually fixed the testcases with those patches because I have no idea how saving / resroring works, but this makes it really easier to spot the errors, that actually where real errors.
The error output now are two: Actual (readin.takeFirst()) : " <divecomputer>" Expected (written.takeFirst()): " <divecomputer model='csv' deviceid='ffffffff'>" Loc: [/home/tcanabrava/Projects/subsurface/tests/testparse.cpp(125)] FAIL! : TestParse::testParseCompareHUDCOutput() Compared values are not the same Actual (readin.takeFirst()) : "</divesites>" Expected (written.takeFirst()): "<site uuid='deadbeef' name='Suomi - - H\u00E4lv\u00E4l\u00E4'>" Loc: [/home/tcanabrava/Projects/subsurface/tests/testparse.cpp(221)] seems that we are not saving the divecomputer for csv, and we miss some divesites.
From d2621760ac9ada38cbfe9ec0a5d94fbd77880724 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Tue, 27 Dec 2016 13:46:13 +0100 Subject: [PATCH 2/2] Test line-by-line for equality on Test We where testing the whole document, wich made qDebug completely bogus to see where we failed at testing the generated file. If we test line-by-line, we can know more easily where we failed. Signed-off-by: Tomaz Canabrava <[email protected]> --- tests/testparse.cpp | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/tests/testparse.cpp b/tests/testparse.cpp index e9d313e5..6f1b6eb1 100644 --- a/tests/testparse.cpp +++ b/tests/testparse.cpp @@ -119,9 +119,11 @@ void TestParse::testParseCompareOutput() out.open(QFile::ReadOnly); QTextStream orgS(&org); QTextStream outS(&out); - QString readin = orgS.readAll(); - QString written = outS.readAll(); - QCOMPARE(readin, written); + QStringList readin = orgS.readAll().split("\n"); + QStringList written = outS.readAll().split("\n"); + while(readin.size() && written.size()){ + QCOMPARE(readin.takeFirst(), written.takeFirst()); + } clear_dive_file_data(); } @@ -144,9 +146,11 @@ void TestParse::testParseCompareDM4Output() out.open(QFile::ReadOnly); QTextStream orgS(&org); QTextStream outS(&out); - QString readin = orgS.readAll(); - QString written = outS.readAll(); - QCOMPARE(readin, written); + QStringList readin = orgS.readAll().split("\n"); + QStringList written = outS.readAll().split("\n"); + while(readin.size() && written.size()){ + QCOMPARE(readin.takeFirst(), written.takeFirst()); + } clear_dive_file_data(); } @@ -211,9 +215,11 @@ void TestParse::testParseCompareHUDCOutput() out.open(QFile::ReadOnly); QTextStream orgS(&org); QTextStream outS(&out); - QString readin = orgS.readAll(); - QString written = outS.readAll(); - QCOMPARE(readin, written); + QStringList readin = orgS.readAll().split("\n"); + QStringList written = outS.readAll().split("\n"); + while(readin.size() && written.size()){ + QCOMPARE(readin.takeFirst(), written.takeFirst()); + } clear_dive_file_data(); } @@ -357,9 +363,11 @@ void TestParse::testParseCompareNewFormatOutput() out.open(QFile::ReadOnly); QTextStream orgS(&org); QTextStream outS(&out); - QString readin = orgS.readAll(); - QString written = outS.readAll(); - QCOMPARE(readin, written); + QStringList readin = orgS.readAll().split("\n"); + QStringList written = outS.readAll().split("\n"); + while(readin.size() && written.size()){ + QCOMPARE(readin.takeFirst(), written.takeFirst()); + } clear_dive_file_data(); } @@ -389,9 +397,11 @@ void TestParse::testParseCompareDLDOutput() out.open(QFile::ReadOnly); QTextStream orgS(&org); QTextStream outS(&out); - QString readin = orgS.readAll(); - QString written = outS.readAll(); - QCOMPARE(readin, written); + QStringList readin = orgS.readAll().split("\n"); + QStringList written = outS.readAll().split("\n"); + while(readin.size() && written.size()){ + QCOMPARE(readin.takeFirst(), written.takeFirst()); + } clear_dive_file_data(); } -- 2.11.0
From a3077af6ff3a019aec9bfc0bafb2e704fe551638 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Tue, 27 Dec 2016 13:31:30 +0100 Subject: [PATCH 1/2] Correctly open the resource file Signed-off-by: Tomaz Canabrava <[email protected]> --- core/qthelper.cpp | 2 +- tests/testparse.cpp | 6 ++++++ tests/testparse.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/qthelper.cpp b/core/qthelper.cpp index e0a5b155..885e89d9 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -320,7 +320,7 @@ static xmlDocPtr get_stylesheet_doc(const xmlChar *uri, xmlDictPtr, int, void *, QFile f(QLatin1String(":/xslt/") + (const char *)uri); if (!f.open(QIODevice::ReadOnly)) { if (verbose > 0) { - qDebug() << "cannot open stylesheet" << QLatin1String(":/xslt/") + (const char *)uri; + qDebug() << "cannot open stylesheet" << QLatin1String(":/xslt/") + (const char *)uri << f.errorString(); return NULL; } } diff --git a/tests/testparse.cpp b/tests/testparse.cpp index 8d4cedb4..e9d313e5 100644 --- a/tests/testparse.cpp +++ b/tests/testparse.cpp @@ -4,6 +4,12 @@ #include "core/divelist.h" #include <QTextStream> +void TestParse::initTestCase() +{ + /* we need to manually tell that the resource exists, because we are using it as library. */ + Q_INIT_RESOURCE(subsurface); +} + char *intdup(int index) { char tmpbuf[21]; diff --git a/tests/testparse.h b/tests/testparse.h index 5616f071..d99f9e53 100644 --- a/tests/testparse.h +++ b/tests/testparse.h @@ -6,6 +6,7 @@ class TestParse : public QObject{ Q_OBJECT private slots: + void initTestCase(); void testParseCSV(); void testParseDivingLog(); void testParseV2NoQuestion(); -- 2.11.0
_______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
