Chris@1867
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@1867
|
2
|
Chris@1867
|
3 /*
|
Chris@1867
|
4 Sonic Visualiser
|
Chris@1867
|
5 An audio file viewer and annotation editor.
|
Chris@1867
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@1867
|
7
|
Chris@1867
|
8 This program is free software; you can redistribute it and/or
|
Chris@1867
|
9 modify it under the terms of the GNU General Public License as
|
Chris@1867
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@1867
|
11 License, or (at your option) any later version. See the file
|
Chris@1867
|
12 COPYING included with this distribution for more information.
|
Chris@1867
|
13 */
|
Chris@1867
|
14
|
Chris@1867
|
15 #ifndef TEST_CSV_READER_H
|
Chris@1867
|
16 #define TEST_CSV_READER_H
|
Chris@1867
|
17
|
Chris@1867
|
18 #include "../CSVFileReader.h"
|
Chris@1867
|
19
|
Chris@1867
|
20 #include "data/model/SparseOneDimensionalModel.h"
|
Chris@1867
|
21 #include "data/model/SparseTimeValueModel.h"
|
Chris@1867
|
22 #include "data/model/RegionModel.h"
|
Chris@1867
|
23 #include "data/model/EditableDenseThreeDimensionalModel.h"
|
Chris@1867
|
24
|
Chris@1867
|
25 #include "base/Debug.h"
|
Chris@1867
|
26
|
Chris@1867
|
27 #include <cmath>
|
Chris@1867
|
28
|
Chris@1867
|
29 #include <QObject>
|
Chris@1867
|
30 #include <QtTest>
|
Chris@1867
|
31 #include <QDir>
|
Chris@1867
|
32
|
Chris@1867
|
33 #include <iostream>
|
Chris@1867
|
34
|
Chris@1867
|
35 using namespace std;
|
Chris@1867
|
36
|
Chris@1867
|
37 class CSVReaderTest : public QObject
|
Chris@1867
|
38 {
|
Chris@1867
|
39 Q_OBJECT
|
Chris@1867
|
40
|
Chris@1867
|
41 private:
|
Chris@1867
|
42 QDir csvDir;
|
Chris@1867
|
43 sv_samplerate_t mainRate;
|
Chris@1867
|
44
|
Chris@1867
|
45 public:
|
Chris@1867
|
46 CSVReaderTest(QString base) {
|
Chris@1867
|
47 if (base == "") {
|
Chris@1867
|
48 base = "svcore/data/fileio/test";
|
Chris@1867
|
49 }
|
Chris@1867
|
50 csvDir = QDir(base + "/csv");
|
Chris@1867
|
51 mainRate = 44100;
|
Chris@1867
|
52 }
|
Chris@1867
|
53
|
Chris@1867
|
54 private:
|
Chris@1867
|
55 void loadFrom(QString filename, Model *&model) {
|
Chris@1867
|
56 QString path(csvDir.filePath(filename));
|
Chris@1867
|
57 CSVFormat f;
|
Chris@1867
|
58 f.guessFormatFor(path);
|
Chris@1867
|
59 CSVFileReader reader(path, f, mainRate);
|
Chris@1867
|
60 model = reader.load();
|
Chris@1867
|
61 QVERIFY(model);
|
Chris@1867
|
62 QVERIFY(reader.isOK());
|
Chris@1867
|
63 QCOMPARE(reader.getError(), QString());
|
Chris@1867
|
64 }
|
Chris@1867
|
65
|
Chris@1867
|
66 private slots:
|
Chris@1867
|
67 void init() {
|
Chris@1867
|
68 if (!csvDir.exists()) {
|
Chris@1867
|
69 SVCERR << "ERROR: CSV test file directory \"" << csvDir.absolutePath() << "\" does not exist" << endl;
|
Chris@1867
|
70 QVERIFY2(csvDir.exists(), "CSV test file directory not found");
|
Chris@1867
|
71 }
|
Chris@1867
|
72 }
|
Chris@1867
|
73
|
Chris@1867
|
74 void modelType1DSamples() {
|
Chris@1867
|
75 Model *model = nullptr;
|
Chris@1867
|
76 loadFrom("model-type-1d-samples.csv", model);
|
Chris@1867
|
77 auto actual = qobject_cast<SparseOneDimensionalModel *>(model);
|
Chris@1867
|
78 QVERIFY(actual);
|
Chris@1867
|
79 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
80 //!!! + the actual contents
|
Chris@1867
|
81 delete model;
|
Chris@1867
|
82 }
|
Chris@1867
|
83
|
Chris@1872
|
84 void modelType1DSamplesWithHeader() {
|
Chris@1872
|
85 Model *model = nullptr;
|
Chris@1872
|
86 loadFrom("model-type-1d-samples-header.csv", model);
|
Chris@1872
|
87 auto actual = qobject_cast<SparseOneDimensionalModel *>(model);
|
Chris@1872
|
88 QVERIFY(actual);
|
Chris@1872
|
89 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1872
|
90 //!!! + the actual contents
|
Chris@1872
|
91 delete model;
|
Chris@1872
|
92 }
|
Chris@1872
|
93
|
Chris@1867
|
94 void modelType1DSeconds() {
|
Chris@1867
|
95 Model *model = nullptr;
|
Chris@1867
|
96 loadFrom("model-type-1d-seconds.csv", model);
|
Chris@1867
|
97 auto actual = qobject_cast<SparseOneDimensionalModel *>(model);
|
Chris@1867
|
98 QVERIFY(actual);
|
Chris@1867
|
99 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
100 delete model;
|
Chris@1867
|
101 }
|
Chris@1867
|
102
|
Chris@1872
|
103 void modelType1DSecondsWithHeader() {
|
Chris@1872
|
104 Model *model = nullptr;
|
Chris@1872
|
105 loadFrom("model-type-1d-seconds-header.csv", model);
|
Chris@1872
|
106 auto actual = qobject_cast<SparseOneDimensionalModel *>(model);
|
Chris@1872
|
107 QVERIFY(actual);
|
Chris@1872
|
108 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1872
|
109 delete model;
|
Chris@1872
|
110 }
|
Chris@1872
|
111
|
Chris@1867
|
112 void modelType2DDurationSamples() {
|
Chris@1867
|
113 Model *model = nullptr;
|
Chris@1867
|
114 loadFrom("model-type-2d-duration-samples.csv", model);
|
Chris@1867
|
115 auto actual = qobject_cast<RegionModel *>(model);
|
Chris@1867
|
116 QVERIFY(actual);
|
Chris@1867
|
117 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
118 delete model;
|
Chris@1867
|
119 }
|
Chris@1872
|
120
|
Chris@1872
|
121 void modelType2DDurationSamplesWithHeader() {
|
Chris@1872
|
122 Model *model = nullptr;
|
Chris@1872
|
123 loadFrom("model-type-2d-duration-samples-header.csv", model);
|
Chris@1872
|
124 auto actual = qobject_cast<RegionModel *>(model);
|
Chris@1872
|
125 QVERIFY(actual);
|
Chris@1872
|
126 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1872
|
127 delete model;
|
Chris@1872
|
128 }
|
Chris@1867
|
129
|
Chris@1867
|
130 void modelType2DDurationSeconds() {
|
Chris@1867
|
131 Model *model = nullptr;
|
Chris@1867
|
132 loadFrom("model-type-2d-duration-seconds.csv", model);
|
Chris@1867
|
133 auto actual = qobject_cast<RegionModel *>(model);
|
Chris@1867
|
134 QVERIFY(actual);
|
Chris@1867
|
135 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
136 delete model;
|
Chris@1867
|
137 }
|
Chris@1867
|
138
|
Chris@1872
|
139 void modelType2DDurationSecondsWithHeader() {
|
Chris@1872
|
140 Model *model = nullptr;
|
Chris@1872
|
141 loadFrom("model-type-2d-duration-seconds-header.csv", model);
|
Chris@1872
|
142 auto actual = qobject_cast<RegionModel *>(model);
|
Chris@1872
|
143 QVERIFY(actual);
|
Chris@1872
|
144 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1872
|
145 delete model;
|
Chris@1872
|
146 }
|
Chris@1872
|
147
|
Chris@1867
|
148 void badNegativeDuration() {
|
Chris@1867
|
149 Model *model = nullptr;
|
Chris@1867
|
150 loadFrom("bad-negative-duration.csv", model);
|
Chris@1867
|
151 auto actual = qobject_cast<RegionModel *>(model);
|
Chris@1867
|
152 QVERIFY(actual);
|
Chris@1867
|
153 //!!! + check duration has been corrected
|
Chris@1867
|
154 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
155 delete model;
|
Chris@1867
|
156 }
|
Chris@1867
|
157
|
Chris@1867
|
158 void modelType2DEndTimeSamples() {
|
Chris@1867
|
159 Model *model = nullptr;
|
Chris@1867
|
160 loadFrom("model-type-2d-endtime-samples.csv", model);
|
Chris@1867
|
161 auto actual = qobject_cast<RegionModel *>(model);
|
Chris@1867
|
162 QVERIFY(actual);
|
Chris@1867
|
163 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
164 delete model;
|
Chris@1867
|
165 }
|
Chris@1867
|
166
|
Chris@1872
|
167 void modelType2DEndTimeSamplesWithHeader() {
|
Chris@1872
|
168 Model *model = nullptr;
|
Chris@1872
|
169 loadFrom("model-type-2d-endtime-samples-header.csv", model);
|
Chris@1872
|
170 auto actual = qobject_cast<RegionModel *>(model);
|
Chris@1872
|
171 QVERIFY(actual);
|
Chris@1872
|
172 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1872
|
173 delete model;
|
Chris@1872
|
174 }
|
Chris@1872
|
175
|
Chris@1867
|
176 void modelType2DEndTimeSeconds() {
|
Chris@1867
|
177 Model *model = nullptr;
|
Chris@1867
|
178 loadFrom("model-type-2d-endtime-seconds.csv", model);
|
Chris@1867
|
179 auto actual = qobject_cast<RegionModel *>(model);
|
Chris@1867
|
180 QVERIFY(actual);
|
Chris@1867
|
181 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
182 delete model;
|
Chris@1867
|
183 }
|
Chris@1867
|
184
|
Chris@1872
|
185 void modelType2DEndTimeSecondsWithHeader() {
|
Chris@1872
|
186 Model *model = nullptr;
|
Chris@1872
|
187 loadFrom("model-type-2d-endtime-seconds-header.csv", model);
|
Chris@1872
|
188 auto actual = qobject_cast<RegionModel *>(model);
|
Chris@1872
|
189 QVERIFY(actual);
|
Chris@1872
|
190 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1872
|
191 delete model;
|
Chris@1872
|
192 }
|
Chris@1872
|
193
|
Chris@1867
|
194 void modelType2DImplicit() {
|
Chris@1867
|
195 Model *model = nullptr;
|
Chris@1867
|
196 loadFrom("model-type-2d-implicit.csv", model);
|
Chris@1867
|
197 auto actual = qobject_cast<SparseTimeValueModel *>(model);
|
Chris@1867
|
198 QVERIFY(actual);
|
Chris@1867
|
199 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
200 delete model;
|
Chris@1867
|
201 }
|
Chris@1867
|
202
|
Chris@1872
|
203 void modelType2DImplicitWithHeader() {
|
Chris@1872
|
204 Model *model = nullptr;
|
Chris@1872
|
205 loadFrom("model-type-2d-implicit-header.csv", model);
|
Chris@1872
|
206 auto actual = qobject_cast<SparseTimeValueModel *>(model);
|
Chris@1872
|
207 QVERIFY(actual);
|
Chris@1872
|
208 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1872
|
209 delete model;
|
Chris@1872
|
210 }
|
Chris@1872
|
211
|
Chris@1867
|
212 void modelType2DSamples() {
|
Chris@1867
|
213 Model *model = nullptr;
|
Chris@1867
|
214 loadFrom("model-type-2d-samples.csv", model);
|
Chris@1867
|
215 auto actual = qobject_cast<SparseTimeValueModel *>(model);
|
Chris@1867
|
216 QVERIFY(actual);
|
Chris@1867
|
217 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
218 delete model;
|
Chris@1867
|
219 }
|
Chris@1867
|
220
|
Chris@1872
|
221 void modelType2DSamplesWithHeader() {
|
Chris@1872
|
222 Model *model = nullptr;
|
Chris@1872
|
223 loadFrom("model-type-2d-samples-header.csv", model);
|
Chris@1872
|
224 auto actual = qobject_cast<SparseTimeValueModel *>(model);
|
Chris@1872
|
225 QVERIFY(actual);
|
Chris@1872
|
226 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1872
|
227 delete model;
|
Chris@1872
|
228 }
|
Chris@1872
|
229
|
Chris@1867
|
230 void modelType2DSeconds() {
|
Chris@1867
|
231 Model *model = nullptr;
|
Chris@1867
|
232 loadFrom("model-type-2d-seconds.csv", model);
|
Chris@1867
|
233 auto actual = qobject_cast<SparseTimeValueModel *>(model);
|
Chris@1867
|
234 QVERIFY(actual);
|
Chris@1867
|
235 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
236 delete model;
|
Chris@1867
|
237 }
|
Chris@1867
|
238
|
Chris@1872
|
239 void modelType2DSecondsWithHeader() {
|
Chris@1872
|
240 Model *model = nullptr;
|
Chris@1872
|
241 loadFrom("model-type-2d-seconds-header.csv", model);
|
Chris@1872
|
242 auto actual = qobject_cast<SparseTimeValueModel *>(model);
|
Chris@1872
|
243 QVERIFY(actual);
|
Chris@1872
|
244 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1872
|
245 delete model;
|
Chris@1872
|
246 }
|
Chris@1872
|
247
|
Chris@1867
|
248 void modelType3DImplicit() {
|
Chris@1867
|
249 Model *model = nullptr;
|
Chris@1867
|
250 loadFrom("model-type-3d-implicit.csv", model);
|
Chris@1867
|
251 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
|
Chris@1867
|
252 QVERIFY(actual);
|
Chris@1867
|
253 QCOMPARE(actual->getWidth(), 6);
|
Chris@1867
|
254 QCOMPARE(actual->getHeight(), 6);
|
Chris@1867
|
255 delete model;
|
Chris@1867
|
256 }
|
Chris@1867
|
257
|
Chris@1872
|
258 void modelType3DImplicitWithHeader() {
|
Chris@1872
|
259 Model *model = nullptr;
|
Chris@1872
|
260 loadFrom("model-type-3d-implicit-header.csv", model);
|
Chris@1872
|
261 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
|
Chris@1872
|
262 QVERIFY(actual);
|
Chris@1872
|
263 QCOMPARE(actual->getWidth(), 6);
|
Chris@1872
|
264 QCOMPARE(actual->getHeight(), 6);
|
Chris@1872
|
265 delete model;
|
Chris@1872
|
266 }
|
Chris@1872
|
267
|
Chris@1867
|
268 void modelType3DSamples() {
|
Chris@1867
|
269 Model *model = nullptr;
|
Chris@1867
|
270 loadFrom("model-type-3d-samples.csv", model);
|
Chris@1867
|
271 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
|
Chris@1867
|
272 QVERIFY(actual);
|
Chris@1867
|
273 QCOMPARE(actual->getWidth(), 6);
|
Chris@1867
|
274 QCOMPARE(actual->getHeight(), 6);
|
Chris@1867
|
275 delete model;
|
Chris@1867
|
276 }
|
Chris@1867
|
277
|
Chris@1872
|
278 void modelType3DSamplesWithHeader() {
|
Chris@1872
|
279 Model *model = nullptr;
|
Chris@1872
|
280 loadFrom("model-type-3d-samples-header.csv", model);
|
Chris@1872
|
281 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
|
Chris@1872
|
282 QVERIFY(actual);
|
Chris@1872
|
283 QCOMPARE(actual->getWidth(), 6);
|
Chris@1872
|
284 QCOMPARE(actual->getHeight(), 6);
|
Chris@1872
|
285 delete model;
|
Chris@1872
|
286 }
|
Chris@1872
|
287
|
Chris@1867
|
288 void modelType3DSeconds() {
|
Chris@1867
|
289 Model *model = nullptr;
|
Chris@1867
|
290 loadFrom("model-type-3d-seconds.csv", model);
|
Chris@1867
|
291 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
|
Chris@1867
|
292 QVERIFY(actual);
|
Chris@1867
|
293 QCOMPARE(actual->getWidth(), 6);
|
Chris@1867
|
294 QCOMPARE(actual->getHeight(), 6);
|
Chris@1867
|
295 delete model;
|
Chris@1867
|
296 }
|
Chris@1867
|
297
|
Chris@1872
|
298 void modelType3DSecondsWithHeader() {
|
Chris@1872
|
299 Model *model = nullptr;
|
Chris@1872
|
300 loadFrom("model-type-3d-seconds-header.csv", model);
|
Chris@1872
|
301 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
|
Chris@1872
|
302 QVERIFY(actual);
|
Chris@1872
|
303 QCOMPARE(actual->getWidth(), 6);
|
Chris@1872
|
304 QCOMPARE(actual->getHeight(), 6);
|
Chris@1872
|
305 delete model;
|
Chris@1872
|
306 }
|
Chris@1872
|
307
|
Chris@1867
|
308 void withBlankLines1D() {
|
Chris@1867
|
309 Model *model = nullptr;
|
Chris@1867
|
310 loadFrom("with-blank-lines-1d.csv", model);
|
Chris@1867
|
311 auto actual = qobject_cast<SparseOneDimensionalModel *>(model);
|
Chris@1867
|
312 QVERIFY(actual);
|
Chris@1867
|
313 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
314 delete model;
|
Chris@1867
|
315 }
|
Chris@1867
|
316
|
Chris@1867
|
317 void withBlankLines2D() {
|
Chris@1867
|
318 Model *model = nullptr;
|
Chris@1867
|
319 loadFrom("with-blank-lines-2d.csv", model);
|
Chris@1867
|
320 auto actual = qobject_cast<SparseTimeValueModel *>(model);
|
Chris@1867
|
321 QVERIFY(actual);
|
Chris@1867
|
322 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
323 delete model;
|
Chris@1867
|
324 }
|
Chris@1867
|
325
|
Chris@1867
|
326 void withBlankLines3D() {
|
Chris@1867
|
327 Model *model = nullptr;
|
Chris@1867
|
328 loadFrom("with-blank-lines-3d.csv", model);
|
Chris@1867
|
329 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
|
Chris@1867
|
330 QVERIFY(actual);
|
Chris@1867
|
331 QCOMPARE(actual->getWidth(), 6);
|
Chris@1867
|
332 QCOMPARE(actual->getHeight(), 6);
|
Chris@1867
|
333 delete model;
|
Chris@1867
|
334 }
|
Chris@1867
|
335
|
Chris@1867
|
336 void quoting() {
|
Chris@1867
|
337 Model *model = nullptr;
|
Chris@1867
|
338 loadFrom("quoting.csv", model);
|
Chris@1867
|
339 auto actual = qobject_cast<SparseTimeValueModel *>(model);
|
Chris@1867
|
340 QVERIFY(actual);
|
Chris@1867
|
341 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
342 delete model;
|
Chris@1867
|
343 }
|
Chris@1867
|
344 };
|
Chris@1867
|
345
|
Chris@1867
|
346 #endif
|