Chris@1345
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@1345
|
2
|
Chris@1345
|
3 /*
|
Chris@1345
|
4 Sonic Visualiser
|
Chris@1345
|
5 An audio file viewer and annotation editor.
|
Chris@1345
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@1345
|
7
|
Chris@1345
|
8 This program is free software; you can redistribute it and/or
|
Chris@1345
|
9 modify it under the terms of the GNU General Public License as
|
Chris@1345
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@1345
|
11 License, or (at your option) any later version. See the file
|
Chris@1345
|
12 COPYING included with this distribution for more information.
|
Chris@1345
|
13 */
|
Chris@1345
|
14
|
Chris@1524
|
15 #ifndef TEST_CSV_FORMAT_H
|
Chris@1524
|
16 #define TEST_CSV_FORMAT_H
|
Chris@1345
|
17
|
Chris@1524
|
18 // Tests for the code that guesses the most likely format for parsing a CSV file
|
Chris@1345
|
19
|
Chris@1524
|
20 #include "../CSVFormat.h"
|
Chris@1524
|
21
|
Chris@1524
|
22 #include "base/Debug.h"
|
Chris@1345
|
23
|
Chris@1345
|
24 #include <cmath>
|
Chris@1345
|
25
|
Chris@1345
|
26 #include <QObject>
|
Chris@1345
|
27 #include <QtTest>
|
Chris@1345
|
28 #include <QDir>
|
Chris@1345
|
29
|
Chris@1345
|
30 #include <iostream>
|
Chris@1345
|
31
|
Chris@1345
|
32 using namespace std;
|
Chris@1345
|
33
|
Chris@1524
|
34 class CSVFormatTest : public QObject
|
Chris@1345
|
35 {
|
Chris@1345
|
36 Q_OBJECT
|
Chris@1345
|
37
|
Chris@1346
|
38 private:
|
Chris@1524
|
39 QDir csvDir;
|
Chris@1346
|
40
|
Chris@1346
|
41 public:
|
Chris@1524
|
42 CSVFormatTest(QString base) {
|
Chris@1346
|
43 if (base == "") {
|
Chris@1346
|
44 base = "svcore/data/fileio/test";
|
Chris@1346
|
45 }
|
Chris@1524
|
46 csvDir = QDir(base + "/csv");
|
Chris@1346
|
47 }
|
Chris@1346
|
48
|
Chris@1524
|
49 private slots:
|
Chris@1524
|
50 void init() {
|
Chris@1524
|
51 if (!csvDir.exists()) {
|
Chris@1524
|
52 SVCERR << "ERROR: CSV test file directory \"" << csvDir.absolutePath() << "\" does not exist" << endl;
|
Chris@1524
|
53 QVERIFY2(csvDir.exists(), "CSV test file directory not found");
|
Chris@1359
|
54 }
|
Chris@1359
|
55 }
|
Chris@1359
|
56
|
Chris@1524
|
57 void separatorComma() {
|
Chris@1524
|
58 CSVFormat f;
|
Chris@1524
|
59 QVERIFY(f.guessFormatFor(csvDir.filePath("separator-comma.csv")));
|
Chris@1524
|
60 QCOMPARE(f.getSeparator(), QChar(','));
|
Chris@1524
|
61 QCOMPARE(f.getColumnCount(), 3);
|
Chris@1524
|
62 }
|
Chris@1524
|
63
|
Chris@1524
|
64 void separatorTab() {
|
Chris@1524
|
65 CSVFormat f;
|
Chris@1524
|
66 QVERIFY(f.guessFormatFor(csvDir.filePath("separator-tab.csv")));
|
Chris@1524
|
67 QCOMPARE(f.getSeparator(), QChar('\t'));
|
Chris@1524
|
68 QCOMPARE(f.getColumnCount(), 3);
|
Chris@1524
|
69 }
|
Chris@1524
|
70
|
Chris@1524
|
71 void separatorPipe() {
|
Chris@1524
|
72 CSVFormat f;
|
Chris@1524
|
73 QVERIFY(f.guessFormatFor(csvDir.filePath("separator-pipe.csv")));
|
Chris@1524
|
74 QCOMPARE(f.getSeparator(), QChar('|'));
|
Chris@1524
|
75 // differs from the others
|
Chris@1524
|
76 QCOMPARE(f.getColumnCount(), 4);
|
Chris@1524
|
77 }
|
Chris@1524
|
78
|
Chris@1524
|
79 void separatorSpace() {
|
Chris@1524
|
80 CSVFormat f;
|
Chris@1524
|
81 QVERIFY(f.guessFormatFor(csvDir.filePath("separator-space.csv")));
|
Chris@1524
|
82 QCOMPARE(f.getSeparator(), QChar(' '));
|
Chris@1524
|
83 // NB fields are separated by 1 or more spaces, not necessarily exactly 1
|
Chris@1524
|
84 QCOMPARE(f.getColumnCount(), 3);
|
Chris@1524
|
85 }
|
Chris@1524
|
86
|
Chris@1524
|
87 void separatorColon() {
|
Chris@1524
|
88 CSVFormat f;
|
Chris@1524
|
89 QVERIFY(f.guessFormatFor(csvDir.filePath("separator-colon.csv")));
|
Chris@1524
|
90 QCOMPARE(f.getSeparator(), QChar(':'));
|
Chris@1524
|
91 QCOMPARE(f.getColumnCount(), 3);
|
Chris@1524
|
92 }
|
Chris@1524
|
93
|
Chris@1524
|
94 void comment() {
|
Chris@1524
|
95 CSVFormat f;
|
Chris@1524
|
96 QVERIFY(f.guessFormatFor(csvDir.filePath("comment.csv")));
|
Chris@1524
|
97 QCOMPARE(f.getSeparator(), QChar(','));
|
Chris@1524
|
98 QCOMPARE(f.getColumnCount(), 4);
|
Chris@1345
|
99 }
|
Chris@1345
|
100
|
Chris@1524
|
101 void qualities() {
|
Chris@1524
|
102 CSVFormat f;
|
Chris@1524
|
103 QVERIFY(f.guessFormatFor(csvDir.filePath("column-qualities.csv")));
|
Chris@1524
|
104 QCOMPARE(f.getSeparator(), QChar(','));
|
Chris@1524
|
105 QCOMPARE(f.getColumnCount(), 7);
|
Chris@1524
|
106 QList<CSVFormat::ColumnQualities> q = f.getColumnQualities();
|
Chris@1524
|
107 QList<CSVFormat::ColumnQualities> expected;
|
Chris@1524
|
108 expected << 0;
|
Chris@1524
|
109 expected << CSVFormat::ColumnQualities(CSVFormat::ColumnNumeric |
|
Chris@1524
|
110 CSVFormat::ColumnIntegral |
|
Chris@1524
|
111 CSVFormat::ColumnIncreasing);
|
Chris@1524
|
112 expected << CSVFormat::ColumnQualities(CSVFormat::ColumnNumeric |
|
Chris@1524
|
113 CSVFormat::ColumnIntegral |
|
Chris@1524
|
114 CSVFormat::ColumnIncreasing |
|
Chris@1524
|
115 CSVFormat::ColumnLarge);
|
Chris@1524
|
116 expected << CSVFormat::ColumnQualities(CSVFormat::ColumnNumeric);
|
Chris@1524
|
117 expected << CSVFormat::ColumnQualities(CSVFormat::ColumnNumeric |
|
Chris@1524
|
118 CSVFormat::ColumnIncreasing);
|
Chris@1524
|
119 expected << CSVFormat::ColumnQualities(CSVFormat::ColumnNumeric |
|
Chris@1524
|
120 CSVFormat::ColumnSmall |
|
Chris@1524
|
121 CSVFormat::ColumnSigned);
|
Chris@1524
|
122 expected << CSVFormat::ColumnQualities(CSVFormat::ColumnNumeric |
|
Chris@1524
|
123 CSVFormat::ColumnIntegral |
|
Chris@1524
|
124 CSVFormat::ColumnIncreasing |
|
Chris@1524
|
125 CSVFormat::ColumnNearEmpty);
|
Chris@1524
|
126 QCOMPARE(q, expected);
|
Chris@1359
|
127 }
|
Chris@1525
|
128
|
Chris@1525
|
129 void modelType1DSamples() {
|
Chris@1525
|
130 CSVFormat f;
|
Chris@1525
|
131 QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-1d-samples.csv")));
|
Chris@1525
|
132 QCOMPARE(f.getColumnCount(), 1);
|
Chris@1525
|
133 QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime);
|
Chris@1525
|
134 QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming);
|
Chris@1525
|
135 QCOMPARE(f.getTimeUnits(), CSVFormat::TimeAudioFrames);
|
Chris@1525
|
136 QCOMPARE(f.getModelType(), CSVFormat::OneDimensionalModel);
|
Chris@1525
|
137 }
|
Chris@1525
|
138
|
Chris@1525
|
139 void modelType1DSeconds() {
|
Chris@1525
|
140 CSVFormat f;
|
Chris@1525
|
141 QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-1d-seconds.csv")));
|
Chris@1525
|
142 QCOMPARE(f.getColumnCount(), 2);
|
Chris@1525
|
143 QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime);
|
Chris@1525
|
144 QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnLabel);
|
Chris@1525
|
145 QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming);
|
Chris@1525
|
146 QCOMPARE(f.getTimeUnits(), CSVFormat::TimeSeconds);
|
Chris@1525
|
147 QCOMPARE(f.getModelType(), CSVFormat::OneDimensionalModel);
|
Chris@1525
|
148 }
|
Chris@1525
|
149
|
Chris@1525
|
150 void modelType2DSamples() {
|
Chris@1525
|
151 CSVFormat f;
|
Chris@1525
|
152 QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-samples.csv")));
|
Chris@1525
|
153 QCOMPARE(f.getColumnCount(), 2);
|
Chris@1525
|
154 QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime);
|
Chris@1525
|
155 QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue);
|
Chris@1525
|
156 QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming);
|
Chris@1525
|
157 QCOMPARE(f.getTimeUnits(), CSVFormat::TimeAudioFrames);
|
Chris@1525
|
158 QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModel);
|
Chris@1525
|
159 }
|
Chris@1525
|
160
|
Chris@1525
|
161 void modelType2DSeconds() {
|
Chris@1525
|
162 CSVFormat f;
|
Chris@1525
|
163 QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-seconds.csv")));
|
Chris@1525
|
164 QCOMPARE(f.getColumnCount(), 2);
|
Chris@1525
|
165 QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime);
|
Chris@1525
|
166 QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue);
|
Chris@1525
|
167 QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming);
|
Chris@1525
|
168 QCOMPARE(f.getTimeUnits(), CSVFormat::TimeSeconds);
|
Chris@1525
|
169 QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModel);
|
Chris@1525
|
170 }
|
Chris@1525
|
171
|
Chris@1525
|
172 void modelType2DImplicit() {
|
Chris@1525
|
173 CSVFormat f;
|
Chris@1525
|
174 QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-implicit.csv")));
|
Chris@1525
|
175 QCOMPARE(f.getColumnCount(), 1);
|
Chris@1525
|
176 QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnValue);
|
Chris@1525
|
177 QCOMPARE(f.getTimingType(), CSVFormat::ImplicitTiming);
|
Chris@1525
|
178 }
|
Chris@1525
|
179
|
Chris@1525
|
180 void modelType2DEndTimeSamples() {
|
Chris@1525
|
181 CSVFormat f;
|
Chris@1525
|
182 QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-endtime-samples.csv")));
|
Chris@1525
|
183 QCOMPARE(f.getColumnCount(), 3);
|
Chris@1525
|
184 QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime);
|
Chris@1525
|
185 QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnEndTime);
|
Chris@1525
|
186 QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue);
|
Chris@1525
|
187 QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming);
|
Chris@1525
|
188 QCOMPARE(f.getTimeUnits(), CSVFormat::TimeAudioFrames);
|
Chris@1525
|
189 QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModelWithDuration);
|
Chris@1525
|
190 }
|
Chris@1525
|
191
|
Chris@1525
|
192 void modelType2DEndTimeSeconds() {
|
Chris@1525
|
193 CSVFormat f;
|
Chris@1525
|
194 QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-endtime-seconds.csv")));
|
Chris@1525
|
195 QCOMPARE(f.getColumnCount(), 3);
|
Chris@1525
|
196 QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime);
|
Chris@1525
|
197 QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnEndTime);
|
Chris@1525
|
198 QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue);
|
Chris@1525
|
199 QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming);
|
Chris@1525
|
200 QCOMPARE(f.getTimeUnits(), CSVFormat::TimeSeconds);
|
Chris@1525
|
201 QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModelWithDuration);
|
Chris@1525
|
202 }
|
Chris@1525
|
203
|
Chris@1525
|
204 void modelType2DDurationSamples() {
|
Chris@1525
|
205 CSVFormat f;
|
Chris@1525
|
206 QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-duration-samples.csv")));
|
Chris@1525
|
207 QCOMPARE(f.getColumnCount(), 3);
|
Chris@1525
|
208 QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime);
|
Chris@1525
|
209 QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnDuration);
|
Chris@1525
|
210 QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue);
|
Chris@1525
|
211 QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming);
|
Chris@1525
|
212 QCOMPARE(f.getTimeUnits(), CSVFormat::TimeAudioFrames);
|
Chris@1525
|
213 QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModelWithDuration);
|
Chris@1525
|
214 }
|
Chris@1525
|
215
|
Chris@1525
|
216 void modelType2DDurationSeconds() {
|
Chris@1525
|
217 CSVFormat f;
|
Chris@1525
|
218 QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-duration-seconds.csv")));
|
Chris@1525
|
219 QCOMPARE(f.getColumnCount(), 3);
|
Chris@1525
|
220 QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime);
|
Chris@1525
|
221 QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnDuration);
|
Chris@1525
|
222 QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue);
|
Chris@1525
|
223 QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming);
|
Chris@1525
|
224 QCOMPARE(f.getTimeUnits(), CSVFormat::TimeSeconds);
|
Chris@1525
|
225 QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModelWithDuration);
|
Chris@1525
|
226 }
|
Chris@1525
|
227
|
Chris@1525
|
228 void modelType3DSamples() {
|
Chris@1525
|
229 CSVFormat f;
|
Chris@1525
|
230 QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-3d-samples.csv")));
|
Chris@1525
|
231 QCOMPARE(f.getColumnCount(), 7);
|
Chris@1525
|
232 QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime);
|
Chris@1525
|
233 QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue);
|
Chris@1525
|
234 QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue);
|
Chris@1525
|
235 QCOMPARE(f.getColumnPurpose(3), CSVFormat::ColumnValue);
|
Chris@1525
|
236 QCOMPARE(f.getColumnPurpose(4), CSVFormat::ColumnValue);
|
Chris@1525
|
237 QCOMPARE(f.getColumnPurpose(5), CSVFormat::ColumnValue);
|
Chris@1525
|
238 QCOMPARE(f.getColumnPurpose(6), CSVFormat::ColumnValue);
|
Chris@1525
|
239 QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming);
|
Chris@1525
|
240 QCOMPARE(f.getTimeUnits(), CSVFormat::TimeAudioFrames);
|
Chris@1525
|
241 QCOMPARE(f.getModelType(), CSVFormat::ThreeDimensionalModel);
|
Chris@1525
|
242 }
|
Chris@1525
|
243
|
Chris@1525
|
244 void modelType3DSeconds() {
|
Chris@1525
|
245 CSVFormat f;
|
Chris@1525
|
246 QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-3d-seconds.csv")));
|
Chris@1525
|
247 QCOMPARE(f.getColumnCount(), 7);
|
Chris@1525
|
248 QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime);
|
Chris@1525
|
249 QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue);
|
Chris@1525
|
250 QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue);
|
Chris@1525
|
251 QCOMPARE(f.getColumnPurpose(3), CSVFormat::ColumnValue);
|
Chris@1525
|
252 QCOMPARE(f.getColumnPurpose(4), CSVFormat::ColumnValue);
|
Chris@1525
|
253 QCOMPARE(f.getColumnPurpose(5), CSVFormat::ColumnValue);
|
Chris@1525
|
254 QCOMPARE(f.getColumnPurpose(6), CSVFormat::ColumnValue);
|
Chris@1525
|
255 QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming);
|
Chris@1525
|
256 QCOMPARE(f.getTimeUnits(), CSVFormat::TimeSeconds);
|
Chris@1525
|
257 QCOMPARE(f.getModelType(), CSVFormat::ThreeDimensionalModel);
|
Chris@1525
|
258 }
|
Chris@1525
|
259
|
Chris@1525
|
260 void modelType3DImplicit() {
|
Chris@1525
|
261 CSVFormat f;
|
Chris@1525
|
262 QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-3d-implicit.csv")));
|
Chris@1525
|
263 QCOMPARE(f.getColumnCount(), 6);
|
Chris@1525
|
264 QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnValue);
|
Chris@1525
|
265 QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue);
|
Chris@1525
|
266 QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue);
|
Chris@1525
|
267 QCOMPARE(f.getColumnPurpose(3), CSVFormat::ColumnValue);
|
Chris@1525
|
268 QCOMPARE(f.getColumnPurpose(4), CSVFormat::ColumnValue);
|
Chris@1525
|
269 QCOMPARE(f.getColumnPurpose(5), CSVFormat::ColumnValue);
|
Chris@1525
|
270 QCOMPARE(f.getTimingType(), CSVFormat::ImplicitTiming);
|
Chris@1525
|
271 QCOMPARE(f.getModelType(), CSVFormat::ThreeDimensionalModel);
|
Chris@1525
|
272 }
|
Chris@1525
|
273
|
Chris@1345
|
274 };
|
Chris@1345
|
275
|
Chris@1345
|
276 #endif
|