2009-02-09 17:32:38 -05:00
|
|
|
#include "SequenceTest.hpp"
|
|
|
|
#include <cassert>
|
|
|
|
|
2009-02-11 15:20:41 -05:00
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(SequenceTest);
|
2009-02-09 17:32:38 -05:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2009-10-19 11:26:56 -04:00
|
|
|
void
|
2009-10-19 12:09:20 -04:00
|
|
|
SequenceTest::createTest ()
|
2009-02-09 17:32:38 -05:00
|
|
|
{
|
2009-02-11 15:20:41 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL(size_t(0), seq->sysexes().size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(size_t(0), seq->notes().size());
|
|
|
|
CPPUNIT_ASSERT(seq->notes().begin() == seq->notes().end());
|
2009-02-09 17:32:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-19 11:26:56 -04:00
|
|
|
void
|
2009-10-19 12:09:20 -04:00
|
|
|
SequenceTest::preserveEventOrderingTest ()
|
2009-02-09 17:32:38 -05:00
|
|
|
{
|
2009-02-11 15:20:41 -05:00
|
|
|
vector< boost::shared_ptr< Event<Time> > > inserted_events;
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
seq->start_write();
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
for (Notes::const_iterator i = test_notes.begin(); i != test_notes.end(); ++i) {
|
|
|
|
uint8_t buffer[2];
|
|
|
|
Event<Time>* event = new Event<Time>(
|
|
|
|
DummyTypeMap::CONTROL, (*i)->on_event().time(), 3, buffer, true
|
|
|
|
);
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
event->buffer()[0] = MIDI_CMD_CONTROL;
|
|
|
|
event->buffer()[1] = event->time() / 100;
|
|
|
|
event->buffer()[2] = event->time() / 100;
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
boost::shared_ptr<Event<Time> > event_ptr(event);
|
|
|
|
|
|
|
|
seq->append((*i)->on_event());
|
|
|
|
inserted_events.push_back(
|
|
|
|
boost::shared_ptr<Event<Time> >(
|
|
|
|
new Event<Time>((*i)->on_event(), true)
|
|
|
|
));
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
seq->append(*event_ptr);
|
|
|
|
inserted_events.push_back(event_ptr);
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
seq->append((*i)->off_event());
|
|
|
|
inserted_events.push_back(
|
|
|
|
boost::shared_ptr<Event<Time> >(
|
|
|
|
new Event<Time>((*i)->off_event(), true)
|
|
|
|
));
|
|
|
|
}
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
seq->end_write();
|
|
|
|
|
|
|
|
TestSink<Time> sink;
|
2009-02-11 15:20:41 -05:00
|
|
|
sink.writing.connect(sigc::mem_fun(&sink, &TestSink<Time>::assertLastEventTimeEarlier));
|
2009-02-09 17:32:38 -05:00
|
|
|
|
2009-02-14 20:24:26 -05:00
|
|
|
|
|
|
|
for (MySequence<Time>::const_iterator i = seq->begin(); i != seq->end(); ++i) {
|
|
|
|
sink.write(i->time(), i->event_type(), i->size(), i->buffer());
|
|
|
|
}
|
2009-10-19 11:26:56 -04:00
|
|
|
|
2009-02-09 17:32:38 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL(size_t(12), test_notes.size());
|
|
|
|
}
|
2009-02-14 20:24:26 -05:00
|
|
|
|
2009-10-19 12:09:20 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
SequenceTest::iteratorSeekTest ()
|
|
|
|
{
|
|
|
|
size_t num_notes = 0;
|
|
|
|
|
|
|
|
seq->clear();
|
|
|
|
|
|
|
|
for (Notes::const_iterator i = test_notes.begin(); i != test_notes.end(); ++i) {
|
2009-10-19 12:14:55 -04:00
|
|
|
seq->notes().insert(*i);
|
2009-10-19 12:09:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool on = true;
|
|
|
|
for (Sequence<Time>::const_iterator i = seq->begin(600); i != seq->end(); ++i) {
|
|
|
|
if (on) {
|
|
|
|
CPPUNIT_ASSERT(((MIDIEvent<Time>&)*i).is_note_on());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(i->time(), Time((num_notes + 6) * 100));
|
|
|
|
++num_notes;
|
|
|
|
on = false;
|
|
|
|
} else {
|
|
|
|
CPPUNIT_ASSERT(((MIDIEvent<Time>&)*i).is_note_off());
|
|
|
|
on = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(num_notes, size_t(6));
|
|
|
|
}
|