unimidi 0.4.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,113 +0,0 @@
1
- require "helper"
2
-
3
- class UniMIDI::FunctionalTest < Test::Unit::TestCase
4
-
5
- # ** these tests assume that TestOutput is connected to TestInput
6
- context "UniMIDI" do
7
-
8
- setup do
9
- @input = TestHelper.devices[:input].open
10
- @output = TestHelper.devices[:output].open
11
- end
12
-
13
- teardown do
14
- @input.close
15
- @output.close
16
- end
17
-
18
- context "full IO" do
19
-
20
- context "using numeric bytes" do
21
-
22
- setup do
23
- @messages = TestHelper.numeric_messages
24
- @messages_arr = @messages.inject(&:+).flatten
25
- @received_arr = []
26
- @pointer = 0
27
- end
28
-
29
- should "do IO" do
30
-
31
- @messages.each do |message|
32
- p "sending: #{message}"
33
-
34
- @output.puts(message)
35
- sleep(1)
36
- received = @input.gets.map { |m| m[:data] }.flatten
37
-
38
- p "received: #{received}"
39
-
40
- assert_equal(@messages_arr.slice(@pointer, received.length), received)
41
- @pointer += received.length
42
- @received_arr += received
43
- end
44
- assert_equal(@messages_arr.length, @received_arr.length)
45
- end
46
- end
47
-
48
- context "using byte Strings" do
49
-
50
- setup do
51
- @messages = TestHelper.string_messages
52
- @messages_str = @messages.join
53
- @received_str = ""
54
- @pointer = 0
55
- end
56
-
57
- should "do IO" do
58
-
59
- @messages.each do |message|
60
-
61
- p "sending: #{message}"
62
-
63
- @output.puts(message)
64
- sleep(1)
65
- received = @input.gets_bytestr.map { |m| m[:data] }.flatten.join
66
- p "received: #{received}"
67
-
68
- assert_equal(@messages_str.slice(@pointer, received.length), received)
69
- @pointer += received.length
70
- @received_str += received
71
- end
72
- assert_equal(@messages_str, @received_str)
73
-
74
- end
75
-
76
- end
77
-
78
- context "using MIDIMessages" do
79
-
80
- setup do
81
- @messages = TestHelper.message_objects
82
- @messages_arr = @messages.map(&:to_bytes).flatten
83
- @received_arr = []
84
- @pointer = 0
85
- end
86
-
87
- should "do IO" do
88
-
89
- @messages.each do |message|
90
-
91
- p "sending: #{message}"
92
-
93
- @output.puts(message)
94
- sleep(1)
95
- received = @input.gets.map { |m| m[:data] }.flatten
96
-
97
- p "received: #{received}"
98
-
99
- assert_equal(@messages_arr.slice(@pointer, received.length), received)
100
- @pointer += received.length
101
- @received_arr += received
102
- end
103
- assert_equal(@messages_arr.length, @received_arr.length)
104
-
105
- end
106
-
107
- end
108
-
109
- end
110
-
111
- end
112
-
113
- end
data/test/helper.rb DELETED
@@ -1,74 +0,0 @@
1
- dir = File.dirname(File.expand_path(__FILE__))
2
- $LOAD_PATH.unshift dir + '/../lib'
3
-
4
- require "test/unit"
5
- require "mocha/test_unit"
6
- require "shoulda-context"
7
- require "unimidi"
8
-
9
- module TestHelper
10
-
11
- extend self
12
-
13
- def sysex_ok?
14
- ENV["_system_name"] != "OSX" || !RUBY_PLATFORM.include?("java")
15
- end
16
-
17
- def devices
18
- if @devices.nil?
19
- @devices = {}
20
- { :input => UniMIDI::Input, :output => UniMIDI::Output }.each do |type, klass|
21
- @devices[type] = klass.gets
22
- end
23
- end
24
- @devices
25
- end
26
-
27
- def bytestrs_to_ints(arr)
28
- data = arr.map { |m| m[:data] }.join
29
- output = []
30
- until (bytestr = data.slice!(0,2)).eql?("")
31
- output << bytestr.hex
32
- end
33
- output
34
- end
35
-
36
- class MIDIObj
37
- def initialize(*bytes)
38
- @bytes = bytes
39
- end
40
- def to_bytes
41
- @bytes
42
- end
43
- end
44
-
45
- def message_objects
46
- numeric_messages.map { |message| MIDIObj.new(*message) }
47
- end
48
-
49
- def numeric_messages
50
- messages = [
51
- [0x90, 100, 100], # note on
52
- [0x90, 43, 100], # note on
53
- [0x90, 76, 100], # note on
54
- [0x90, 60, 100], # note on
55
- [0x80, 100, 100] # note off
56
- ]
57
- if sysex_ok?
58
- messages << [0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7F, 0x00, 0x41, 0xF7]
59
- end
60
- messages
61
- end
62
-
63
- def string_messages
64
- messages = [
65
- "906440", # note on
66
- "804340" # note off
67
- ]
68
- if sysex_ok?
69
- messages << "F04110421240007F0041F7"
70
- end
71
- messages
72
- end
73
-
74
- end
data/test/input_test.rb DELETED
@@ -1,44 +0,0 @@
1
- require 'helper'
2
-
3
- class UniMIDI::InputTest < Test::Unit::TestCase
4
-
5
- context "Input" do
6
-
7
- context "#buffer" do
8
-
9
- setup do
10
- sleep(1)
11
- @input = TestHelper.devices[:input].open
12
- @output = TestHelper.devices[:output].open
13
- @messages = TestHelper.numeric_messages
14
- @bytes = []
15
- end
16
-
17
- teardown do
18
- @input.close
19
- @output.close
20
- end
21
-
22
- should "add received messages to the buffer" do
23
-
24
- @input.buffer.clear
25
-
26
- @messages.each do |message|
27
-
28
- p "sending: #{message}"
29
- @output.puts(message)
30
- @bytes += message
31
- sleep(1)
32
- buffer = @input.buffer.map { |m| m[:data] }.flatten
33
- p "received: #{buffer}"
34
- assert_equal(@bytes, buffer)
35
-
36
- end
37
-
38
- assert_equal(@bytes.length, @input.buffer.map { |m| m[:data] }.flatten.length)
39
-
40
- end
41
-
42
- end
43
- end
44
- end
@@ -1,47 +0,0 @@
1
- require 'helper'
2
-
3
- class UniMIDI::PlatformTest < Test::Unit::TestCase
4
-
5
- def platform_test(adapter, mod, device_class = nil, input_class = nil, output_class = nil)
6
- device_class ||= mod::Device
7
- input_class ||= mod::Input
8
- output_class ||= mod::Output
9
- assert_not_same(input_class, UniMIDI::Input)
10
- assert_not_same(output_class, UniMIDI::Output)
11
- assert_not_same(device_class, UniMIDI::Device)
12
- assert_equal(input_class.first.name, UniMIDI::Input.first.name)
13
- assert_equal(input_class.first.id, UniMIDI::Input.first.id)
14
- assert_not_same(output_class.first, UniMIDI::Output.first)
15
- assert_equal(output_class.first.name, UniMIDI::Output.first.name)
16
- assert_equal(output_class.first.id, UniMIDI::Output.first.id)
17
- end
18
-
19
- context "Platform" do
20
-
21
- should "recognize java" do
22
- if RUBY_PLATFORM.include?("java")
23
- platform_test(UniMIDI::Adapter::MIDIJRuby, ::MIDIJRuby)
24
- end
25
- end
26
-
27
- should "recognize linux" do
28
- if RUBY_PLATFORM.include?("linux")
29
- platform_test(UniMIDI::Adapter::AlsaRawMIDI, ::AlsaRawMIDI)
30
- end
31
- end
32
-
33
- should "recognize osx" do
34
- if RUBY_PLATFORM.include?("darwin")
35
- platform_test(UniMIDI::Adapter::CoreMIDI, ::CoreMIDI, ::CoreMIDI::Endpoint, ::CoreMIDI::Source, ::CoreMIDI::Destination)
36
- end
37
- end
38
-
39
- should "recognize windows" do
40
- if RUBY_PLATFORM.include?("mingw")
41
- platform_test(UniMIDI::Adapter::MIDIWinMM, ::MIDIWinMM)
42
- end
43
- end
44
-
45
- end
46
-
47
- end
@@ -1,18 +0,0 @@
1
- require 'helper'
2
-
3
- class UniMIDI::TypeConversionTest < Test::Unit::TestCase
4
-
5
- context "TypeConversion" do
6
-
7
- context "#numeric_byte_array_to_hex_string" do
8
-
9
- should "convert byte array to hex string" do
10
- result = UniMIDI::TypeConversion.numeric_byte_array_to_hex_string([0x90, 0x40, 0x40])
11
- assert "904040", result
12
- end
13
-
14
- end
15
-
16
- end
17
-
18
- end