# HG changeset patch # User Lucas Thompson # Date 1523955829 -3600 # Node ID b5283878cca2ead064a76b78984577ee515330a3 # Parent bd73a689c8afdf2cb3ff6e9590a63957a9288804 Introduce a TestHelper which contains boiler plate for running a suite of QtTest style objects. Stub CSVStreamWriter and test to integrate into build. diff -r bd73a689c8af -r b5283878cca2 data/fileio/CSVStreamWriter.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/CSVStreamWriter.h Tue Apr 17 10:03:49 2018 +0100 @@ -0,0 +1,26 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Visualiser + An audio file viewer and annotation editor. + Centre for Digital Music, Queen Mary, University of London. + This file copyright 2017 Lucas Thompson. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef _CSV_STREAM_WRITER_H_ +#define _CSV_STREAM_WRITER_H_ + +class CSVStreamWriter +{ + +}; + +#endif + + diff -r bd73a689c8af -r b5283878cca2 data/fileio/test/CSVStreamWriterTest.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/test/CSVStreamWriterTest.h Tue Apr 17 10:03:49 2018 +0100 @@ -0,0 +1,34 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Visualiser + An audio file viewer and annotation editor. + Centre for Digital Music, Queen Mary, University of London. + This file copyright 2013 Chris Cannam. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef TEST_CSV_STREAM_H +#define TEST_CSV_STREAM_H + +#include +#include "../CSVStreamWriter.h" + +class CSVStreamWriterTest : public QObject +{ + Q_OBJECT +public: + +private slots: + void toDo() + { + + } +}; + +#endif \ No newline at end of file diff -r bd73a689c8af -r b5283878cca2 data/fileio/test/files.pri --- a/data/fileio/test/files.pri Mon Oct 09 11:09:21 2017 +0100 +++ b/data/fileio/test/files.pri Tue Apr 17 10:03:49 2018 +0100 @@ -1,10 +1,12 @@ TEST_HEADERS += \ - AudioFileReaderTest.h \ - AudioFileWriterTest.h \ - AudioTestData.h \ - EncodingTest.h \ - MIDIFileReaderTest.h - + ../../../test/TestHelper.h \ + AudioFileReaderTest.h \ + AudioFileWriterTest.h \ + AudioTestData.h \ + EncodingTest.h \ + MIDIFileReaderTest.h \ + CSVStreamWriterTest.h + TEST_SOURCES += \ - svcore-data-fileio-test.cpp + svcore-data-fileio-test.cpp diff -r bd73a689c8af -r b5283878cca2 data/fileio/test/svcore-data-fileio-test.cpp --- a/data/fileio/test/svcore-data-fileio-test.cpp Mon Oct 09 11:09:21 2017 +0100 +++ b/data/fileio/test/svcore-data-fileio-test.cpp Tue Apr 17 10:03:49 2018 +0100 @@ -12,19 +12,15 @@ COPYING included with this distribution for more information. */ +#include "../../../test/TestHelper.h" #include "AudioFileReaderTest.h" #include "AudioFileWriterTest.h" #include "EncodingTest.h" #include "MIDIFileReaderTest.h" - -#include - -#include +#include "CSVStreamWriterTest.h" int main(int argc, char *argv[]) { - int good = 0, bad = 0; - QString testDir; #ifdef Q_OS_WIN @@ -42,40 +38,16 @@ cerr << "Setting test directory base path to \"" << testDir << "\"" << endl; } - QCoreApplication app(argc, argv); - app.setOrganizationName("sonic-visualiser"); - app.setApplicationName("test-fileio"); - - { - AudioFileReaderTest t(testDir); - if (QTest::qExec(&t, argc, argv) == 0) ++good; - else ++bad; - } - - { - AudioFileWriterTest t(testDir); - if (QTest::qExec(&t, argc, argv) == 0) ++good; - else ++bad; - } - - { - EncodingTest t(testDir); - if (QTest::qExec(&t, argc, argv) == 0) ++good; - else ++bad; - } - - { - MIDIFileReaderTest t(testDir); - if (QTest::qExec(&t, argc, argv) == 0) ++good; - else ++bad; - } - - if (bad > 0) { - cerr << "\n********* " << bad << " test suite(s) failed!\n" << endl; - return 1; - } else { - cerr << "All tests passed" << endl; - return 0; - } + return Test::startTestRunner( + { + Test::createFactory(testDir), + Test::createFactory(testDir), + Test::createFactory(testDir), + Test::createFactory(testDir), + Test::createFactory() + }, + argc, + argv, + "test-fileio" + ); } - diff -r bd73a689c8af -r b5283878cca2 files.pri --- a/files.pri Mon Oct 09 11:09:21 2017 +0100 +++ b/files.pri Tue Apr 17 10:03:49 2018 +0100 @@ -51,6 +51,7 @@ data/fileio/CSVFileReader.h \ data/fileio/CSVFileWriter.h \ data/fileio/CSVFormat.h \ + data/fileio/CSVStreamWriter.h \ data/fileio/DataFileReader.h \ data/fileio/DataFileReaderFactory.h \ data/fileio/FileFinder.h \ @@ -180,6 +181,7 @@ data/fileio/CSVFileReader.cpp \ data/fileio/CSVFileWriter.cpp \ data/fileio/CSVFormat.cpp \ + data/fileio/CSVStreamWriter.cpp \ data/fileio/DataFileReaderFactory.cpp \ data/fileio/FileReadThread.cpp \ data/fileio/FileSource.cpp \ diff -r bd73a689c8af -r b5283878cca2 test/TestHelper.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/TestHelper.h Tue Apr 17 10:03:49 2018 +0100 @@ -0,0 +1,73 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Visualiser + An audio file viewer and annotation editor. + Centre for Digital Music, Queen Mary, University of London. + This file copyright 2017 Lucas Thompson. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef _TEST_HELPER_H_ +#define _TEST_HELPER_H_ + +#include +#include +#include +#include + +#include + +namespace Test +{ + +template +using Factory = std::function()>; + +template +auto createFactory(Args... FArgs) -> Factory +{ + return [&]() { return std::unique_ptr { new T {FArgs...} }; }; +} + +using TestStatus = int; + +auto startTestRunner( + std::initializer_list> tests, + int argc, + char *argv[], + QString testName, + QString orgName = "sonic-visualiser" +) -> TestStatus +{ + int good = 0, bad = 0; + + QCoreApplication app(argc, argv); + app.setOrganizationName(orgName); + app.setApplicationName(testName); + auto executeTest = [&](std::unique_ptr t) { + if (QTest::qExec(t.get(), argc, argv) == 0) ++good; + else ++bad; + }; + + for (const auto& test : tests) { + executeTest(test()); + } + + if (bad > 0) { + cerr << "\n********* " << bad << " test suite(s) failed!\n" << endl; + return 1; + } else { + cerr << "All tests passed" << endl; + return 0; + } +} + +} // namespace + +#endif \ No newline at end of file