mvlc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,66 @@
1
+ require "helper"
2
+
3
+ class MVLC::Instructions::PlayerTest < Minitest::Test
4
+
5
+ context "Player" do
6
+
7
+ setup do
8
+ @player = Object.new
9
+ @player.stubs(:quit)
10
+ @player.stubs(:seek).returns(true)
11
+ VLC::System.stubs(:new).returns(@player)
12
+ @input = Object.new
13
+ @context = MVLC::Context.new(@input)
14
+ assert @context.kind_of?(MVLC::Instructions::Player)
15
+ end
16
+
17
+ context "#on_end_of_file" do
18
+
19
+ setup do
20
+ @context.player.expects(:add_end_of_file_callback).once.returns({})
21
+ end
22
+
23
+ teardown do
24
+ @context.player.unstub(:add_end_of_file_callback)
25
+ end
26
+
27
+ should "assign callback" do
28
+ refute_nil @context.on_end_of_file { something }
29
+ end
30
+
31
+ end
32
+
33
+ context "#method_missing" do
34
+
35
+ setup do
36
+ @context.player.expects(:mplayer_send).once.with(:seek, 50, :percent).returns(true)
37
+ end
38
+
39
+ teardown do
40
+ @context.player.unstub(:mplayer_send)
41
+ end
42
+
43
+ should "delegate" do
44
+ refute_nil @context.seek(50, :percent)
45
+ end
46
+
47
+ end
48
+
49
+ context "#respond_to?" do
50
+
51
+ setup do
52
+ @context.player.expects(:mplayer_respond_to?).once.with(:seek).returns(true)
53
+ end
54
+
55
+ teardown do
56
+ @context.player.unstub(:mplayer_respond_to?)
57
+ end
58
+
59
+ should "delegate" do
60
+ refute_nil @context.respond_to?(:seek)
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+ end
data/test/media/1.mov ADDED
Binary file
data/test/media/2.mov ADDED
Binary file
data/test/media/3.mov ADDED
Binary file
@@ -0,0 +1,315 @@
1
+ require "helper"
2
+
3
+ class MVLC::MIDI::MessageHandlerTest < Minitest::Test
4
+
5
+ context "MessageHandler" do
6
+
7
+ setup do
8
+ @handler = MVLC::MIDI::MessageHandler.new
9
+ end
10
+
11
+ context "#note_message" do
12
+
13
+ setup do
14
+ @message = MIDIMessage::NoteOn.new(0, 10, 100)
15
+ end
16
+
17
+ context "callback exists" do
18
+
19
+ setup do
20
+ @var = nil
21
+ @callback = proc { |vel| @var = vel }
22
+ @handler.add_callback(:note, @message.note, &@callback)
23
+ @callback.expects(:call).once
24
+ end
25
+
26
+ teardown do
27
+ @callback.unstub(:call)
28
+ end
29
+
30
+ context "has catch-all callback" do
31
+
32
+ setup do
33
+ @var2 = nil
34
+ @catchall = proc { |vel| @var2 = vel }
35
+ @handler.add_callback(:note, nil, &@catchall)
36
+ @catchall.expects(:call).once
37
+ end
38
+
39
+ teardown do
40
+ @catchall.unstub(:call)
41
+ end
42
+
43
+ should "call both callbacks" do
44
+ assert @handler.send(:note_message, @message)
45
+ end
46
+
47
+ end
48
+
49
+ context "no catch-all callback" do
50
+
51
+ should "call specific callback" do
52
+ assert @handler.send(:note_message, @message)
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+
59
+ context "callback doesn't exist" do
60
+
61
+ context "has catch-all callback" do
62
+
63
+ setup do
64
+ @var = nil
65
+ @callback = proc { |vel| @var = vel }
66
+ @handler.add_callback(:note, nil, &@callback)
67
+ @callback.expects(:call).once
68
+ end
69
+
70
+ should "call callback" do
71
+ assert @handler.send(:note_message, @message)
72
+ end
73
+
74
+ end
75
+
76
+ context "no catch-all callback" do
77
+
78
+ should "do nothing" do
79
+ refute @handler.send(:note_message, @message)
80
+ end
81
+
82
+ end
83
+
84
+ end
85
+
86
+ end
87
+
88
+ context "#cc_message" do
89
+
90
+ setup do
91
+ @message = MIDIMessage::ControlChange.new(0, 8, 100)
92
+ end
93
+
94
+ context "callback exists" do
95
+
96
+ setup do
97
+ @var = nil
98
+ @callback = proc { |vel| @var = vel }
99
+ @handler.add_callback(:cc, @message.index, &@callback)
100
+ @callback.expects(:call).once
101
+ end
102
+
103
+ teardown do
104
+ @callback.unstub(:call)
105
+ end
106
+
107
+ should "call callback" do
108
+ assert @handler.send(:cc_message, @message)
109
+ end
110
+
111
+ end
112
+
113
+ context "callback doesn't exist" do
114
+
115
+ context "has catch-all callback" do
116
+
117
+ setup do
118
+ @var = nil
119
+ @callback = proc { |vel| @var = vel }
120
+ @handler.add_callback(:cc, nil, &@callback)
121
+ @callback.expects(:call).once
122
+ end
123
+
124
+ should "call callback" do
125
+ assert @handler.send(:cc_message, @message)
126
+ end
127
+
128
+ end
129
+
130
+ context "no catch-all callback" do
131
+
132
+ should "do nothing" do
133
+ refute @handler.send(:cc_message, @message)
134
+ end
135
+
136
+ end
137
+
138
+ end
139
+
140
+ end
141
+
142
+ context "#system_message" do
143
+
144
+ setup do
145
+ @message = MIDIMessage::SystemRealtime.new(0x8) # clock
146
+ end
147
+
148
+ context "callback exists" do
149
+
150
+ setup do
151
+ @var = nil
152
+ @callback = proc { |vel| @var = vel }
153
+ @handler.add_callback(:system, :clock, &@callback)
154
+ @callback.expects(:call).once
155
+ end
156
+
157
+ teardown do
158
+ @callback.unstub(:call)
159
+ end
160
+
161
+ should "call callback" do
162
+ assert @handler.send(:system_message, @message)
163
+ end
164
+
165
+ end
166
+
167
+ context "callback doesn't exist" do
168
+
169
+ should "do nothing" do
170
+ refute @handler.send(:system_message, @message)
171
+ end
172
+
173
+ end
174
+
175
+ end
176
+
177
+ context "#channel_message" do
178
+
179
+ context "omni" do
180
+
181
+ setup do
182
+ @channel = nil
183
+ end
184
+
185
+ context "control change" do
186
+
187
+ setup do
188
+ @message = MIDIMessage::ControlChange.new(0, 8, 100)
189
+ @handler.expects(:cc_message).once.with(@message).returns(true)
190
+ end
191
+
192
+ teardown do
193
+ @handler.unstub(:cc_message)
194
+ end
195
+
196
+ should "handle control change" do
197
+ assert @handler.send(:channel_message, @channel, @message)
198
+ end
199
+
200
+ end
201
+
202
+ context "note" do
203
+
204
+ setup do
205
+ @message = MIDIMessage::NoteOn.new(0, 10, 100)
206
+ @handler.expects(:note_message).once.with(@message).returns(true)
207
+ end
208
+
209
+ teardown do
210
+ @handler.unstub(:note_message)
211
+ end
212
+
213
+ should "handle note" do
214
+ assert @handler.send(:channel_message, @channel, @message)
215
+ end
216
+
217
+ end
218
+
219
+ end
220
+
221
+ context "with channel" do
222
+
223
+ setup do
224
+ @channel = 5
225
+ end
226
+
227
+ context "control change" do
228
+
229
+ setup do
230
+ @message = MIDIMessage::ControlChange.new(@channel, 8, 100)
231
+ end
232
+
233
+ context "matching channel" do
234
+
235
+ setup do
236
+ @handler.expects(:cc_message).once.with(@message).returns(true)
237
+ end
238
+
239
+ teardown do
240
+ @handler.unstub(:cc_message)
241
+ end
242
+
243
+ should "handle control change" do
244
+ assert @handler.send(:channel_message, @channel, @message)
245
+ end
246
+
247
+ end
248
+
249
+ context "non matching channel" do
250
+
251
+ setup do
252
+ @handler.expects(:cc_message).never
253
+ @other_message = MIDIMessage::ControlChange.new(@channel + 1, 8, 100)
254
+ end
255
+
256
+ teardown do
257
+ @handler.unstub(:cc_message)
258
+ end
259
+
260
+ should "do nothing" do
261
+ refute @handler.send(:channel_message, @channel, @other_message)
262
+ end
263
+
264
+ end
265
+
266
+ end
267
+
268
+ context "note" do
269
+
270
+ setup do
271
+ @message = MIDIMessage::NoteOn.new(@channel, 10, 100)
272
+ end
273
+
274
+ context "matching channel" do
275
+
276
+ setup do
277
+ @handler.expects(:note_message).once.with(@message).returns(true)
278
+ end
279
+
280
+ teardown do
281
+ @handler.unstub(:note_message)
282
+ end
283
+
284
+ should "call callback" do
285
+ assert @handler.send(:channel_message, @channel, @message)
286
+ end
287
+
288
+ end
289
+
290
+ context "non matching channel" do
291
+
292
+ setup do
293
+ @handler.expects(:note_message).never
294
+ @other_message = MIDIMessage::ControlChange.new(@channel + 1, 8, 100)
295
+ end
296
+
297
+ teardown do
298
+ @handler.unstub(:note_message)
299
+ end
300
+
301
+ should "not call callback" do
302
+ refute @handler.send(:channel_message, @channel, @other_message)
303
+ end
304
+
305
+ end
306
+
307
+ end
308
+
309
+ end
310
+
311
+ end
312
+
313
+ end
314
+
315
+ end
@@ -0,0 +1,229 @@
1
+ require "helper"
2
+
3
+ class MVLC::MIDI::WrapperTest < Minitest::Test
4
+
5
+ context "Wrapper" do
6
+
7
+ setup do
8
+ @input = Object.new
9
+ @midi = MVLC::MIDI::Wrapper.new(@input)
10
+ end
11
+
12
+ context "#handle_new_event" do
13
+
14
+ context "with no buffer length" do
15
+
16
+ setup do
17
+ @midi.message_handler.expects(:process).once
18
+ @event = {
19
+ :message => MIDIMessage::NoteOn.new(0, 64, 120),
20
+ :timestamp=> 9266.395330429077
21
+ }
22
+ @result = @midi.send(:handle_new_event, @event)
23
+ end
24
+
25
+ teardown do
26
+ @midi.message_handler.unstub(:process)
27
+ end
28
+
29
+ should "return event" do
30
+ refute_nil @result
31
+ assert_equal @event, @result
32
+ end
33
+
34
+ end
35
+
36
+ context "with buffer length" do
37
+
38
+ context "recent message" do
39
+
40
+ setup do
41
+ @midi.message_handler.expects(:process).once
42
+ @event = {
43
+ :message => MIDIMessage::NoteOn.new(0, 64, 120),
44
+ :timestamp=> 9266.395330429077
45
+ }
46
+ @result = @midi.send(:handle_new_event, @event)
47
+ end
48
+
49
+ teardown do
50
+ @midi.message_handler.unstub(:process)
51
+ end
52
+
53
+ should "return event" do
54
+ refute_nil @result
55
+ assert_equal @event, @result
56
+ end
57
+
58
+ end
59
+
60
+ context "with too-old message" do
61
+
62
+ setup do
63
+ @midi.instance_variable_set("@buffer_length", 1)
64
+ @midi.instance_variable_set("@start_time", Time.now.to_i)
65
+ sleep(2)
66
+ @midi.message_handler.expects(:process).never
67
+ @event = {
68
+ :message => MIDIMessage::NoteOn.new(0, 64, 120),
69
+ :timestamp => 0.1
70
+ }
71
+ @result = @midi.send(:handle_new_event, @event)
72
+ end
73
+
74
+ teardown do
75
+ @midi.message_handler.unstub(:process)
76
+ end
77
+
78
+ should "not return event" do
79
+ assert_nil @result
80
+ end
81
+
82
+ end
83
+
84
+ end
85
+
86
+ end
87
+
88
+ context "#initialize_listener" do
89
+
90
+ setup do
91
+ @midi.listener.expects(:on_message).once
92
+ @result = @midi.send(:initialize_listener)
93
+ end
94
+
95
+ teardown do
96
+ @midi.listener.unstub(:on_message)
97
+ end
98
+
99
+ should "return listener" do
100
+ refute_nil @result
101
+ assert_equal MIDIEye::Listener, @result.class
102
+ end
103
+
104
+ end
105
+
106
+ context "#start" do
107
+
108
+ setup do
109
+ @midi.listener.expects(:on_message).once
110
+ @midi.listener.expects(:start).once
111
+ end
112
+
113
+ teardown do
114
+ @midi.listener.unstub(:on_message)
115
+ @midi.listener.unstub(:start)
116
+ end
117
+
118
+ should "activate callbacks" do
119
+ assert @midi.start
120
+ end
121
+
122
+ end
123
+
124
+ context "#add_note_callback" do
125
+
126
+ setup do
127
+ @var = nil
128
+ @midi.add_note_callback(10) { |vel| @var = vel }
129
+ end
130
+
131
+ should "store callback" do
132
+ refute_nil @midi.message_handler.callback[:note][10]
133
+ assert_equal Proc, @midi.message_handler.callback[:note][10].class
134
+ end
135
+
136
+ end
137
+
138
+ context "#add_system_callback" do
139
+
140
+ setup do
141
+ @var = nil
142
+ @midi.add_system_callback(:start) { |val| @var = val }
143
+ end
144
+
145
+ should "store callback" do
146
+ refute_nil @midi.message_handler.callback[:system][:start]
147
+ assert_equal Proc, @midi.message_handler.callback[:system][:start].class
148
+ end
149
+
150
+ end
151
+
152
+ context "#add_cc_callback" do
153
+
154
+ setup do
155
+ @var = nil
156
+ @midi.add_cc_callback(2) { |val| @var = val }
157
+ end
158
+
159
+ should "store callback" do
160
+ refute_nil @midi.message_handler.callback[:cc][2]
161
+ assert_equal Proc, @midi.message_handler.callback[:cc][2].class
162
+ end
163
+
164
+ end
165
+
166
+ context "#channel=" do
167
+
168
+ setup do
169
+ # stub out MIDIEye
170
+ @listener = Object.new
171
+ @listener.stubs(:event).returns([])
172
+ @midi.instance_variable_set("@listener", @listener)
173
+ end
174
+
175
+ teardown do
176
+ @listener.unstub(:clear)
177
+ @listener.unstub(:on_message)
178
+ @listener.unstub(:event)
179
+ @listener.unstub(:running?)
180
+ end
181
+
182
+ context "before listener is started" do
183
+
184
+ setup do
185
+ @listener.stubs(:running?).returns(false)
186
+ @listener.expects(:clear).never
187
+ @listener.expects(:on_message).never
188
+ end
189
+
190
+ should "change channel" do
191
+ assert_equal 3, @midi.channel = 3
192
+ assert_equal 3, @midi.channel
193
+ refute @midi.omni?
194
+ end
195
+
196
+ should "set channel nil" do
197
+ assert_nil @midi.channel = nil
198
+ assert_nil @midi.channel
199
+ assert @midi.omni?
200
+ end
201
+ end
202
+
203
+ context "after listener is started" do
204
+
205
+ setup do
206
+ @listener.stubs(:running?).returns(true)
207
+ @listener.expects(:clear).once
208
+ @listener.expects(:on_message).once
209
+ end
210
+
211
+ should "change channel" do
212
+ assert_equal 3, @midi.channel = 3
213
+ assert_equal 3, @midi.channel
214
+ refute @midi.omni?
215
+ end
216
+
217
+ should "set channel nil" do
218
+ assert_nil @midi.channel = nil
219
+ assert_nil @midi.channel
220
+ assert @midi.omni?
221
+ end
222
+
223
+ end
224
+
225
+ end
226
+
227
+ end
228
+
229
+ end