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@1867
|
84 void modelType1DSeconds() {
|
Chris@1867
|
85 Model *model = nullptr;
|
Chris@1867
|
86 loadFrom("model-type-1d-seconds.csv", model);
|
Chris@1867
|
87 auto actual = qobject_cast<SparseOneDimensionalModel *>(model);
|
Chris@1867
|
88 QVERIFY(actual);
|
Chris@1867
|
89 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
90 delete model;
|
Chris@1867
|
91 }
|
Chris@1867
|
92
|
Chris@1867
|
93 void modelType2DDurationSamples() {
|
Chris@1867
|
94 Model *model = nullptr;
|
Chris@1867
|
95 loadFrom("model-type-2d-duration-samples.csv", model);
|
Chris@1867
|
96 auto actual = qobject_cast<RegionModel *>(model);
|
Chris@1867
|
97 QVERIFY(actual);
|
Chris@1867
|
98 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
99 delete model;
|
Chris@1867
|
100 }
|
Chris@1867
|
101
|
Chris@1867
|
102 void modelType2DDurationSeconds() {
|
Chris@1867
|
103 Model *model = nullptr;
|
Chris@1867
|
104 loadFrom("model-type-2d-duration-seconds.csv", model);
|
Chris@1867
|
105 auto actual = qobject_cast<RegionModel *>(model);
|
Chris@1867
|
106 QVERIFY(actual);
|
Chris@1867
|
107 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
108 delete model;
|
Chris@1867
|
109 }
|
Chris@1867
|
110
|
Chris@1867
|
111 void badNegativeDuration() {
|
Chris@1867
|
112 Model *model = nullptr;
|
Chris@1867
|
113 loadFrom("bad-negative-duration.csv", model);
|
Chris@1867
|
114 auto actual = qobject_cast<RegionModel *>(model);
|
Chris@1867
|
115 QVERIFY(actual);
|
Chris@1867
|
116 //!!! + check duration has been corrected
|
Chris@1867
|
117 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
118 delete model;
|
Chris@1867
|
119 }
|
Chris@1867
|
120
|
Chris@1867
|
121 void modelType2DEndTimeSamples() {
|
Chris@1867
|
122 Model *model = nullptr;
|
Chris@1867
|
123 loadFrom("model-type-2d-endtime-samples.csv", model);
|
Chris@1867
|
124 auto actual = qobject_cast<RegionModel *>(model);
|
Chris@1867
|
125 QVERIFY(actual);
|
Chris@1867
|
126 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
127 delete model;
|
Chris@1867
|
128 }
|
Chris@1867
|
129
|
Chris@1867
|
130 void modelType2DEndTimeSeconds() {
|
Chris@1867
|
131 Model *model = nullptr;
|
Chris@1867
|
132 loadFrom("model-type-2d-endtime-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@1867
|
139 void modelType2DImplicit() {
|
Chris@1867
|
140 Model *model = nullptr;
|
Chris@1867
|
141 loadFrom("model-type-2d-implicit.csv", model);
|
Chris@1867
|
142 auto actual = qobject_cast<SparseTimeValueModel *>(model);
|
Chris@1867
|
143 QVERIFY(actual);
|
Chris@1867
|
144 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
145 delete model;
|
Chris@1867
|
146 }
|
Chris@1867
|
147
|
Chris@1867
|
148 void modelType2DSamples() {
|
Chris@1867
|
149 Model *model = nullptr;
|
Chris@1867
|
150 loadFrom("model-type-2d-samples.csv", model);
|
Chris@1867
|
151 auto actual = qobject_cast<SparseTimeValueModel *>(model);
|
Chris@1867
|
152 QVERIFY(actual);
|
Chris@1867
|
153 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
154 delete model;
|
Chris@1867
|
155 }
|
Chris@1867
|
156
|
Chris@1867
|
157 void modelType2DSeconds() {
|
Chris@1867
|
158 Model *model = nullptr;
|
Chris@1867
|
159 loadFrom("model-type-2d-seconds.csv", model);
|
Chris@1867
|
160 auto actual = qobject_cast<SparseTimeValueModel *>(model);
|
Chris@1867
|
161 QVERIFY(actual);
|
Chris@1867
|
162 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
163 delete model;
|
Chris@1867
|
164 }
|
Chris@1867
|
165
|
Chris@1867
|
166 void modelType3DImplicit() {
|
Chris@1867
|
167 Model *model = nullptr;
|
Chris@1867
|
168 loadFrom("model-type-3d-implicit.csv", model);
|
Chris@1867
|
169 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
|
Chris@1867
|
170 QVERIFY(actual);
|
Chris@1867
|
171 QCOMPARE(actual->getWidth(), 6);
|
Chris@1867
|
172 QCOMPARE(actual->getHeight(), 6);
|
Chris@1867
|
173 delete model;
|
Chris@1867
|
174 }
|
Chris@1867
|
175
|
Chris@1867
|
176 void modelType3DSamples() {
|
Chris@1867
|
177 Model *model = nullptr;
|
Chris@1867
|
178 loadFrom("model-type-3d-samples.csv", model);
|
Chris@1867
|
179 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
|
Chris@1867
|
180 QVERIFY(actual);
|
Chris@1867
|
181 QCOMPARE(actual->getWidth(), 6);
|
Chris@1867
|
182 QCOMPARE(actual->getHeight(), 6);
|
Chris@1867
|
183 delete model;
|
Chris@1867
|
184 }
|
Chris@1867
|
185
|
Chris@1867
|
186 void modelType3DSeconds() {
|
Chris@1867
|
187 Model *model = nullptr;
|
Chris@1867
|
188 loadFrom("model-type-3d-seconds.csv", model);
|
Chris@1867
|
189 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
|
Chris@1867
|
190 QVERIFY(actual);
|
Chris@1867
|
191 QCOMPARE(actual->getWidth(), 6);
|
Chris@1867
|
192 QCOMPARE(actual->getHeight(), 6);
|
Chris@1867
|
193 delete model;
|
Chris@1867
|
194 }
|
Chris@1867
|
195
|
Chris@1867
|
196 void withBlankLines1D() {
|
Chris@1867
|
197 Model *model = nullptr;
|
Chris@1867
|
198 loadFrom("with-blank-lines-1d.csv", model);
|
Chris@1867
|
199 auto actual = qobject_cast<SparseOneDimensionalModel *>(model);
|
Chris@1867
|
200 QVERIFY(actual);
|
Chris@1867
|
201 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
202 delete model;
|
Chris@1867
|
203 }
|
Chris@1867
|
204
|
Chris@1867
|
205 void withBlankLines2D() {
|
Chris@1867
|
206 Model *model = nullptr;
|
Chris@1867
|
207 loadFrom("with-blank-lines-2d.csv", model);
|
Chris@1867
|
208 auto actual = qobject_cast<SparseTimeValueModel *>(model);
|
Chris@1867
|
209 QVERIFY(actual);
|
Chris@1867
|
210 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
211 delete model;
|
Chris@1867
|
212 }
|
Chris@1867
|
213
|
Chris@1867
|
214 void withBlankLines3D() {
|
Chris@1867
|
215 Model *model = nullptr;
|
Chris@1867
|
216 loadFrom("with-blank-lines-3d.csv", model);
|
Chris@1867
|
217 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
|
Chris@1867
|
218 QVERIFY(actual);
|
Chris@1867
|
219 QCOMPARE(actual->getWidth(), 6);
|
Chris@1867
|
220 QCOMPARE(actual->getHeight(), 6);
|
Chris@1867
|
221 delete model;
|
Chris@1867
|
222 }
|
Chris@1867
|
223
|
Chris@1867
|
224 void quoting() {
|
Chris@1867
|
225 Model *model = nullptr;
|
Chris@1867
|
226 loadFrom("quoting.csv", model);
|
Chris@1867
|
227 auto actual = qobject_cast<SparseTimeValueModel *>(model);
|
Chris@1867
|
228 QVERIFY(actual);
|
Chris@1867
|
229 QCOMPARE(actual->getAllEvents().size(), 5);
|
Chris@1867
|
230 delete model;
|
Chris@1867
|
231 }
|
Chris@1867
|
232 };
|
Chris@1867
|
233
|
Chris@1867
|
234 #endif
|