changeset 1446:0a743cd7b83d streaming-csv-writer

Write failing test for multi-selection output - line break issue between regions.
author Lucas Thompson <dev@lucas.im>
date Tue, 17 Apr 2018 10:03:50 +0100
parents 4437209348ef
children 5bd240517c1a
files data/fileio/test/CSVStreamWriterTest.h
diffstat 1 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/test/CSVStreamWriterTest.h	Tue Apr 17 10:03:50 2018 +0100
+++ b/data/fileio/test/CSVStreamWriterTest.h	Tue Apr 17 10:03:50 2018 +0100
@@ -23,6 +23,7 @@
 
 #include "base/ProgressReporter.h"
 #include "base/DataExportOptions.h"
+#include "base/Selection.h"
 #include "../CSVStreamWriter.h"
 #include "../../model/test/MockWaveModel.h"
 
@@ -247,6 +248,40 @@
         };
         QVERIFY( oss.str() == expectedOutput );
     }
+
+    void multipleSelectionOutput()
+    {
+        MockWaveModel mwm({ DC, DC }, 16, 4);
+        StubReporter reporter { []() -> bool { return false; } };
+        std::ostringstream oss;
+        MultiSelection regions;
+        regions.addSelection({0, 2});
+        regions.addSelection({4, 6});
+        regions.addSelection({16, 18});
+        const std::string expectedOutput {
+          "0,0,0\n"
+          "1,0,0\n"
+          "4,1,1\n"
+          "5,1,1\n"
+          "16,1,1\n"
+          "17,1,1"
+        };
+        const auto wroteMultiSection = CSVStreamWriter::writeInChunks(
+            oss,
+            mwm,
+            regions,
+            &reporter,
+            ",",
+            DataExportDefaults,
+            2
+        );
+        QVERIFY( wroteMultiSection == true );
+        QVERIFY( reporter.getCallCount() == 3 );
+        const std::vector<int> expectedCallLog { 33, 66, 100 };
+        QVERIFY( reporter.getPercentageLog() == expectedCallLog );
+        qDebug("%s", oss.str().c_str());
+        QVERIFY( oss.str() == expectedOutput );
+    }
 };
 
 #endif
\ No newline at end of file