Mercurial > hg > svcore
comparison data/fileio/test/CSVStreamWriterTest.h @ 1440:04caefd35391 streaming-csv-writer
Add failing test for non zero selection start
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Tue, 17 Apr 2018 10:03:50 +0100 |
parents | 09c2ba31a711 |
children | 0a743cd7b83d |
comparison
equal
deleted
inserted
replaced
1439:9d4d4de3dced | 1440:04caefd35391 |
---|---|
35 : m_isCancelled(isCancelled) {} | 35 : m_isCancelled(isCancelled) {} |
36 bool isDefinite() const override { return true; } | 36 bool isDefinite() const override { return true; } |
37 void setDefinite(bool) override {} | 37 void setDefinite(bool) override {} |
38 bool wasCancelled() const override { return m_isCancelled(); } | 38 bool wasCancelled() const override { return m_isCancelled(); } |
39 void setMessage(QString) override {} | 39 void setMessage(QString) override {} |
40 void setProgress(int) override { ++m_calls; } | 40 void setProgress(int p) override |
41 { | |
42 ++m_calls; | |
43 m_percentageLog.push_back(p); | |
44 } | |
45 | |
41 size_t getCallCount() const { return m_calls; } | 46 size_t getCallCount() const { return m_calls; } |
47 std::vector<int> getPercentageLog() const { return m_percentageLog; } | |
42 void reset() { m_calls = 0; } | 48 void reset() { m_calls = 0; } |
43 private: | 49 private: |
44 size_t m_calls = 0; | 50 size_t m_calls = 0; |
45 std::function<bool()> m_isCancelled; | 51 std::function<bool()> m_isCancelled; |
52 std::vector<int> m_percentageLog; | |
46 }; | 53 }; |
47 } // namespace | 54 } // namespace |
48 | 55 |
49 class CSVStreamWriterTest : public QObject | 56 class CSVStreamWriterTest : public QObject |
50 { | 57 { |
167 4 | 174 4 |
168 ); | 175 ); |
169 QVERIFY( cancelMidway.getCallCount() == 3 ); | 176 QVERIFY( cancelMidway.getCallCount() == 3 ); |
170 QVERIFY( cancelledMidway == false ); | 177 QVERIFY( cancelledMidway == false ); |
171 } | 178 } |
179 | |
180 void zeroStartTimeReportsPercentageCorrectly() | |
181 { | |
182 MockWaveModel mwm({ DC, DC }, 16, 4); | |
183 StubReporter reporter { []() -> bool { return false; } }; | |
184 std::ostringstream oss; | |
185 const auto succeeded = CSVStreamWriter::writeInChunks( | |
186 oss, | |
187 mwm, | |
188 &reporter, | |
189 ",", | |
190 DataExportDefaults, | |
191 4 | |
192 ); | |
193 QVERIFY( succeeded == true ); | |
194 QVERIFY( reporter.getCallCount() == 6 ); | |
195 const std::vector<int> expectedCallLog { | |
196 16, | |
197 33, | |
198 50, | |
199 66, | |
200 83, | |
201 100 | |
202 }; | |
203 QVERIFY( reporter.getPercentageLog() == expectedCallLog ); | |
204 QVERIFY( oss.str() == getExpectedString() ); | |
205 } | |
206 | |
207 void nonZeroStartTimeReportsPercentageCorrectly() | |
208 { | |
209 MockWaveModel mwm({ DC, DC }, 16, 4); | |
210 StubReporter reporter { []() -> bool { return false; } }; | |
211 std::ostringstream oss; | |
212 const auto writeSubSection = CSVStreamWriter::writeInChunks( | |
213 oss, | |
214 mwm, | |
215 {4, 20}, | |
216 &reporter, | |
217 ",", | |
218 DataExportDefaults, | |
219 4 | |
220 ); | |
221 QVERIFY( reporter.getCallCount() == 4 ); | |
222 const std::vector<int> expectedCallLog { | |
223 25, | |
224 50, | |
225 75, | |
226 100 | |
227 }; | |
228 QVERIFY( reporter.getPercentageLog() == expectedCallLog ); | |
229 QVERIFY( writeSubSection == true ); | |
230 const std::string expectedOutput { | |
231 "4,1,1\n" | |
232 "5,1,1\n" | |
233 "6,1,1\n" | |
234 "7,1,1\n" | |
235 "8,1,1\n" | |
236 "9,1,1\n" | |
237 "10,1,1\n" | |
238 "11,1,1\n" | |
239 "12,1,1\n" | |
240 "13,1,1\n" | |
241 "14,1,1\n" | |
242 "15,1,1\n" | |
243 "16,1,1\n" | |
244 "17,1,1\n" | |
245 "18,1,1\n" | |
246 "19,1,1" | |
247 }; | |
248 QVERIFY( oss.str() == expectedOutput ); | |
249 } | |
172 }; | 250 }; |
173 | 251 |
174 #endif | 252 #endif |