comparison data/fileio/test/CSVReaderTest.h @ 1867:2654bf447a84

CSV reader tests and fixes - avoid creating null events for lines in which the timings could not be read
author Chris Cannam
date Thu, 11 Jun 2020 14:09:59 +0100
parents
children 566476eeeb80
comparison
equal deleted inserted replaced
1866:b4b11af915f4 1867:2654bf447a84
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Visualiser
5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London.
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version. See the file
12 COPYING included with this distribution for more information.
13 */
14
15 #ifndef TEST_CSV_READER_H
16 #define TEST_CSV_READER_H
17
18 #include "../CSVFileReader.h"
19
20 #include "data/model/SparseOneDimensionalModel.h"
21 #include "data/model/SparseTimeValueModel.h"
22 #include "data/model/RegionModel.h"
23 #include "data/model/EditableDenseThreeDimensionalModel.h"
24
25 #include "base/Debug.h"
26
27 #include <cmath>
28
29 #include <QObject>
30 #include <QtTest>
31 #include <QDir>
32
33 #include <iostream>
34
35 using namespace std;
36
37 class CSVReaderTest : public QObject
38 {
39 Q_OBJECT
40
41 private:
42 QDir csvDir;
43 sv_samplerate_t mainRate;
44
45 public:
46 CSVReaderTest(QString base) {
47 if (base == "") {
48 base = "svcore/data/fileio/test";
49 }
50 csvDir = QDir(base + "/csv");
51 mainRate = 44100;
52 }
53
54 private:
55 void loadFrom(QString filename, Model *&model) {
56 QString path(csvDir.filePath(filename));
57 CSVFormat f;
58 f.guessFormatFor(path);
59 CSVFileReader reader(path, f, mainRate);
60 model = reader.load();
61 QVERIFY(model);
62 QVERIFY(reader.isOK());
63 QCOMPARE(reader.getError(), QString());
64 }
65
66 private slots:
67 void init() {
68 if (!csvDir.exists()) {
69 SVCERR << "ERROR: CSV test file directory \"" << csvDir.absolutePath() << "\" does not exist" << endl;
70 QVERIFY2(csvDir.exists(), "CSV test file directory not found");
71 }
72 }
73
74 void modelType1DSamples() {
75 Model *model = nullptr;
76 loadFrom("model-type-1d-samples.csv", model);
77 auto actual = qobject_cast<SparseOneDimensionalModel *>(model);
78 QVERIFY(actual);
79 QCOMPARE(actual->getAllEvents().size(), 5);
80 //!!! + the actual contents
81 delete model;
82 }
83
84 void modelType1DSeconds() {
85 Model *model = nullptr;
86 loadFrom("model-type-1d-seconds.csv", model);
87 auto actual = qobject_cast<SparseOneDimensionalModel *>(model);
88 QVERIFY(actual);
89 QCOMPARE(actual->getAllEvents().size(), 5);
90 delete model;
91 }
92
93 void modelType2DDurationSamples() {
94 Model *model = nullptr;
95 loadFrom("model-type-2d-duration-samples.csv", model);
96 auto actual = qobject_cast<RegionModel *>(model);
97 QVERIFY(actual);
98 QCOMPARE(actual->getAllEvents().size(), 5);
99 delete model;
100 }
101
102 void modelType2DDurationSeconds() {
103 Model *model = nullptr;
104 loadFrom("model-type-2d-duration-seconds.csv", model);
105 auto actual = qobject_cast<RegionModel *>(model);
106 QVERIFY(actual);
107 QCOMPARE(actual->getAllEvents().size(), 5);
108 delete model;
109 }
110
111 void badNegativeDuration() {
112 Model *model = nullptr;
113 loadFrom("bad-negative-duration.csv", model);
114 auto actual = qobject_cast<RegionModel *>(model);
115 QVERIFY(actual);
116 //!!! + check duration has been corrected
117 QCOMPARE(actual->getAllEvents().size(), 5);
118 delete model;
119 }
120
121 void modelType2DEndTimeSamples() {
122 Model *model = nullptr;
123 loadFrom("model-type-2d-endtime-samples.csv", model);
124 auto actual = qobject_cast<RegionModel *>(model);
125 QVERIFY(actual);
126 QCOMPARE(actual->getAllEvents().size(), 5);
127 delete model;
128 }
129
130 void modelType2DEndTimeSeconds() {
131 Model *model = nullptr;
132 loadFrom("model-type-2d-endtime-seconds.csv", model);
133 auto actual = qobject_cast<RegionModel *>(model);
134 QVERIFY(actual);
135 QCOMPARE(actual->getAllEvents().size(), 5);
136 delete model;
137 }
138
139 void modelType2DImplicit() {
140 Model *model = nullptr;
141 loadFrom("model-type-2d-implicit.csv", model);
142 auto actual = qobject_cast<SparseTimeValueModel *>(model);
143 QVERIFY(actual);
144 QCOMPARE(actual->getAllEvents().size(), 5);
145 delete model;
146 }
147
148 void modelType2DSamples() {
149 Model *model = nullptr;
150 loadFrom("model-type-2d-samples.csv", model);
151 auto actual = qobject_cast<SparseTimeValueModel *>(model);
152 QVERIFY(actual);
153 QCOMPARE(actual->getAllEvents().size(), 5);
154 delete model;
155 }
156
157 void modelType2DSeconds() {
158 Model *model = nullptr;
159 loadFrom("model-type-2d-seconds.csv", model);
160 auto actual = qobject_cast<SparseTimeValueModel *>(model);
161 QVERIFY(actual);
162 QCOMPARE(actual->getAllEvents().size(), 5);
163 delete model;
164 }
165
166 void modelType3DImplicit() {
167 Model *model = nullptr;
168 loadFrom("model-type-3d-implicit.csv", model);
169 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
170 QVERIFY(actual);
171 QCOMPARE(actual->getWidth(), 6);
172 QCOMPARE(actual->getHeight(), 6);
173 delete model;
174 }
175
176 void modelType3DSamples() {
177 Model *model = nullptr;
178 loadFrom("model-type-3d-samples.csv", model);
179 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
180 QVERIFY(actual);
181 QCOMPARE(actual->getWidth(), 6);
182 QCOMPARE(actual->getHeight(), 6);
183 delete model;
184 }
185
186 void modelType3DSeconds() {
187 Model *model = nullptr;
188 loadFrom("model-type-3d-seconds.csv", model);
189 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
190 QVERIFY(actual);
191 QCOMPARE(actual->getWidth(), 6);
192 QCOMPARE(actual->getHeight(), 6);
193 delete model;
194 }
195
196 void withBlankLines1D() {
197 Model *model = nullptr;
198 loadFrom("with-blank-lines-1d.csv", model);
199 auto actual = qobject_cast<SparseOneDimensionalModel *>(model);
200 QVERIFY(actual);
201 QCOMPARE(actual->getAllEvents().size(), 5);
202 delete model;
203 }
204
205 void withBlankLines2D() {
206 Model *model = nullptr;
207 loadFrom("with-blank-lines-2d.csv", model);
208 auto actual = qobject_cast<SparseTimeValueModel *>(model);
209 QVERIFY(actual);
210 QCOMPARE(actual->getAllEvents().size(), 5);
211 delete model;
212 }
213
214 void withBlankLines3D() {
215 Model *model = nullptr;
216 loadFrom("with-blank-lines-3d.csv", model);
217 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
218 QVERIFY(actual);
219 QCOMPARE(actual->getWidth(), 6);
220 QCOMPARE(actual->getHeight(), 6);
221 delete model;
222 }
223
224 void quoting() {
225 Model *model = nullptr;
226 loadFrom("quoting.csv", model);
227 auto actual = qobject_cast<SparseTimeValueModel *>(model);
228 QVERIFY(actual);
229 QCOMPARE(actual->getAllEvents().size(), 5);
230 delete model;
231 }
232 };
233
234 #endif