@@ -0,0 +1,3 | |||||
|
1 | Not Found | |||
|
2 | ||||
|
3 | The requested URL /AMDA/data/WSRESULT/imf(0)-1343153090-1343153092-60.txt was not found on this server. No newline at end of file |
@@ -1,134 +1,145 | |||||
1 | #include "AmdaResultParser.h" |
|
1 | #include "AmdaResultParser.h" | |
2 |
|
2 | |||
3 | #include <Data/ScalarSeries.h> |
|
3 | #include <Data/ScalarSeries.h> | |
4 |
|
4 | |||
5 | #include <QDateTime> |
|
5 | #include <QDateTime> | |
6 | #include <QFile> |
|
6 | #include <QFile> | |
7 | #include <QRegularExpression> |
|
7 | #include <QRegularExpression> | |
8 |
|
8 | |||
9 | #include <cmath> |
|
9 | #include <cmath> | |
10 |
|
10 | |||
11 | Q_LOGGING_CATEGORY(LOG_AmdaResultParser, "AmdaResultParser") |
|
11 | Q_LOGGING_CATEGORY(LOG_AmdaResultParser, "AmdaResultParser") | |
12 |
|
12 | |||
13 | namespace { |
|
13 | namespace { | |
14 |
|
14 | |||
|
15 | /// Message in result file when the file was not found on server | |||
|
16 | const auto FILE_NOT_FOUND_MESSAGE = QStringLiteral("Not Found"); | |||
|
17 | ||||
15 | /// Format for dates in result files |
|
18 | /// Format for dates in result files | |
16 | const auto DATE_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz"); |
|
19 | const auto DATE_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz"); | |
17 |
|
20 | |||
18 | /// Separator between values in a result line |
|
21 | /// Separator between values in a result line | |
19 | const auto RESULT_LINE_SEPARATOR = QRegularExpression{QStringLiteral("\\s+")}; |
|
22 | const auto RESULT_LINE_SEPARATOR = QRegularExpression{QStringLiteral("\\s+")}; | |
20 |
|
23 | |||
21 | /// Regex to find unit in a line. Examples of valid lines: |
|
24 | /// Regex to find unit in a line. Examples of valid lines: | |
22 | /// ... - Units : nT - ... |
|
25 | /// ... - Units : nT - ... | |
23 | /// ... -Units:nT- ... |
|
26 | /// ... -Units:nT- ... | |
24 | /// ... -Units: m²- ... |
|
27 | /// ... -Units: m²- ... | |
25 | /// ... - Units : m/s - ... |
|
28 | /// ... - Units : m/s - ... | |
26 | const auto UNIT_REGEX = QRegularExpression{QStringLiteral("-\\s*Units\\s*:\\s*(.+?)\\s*-")}; |
|
29 | const auto UNIT_REGEX = QRegularExpression{QStringLiteral("-\\s*Units\\s*:\\s*(.+?)\\s*-")}; | |
27 |
|
30 | |||
28 | /// Converts a string date to a double date |
|
31 | /// Converts a string date to a double date | |
29 | /// @return a double that represents the date in seconds, NaN if the string date can't be converted |
|
32 | /// @return a double that represents the date in seconds, NaN if the string date can't be converted | |
30 | double doubleDate(const QString &stringDate) noexcept |
|
33 | double doubleDate(const QString &stringDate) noexcept | |
31 | { |
|
34 | { | |
32 | auto dateTime = QDateTime::fromString(stringDate, DATE_FORMAT); |
|
35 | auto dateTime = QDateTime::fromString(stringDate, DATE_FORMAT); | |
33 | return dateTime.isValid() ? (dateTime.toMSecsSinceEpoch() / 1000.) |
|
36 | return dateTime.isValid() ? (dateTime.toMSecsSinceEpoch() / 1000.) | |
34 | : std::numeric_limits<double>::quiet_NaN(); |
|
37 | : std::numeric_limits<double>::quiet_NaN(); | |
35 | } |
|
38 | } | |
36 |
|
39 | |||
37 | /** |
|
40 | /** | |
38 | * Reads stream to retrieve x-axis unit |
|
41 | * Reads stream to retrieve x-axis unit | |
39 | * @param stream the stream to read |
|
42 | * @param stream the stream to read | |
40 | * @return the unit that has been read in the stream, a default unit (time unit with no label) if an |
|
43 | * @return the unit that has been read in the stream, a default unit (time unit with no label) if an | |
41 | * error occured during reading |
|
44 | * error occured during reading | |
42 | */ |
|
45 | */ | |
43 | Unit readXAxisUnit(QTextStream &stream) |
|
46 | Unit readXAxisUnit(QTextStream &stream) | |
44 | { |
|
47 | { | |
45 | QString line{}; |
|
48 | QString line{}; | |
46 |
|
49 | |||
47 | if (stream.readLineInto(&line)) { |
|
50 | if (stream.readLineInto(&line)) { | |
48 | auto match = UNIT_REGEX.match(line); |
|
51 | auto match = UNIT_REGEX.match(line); | |
49 | if (match.hasMatch()) { |
|
52 | if (match.hasMatch()) { | |
50 | return Unit{match.captured(1), true}; |
|
53 | return Unit{match.captured(1), true}; | |
51 | } |
|
54 | } | |
52 | else { |
|
55 | else { | |
53 | qCWarning(LOG_AmdaResultParser()) |
|
56 | qCWarning(LOG_AmdaResultParser()) | |
54 | << QObject::tr("Can't read unit: invalid line %1").arg(line); |
|
57 | << QObject::tr("Can't read unit: invalid line %1").arg(line); | |
55 | } |
|
58 | } | |
56 | } |
|
59 | } | |
57 | else { |
|
60 | else { | |
58 | qCWarning(LOG_AmdaResultParser()) << QObject::tr("Can't read unit: end of file"); |
|
61 | qCWarning(LOG_AmdaResultParser()) << QObject::tr("Can't read unit: end of file"); | |
59 | } |
|
62 | } | |
60 |
|
63 | |||
61 | // Error cases |
|
64 | // Error cases | |
62 | return Unit{{}, true}; |
|
65 | return Unit{{}, true}; | |
63 | } |
|
66 | } | |
64 |
|
67 | |||
65 | /** |
|
68 | /** | |
66 | * Reads stream to retrieve results |
|
69 | * Reads stream to retrieve results | |
67 | * @param stream the stream to read |
|
70 | * @param stream the stream to read | |
68 | * @return the pair of vectors x-axis data/values data that has been read in the stream |
|
71 | * @return the pair of vectors x-axis data/values data that has been read in the stream | |
69 | */ |
|
72 | */ | |
70 | QPair<QVector<double>, QVector<double> > readResults(QTextStream &stream) |
|
73 | QPair<QVector<double>, QVector<double> > readResults(QTextStream &stream) | |
71 | { |
|
74 | { | |
72 | auto xData = QVector<double>{}; |
|
75 | auto xData = QVector<double>{}; | |
73 | auto valuesData = QVector<double>{}; |
|
76 | auto valuesData = QVector<double>{}; | |
74 |
|
77 | |||
75 | QString line{}; |
|
78 | QString line{}; | |
76 | while (stream.readLineInto(&line)) { |
|
79 | while (stream.readLineInto(&line)) { | |
77 | auto lineData = line.split(RESULT_LINE_SEPARATOR, QString::SkipEmptyParts); |
|
80 | auto lineData = line.split(RESULT_LINE_SEPARATOR, QString::SkipEmptyParts); | |
78 | if (lineData.size() == 2) { |
|
81 | if (lineData.size() == 2) { | |
79 | // X : the data is converted from date to double (in secs) |
|
82 | // X : the data is converted from date to double (in secs) | |
80 | auto x = doubleDate(lineData.at(0)); |
|
83 | auto x = doubleDate(lineData.at(0)); | |
81 |
|
84 | |||
82 | // Value |
|
85 | // Value | |
83 | bool valueOk; |
|
86 | bool valueOk; | |
84 | auto value = lineData.at(1).toDouble(&valueOk); |
|
87 | auto value = lineData.at(1).toDouble(&valueOk); | |
85 |
|
88 | |||
86 | // Adds result only if x and value are valid |
|
89 | // Adds result only if x and value are valid | |
87 | if (!std::isnan(x) && !std::isnan(value) && valueOk) { |
|
90 | if (!std::isnan(x) && !std::isnan(value) && valueOk) { | |
88 | xData.push_back(x); |
|
91 | xData.push_back(x); | |
89 | valuesData.push_back(value); |
|
92 | valuesData.push_back(value); | |
90 | } |
|
93 | } | |
91 | else { |
|
94 | else { | |
92 | qCWarning(LOG_AmdaResultParser()) |
|
95 | qCWarning(LOG_AmdaResultParser()) | |
93 | << QObject::tr( |
|
96 | << QObject::tr( | |
94 | "Can't retrieve results from line %1: x and/or value are invalid") |
|
97 | "Can't retrieve results from line %1: x and/or value are invalid") | |
95 | .arg(line); |
|
98 | .arg(line); | |
96 | } |
|
99 | } | |
97 | } |
|
100 | } | |
98 | else { |
|
101 | else { | |
99 | qCWarning(LOG_AmdaResultParser()) |
|
102 | qCWarning(LOG_AmdaResultParser()) | |
100 | << QObject::tr("Can't retrieve results from line %1: invalid line").arg(line); |
|
103 | << QObject::tr("Can't retrieve results from line %1: invalid line").arg(line); | |
101 | } |
|
104 | } | |
102 | } |
|
105 | } | |
103 |
|
106 | |||
104 | return qMakePair(std::move(xData), std::move(valuesData)); |
|
107 | return qMakePair(std::move(xData), std::move(valuesData)); | |
105 | } |
|
108 | } | |
106 |
|
109 | |||
107 | } // namespace |
|
110 | } // namespace | |
108 |
|
111 | |||
109 | std::shared_ptr<IDataSeries> AmdaResultParser::readTxt(const QString &filePath) noexcept |
|
112 | std::shared_ptr<IDataSeries> AmdaResultParser::readTxt(const QString &filePath) noexcept | |
110 | { |
|
113 | { | |
111 | QFile file{filePath}; |
|
114 | QFile file{filePath}; | |
112 |
|
115 | |||
113 | if (!file.open(QFile::ReadOnly | QIODevice::Text)) { |
|
116 | if (!file.open(QFile::ReadOnly | QIODevice::Text)) { | |
114 | qCCritical(LOG_AmdaResultParser()) |
|
117 | qCCritical(LOG_AmdaResultParser()) | |
115 | << QObject::tr("Can't retrieve AMDA data from file %1: %2") |
|
118 | << QObject::tr("Can't retrieve AMDA data from file %1: %2") | |
116 | .arg(filePath, file.errorString()); |
|
119 | .arg(filePath, file.errorString()); | |
117 | return nullptr; |
|
120 | return nullptr; | |
118 | } |
|
121 | } | |
119 |
|
122 | |||
120 | QTextStream stream{&file}; |
|
123 | QTextStream stream{&file}; | |
121 |
|
124 | |||
122 | // Ignore first two lines (comments lines) |
|
125 | // Checks if the file was found on the server | |
123 | stream.readLine(); |
|
126 | auto firstLine = stream.readLine(); | |
|
127 | if (firstLine.compare(FILE_NOT_FOUND_MESSAGE) == 0) { | |||
|
128 | qCCritical(LOG_AmdaResultParser()) | |||
|
129 | << QObject::tr("Can't retrieve AMDA data from file %1: file was not found on server") | |||
|
130 | .arg(filePath); | |||
|
131 | return nullptr; | |||
|
132 | } | |||
|
133 | ||||
|
134 | // Ignore comments lines | |||
124 | stream.readLine(); |
|
135 | stream.readLine(); | |
125 |
|
136 | |||
126 | // Reads x-axis unit |
|
137 | // Reads x-axis unit | |
127 | auto xAxisUnit = readXAxisUnit(stream); |
|
138 | auto xAxisUnit = readXAxisUnit(stream); | |
128 |
|
139 | |||
129 | // Reads results |
|
140 | // Reads results | |
130 | auto results = readResults(stream); |
|
141 | auto results = readResults(stream); | |
131 |
|
142 | |||
132 | return std::make_shared<ScalarSeries>(std::move(results.first), std::move(results.second), |
|
143 | return std::make_shared<ScalarSeries>(std::move(results.first), std::move(results.second), | |
133 | xAxisUnit, Unit{}); |
|
144 | xAxisUnit, Unit{}); | |
134 | } |
|
145 | } |
@@ -1,179 +1,182 | |||||
1 | #include "AmdaResultParser.h" |
|
1 | #include "AmdaResultParser.h" | |
2 |
|
2 | |||
3 | #include <Data/ScalarSeries.h> |
|
3 | #include <Data/ScalarSeries.h> | |
4 |
|
4 | |||
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 | #include <QtTest> |
|
6 | #include <QtTest> | |
7 |
|
7 | |||
8 | namespace { |
|
8 | namespace { | |
9 |
|
9 | |||
10 | /// Path for the tests |
|
10 | /// Path for the tests | |
11 | const auto TESTS_RESOURCES_PATH |
|
11 | const auto TESTS_RESOURCES_PATH | |
12 | = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaResultParser"}.absoluteFilePath(); |
|
12 | = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaResultParser"}.absoluteFilePath(); | |
13 |
|
13 | |||
14 | QString inputFilePath(const QString &inputFileName) |
|
14 | QString inputFilePath(const QString &inputFileName) | |
15 | { |
|
15 | { | |
16 | return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath(); |
|
16 | return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath(); | |
17 | } |
|
17 | } | |
18 |
|
18 | |||
19 | struct ExpectedResults { |
|
19 | struct ExpectedResults { | |
20 | explicit ExpectedResults() = default; |
|
20 | explicit ExpectedResults() = default; | |
21 |
|
21 | |||
22 | /// Ctor with QVector<QDateTime> as x-axis data. Datetimes are converted to doubles |
|
22 | /// Ctor with QVector<QDateTime> as x-axis data. Datetimes are converted to doubles | |
23 | explicit ExpectedResults(Unit xAxisUnit, Unit valuesUnit, const QVector<QDateTime> &xAxisData, |
|
23 | explicit ExpectedResults(Unit xAxisUnit, Unit valuesUnit, const QVector<QDateTime> &xAxisData, | |
24 | QVector<double> valuesData) |
|
24 | QVector<double> valuesData) | |
25 | : m_ParsingOK{true}, |
|
25 | : m_ParsingOK{true}, | |
26 | m_XAxisUnit{xAxisUnit}, |
|
26 | m_XAxisUnit{xAxisUnit}, | |
27 | m_ValuesUnit{valuesUnit}, |
|
27 | m_ValuesUnit{valuesUnit}, | |
28 | m_XAxisData{}, |
|
28 | m_XAxisData{}, | |
29 | m_ValuesData{std::move(valuesData)} |
|
29 | m_ValuesData{std::move(valuesData)} | |
30 | { |
|
30 | { | |
31 | // Converts QVector<QDateTime> to QVector<double> |
|
31 | // Converts QVector<QDateTime> to QVector<double> | |
32 | std::transform(xAxisData.cbegin(), xAxisData.cend(), std::back_inserter(m_XAxisData), |
|
32 | std::transform(xAxisData.cbegin(), xAxisData.cend(), std::back_inserter(m_XAxisData), | |
33 | [](const auto &dateTime) { return dateTime.toMSecsSinceEpoch() / 1000.; }); |
|
33 | [](const auto &dateTime) { return dateTime.toMSecsSinceEpoch() / 1000.; }); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | /** |
|
36 | /** | |
37 | * Validates a DataSeries compared to the expected results |
|
37 | * Validates a DataSeries compared to the expected results | |
38 | * @param results the DataSeries to validate |
|
38 | * @param results the DataSeries to validate | |
39 | */ |
|
39 | */ | |
40 | void validate(std::shared_ptr<IDataSeries> results) |
|
40 | void validate(std::shared_ptr<IDataSeries> results) | |
41 | { |
|
41 | { | |
42 | if (m_ParsingOK) { |
|
42 | if (m_ParsingOK) { | |
43 | auto scalarSeries = dynamic_cast<ScalarSeries *>(results.get()); |
|
43 | auto scalarSeries = dynamic_cast<ScalarSeries *>(results.get()); | |
44 | QVERIFY(scalarSeries != nullptr); |
|
44 | QVERIFY(scalarSeries != nullptr); | |
45 |
|
45 | |||
46 | // Checks units |
|
46 | // Checks units | |
47 | QVERIFY(scalarSeries->xAxisUnit() == m_XAxisUnit); |
|
47 | QVERIFY(scalarSeries->xAxisUnit() == m_XAxisUnit); | |
48 | QVERIFY(scalarSeries->valuesUnit() == m_ValuesUnit); |
|
48 | QVERIFY(scalarSeries->valuesUnit() == m_ValuesUnit); | |
49 |
|
49 | |||
50 | // Checks values |
|
50 | // Checks values | |
51 | QVERIFY(scalarSeries->xAxisData()->data() == m_XAxisData); |
|
51 | QVERIFY(scalarSeries->xAxisData()->data() == m_XAxisData); | |
52 | QVERIFY(scalarSeries->valuesData()->data() == m_ValuesData); |
|
52 | QVERIFY(scalarSeries->valuesData()->data() == m_ValuesData); | |
53 | } |
|
53 | } | |
54 | else { |
|
54 | else { | |
55 | QVERIFY(results == nullptr); |
|
55 | QVERIFY(results == nullptr); | |
56 | } |
|
56 | } | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | // Parsing was successfully completed |
|
59 | // Parsing was successfully completed | |
60 | bool m_ParsingOK{false}; |
|
60 | bool m_ParsingOK{false}; | |
61 | // Expected x-axis unit |
|
61 | // Expected x-axis unit | |
62 | Unit m_XAxisUnit{}; |
|
62 | Unit m_XAxisUnit{}; | |
63 | // Expected values unit |
|
63 | // Expected values unit | |
64 | Unit m_ValuesUnit{}; |
|
64 | Unit m_ValuesUnit{}; | |
65 | // Expected x-axis data |
|
65 | // Expected x-axis data | |
66 | QVector<double> m_XAxisData{}; |
|
66 | QVector<double> m_XAxisData{}; | |
67 | // Expected values data |
|
67 | // Expected values data | |
68 | QVector<double> m_ValuesData{}; |
|
68 | QVector<double> m_ValuesData{}; | |
69 | }; |
|
69 | }; | |
70 |
|
70 | |||
71 | } // namespace |
|
71 | } // namespace | |
72 |
|
72 | |||
73 | Q_DECLARE_METATYPE(ExpectedResults) |
|
73 | Q_DECLARE_METATYPE(ExpectedResults) | |
74 |
|
74 | |||
75 | class TestAmdaResultParser : public QObject { |
|
75 | class TestAmdaResultParser : public QObject { | |
76 | Q_OBJECT |
|
76 | Q_OBJECT | |
77 | private slots: |
|
77 | private slots: | |
78 | /// Input test data |
|
78 | /// Input test data | |
79 | /// @sa testTxtJson() |
|
79 | /// @sa testTxtJson() | |
80 | void testReadTxt_data(); |
|
80 | void testReadTxt_data(); | |
81 |
|
81 | |||
82 | /// Tests parsing of a TXT file |
|
82 | /// Tests parsing of a TXT file | |
83 | void testReadTxt(); |
|
83 | void testReadTxt(); | |
84 | }; |
|
84 | }; | |
85 |
|
85 | |||
86 | void TestAmdaResultParser::testReadTxt_data() |
|
86 | void TestAmdaResultParser::testReadTxt_data() | |
87 | { |
|
87 | { | |
88 | // ////////////// // |
|
88 | // ////////////// // | |
89 | // Test structure // |
|
89 | // Test structure // | |
90 | // ////////////// // |
|
90 | // ////////////// // | |
91 |
|
91 | |||
92 | // Name of TXT file to read |
|
92 | // Name of TXT file to read | |
93 | QTest::addColumn<QString>("inputFileName"); |
|
93 | QTest::addColumn<QString>("inputFileName"); | |
94 | // Expected results |
|
94 | // Expected results | |
95 | QTest::addColumn<ExpectedResults>("expectedResults"); |
|
95 | QTest::addColumn<ExpectedResults>("expectedResults"); | |
96 |
|
96 | |||
97 | // ////////// // |
|
97 | // ////////// // | |
98 | // Test cases // |
|
98 | // Test cases // | |
99 | // ////////// // |
|
99 | // ////////// // | |
100 |
|
100 | |||
101 | auto dateTime = [](int year, int month, int day, int hours, int minutes, int seconds) { |
|
101 | auto dateTime = [](int year, int month, int day, int hours, int minutes, int seconds) { | |
102 | return QDateTime{{year, month, day}, {hours, minutes, seconds}}; |
|
102 | return QDateTime{{year, month, day}, {hours, minutes, seconds}}; | |
103 | }; |
|
103 | }; | |
104 |
|
104 | |||
105 | // Valid file |
|
105 | // Valid file | |
106 | QTest::newRow("Valid file") |
|
106 | QTest::newRow("Valid file") | |
107 | << QStringLiteral("ValidScalar1.txt") |
|
107 | << QStringLiteral("ValidScalar1.txt") | |
108 | << ExpectedResults{ |
|
108 | << ExpectedResults{ | |
109 | Unit{QStringLiteral("nT"), true}, Unit{}, |
|
109 | Unit{QStringLiteral("nT"), true}, Unit{}, | |
110 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), |
|
110 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), | |
111 | dateTime(2013, 9, 23, 9, 2, 30), dateTime(2013, 9, 23, 9, 3, 30), |
|
111 | dateTime(2013, 9, 23, 9, 2, 30), dateTime(2013, 9, 23, 9, 3, 30), | |
112 | dateTime(2013, 9, 23, 9, 4, 30), dateTime(2013, 9, 23, 9, 5, 30), |
|
112 | dateTime(2013, 9, 23, 9, 4, 30), dateTime(2013, 9, 23, 9, 5, 30), | |
113 | dateTime(2013, 9, 23, 9, 6, 30), dateTime(2013, 9, 23, 9, 7, 30), |
|
113 | dateTime(2013, 9, 23, 9, 6, 30), dateTime(2013, 9, 23, 9, 7, 30), | |
114 | dateTime(2013, 9, 23, 9, 8, 30), dateTime(2013, 9, 23, 9, 9, 30)}, |
|
114 | dateTime(2013, 9, 23, 9, 8, 30), dateTime(2013, 9, 23, 9, 9, 30)}, | |
115 | QVector<double>{-2.83950, -2.71850, -2.52150, -2.57633, -2.58050, -2.48325, -2.63025, |
|
115 | QVector<double>{-2.83950, -2.71850, -2.52150, -2.57633, -2.58050, -2.48325, -2.63025, | |
116 | -2.55800, -2.43250, -2.42200}}; |
|
116 | -2.55800, -2.43250, -2.42200}}; | |
117 |
|
117 | |||
118 | // Valid files but with some invalid lines (wrong unit, wrong values, etc.) |
|
118 | // Valid files but with some invalid lines (wrong unit, wrong values, etc.) | |
119 | QTest::newRow("No unit file") << QStringLiteral("NoUnit.txt") |
|
119 | QTest::newRow("No unit file") << QStringLiteral("NoUnit.txt") | |
120 | << ExpectedResults{Unit{QStringLiteral(""), true}, Unit{}, |
|
120 | << ExpectedResults{Unit{QStringLiteral(""), true}, Unit{}, | |
121 | QVector<QDateTime>{}, QVector<double>{}}; |
|
121 | QVector<QDateTime>{}, QVector<double>{}}; | |
122 | QTest::newRow("Wrong unit file") |
|
122 | QTest::newRow("Wrong unit file") | |
123 | << QStringLiteral("WrongUnit.txt") |
|
123 | << QStringLiteral("WrongUnit.txt") | |
124 | << ExpectedResults{Unit{QStringLiteral(""), true}, Unit{}, |
|
124 | << ExpectedResults{Unit{QStringLiteral(""), true}, Unit{}, | |
125 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 0, 30), |
|
125 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 0, 30), | |
126 | dateTime(2013, 9, 23, 9, 1, 30), |
|
126 | dateTime(2013, 9, 23, 9, 1, 30), | |
127 | dateTime(2013, 9, 23, 9, 2, 30)}, |
|
127 | dateTime(2013, 9, 23, 9, 2, 30)}, | |
128 | QVector<double>{-2.83950, -2.71850, -2.52150}}; |
|
128 | QVector<double>{-2.83950, -2.71850, -2.52150}}; | |
129 |
|
129 | |||
130 | QTest::newRow("Wrong results file (date of first line is invalid") |
|
130 | QTest::newRow("Wrong results file (date of first line is invalid") | |
131 | << QStringLiteral("WrongDate.txt") |
|
131 | << QStringLiteral("WrongDate.txt") | |
132 | << ExpectedResults{ |
|
132 | << ExpectedResults{ | |
133 | Unit{QStringLiteral("nT"), true}, Unit{}, |
|
133 | Unit{QStringLiteral("nT"), true}, Unit{}, | |
134 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, |
|
134 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, | |
135 | QVector<double>{-2.71850, -2.52150}}; |
|
135 | QVector<double>{-2.71850, -2.52150}}; | |
136 |
|
136 | |||
137 | QTest::newRow("Wrong results file (too many values for first line") |
|
137 | QTest::newRow("Wrong results file (too many values for first line") | |
138 | << QStringLiteral("TooManyValues.txt") |
|
138 | << QStringLiteral("TooManyValues.txt") | |
139 | << ExpectedResults{ |
|
139 | << ExpectedResults{ | |
140 | Unit{QStringLiteral("nT"), true}, Unit{}, |
|
140 | Unit{QStringLiteral("nT"), true}, Unit{}, | |
141 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, |
|
141 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, | |
142 | QVector<double>{-2.71850, -2.52150}}; |
|
142 | QVector<double>{-2.71850, -2.52150}}; | |
143 |
|
143 | |||
144 | QTest::newRow("Wrong results file (value of first line is invalid") |
|
144 | QTest::newRow("Wrong results file (value of first line is invalid") | |
145 | << QStringLiteral("WrongValue.txt") |
|
145 | << QStringLiteral("WrongValue.txt") | |
146 | << ExpectedResults{ |
|
146 | << ExpectedResults{ | |
147 | Unit{QStringLiteral("nT"), true}, Unit{}, |
|
147 | Unit{QStringLiteral("nT"), true}, Unit{}, | |
148 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, |
|
148 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, | |
149 | QVector<double>{-2.71850, -2.52150}}; |
|
149 | QVector<double>{-2.71850, -2.52150}}; | |
150 |
|
150 | |||
151 | QTest::newRow("Wrong results file (value of first line is NaN") |
|
151 | QTest::newRow("Wrong results file (value of first line is NaN") | |
152 | << QStringLiteral("NaNValue.txt") |
|
152 | << QStringLiteral("NaNValue.txt") | |
153 | << ExpectedResults{ |
|
153 | << ExpectedResults{ | |
154 | Unit{QStringLiteral("nT"), true}, Unit{}, |
|
154 | Unit{QStringLiteral("nT"), true}, Unit{}, | |
155 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, |
|
155 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, | |
156 | QVector<double>{-2.71850, -2.52150}}; |
|
156 | QVector<double>{-2.71850, -2.52150}}; | |
157 |
|
157 | |||
158 | // Invalid file |
|
158 | // Invalid files | |
159 |
QTest::newRow("Invalid file (unexisting file)") |
|
159 | QTest::newRow("Invalid file (unexisting file)") | |
160 | << ExpectedResults{}; |
|
160 | << QStringLiteral("UnexistingFile.txt") << ExpectedResults{}; | |
|
161 | ||||
|
162 | QTest::newRow("Invalid file (file not found on server)") | |||
|
163 | << QStringLiteral("FileNotFound.txt") << ExpectedResults{}; | |||
161 | } |
|
164 | } | |
162 |
|
165 | |||
163 | void TestAmdaResultParser::testReadTxt() |
|
166 | void TestAmdaResultParser::testReadTxt() | |
164 | { |
|
167 | { | |
165 | QFETCH(QString, inputFileName); |
|
168 | QFETCH(QString, inputFileName); | |
166 | QFETCH(ExpectedResults, expectedResults); |
|
169 | QFETCH(ExpectedResults, expectedResults); | |
167 |
|
170 | |||
168 | // Parses file |
|
171 | // Parses file | |
169 | auto filePath = inputFilePath(inputFileName); |
|
172 | auto filePath = inputFilePath(inputFileName); | |
170 | auto results = AmdaResultParser::readTxt(filePath); |
|
173 | auto results = AmdaResultParser::readTxt(filePath); | |
171 |
|
174 | |||
172 | // ///////////////// // |
|
175 | // ///////////////// // | |
173 | // Validates results // |
|
176 | // Validates results // | |
174 | // ///////////////// // |
|
177 | // ///////////////// // | |
175 | expectedResults.validate(results); |
|
178 | expectedResults.validate(results); | |
176 | } |
|
179 | } | |
177 |
|
180 | |||
178 | QTEST_MAIN(TestAmdaResultParser) |
|
181 | QTEST_MAIN(TestAmdaResultParser) | |
179 | #include "TestAmdaResultParser.moc" |
|
182 | #include "TestAmdaResultParser.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now