Fix some bits of the libardour unit tests.
[ardour.git] / libs / ardour / test / mantis_3356.cc
1 #include <stdexcept>
2 #include "midi++/manager.h"
3 #include "pbd/textreceiver.h"
4 #include "ardour/session.h"
5 #include "ardour/audioengine.h"
6 #include "ardour/smf_source.h"
7 #include "ardour/midi_model.h"
8 #include "test/mantis_3356.h"
9
10 CPPUNIT_TEST_SUITE_REGISTRATION (Mantis3356Test);
11
12 using namespace std;
13 using namespace ARDOUR;
14 using namespace PBD;
15
16 TextReceiver text_receiver ("test");
17
18 void
19 Mantis3356Test::test ()
20 {
21         init (false, true);
22         SessionEvent::create_per_thread_pool ("test", 512);
23
24         text_receiver.listen_to (error);
25         text_receiver.listen_to (info);
26         text_receiver.listen_to (fatal);
27         text_receiver.listen_to (warning);
28
29         AudioEngine engine ("test", "");
30         MIDI::Manager::create (engine.jack ());
31         CPPUNIT_ASSERT (engine.start () == 0);
32
33         Session session (engine, "../libs/ardour/test/data/mantis_3356", "mantis_3356");
34         engine.set_session (&session);
35
36         Session::SourceMap sources = session.get_sources ();
37
38         boost::shared_ptr<SMFSource> source = boost::dynamic_pointer_cast<SMFSource> (sources[ID ("87")]);
39         CPPUNIT_ASSERT (source);
40
41         boost::shared_ptr<MidiModel> model = source->model ();
42         CPPUNIT_ASSERT (model);
43
44         stringstream result;
45
46         for (MidiModel::const_iterator i = model->begin(); i != model->end(); ++i) {
47                 result << *i << "\n";
48         }
49
50         ifstream ref ("../libs/ardour/test/data/mantis_3356.ref");
51
52         while (1) {
53                 string a;
54                 string b;
55
56                 getline (ref, a);
57                 getline (result, b);
58
59                 CPPUNIT_ASSERT (a == b);
60
61                 if (result.eof() && ref.eof()) {
62                         break;
63                 }
64
65                 CPPUNIT_ASSERT (!result.eof ());
66                 CPPUNIT_ASSERT (!ref.eof ());
67         }
68
69 }