13
0

Improve coverage of evoral tests

This commit is contained in:
David Robillard 2016-12-04 15:17:08 -05:00
parent 9aac954744
commit 9dbc524060
4 changed files with 100 additions and 6 deletions

View File

@ -38,6 +38,54 @@ using namespace Evoral;
); \
}
void
CurveTest::trivial ()
{
float vec[1024];
boost::shared_ptr<Evoral::ControlList> cl = TestCtrlList();
cl->create_curve ();
// Empty curve
cl->curve().get_vector (1024.0, 2047.0, vec, 1024);
for (int i = 0; i < 1024; ++i) {
CPPUNIT_ASSERT_EQUAL (0.0f, vec[i]);
}
// Single point curve
cl->fast_simple_add(0.0, 42.0);
cl->curve().get_vector (1024.0, 2047.0, vec, 1024);
for (int i = 0; i < 1024; ++i) {
CPPUNIT_ASSERT_EQUAL (42.0f, vec[i]);
}
}
void
CurveTest::rtGet ()
{
float vec[1024];
// Create simple control list
boost::shared_ptr<Evoral::ControlList> cl = TestCtrlList();
cl->create_curve ();
cl->fast_simple_add(0.0, 42.0);
{
// Write-lock list
Glib::Threads::RWLock::WriterLock lm(cl->lock());
// Attempt to get vector in RT (expect failure)
CPPUNIT_ASSERT (!cl->curve().rt_safe_get_vector (1024.0, 2047.0, vec, 1024));
}
// Attempt to get vector in RT (expect success)
CPPUNIT_ASSERT (cl->curve().rt_safe_get_vector (1024.0, 2047.0, vec, 1024));
for (int i = 0; i < 1024; ++i) {
CPPUNIT_ASSERT_EQUAL (42.0f, vec[i]);
}
}
void
CurveTest::twoPointLinear ()
{

View File

@ -6,6 +6,8 @@
class CurveTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE (CurveTest);
CPPUNIT_TEST (trivial);
CPPUNIT_TEST (rtGet);
CPPUNIT_TEST (twoPointLinear);
CPPUNIT_TEST (threePointLinear);
CPPUNIT_TEST (threePointDiscete);
@ -14,6 +16,8 @@ class CurveTest : public CppUnit::TestFixture
CPPUNIT_TEST_SUITE_END ();
public:
void trivial ();
void rtGet ();
void twoPointLinear ();
void threePointLinear ();
void threePointDiscete ();

View File

@ -14,6 +14,18 @@ SequenceTest::createTest ()
CPPUNIT_ASSERT(seq->notes().begin() == seq->notes().end());
}
void
SequenceTest::copyTest ()
{
DummyTypeMap map;
MySequence<Time> a(map);
for (Notes::const_iterator i = test_notes.begin(); i != test_notes.end(); ++i) {
a.notes().insert(*i);
}
MySequence<Time> b(a);
CPPUNIT_ASSERT_EQUAL(b.notes().size(), a.notes().size());
}
void
SequenceTest::preserveEventOrderingTest ()
@ -74,6 +86,7 @@ SequenceTest::iteratorSeekTest ()
seq->notes().insert(*i);
}
// Iterate over all notes
bool on = true;
for (Sequence<Time>::const_iterator i = seq->begin(Evoral::Beats(600)); i != seq->end(); ++i) {
if (on) {
@ -87,7 +100,38 @@ SequenceTest::iteratorSeekTest ()
}
}
CPPUNIT_ASSERT_EQUAL(num_notes, size_t(6));
CPPUNIT_ASSERT_EQUAL(size_t(6), num_notes);
// Test invalidation
Sequence<Time>::const_iterator i = seq->begin(Time(600));
std::set< boost::weak_ptr< Note<Time> > > active_notes;
i.invalidate(&active_notes);
CPPUNIT_ASSERT_EQUAL((size_t)1, active_notes.size());
// Test resuming after invalidation
i = seq->begin(Time(601), false, std::set<Evoral::Parameter>(), &active_notes);
CPPUNIT_ASSERT(i->is_note_off());
on = false;
num_notes = 1;
for (; i != seq->end(); ++i) {
if (on) {
CPPUNIT_ASSERT(i->is_note_on());
CPPUNIT_ASSERT_EQUAL(Time((num_notes + 6) * 100), i->time());
++num_notes;
on = false;
} else {
CPPUNIT_ASSERT(i->is_note_off());
on = true;
}
}
CPPUNIT_ASSERT_EQUAL(size_t(6), num_notes);
// Test equality of copied iterators
i = seq->begin();
++i;
Sequence<Time>::const_iterator j = i;
CPPUNIT_ASSERT(i == j);
}
void
@ -149,9 +193,4 @@ SequenceTest::controlInterpolationTest ()
last_time = i->first;
last_value = i->second;
}
// Add some notes
for (Notes::const_iterator i = test_notes.begin(); i != test_notes.end(); ++i) {
seq->notes().insert(*i);
}
}

View File

@ -52,6 +52,7 @@ template<typename Time>
class MySequence : public Sequence<Time> {
public:
MySequence(DummyTypeMap&map) : Sequence<Time>(map) {}
MySequence(const MySequence& copy) : ControlSet(copy), Sequence<Time>(copy) {}
virtual bool find_next_event(double start, double end, ControlEvent& ev, bool only_active) const { return false; }
@ -111,6 +112,7 @@ class SequenceTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE (SequenceTest);
CPPUNIT_TEST (createTest);
CPPUNIT_TEST (copyTest);
CPPUNIT_TEST (preserveEventOrderingTest);
CPPUNIT_TEST (iteratorSeekTest);
CPPUNIT_TEST (controlInterpolationTest);
@ -140,6 +142,7 @@ public:
}
void createTest ();
void copyTest ();
void preserveEventOrderingTest ();
void iteratorSeekTest ();
void controlInterpolationTest ();