MIDIClock_SlaveTest: refactor as subclass of MIDIClock_Slave for testability
[ardour.git] / libs / ardour / test / midi_clock_slave_test.h
1 /* 
2  * Copyright(C) 2000-2008 Paul Davis
3  * Author: Hans Baier
4  * 
5  * Evoral is free software; you can redistribute it and/or modify it under the
6  * terms of the GNU General Public License as published by the Free Software
7  * Foundation; either version 2 of the License, or(at your option) any later
8  * version.
9  * 
10  * Evoral is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for details.
13  * 
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 #include <cassert>
20 #include <stdint.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
23
24 #include "ardour/tempo.h"
25 #include "ardour/slave.h"
26
27 namespace ARDOUR {
28
29 class TestSlaveSessionProxy : public ISlaveSessionProxy {
30   #define FRAME_RATE 44100
31   nframes64_t _period_size;
32
33   double       transport_speed;
34   nframes64_t _transport_frame;
35   nframes64_t _frame_time;
36   TempoMap    _tempo_map;
37
38   Tempo     tempo;
39   Meter     meter;
40   BBT_Time  zero;
41
42   public:
43         TestSlaveSessionProxy() : 
44            transport_speed  (1.0), 
45           _transport_frame  (0), 
46           _frame_time       (1000000),
47           _tempo_map        (FRAME_RATE),
48           tempo             (120),
49           meter             (4.0, 4.0)
50         {
51           _tempo_map.add_tempo (tempo, zero);
52           _tempo_map.add_meter (meter, zero);          
53         }
54
55         // Controlling the mock object
56         void set_period_size (nframes64_t a_size) { _period_size = a_size; }
57         void next_period ()                       { 
58           _transport_frame += _period_size; 
59           _frame_time += _period_size;
60         }
61
62         // Implementation
63         TempoMap&   tempo_map ()                { return _tempo_map; }
64         nframes_t   frame_rate ()               const { return FRAME_RATE; }
65         nframes64_t audible_frame ()            const { return _transport_frame; }
66         nframes64_t transport_frame ()          const { return _transport_frame; }
67         nframes_t   frames_since_cycle_start () const { return 0; }
68         nframes64_t frame_time ()               const { return _frame_time; }
69
70         void request_locate (nframes64_t frame, bool with_roll = false) { 
71           _transport_frame = frame; 
72         }
73
74         void request_transport_speed (const double speed) { transport_speed = speed; }
75 };
76
77 class MIDIClock_SlaveTest : public CppUnit::TestFixture, ARDOUR::MIDIClock_Slave
78 {
79     CPPUNIT_TEST_SUITE(MIDIClock_SlaveTest);
80     CPPUNIT_TEST(testStepResponse);
81     CPPUNIT_TEST_SUITE_END();
82
83     public:
84         
85         void setUp() {
86           session = new TestSlaveSessionProxy ();
87         }
88         
89         void tearDown() {
90         }
91
92         void testStepResponse();
93 };
94
95 } // namespace ARDOUR