annotate data/fileio/test/CSVReaderTest.h @ 1886:f803d3c33f76 tip

Switch off copious debug in soft synth driving
author Chris Cannam
date Fri, 14 Aug 2020 10:44:44 +0100
parents 9a288b9b7a72
children
rev   line source
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@1875 79 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1873 80 vector<sv_frame_t> expected { 45678, 123239, 320130, 452103, 620301 };
Chris@1873 81 for (int i = 0; in_range_for(expected, i); ++i) {
Chris@1873 82 QCOMPARE(actual->getAllEvents()[i], Event(expected[i]));
Chris@1873 83 }
Chris@1867 84 delete model;
Chris@1867 85 }
Chris@1867 86
Chris@1872 87 void modelType1DSamplesWithHeader() {
Chris@1872 88 Model *model = nullptr;
Chris@1872 89 loadFrom("model-type-1d-samples-header.csv", model);
Chris@1872 90 auto actual = qobject_cast<SparseOneDimensionalModel *>(model);
Chris@1872 91 QVERIFY(actual);
Chris@1875 92 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1873 93 vector<sv_frame_t> expected { 45678, 123239, 320130, 452103, 620301 };
Chris@1873 94 for (int i = 0; in_range_for(expected, i); ++i) {
Chris@1873 95 QCOMPARE(actual->getAllEvents()[i], Event(expected[i]));
Chris@1873 96 }
Chris@1872 97 delete model;
Chris@1872 98 }
Chris@1872 99
Chris@1867 100 void modelType1DSeconds() {
Chris@1867 101 Model *model = nullptr;
Chris@1867 102 loadFrom("model-type-1d-seconds.csv", model);
Chris@1867 103 auto actual = qobject_cast<SparseOneDimensionalModel *>(model);
Chris@1867 104 QVERIFY(actual);
Chris@1875 105 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1867 106 delete model;
Chris@1867 107 }
Chris@1867 108
Chris@1872 109 void modelType1DSecondsWithHeader() {
Chris@1872 110 Model *model = nullptr;
Chris@1872 111 loadFrom("model-type-1d-seconds-header.csv", model);
Chris@1872 112 auto actual = qobject_cast<SparseOneDimensionalModel *>(model);
Chris@1872 113 QVERIFY(actual);
Chris@1875 114 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1872 115 delete model;
Chris@1872 116 }
Chris@1872 117
Chris@1867 118 void modelType2DDurationSamples() {
Chris@1867 119 Model *model = nullptr;
Chris@1867 120 loadFrom("model-type-2d-duration-samples.csv", model);
Chris@1867 121 auto actual = qobject_cast<RegionModel *>(model);
Chris@1867 122 QVERIFY(actual);
Chris@1876 123 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1867 124 delete model;
Chris@1867 125 }
Chris@1872 126
Chris@1872 127 void modelType2DDurationSamplesWithHeader() {
Chris@1872 128 Model *model = nullptr;
Chris@1872 129 loadFrom("model-type-2d-duration-samples-header.csv", model);
Chris@1872 130 auto actual = qobject_cast<RegionModel *>(model);
Chris@1872 131 QVERIFY(actual);
Chris@1875 132 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1872 133 delete model;
Chris@1872 134 }
Chris@1867 135
Chris@1867 136 void modelType2DDurationSeconds() {
Chris@1867 137 Model *model = nullptr;
Chris@1867 138 loadFrom("model-type-2d-duration-seconds.csv", model);
Chris@1867 139 auto actual = qobject_cast<RegionModel *>(model);
Chris@1867 140 QVERIFY(actual);
Chris@1875 141 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1867 142 delete model;
Chris@1867 143 }
Chris@1867 144
Chris@1872 145 void modelType2DDurationSecondsWithHeader() {
Chris@1872 146 Model *model = nullptr;
Chris@1872 147 loadFrom("model-type-2d-duration-seconds-header.csv", model);
Chris@1872 148 auto actual = qobject_cast<RegionModel *>(model);
Chris@1872 149 QVERIFY(actual);
Chris@1875 150 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1872 151 delete model;
Chris@1872 152 }
Chris@1872 153
Chris@1867 154 void badNegativeDuration() {
Chris@1867 155 Model *model = nullptr;
Chris@1867 156 loadFrom("bad-negative-duration.csv", model);
Chris@1867 157 auto actual = qobject_cast<RegionModel *>(model);
Chris@1867 158 QVERIFY(actual);
Chris@1867 159 //!!! + check duration has been corrected
Chris@1875 160 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1867 161 delete model;
Chris@1867 162 }
Chris@1867 163
Chris@1867 164 void modelType2DEndTimeSamples() {
Chris@1867 165 Model *model = nullptr;
Chris@1867 166 loadFrom("model-type-2d-endtime-samples.csv", model);
Chris@1867 167 auto actual = qobject_cast<RegionModel *>(model);
Chris@1867 168 QVERIFY(actual);
Chris@1875 169 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1867 170 delete model;
Chris@1867 171 }
Chris@1867 172
Chris@1872 173 void modelType2DEndTimeSamplesWithHeader() {
Chris@1872 174 Model *model = nullptr;
Chris@1872 175 loadFrom("model-type-2d-endtime-samples-header.csv", model);
Chris@1872 176 auto actual = qobject_cast<RegionModel *>(model);
Chris@1872 177 QVERIFY(actual);
Chris@1875 178 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1872 179 delete model;
Chris@1872 180 }
Chris@1872 181
Chris@1867 182 void modelType2DEndTimeSeconds() {
Chris@1867 183 Model *model = nullptr;
Chris@1867 184 loadFrom("model-type-2d-endtime-seconds.csv", model);
Chris@1867 185 auto actual = qobject_cast<RegionModel *>(model);
Chris@1867 186 QVERIFY(actual);
Chris@1875 187 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1867 188 delete model;
Chris@1867 189 }
Chris@1867 190
Chris@1872 191 void modelType2DEndTimeSecondsWithHeader() {
Chris@1872 192 Model *model = nullptr;
Chris@1872 193 loadFrom("model-type-2d-endtime-seconds-header.csv", model);
Chris@1872 194 auto actual = qobject_cast<RegionModel *>(model);
Chris@1872 195 QVERIFY(actual);
Chris@1875 196 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1872 197 delete model;
Chris@1872 198 }
Chris@1872 199
Chris@1867 200 void modelType2DImplicit() {
Chris@1867 201 Model *model = nullptr;
Chris@1867 202 loadFrom("model-type-2d-implicit.csv", model);
Chris@1867 203 auto actual = qobject_cast<SparseTimeValueModel *>(model);
Chris@1867 204 QVERIFY(actual);
Chris@1875 205 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1873 206 vector<sv_frame_t> expectedFrames { 0, 1024, 2048, 3072, 4096 };
Chris@1873 207 vector<float> expectedValues { 4.f, 4.2f, 0.4f, 3.8f, -2.3f };
Chris@1873 208 vector<QString> expectedLabels { {}, {}, "A label", {}, {} };
Chris@1873 209 for (int i = 0; in_range_for(expectedFrames, i); ++i) {
Chris@1873 210 QCOMPARE(actual->getAllEvents()[i],
Chris@1873 211 Event(expectedFrames[i],
Chris@1873 212 expectedValues[i],
Chris@1873 213 expectedLabels[i]));
Chris@1873 214 }
Chris@1867 215 delete model;
Chris@1867 216 }
Chris@1867 217
Chris@1872 218 void modelType2DImplicitWithHeader() {
Chris@1872 219 Model *model = nullptr;
Chris@1872 220 loadFrom("model-type-2d-implicit-header.csv", model);
Chris@1872 221 auto actual = qobject_cast<SparseTimeValueModel *>(model);
Chris@1872 222 QVERIFY(actual);
Chris@1875 223 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1873 224 vector<sv_frame_t> expectedFrames { 0, 1024, 2048, 3072, 4096 };
Chris@1873 225 vector<float> expectedValues { 4.f, 4.2f, 0.4f, 3.8f, -2.3f };
Chris@1873 226 vector<QString> expectedLabels { {}, {}, "A label", {}, {} };
Chris@1873 227 for (int i = 0; in_range_for(expectedFrames, i); ++i) {
Chris@1873 228 QCOMPARE(actual->getAllEvents()[i],
Chris@1873 229 Event(expectedFrames[i],
Chris@1873 230 expectedValues[i],
Chris@1873 231 expectedLabels[i]));
Chris@1873 232 }
Chris@1872 233 delete model;
Chris@1872 234 }
Chris@1872 235
Chris@1867 236 void modelType2DSamples() {
Chris@1867 237 Model *model = nullptr;
Chris@1867 238 loadFrom("model-type-2d-samples.csv", model);
Chris@1867 239 auto actual = qobject_cast<SparseTimeValueModel *>(model);
Chris@1867 240 QVERIFY(actual);
Chris@1875 241 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1867 242 delete model;
Chris@1867 243 }
Chris@1867 244
Chris@1872 245 void modelType2DSamplesWithHeader() {
Chris@1872 246 Model *model = nullptr;
Chris@1872 247 loadFrom("model-type-2d-samples-header.csv", model);
Chris@1872 248 auto actual = qobject_cast<SparseTimeValueModel *>(model);
Chris@1872 249 QVERIFY(actual);
Chris@1875 250 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1872 251 delete model;
Chris@1872 252 }
Chris@1872 253
Chris@1867 254 void modelType2DSeconds() {
Chris@1867 255 Model *model = nullptr;
Chris@1867 256 loadFrom("model-type-2d-seconds.csv", model);
Chris@1867 257 auto actual = qobject_cast<SparseTimeValueModel *>(model);
Chris@1867 258 QVERIFY(actual);
Chris@1875 259 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1867 260 delete model;
Chris@1867 261 }
Chris@1867 262
Chris@1872 263 void modelType2DSecondsWithHeader() {
Chris@1872 264 Model *model = nullptr;
Chris@1872 265 loadFrom("model-type-2d-seconds-header.csv", model);
Chris@1872 266 auto actual = qobject_cast<SparseTimeValueModel *>(model);
Chris@1872 267 QVERIFY(actual);
Chris@1875 268 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1872 269 delete model;
Chris@1872 270 }
Chris@1872 271
Chris@1867 272 void modelType3DImplicit() {
Chris@1867 273 Model *model = nullptr;
Chris@1867 274 loadFrom("model-type-3d-implicit.csv", model);
Chris@1867 275 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
Chris@1867 276 QVERIFY(actual);
Chris@1867 277 QCOMPARE(actual->getWidth(), 6);
Chris@1867 278 QCOMPARE(actual->getHeight(), 6);
Chris@1867 279 delete model;
Chris@1867 280 }
Chris@1867 281
Chris@1872 282 void modelType3DImplicitWithHeader() {
Chris@1872 283 Model *model = nullptr;
Chris@1872 284 loadFrom("model-type-3d-implicit-header.csv", model);
Chris@1872 285 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
Chris@1872 286 QVERIFY(actual);
Chris@1872 287 QCOMPARE(actual->getWidth(), 6);
Chris@1872 288 QCOMPARE(actual->getHeight(), 6);
Chris@1872 289 delete model;
Chris@1872 290 }
Chris@1872 291
Chris@1867 292 void modelType3DSamples() {
Chris@1867 293 Model *model = nullptr;
Chris@1867 294 loadFrom("model-type-3d-samples.csv", model);
Chris@1867 295 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
Chris@1867 296 QVERIFY(actual);
Chris@1867 297 QCOMPARE(actual->getWidth(), 6);
Chris@1867 298 QCOMPARE(actual->getHeight(), 6);
Chris@1867 299 delete model;
Chris@1867 300 }
Chris@1867 301
Chris@1872 302 void modelType3DSamplesWithHeader() {
Chris@1872 303 Model *model = nullptr;
Chris@1872 304 loadFrom("model-type-3d-samples-header.csv", model);
Chris@1872 305 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
Chris@1872 306 QVERIFY(actual);
Chris@1872 307 QCOMPARE(actual->getWidth(), 6);
Chris@1872 308 QCOMPARE(actual->getHeight(), 6);
Chris@1872 309 delete model;
Chris@1872 310 }
Chris@1872 311
Chris@1867 312 void modelType3DSeconds() {
Chris@1867 313 Model *model = nullptr;
Chris@1867 314 loadFrom("model-type-3d-seconds.csv", model);
Chris@1867 315 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
Chris@1867 316 QVERIFY(actual);
Chris@1867 317 QCOMPARE(actual->getWidth(), 6);
Chris@1867 318 QCOMPARE(actual->getHeight(), 6);
Chris@1867 319 delete model;
Chris@1867 320 }
Chris@1867 321
Chris@1872 322 void modelType3DSecondsWithHeader() {
Chris@1872 323 Model *model = nullptr;
Chris@1872 324 loadFrom("model-type-3d-seconds-header.csv", model);
Chris@1872 325 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
Chris@1872 326 QVERIFY(actual);
Chris@1872 327 QCOMPARE(actual->getWidth(), 6);
Chris@1872 328 QCOMPARE(actual->getHeight(), 6);
Chris@1872 329 delete model;
Chris@1872 330 }
Chris@1872 331
Chris@1867 332 void withBlankLines1D() {
Chris@1867 333 Model *model = nullptr;
Chris@1867 334 loadFrom("with-blank-lines-1d.csv", model);
Chris@1867 335 auto actual = qobject_cast<SparseOneDimensionalModel *>(model);
Chris@1867 336 QVERIFY(actual);
Chris@1875 337 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1867 338 delete model;
Chris@1867 339 }
Chris@1867 340
Chris@1867 341 void withBlankLines2D() {
Chris@1867 342 Model *model = nullptr;
Chris@1867 343 loadFrom("with-blank-lines-2d.csv", model);
Chris@1867 344 auto actual = qobject_cast<SparseTimeValueModel *>(model);
Chris@1867 345 QVERIFY(actual);
Chris@1875 346 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1867 347 delete model;
Chris@1867 348 }
Chris@1867 349
Chris@1867 350 void withBlankLines3D() {
Chris@1867 351 Model *model = nullptr;
Chris@1867 352 loadFrom("with-blank-lines-3d.csv", model);
Chris@1867 353 auto actual = qobject_cast<EditableDenseThreeDimensionalModel *>(model);
Chris@1867 354 QVERIFY(actual);
Chris@1867 355 QCOMPARE(actual->getWidth(), 6);
Chris@1867 356 QCOMPARE(actual->getHeight(), 6);
Chris@1867 357 delete model;
Chris@1867 358 }
Chris@1867 359
Chris@1867 360 void quoting() {
Chris@1867 361 Model *model = nullptr;
Chris@1867 362 loadFrom("quoting.csv", model);
Chris@1867 363 auto actual = qobject_cast<SparseTimeValueModel *>(model);
Chris@1867 364 QVERIFY(actual);
Chris@1875 365 QCOMPARE(int(actual->getAllEvents().size()), 5);
Chris@1867 366 delete model;
Chris@1867 367 }
Chris@1867 368 };
Chris@1867 369
Chris@1867 370 #endif