annotate data/fileio/test/MIDIFileReaderTest.h @ 1728:a47a23c824ac

Merge
author Chris Cannam
date Wed, 22 May 2019 15:37:44 +0100
parents 87ae75da6527
children
rev   line source
Chris@1359 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@1359 2
Chris@1359 3 /*
Chris@1359 4 Sonic Visualiser
Chris@1359 5 An audio file viewer and annotation editor.
Chris@1359 6 Centre for Digital Music, Queen Mary, University of London.
Chris@1359 7 This file copyright 2013 Chris Cannam.
Chris@1359 8
Chris@1359 9 This program is free software; you can redistribute it and/or
Chris@1359 10 modify it under the terms of the GNU General Public License as
Chris@1359 11 published by the Free Software Foundation; either version 2 of the
Chris@1359 12 License, or (at your option) any later version. See the file
Chris@1359 13 COPYING included with this distribution for more information.
Chris@1359 14 */
Chris@1359 15
Chris@1359 16 #ifndef TEST_MIDI_FILE_READER_H
Chris@1359 17 #define TEST_MIDI_FILE_READER_H
Chris@1359 18
Chris@1359 19 #include "../MIDIFileReader.h"
Chris@1359 20
Chris@1359 21 #include <cmath>
Chris@1359 22
Chris@1359 23 #include <QObject>
Chris@1359 24 #include <QtTest>
Chris@1359 25 #include <QDir>
Chris@1359 26
Chris@1359 27 #include "base/Debug.h"
Chris@1359 28
Chris@1359 29 #include <iostream>
Chris@1359 30
Chris@1359 31 using namespace std;
Chris@1359 32
Chris@1359 33 class MIDIFileReaderTest : public QObject
Chris@1359 34 {
Chris@1359 35 Q_OBJECT
Chris@1359 36
Chris@1359 37 private:
Chris@1359 38 QString testDirBase;
Chris@1359 39 QString midiDir;
Chris@1359 40
Chris@1359 41 const char *strOf(QString s) {
Chris@1359 42 return strdup(s.toLocal8Bit().data());
Chris@1359 43 }
Chris@1359 44
Chris@1359 45 public:
Chris@1359 46 MIDIFileReaderTest(QString base) {
Chris@1359 47 if (base == "") {
Chris@1359 48 base = "svcore/data/fileio/test";
Chris@1359 49 }
Chris@1359 50 testDirBase = base;
Chris@1359 51 midiDir = base + "/midi";
Chris@1359 52 }
Chris@1359 53
Chris@1359 54 private slots:
Chris@1359 55 void init()
Chris@1359 56 {
Chris@1359 57 if (!QDir(midiDir).exists()) {
Chris@1428 58 SVCERR << "ERROR: MIDI file directory \"" << midiDir << "\" does not exist" << endl;
Chris@1359 59 QVERIFY2(QDir(midiDir).exists(), "MIDI file directory not found");
Chris@1359 60 }
Chris@1359 61 }
Chris@1359 62
Chris@1359 63 void read_data()
Chris@1359 64 {
Chris@1359 65 QTest::addColumn<QString>("filename");
Chris@1359 66 QStringList files = QDir(midiDir).entryList(QDir::Files);
Chris@1359 67 foreach (QString filename, files) {
Chris@1359 68 QTest::newRow(strOf(filename)) << filename;
Chris@1359 69 }
Chris@1359 70 }
Chris@1359 71
Chris@1359 72 void read()
Chris@1359 73 {
Chris@1359 74 QFETCH(QString, filename);
Chris@1359 75 QString path = midiDir + "/" + filename;
Chris@1359 76 MIDIFileReader reader(path, nullptr, 44100);
Chris@1359 77 Model *m = reader.load();
Chris@1359 78 if (!m) {
Chris@1428 79 SVCERR << "MIDI load failed for path: \"" << path << "\"" << endl;
Chris@1359 80 }
Chris@1359 81 QVERIFY(m != nullptr);
Chris@1359 82 //!!! Ah, now here we could do something a bit more informative
Chris@1359 83 }
Chris@1359 84
Chris@1359 85 };
Chris@1359 86
Chris@1359 87 #endif
Chris@1359 88