summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2018-06-16 16:32:02 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2018-06-16 16:32:02 +0200
commite694a23ab28686ecc0635c2ac8c625e743b89a3b (patch)
treea600834559486d845aa5b9bc58bdf653a0a0d6aa
parentd01b79c6e16760e7a5ef44b5f600246c8a98972e (diff)
Experimentally port drumkitparsertest to DGUnit.
-rw-r--r--test/Makefile.am7
-rw-r--r--test/dgtest.cc37
-rw-r--r--test/dgunit.h58
-rw-r--r--test/drumkitparsertest.cc45
4 files changed, 85 insertions, 62 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index bf21a0b..56b7f72 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -223,14 +223,13 @@ instrumentparsertest_SOURCES = \
scopedfile.cc \
test.cc
-drumkitparsertest_CXXFLAGS = -DOUTPUT=\"drumkitparsertest\" $(CPPUNIT_CFLAGS) \
+drumkitparsertest_CXXFLAGS = -DOUTPUT=\"drumkitparsertest\" \
-I$(top_srcdir)/src -I$(top_srcdir)/include
-drumkitparsertest_LDFLAGS = $(CPPUNIT_LIBS) \
- $(top_srcdir)/src/libdg.la
+drumkitparsertest_LDFLAGS = $(top_srcdir)/src/libdg.la
drumkitparsertest_SOURCES = \
$(top_srcdir)/hugin/hugin.c \
drumkitparsertest.cc \
scopedfile.cc \
- test.cc
+ dgtest.cc
endif
diff --git a/test/dgtest.cc b/test/dgtest.cc
new file mode 100644
index 0000000..21e1543
--- /dev/null
+++ b/test/dgtest.cc
@@ -0,0 +1,37 @@
+/* -*- Mode: c++ -*- */
+/***************************************************************************
+ * dgtest.cc
+ *
+ * Sat Jun 16 15:48:36 CEST 2018
+ * Copyright 2018 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#define DGUNIT_MAIN
+#include "dgunit.h"
+
+#include <fstream>
+
+int main(int argc, char* argv[])
+{
+ std::ofstream xmlfile;
+ xmlfile.open("result_" OUTPUT ".xml");
+ return DGUnit::runTests(xmlfile);
+}
diff --git a/test/dgunit.h b/test/dgunit.h
index 4439134..5bb47bb 100644
--- a/test/dgunit.h
+++ b/test/dgunit.h
@@ -29,6 +29,7 @@
#include <cstddef>
#include <iostream>
#include <list>
+#include <vector>
#include <functional>
#include <string>
#include <sstream>
@@ -37,11 +38,19 @@
class DGUnit
{
public:
- DGUnit(const std::string& test_name, const std::string& test_suite = "all")
- : test_name(test_name)
- , test_suite(test_suite)
+ DGUnit()
{
- suites.emplace_back(this);
+ if(DGUnit::suite_list == nullptr)
+ {
+ DGUnit::suite_list = this;
+ return;
+ }
+
+ auto unit = DGUnit::suite_list;
+ while(unit->next_unit)
+ {
+ }
+ unit->next_unit = this;
}
//! Overload to prepare stuff for each of the tests.
@@ -52,8 +61,8 @@ public:
struct test_result
{
- const char* func;
- const char* file;
+ std::string func;
+ std::string file;
std::size_t line;
std::string msg;
int id;
@@ -63,9 +72,7 @@ public:
//! \param test_suite the name of a test suite or null for all.
//! \param test_name the name of a test name inside a test suite. Only valid
//! if test_suite is non-null. nullptr for all tests.
- static int runTests(std::ofstream& out,
- const std::string& test_suite = "all",
- const std::string& test_name = "all")
+ static int runTests(std::ofstream& out)
{
std::size_t test_num{0};
std::size_t failed{0};
@@ -73,22 +80,8 @@ public:
std::list<test_result> failed_tests;
std::list<test_result> successful_tests;
- std::cout << "Run tests\n";
- for(auto suite : suites)
+ for(auto suite = DGUnit::suite_list; suite; suite = suite->next_unit)
{
- if(test_suite != "all" && suite->test_suite != test_suite)
- {
- continue;
- }
-
- if(test_name != "all" && suite->test_name != test_name)
- {
- continue;
- }
-
- std::cout << "Test: " << suite->test_suite << "::"
- << suite->test_name << std::endl;
-
for(auto test : suite->tests)
{
++test_num;
@@ -115,7 +108,7 @@ public:
fflush(stdout);
test_result result{test.second};
result.id = test_num;
- successful_tests.emplace_back(result);
+ successful_tests.push_back(result);
}
}
@@ -134,7 +127,7 @@ public:
out << " <Message>" << test.msg << "</Message>\n";
out << " </FailedTest>\n";
}
- out << " <FailedTests>\n";
+ out << " </FailedTests>\n";
out << " <SuccessfulTests>\n";
for(auto test : successful_tests)
{
@@ -164,7 +157,7 @@ protected:
#define DGUNIT_TEST(func) \
registerTest(this, &func, #func)
- void assert(bool value, const char* expr,
+ void dg_assert(bool value, const char* expr,
const char* file, std::size_t line)
{
if(!value)
@@ -177,7 +170,7 @@ protected:
}
//! Convenience macro to pass along filename and linenumber
#define DGUNIT_ASSERT(value) \
- assert(value, #value, __FILE__, __LINE__)
+ dg_assert(value, #value, __FILE__, __LINE__)
template<typename T>
void assert_equal(T expected, T value,
@@ -197,12 +190,11 @@ protected:
assert_equal(expected, value, __FILE__, __LINE__)
private:
- static std::list<class DGUnit*> suites;
- std::list<std::pair<std::function<void()>, const char*>> tests;
- const std::string test_name;
- const std::string test_suite;
+ static DGUnit* suite_list;
+ DGUnit* next_unit{nullptr};
+ std::vector<std::pair<std::function<void()>, const char*>> tests;
};
#ifdef DGUNIT_MAIN
-std::list<class DGUnit*> DGUnit::suites;
+DGUnit* DGUnit::suite_list{nullptr};
#endif
diff --git a/test/drumkitparsertest.cc b/test/drumkitparsertest.cc
index 13bb752..e2d30fc 100644
--- a/test/drumkitparsertest.cc
+++ b/test/drumkitparsertest.cc
@@ -24,7 +24,7 @@
* along with DrumGizmo; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#include <cppunit/extensions/HelperMacros.h>
+#include "dgunit.h"
#include <drumkitparser.h>
#include <drumkit.h>
@@ -32,23 +32,18 @@
#include "scopedfile.h"
class DrumkitParserTest
- : public CppUnit::TestFixture
+ : public DGUnit
{
- CPPUNIT_TEST_SUITE(DrumkitParserTest);
- CPPUNIT_TEST(testTest);
- CPPUNIT_TEST_SUITE_END();
-
- Settings settings;
- Random rand;
-
public:
- void setUp()
+ DrumkitParserTest()
+ : DGUnit()
{
+ std::cout << __PRETTY_FUNCTION__ << "\n";
+ DGUNIT_TEST(DrumkitParserTest::testTest);
}
- void tearDown()
- {
- }
+ Settings settings;
+ Random rand;
//! This just creates some drumkit.
void testTest()
@@ -120,23 +115,23 @@ public:
DrumKit drumkit;
DrumKitParser parser(settings, drumkit, rand);
- CPPUNIT_ASSERT_EQUAL(0, parser.parseFile(scoped_file.filename()));
+ DGUNIT_ASSERT_EQUAL(0, parser.parseFile(scoped_file.filename()));
- CPPUNIT_ASSERT_EQUAL(std::size_t(2), drumkit.instruments.size());
- CPPUNIT_ASSERT_EQUAL(std::size_t(4), drumkit.channels.size());
+ DGUNIT_ASSERT_EQUAL(std::size_t(2), drumkit.instruments.size());
+ DGUNIT_ASSERT_EQUAL(std::size_t(4), drumkit.channels.size());
- CPPUNIT_ASSERT_EQUAL(std::string("AmbLeft"), drumkit.channels[0].name);
- CPPUNIT_ASSERT_EQUAL(std::string("AmbRight"), drumkit.channels[1].name);
- CPPUNIT_ASSERT_EQUAL(std::string("SnareTop"), drumkit.channels[2].name);
- CPPUNIT_ASSERT_EQUAL(std::string("SnareBottom"), drumkit.channels[3].name);
+ DGUNIT_ASSERT_EQUAL(std::string("AmbLeft"), drumkit.channels[0].name);
+ DGUNIT_ASSERT_EQUAL(std::string("AmbRight"), drumkit.channels[1].name);
+ DGUNIT_ASSERT_EQUAL(std::string("SnareTop"), drumkit.channels[2].name);
+ DGUNIT_ASSERT_EQUAL(std::string("SnareBottom"), drumkit.channels[3].name);
- CPPUNIT_ASSERT_EQUAL(std::string("CrocellKit"), drumkit._name);
- CPPUNIT_ASSERT_EQUAL(std::string("my description"), drumkit._description);
- CPPUNIT_ASSERT_EQUAL(std::size_t(48000), drumkit._samplerate);
+ DGUNIT_ASSERT_EQUAL(std::string("CrocellKit"), drumkit._name);
+ DGUNIT_ASSERT_EQUAL(std::string("my description"), drumkit._description);
+ DGUNIT_ASSERT_EQUAL(std::size_t(48000), drumkit._samplerate);
- CPPUNIT_ASSERT(VersionStr("2.0.0") == drumkit._version);
+ DGUNIT_ASSERT(VersionStr("2.0.0") == drumkit._version);
}
};
// Registers the fixture into the 'registry'
-CPPUNIT_TEST_SUITE_REGISTRATION(DrumkitParserTest);
+DrumkitParserTest drumkit_parser_test;