diff options
| author | 2021-12-17 07:06:30 -0500 | |
|---|---|---|
| committer | 2021-12-17 07:06:30 -0500 | |
| commit | 1fdc150116cad39aae5c5da407c3312b47a59e3a (patch) | |
| tree | 123c79a4d7ad2d45781ba03ce939f7539fb428d8 /SQLiteStudio3/Tests/DsvFormatsTest | |
| parent | feda8a7db8d1d7c5439aa8f8feef7cc0dd2b59a0 (diff) | |
New upstream version 3.3.3+dfsg1.upstream/3.3.3+dfsg1
Diffstat (limited to 'SQLiteStudio3/Tests/DsvFormatsTest')
| -rw-r--r-- | SQLiteStudio3/Tests/DsvFormatsTest/tst_dsvformatstesttest.cpp | 99 |
1 files changed, 98 insertions, 1 deletions
diff --git a/SQLiteStudio3/Tests/DsvFormatsTest/tst_dsvformatstesttest.cpp b/SQLiteStudio3/Tests/DsvFormatsTest/tst_dsvformatstesttest.cpp index 903e6f6..3823c35 100644 --- a/SQLiteStudio3/Tests/DsvFormatsTest/tst_dsvformatstesttest.cpp +++ b/SQLiteStudio3/Tests/DsvFormatsTest/tst_dsvformatstesttest.cpp @@ -2,6 +2,7 @@ #include <QList> #include <QStringList> #include <QtTest> +#include <QTextStream> #include "tsvserializer.h" #include "csvserializer.h" @@ -27,6 +28,12 @@ private: void testTsv1(); void testTsv2(); void testCsv1(); + void testCsv2Unix(); + void testCsv2Win(); + void testCsv2Mac(); + void testCsv3Unix(); + void testCsv3Win(); + void testCsv3Mac(); void testCsvPerformance(); }; @@ -106,6 +113,96 @@ void DsvFormatsTestTest::testCsv1() QVERIFY(result.first().size() == 2); } +void DsvFormatsTestTest::testCsv2Unix() +{ + QString data = "v1,v2\nv3,v4\n"; + QList<QStringList> result = CsvSerializer::deserialize(data, CsvFormat::DEFAULT); + QCOMPARE(result.size(), 2); + QCOMPARE(result[0].size(), 2); + QCOMPARE(result[0][0], "v1"); + QCOMPARE(result[0][1], "v2"); + QCOMPARE(result[1].size(), 2); + QCOMPARE(result[1][0], "v3"); + QCOMPARE(result[1][1], "v4"); +} + +void DsvFormatsTestTest::testCsv2Win() +{ + QString data = "v1,v2\r\nv3,v4\r\n"; + QList<QStringList> result = CsvSerializer::deserialize(data, CsvFormat::DEFAULT); + QCOMPARE(result.size(), 2); + QCOMPARE(result[0].size(), 2); + QCOMPARE(result[0][0], "v1"); + QCOMPARE(result[0][1], "v2"); + QCOMPARE(result[1].size(), 2); + QCOMPARE(result[1][0], "v3"); + QCOMPARE(result[1][1], "v4"); +} + +void DsvFormatsTestTest::testCsv2Mac() +{ + QString data = "v1,v2\rv3,v4\r"; + QList<QStringList> result = CsvSerializer::deserialize(data, CsvFormat::DEFAULT); + QCOMPARE(result.size(), 2); + QCOMPARE(result[0].size(), 2); + QCOMPARE(result[0][0], "v1"); + QCOMPARE(result[0][1], "v2"); + QCOMPARE(result[1].size(), 2); + QCOMPARE(result[1][0], "v3"); + QCOMPARE(result[1][1], "v4"); +} + +void DsvFormatsTestTest::testCsv3Unix() +{ + QString data = "v1,v2\nv3,v4\n"; + QTextStream stream(&data); + QList<QStringList> result; + result << CsvSerializer::deserializeOneEntry(stream, CsvFormat::DEFAULT); + result << CsvSerializer::deserializeOneEntry(stream, CsvFormat::DEFAULT); + + QCOMPARE(result.size(), 2); + QCOMPARE(result[0].size(), 2); + QCOMPARE(result[0][0], "v1"); + QCOMPARE(result[0][1], "v2"); + QCOMPARE(result[1].size(), 2); + QCOMPARE(result[1][0], "v3"); + QCOMPARE(result[1][1], "v4"); +} + +void DsvFormatsTestTest::testCsv3Win() +{ + QString data = "v1,v2\r\nv3,v4\r\n"; + QTextStream stream(&data); + QList<QStringList> result; + result << CsvSerializer::deserializeOneEntry(stream, CsvFormat::DEFAULT); + result << CsvSerializer::deserializeOneEntry(stream, CsvFormat::DEFAULT); + + QCOMPARE(result.size(), 2); + QCOMPARE(result[0].size(), 2); + QCOMPARE(result[0][0], "v1"); + QCOMPARE(result[0][1], "v2"); + QCOMPARE(result[1].size(), 2); + QCOMPARE(result[1][0], "v3"); + QCOMPARE(result[1][1], "v4"); +} + +void DsvFormatsTestTest::testCsv3Mac() +{ + QString data = "v1,v2\rv3,v4\r"; + QTextStream stream(&data); + QList<QStringList> result; + result << CsvSerializer::deserializeOneEntry(stream, CsvFormat::DEFAULT); + result << CsvSerializer::deserializeOneEntry(stream, CsvFormat::DEFAULT); + + QCOMPARE(result.size(), 2); + QCOMPARE(result[0].size(), 2); + QCOMPARE(result[0][0], "v1"); + QCOMPARE(result[0][1], "v2"); + QCOMPARE(result[1].size(), 2); + QCOMPARE(result[1][0], "v3"); + QCOMPARE(result[1][1], "v4"); +} + void DsvFormatsTestTest::testCsvPerformance() { QString input; @@ -118,7 +215,7 @@ void DsvFormatsTestTest::testCsvPerformance() theFile.seek(0); QTextStream stream(&theFile); - QTime timer; + QElapsedTimer timer; timer.start(); QList<QStringList> result = CsvSerializer::deserialize(stream, CsvFormat::DEFAULT); int time = timer.elapsed(); |
