From 195581ceb2d255032acf8e9fc43d841cc68db5e8 2017-07-12 07:47:40 From: Alexandre Leroux Date: 2017-07-12 07:47:40 Subject: [PATCH] Unit tests cases --- diff --git a/plugins/amda/tests-resources/TestAmdaResultParser/NaNValue.txt b/plugins/amda/tests-resources/TestAmdaResultParser/NaNValue.txt new file mode 100644 index 0000000..dab62ce --- /dev/null +++ b/plugins/amda/tests-resources/TestAmdaResultParser/NaNValue.txt @@ -0,0 +1,6 @@ +#Sampling Time : 60 +#Time Format : YYYY-MM-DDThh:mm:ss.mls +#imf(0) - Type : Local Parameter @ CDPP/AMDA - Name : bx_gse - Units : nT - Size : 1 - Frame : GSE - Mission : ACE - Instrument : MFI - Dataset : mfi_final-prelim +2013-09-23T09:00:30.000 NaN +2013-09-23T09:01:30.000 -2.71850 +2013-09-23T09:02:30.000 -2.52150 \ No newline at end of file diff --git a/plugins/amda/tests-resources/TestAmdaResultParser/NoUnit.txt b/plugins/amda/tests-resources/TestAmdaResultParser/NoUnit.txt new file mode 100644 index 0000000..648be9f --- /dev/null +++ b/plugins/amda/tests-resources/TestAmdaResultParser/NoUnit.txt @@ -0,0 +1,2 @@ +#Sampling Time : 60 +#Time Format : YYYY-MM-DDThh:mm:ss.mls \ No newline at end of file diff --git a/plugins/amda/tests-resources/TestAmdaResultParser/TooManyValues.txt b/plugins/amda/tests-resources/TestAmdaResultParser/TooManyValues.txt new file mode 100644 index 0000000..c58e9d4 --- /dev/null +++ b/plugins/amda/tests-resources/TestAmdaResultParser/TooManyValues.txt @@ -0,0 +1,6 @@ +#Sampling Time : 60 +#Time Format : YYYY-MM-DDThh:mm:ss.mls +#imf(0) - Type : Local Parameter @ CDPP/AMDA - Name : bx_gse - Units : nT - Size : 1 - Frame : GSE - Mission : ACE - Instrument : MFI - Dataset : mfi_final-prelim +2013-09-23T09:00:30.000 -2.83950 1.05141 3.01547 +2013-09-23T09:01:30.000 -2.71850 +2013-09-23T09:02:30.000 -2.52150 \ No newline at end of file diff --git a/plugins/amda/tests-resources/TestAmdaResultParser/ValidScalar1.txt b/plugins/amda/tests-resources/TestAmdaResultParser/ValidScalar1.txt new file mode 100644 index 0000000..41b585a --- /dev/null +++ b/plugins/amda/tests-resources/TestAmdaResultParser/ValidScalar1.txt @@ -0,0 +1,13 @@ +#Sampling Time : 60 +#Time Format : YYYY-MM-DDThh:mm:ss.mls +#imf(0) - Type : Local Parameter @ CDPP/AMDA - Name : bx_gse - Units : nT - Size : 1 - Frame : GSE - Mission : ACE - Instrument : MFI - Dataset : mfi_final-prelim +2013-09-23T09:00:30.000 -2.83950 +2013-09-23T09:01:30.000 -2.71850 +2013-09-23T09:02:30.000 -2.52150 +2013-09-23T09:03:30.000 -2.57633 +2013-09-23T09:04:30.000 -2.58050 +2013-09-23T09:05:30.000 -2.48325 +2013-09-23T09:06:30.000 -2.63025 +2013-09-23T09:07:30.000 -2.55800 +2013-09-23T09:08:30.000 -2.43250 +2013-09-23T09:09:30.000 -2.42200 \ No newline at end of file diff --git a/plugins/amda/tests-resources/TestAmdaResultParser/WrongDate.txt b/plugins/amda/tests-resources/TestAmdaResultParser/WrongDate.txt new file mode 100644 index 0000000..7dc5266 --- /dev/null +++ b/plugins/amda/tests-resources/TestAmdaResultParser/WrongDate.txt @@ -0,0 +1,6 @@ +#Sampling Time : 60 +#Time Format : YYYY-MM-DDThh:mm:ss.mls +#imf(0) - Type : Local Parameter @ CDPP/AMDA - Name : bx_gse - Units : nT - Size : 1 - Frame : GSE - Mission : ACE - Instrument : MFI - Dataset : mfi_final-prelim +23/09/2013 07:50:30 -2.83950 +2013-09-23T09:01:30.000 -2.71850 +2013-09-23T09:02:30.000 -2.52150 \ No newline at end of file diff --git a/plugins/amda/tests-resources/TestAmdaResultParser/WrongUnit.txt b/plugins/amda/tests-resources/TestAmdaResultParser/WrongUnit.txt new file mode 100644 index 0000000..5a62942 --- /dev/null +++ b/plugins/amda/tests-resources/TestAmdaResultParser/WrongUnit.txt @@ -0,0 +1,6 @@ +#Sampling Time : 60 +#Time Format : YYYY-MM-DDThh:mm:ss.mls +#Wrong unit comment +2013-09-23T09:00:30.000 -2.83950 +2013-09-23T09:01:30.000 -2.71850 +2013-09-23T09:02:30.000 -2.52150 \ No newline at end of file diff --git a/plugins/amda/tests-resources/TestAmdaResultParser/WrongValue.txt b/plugins/amda/tests-resources/TestAmdaResultParser/WrongValue.txt new file mode 100644 index 0000000..578a209 --- /dev/null +++ b/plugins/amda/tests-resources/TestAmdaResultParser/WrongValue.txt @@ -0,0 +1,6 @@ +#Sampling Time : 60 +#Time Format : YYYY-MM-DDThh:mm:ss.mls +#imf(0) - Type : Local Parameter @ CDPP/AMDA - Name : bx_gse - Units : nT - Size : 1 - Frame : GSE - Mission : ACE - Instrument : MFI - Dataset : mfi_final-prelim +2013-09-23T09:00:30.000 abc +2013-09-23T09:01:30.000 -2.71850 +2013-09-23T09:02:30.000 -2.52150 \ No newline at end of file diff --git a/plugins/amda/tests/TestAmdaResultParser.cpp b/plugins/amda/tests/TestAmdaResultParser.cpp index 9f76814..2d381aa 100644 --- a/plugins/amda/tests/TestAmdaResultParser.cpp +++ b/plugins/amda/tests/TestAmdaResultParser.cpp @@ -1,5 +1,7 @@ #include "AmdaResultParser.h" +#include + #include #include @@ -92,6 +94,70 @@ void TestAmdaResultParser::testReadTxt_data() // Expected results QTest::addColumn("expectedResults"); + // ////////// // + // Test cases // + // ////////// // + + auto dateTime = [](int year, int month, int day, int hours, int minutes, int seconds) { + return QDateTime{{year, month, day}, {hours, minutes, seconds}}; + }; + + // Valid file + QTest::newRow("Valid file") + << QStringLiteral("ValidScalar1.txt") + << ExpectedResults{ + Unit{QStringLiteral("nT"), true}, Unit{}, + QVector{dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), + dateTime(2013, 9, 23, 9, 2, 30), dateTime(2013, 9, 23, 9, 3, 30), + dateTime(2013, 9, 23, 9, 4, 30), dateTime(2013, 9, 23, 9, 5, 30), + dateTime(2013, 9, 23, 9, 6, 30), dateTime(2013, 9, 23, 9, 7, 30), + dateTime(2013, 9, 23, 9, 8, 30), dateTime(2013, 9, 23, 9, 9, 30)}, + QVector{-2.83950, -2.71850, -2.52150, -2.57633, -2.58050, -2.48325, -2.63025, + -2.55800, -2.43250, -2.42200}}; + + // Valid files but with some invalid lines (wrong unit, wrong values, etc.) + QTest::newRow("No unit file") << QStringLiteral("NoUnit.txt") + << ExpectedResults{Unit{QStringLiteral(""), true}, Unit{}, + QVector{}, QVector{}}; + QTest::newRow("Wrong unit file") + << QStringLiteral("WrongUnit.txt") + << ExpectedResults{Unit{QStringLiteral(""), true}, Unit{}, + QVector{dateTime(2013, 9, 23, 9, 0, 30), + dateTime(2013, 9, 23, 9, 1, 30), + dateTime(2013, 9, 23, 9, 2, 30)}, + QVector{-2.83950, -2.71850, -2.52150}}; + + QTest::newRow("Wrong results file (date of first line is invalid") + << QStringLiteral("WrongDate.txt") + << ExpectedResults{ + Unit{QStringLiteral("nT"), true}, Unit{}, + QVector{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, + QVector{-2.71850, -2.52150}}; + + QTest::newRow("Wrong results file (too many values for first line") + << QStringLiteral("TooManyValues.txt") + << ExpectedResults{ + Unit{QStringLiteral("nT"), true}, Unit{}, + QVector{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, + QVector{-2.71850, -2.52150}}; + + QTest::newRow("Wrong results file (value of first line is invalid") + << QStringLiteral("WrongValue.txt") + << ExpectedResults{ + Unit{QStringLiteral("nT"), true}, Unit{}, + QVector{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, + QVector{-2.71850, -2.52150}}; + + QTest::newRow("Wrong results file (value of first line is NaN") + << QStringLiteral("NaNValue.txt") + << ExpectedResults{ + Unit{QStringLiteral("nT"), true}, Unit{}, + QVector{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, + QVector{-2.71850, -2.52150}}; + + // Invalid file + QTest::newRow("Invalid file (unexisting file)") + << QStringLiteral("UnexistingFile.txt") << ExpectedResults{}; } void TestAmdaResultParser::testReadTxt()