unimidi 0.4.7 → 0.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/LICENSE +1 -1
 - data/README.md +1 -1
 - data/lib/unimidi.rb +4 -3
 - data/lib/unimidi/device.rb +18 -7
 - data/lib/unimidi/input/buffer_access.rb +1 -1
 - data/lib/unimidi/input/stream_reader.rb +1 -1
 - data/lib/unimidi/loader.rb +22 -19
 - data/lib/unimidi/output.rb +7 -7
 - data/lib/unimidi/platform.rb +13 -5
 - data/lib/unimidi/type_conversion.rb +6 -6
 - data/test/helper.rb +1 -64
 - data/test/integration/helper.rb +76 -0
 - data/test/{input_test.rb → integration/input_test.rb} +4 -4
 - data/test/{functional_test.rb → integration/io_test.rb} +7 -7
 - data/test/unit/device_test.rb +197 -0
 - data/test/unit/helper.rb +40 -0
 - data/test/unit/platform_test.rb +37 -0
 - data/test/{type_conversion_test.rb → unit/type_conversion_test.rb} +1 -1
 - metadata +11 -10
 - data/test/adapter_test.rb +0 -66
 - data/test/class_methods_test.rb +0 -95
 - data/test/platform_test.rb +0 -47
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: bf68a7b6957f53fe2ccdb7922af43d3ee59bcc8e
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: ad6dc382083631d6f8277e319d39af5e5bc27cad
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 8386b3217cae71e3712d12644c2371b6fd9b6bbcf11fb3b1537a38773a4fc077da771ef3713e417bca1248d6a4f1f6ab605dbd505a5aa0a686377b60b8605b88
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 630f39aa818ad71e336dca7597e14a8c5b9bdf1237e9d8839aede3e50f504b763aa60f1a7512426903163f3e270f43d785c246f1bff0950adf84d2f2508868c4
         
     | 
    
        data/LICENSE
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    
    
        data/lib/unimidi.rb
    CHANGED
    
    | 
         @@ -1,24 +1,25 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #
         
     | 
| 
      
 2 
     | 
    
         
            +
            # UniMIDI
         
     | 
| 
       2 
3 
     | 
    
         
             
            # Realtime MIDI IO for Ruby
         
     | 
| 
       3 
4 
     | 
    
         
             
            #
         
     | 
| 
       4 
     | 
    
         
            -
            # (c)2010- 
     | 
| 
      
 5 
     | 
    
         
            +
            # (c)2010-2017 Ari Russo
         
     | 
| 
       5 
6 
     | 
    
         
             
            # Licensed under the Apache 2.0 License
         
     | 
| 
       6 
7 
     | 
    
         
             
            #
         
     | 
| 
       7 
8 
     | 
    
         | 
| 
       8 
9 
     | 
    
         
             
            # modules
         
     | 
| 
       9 
10 
     | 
    
         
             
            require "unimidi/command"
         
     | 
| 
       10 
11 
     | 
    
         
             
            require "unimidi/device"
         
     | 
| 
       11 
     | 
    
         
            -
            require "unimidi/loader"
         
     | 
| 
       12 
12 
     | 
    
         
             
            require "unimidi/platform"
         
     | 
| 
       13 
13 
     | 
    
         
             
            require "unimidi/type_conversion"
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
15 
     | 
    
         
             
            # classes
         
     | 
| 
       16 
16 
     | 
    
         
             
            require "unimidi/input"
         
     | 
| 
      
 17 
     | 
    
         
            +
            require "unimidi/loader"
         
     | 
| 
       17 
18 
     | 
    
         
             
            require "unimidi/output"
         
     | 
| 
       18 
19 
     | 
    
         | 
| 
       19 
20 
     | 
    
         
             
            module UniMIDI
         
     | 
| 
       20 
21 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
              VERSION = "0.4. 
     | 
| 
      
 22 
     | 
    
         
            +
              VERSION = "0.4.8"
         
     | 
| 
       22 
23 
     | 
    
         | 
| 
       23 
24 
     | 
    
         
             
              Platform.bootstrap
         
     | 
| 
       24 
25 
     | 
    
         | 
    
        data/lib/unimidi/device.rb
    CHANGED
    
    | 
         @@ -63,38 +63,43 @@ module UniMIDI 
     | 
|
| 
       63 
63 
     | 
    
         
             
                  end
         
     | 
| 
       64 
64 
     | 
    
         | 
| 
       65 
65 
     | 
    
         
             
                  # Select the device at the given index and enable it
         
     | 
| 
       66 
     | 
    
         
            -
                  # @param [ 
     | 
| 
      
 66 
     | 
    
         
            +
                  # @param [Integer] index
         
     | 
| 
       67 
67 
     | 
    
         
             
                  # @return [Input, Output]
         
     | 
| 
       68 
68 
     | 
    
         
             
                  def use(index, &block)
         
     | 
| 
       69 
69 
     | 
    
         
             
                    index = case index
         
     | 
| 
       70 
70 
     | 
    
         
             
                            when :first then 0
         
     | 
| 
       71 
     | 
    
         
            -
                            when :last then all. 
     | 
| 
      
 71 
     | 
    
         
            +
                            when :last then all.count - 1
         
     | 
| 
       72 
72 
     | 
    
         
             
                            else index
         
     | 
| 
       73 
73 
     | 
    
         
             
                            end
         
     | 
| 
       74 
     | 
    
         
            -
                    use_device( 
     | 
| 
      
 74 
     | 
    
         
            +
                    use_device(at(index), &block)
         
     | 
| 
       75 
75 
     | 
    
         
             
                  end
         
     | 
| 
       76 
76 
     | 
    
         
             
                  alias_method :open, :use
         
     | 
| 
       77 
77 
     | 
    
         | 
| 
       78 
78 
     | 
    
         
             
                  # Select the device at the given index
         
     | 
| 
       79 
     | 
    
         
            -
                  # @param [ 
     | 
| 
      
 79 
     | 
    
         
            +
                  # @param [Integer] index
         
     | 
| 
       80 
80 
     | 
    
         
             
                  # @return [Input, Output]
         
     | 
| 
       81 
     | 
    
         
            -
                  def  
     | 
| 
      
 81 
     | 
    
         
            +
                  def at(index)
         
     | 
| 
       82 
82 
     | 
    
         
             
                    all[index]
         
     | 
| 
       83 
83 
     | 
    
         
             
                  end
         
     | 
| 
      
 84 
     | 
    
         
            +
                  alias_method :[], :at
         
     | 
| 
       84 
85 
     | 
    
         | 
| 
       85 
86 
     | 
    
         
             
                  private
         
     | 
| 
       86 
87 
     | 
    
         | 
| 
       87 
88 
     | 
    
         
             
                  # The direction of the device eg "input", "output"
         
     | 
| 
       88 
89 
     | 
    
         
             
                  # @return [String]
         
     | 
| 
       89 
90 
     | 
    
         
             
                  def get_direction
         
     | 
| 
       90 
     | 
    
         
            -
                     
     | 
| 
      
 91 
     | 
    
         
            +
                    name.split("::").last.downcase
         
     | 
| 
       91 
92 
     | 
    
         
             
                  end
         
     | 
| 
       92 
93 
     | 
    
         | 
| 
       93 
94 
     | 
    
         
             
                  # Enable the given device
         
     | 
| 
       94 
95 
     | 
    
         
             
                  # @param [Input, Output] device
         
     | 
| 
       95 
96 
     | 
    
         
             
                  # @return [Input, Output]
         
     | 
| 
       96 
97 
     | 
    
         
             
                  def use_device(device, &block)
         
     | 
| 
       97 
     | 
    
         
            -
                     
     | 
| 
      
 98 
     | 
    
         
            +
                    if device.enabled?
         
     | 
| 
      
 99 
     | 
    
         
            +
                      yield(device) if block_given?
         
     | 
| 
      
 100 
     | 
    
         
            +
                    else
         
     | 
| 
      
 101 
     | 
    
         
            +
                      device.open(&block)
         
     | 
| 
      
 102 
     | 
    
         
            +
                    end
         
     | 
| 
       98 
103 
     | 
    
         
             
                    device
         
     | 
| 
       99 
104 
     | 
    
         
             
                  end
         
     | 
| 
       100 
105 
     | 
    
         | 
| 
         @@ -155,6 +160,12 @@ module UniMIDI 
     | 
|
| 
       155 
160 
     | 
    
         
             
                    end
         
     | 
| 
       156 
161 
     | 
    
         
             
                  end
         
     | 
| 
       157 
162 
     | 
    
         | 
| 
      
 163 
     | 
    
         
            +
                  # Returns true if the device is not enabled
         
     | 
| 
      
 164 
     | 
    
         
            +
                  # @return [Boolean]
         
     | 
| 
      
 165 
     | 
    
         
            +
                  def closed?
         
     | 
| 
      
 166 
     | 
    
         
            +
                    !@enabled
         
     | 
| 
      
 167 
     | 
    
         
            +
                  end
         
     | 
| 
      
 168 
     | 
    
         
            +
             
     | 
| 
       158 
169 
     | 
    
         
             
                  # Add attributes for the device instance
         
     | 
| 
       159 
170 
     | 
    
         
             
                  # :direction, :id, :name
         
     | 
| 
       160 
171 
     | 
    
         
             
                  def self.included(base)
         
     | 
| 
         @@ -35,7 +35,7 @@ module UniMIDI 
     | 
|
| 
       35 
35 
     | 
    
         
             
                  # Gets any messages in the buffer in the same format as Input#gets_data. . This doesn't remove
         
     | 
| 
       36 
36 
     | 
    
         
             
                  # the messages from the buffer or have any effect on the StreamReader pointer position
         
     | 
| 
       37 
37 
     | 
    
         
             
                  # @param [*Object] args
         
     | 
| 
       38 
     | 
    
         
            -
                  # @return [Array< 
     | 
| 
      
 38 
     | 
    
         
            +
                  # @return [Array<Integer>]
         
     | 
| 
       39 
39 
     | 
    
         
             
                  def gets_buffer_data(*args)
         
     | 
| 
       40 
40 
     | 
    
         
             
                    @device.buffer.map { |msg| msg[:data] }
         
     | 
| 
       41 
41 
     | 
    
         
             
                  end
         
     | 
    
        data/lib/unimidi/loader.rb
    CHANGED
    
    | 
         @@ -1,29 +1,32 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module UniMIDI
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
              # Populate UniMIDI devices using the underlying device objects from the platform-specific gems
         
     | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
      
 4 
     | 
    
         
            +
              class Loader
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
                 
     | 
| 
      
 6 
     | 
    
         
            +
                class << self
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
      
 8 
     | 
    
         
            +
                  # Use the given platform-specific adapter to load devices
         
     | 
| 
      
 9 
     | 
    
         
            +
                  # @param [UniMIDI::Adapter::Loader] loader
         
     | 
| 
      
 10 
     | 
    
         
            +
                  def use(loader)
         
     | 
| 
      
 11 
     | 
    
         
            +
                    @loader = loader
         
     | 
| 
      
 12 
     | 
    
         
            +
                  end
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                   
     | 
| 
       19 
     | 
    
         
            -
                     
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                       
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
                  # Get all MIDI devices
         
     | 
| 
      
 15 
     | 
    
         
            +
                  # @param [Hash] options
         
     | 
| 
      
 16 
     | 
    
         
            +
                  # @option options [Symbol] :direction Return only a particular direction of device eg :input, :output
         
     | 
| 
      
 17 
     | 
    
         
            +
                  # @return [Array<Input>, Array<Output>]
         
     | 
| 
      
 18 
     | 
    
         
            +
                  def devices(options = {})
         
     | 
| 
      
 19 
     | 
    
         
            +
                    if @devices.nil?
         
     | 
| 
      
 20 
     | 
    
         
            +
                      inputs = @loader.inputs.map { |device| ::UniMIDI::Input.new(device) }
         
     | 
| 
      
 21 
     | 
    
         
            +
                      outputs = @loader.outputs.map { |device| ::UniMIDI::Output.new(device) }
         
     | 
| 
      
 22 
     | 
    
         
            +
                      @devices = {
         
     | 
| 
      
 23 
     | 
    
         
            +
                        :input => inputs,
         
     | 
| 
      
 24 
     | 
    
         
            +
                        :output => outputs
         
     | 
| 
      
 25 
     | 
    
         
            +
                      }
         
     | 
| 
      
 26 
     | 
    
         
            +
                    end
         
     | 
| 
      
 27 
     | 
    
         
            +
                    options[:direction].nil? ? @devices.values.flatten : @devices[options[:direction]]
         
     | 
| 
       25 
28 
     | 
    
         
             
                  end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
       27 
30 
     | 
    
         
             
                end
         
     | 
| 
       28 
31 
     | 
    
         | 
| 
       29 
32 
     | 
    
         
             
              end
         
     | 
    
        data/lib/unimidi/output.rb
    CHANGED
    
    | 
         @@ -12,7 +12,7 @@ module UniMIDI 
     | 
|
| 
       12 
12 
     | 
    
         
             
                  Loader.devices(:direction => :output)
         
     | 
| 
       13 
13 
     | 
    
         
             
                end
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
                # Sends a message to the output. 
     | 
| 
      
 15 
     | 
    
         
            +
                # Sends a message to the output.
         
     | 
| 
       16 
16 
     | 
    
         
             
                #
         
     | 
| 
       17 
17 
     | 
    
         
             
                # The message format can be:
         
     | 
| 
       18 
18 
     | 
    
         
             
                #
         
     | 
| 
         @@ -21,18 +21,18 @@ module UniMIDI 
     | 
|
| 
       21 
21 
     | 
    
         
             
                # 3. A string of bytes eg "904040"
         
     | 
| 
       22 
22 
     | 
    
         
             
                # 4. An array of strings ["904040", "804040"]
         
     | 
| 
       23 
23 
     | 
    
         
             
                #
         
     | 
| 
       24 
     | 
    
         
            -
                # @param [*Array< 
     | 
| 
       25 
     | 
    
         
            -
                # @return [Array< 
     | 
| 
      
 24 
     | 
    
         
            +
                # @param [*Array<Integer>, *Array<String>, *Integer, *String] messages
         
     | 
| 
      
 25 
     | 
    
         
            +
                # @return [Array<Integer>, Array<String>]
         
     | 
| 
       26 
26 
     | 
    
         
             
                def puts(*messages)
         
     | 
| 
       27 
27 
     | 
    
         
             
                  message = messages.first
         
     | 
| 
       28 
28 
     | 
    
         
             
                  case message
         
     | 
| 
       29 
29 
     | 
    
         
             
                  when Array then messages.each { |array| puts(*array.flatten) }
         
     | 
| 
       30 
     | 
    
         
            -
                  when  
     | 
| 
      
 30 
     | 
    
         
            +
                  when Integer then puts_bytes(*messages)
         
     | 
| 
       31 
31 
     | 
    
         
             
                  when String then puts_s(*messages)
         
     | 
| 
       32 
32 
     | 
    
         
             
                  else
         
     | 
| 
       33 
33 
     | 
    
         
             
                    if message.respond_to?(:to_bytes)
         
     | 
| 
       34 
34 
     | 
    
         
             
                      puts_bytes(*message.to_bytes.flatten)
         
     | 
| 
       35 
     | 
    
         
            -
                    elsif message.respond_to?(:to_a) 
     | 
| 
      
 35 
     | 
    
         
            +
                    elsif message.respond_to?(:to_a)
         
     | 
| 
       36 
36 
     | 
    
         
             
                      puts_bytes(*message.to_a.flatten)
         
     | 
| 
       37 
37 
     | 
    
         
             
                    end
         
     | 
| 
       38 
38 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -51,8 +51,8 @@ module UniMIDI 
     | 
|
| 
       51 
51 
     | 
    
         | 
| 
       52 
52 
     | 
    
         
             
                # Sends a message to the output in a form of bytes eg output.puts_bytes(0x90, 0x40, 0x40).
         
     | 
| 
       53 
53 
     | 
    
         
             
                # This method does not do type checking.
         
     | 
| 
       54 
     | 
    
         
            -
                # @param [*Array< 
     | 
| 
       55 
     | 
    
         
            -
                # @return [Array< 
     | 
| 
      
 54 
     | 
    
         
            +
                # @param [*Array<Integer>] messages
         
     | 
| 
      
 55 
     | 
    
         
            +
                # @return [Array<Integer>, Array<Array<Integer>>]
         
     | 
| 
       56 
56 
     | 
    
         
             
                def puts_bytes(*messages)
         
     | 
| 
       57 
57 
     | 
    
         
             
                  @device.puts_bytes(*messages)
         
     | 
| 
       58 
58 
     | 
    
         
             
                  messages.count < 2 ? messages[0] : messages
         
     | 
    
        data/lib/unimidi/platform.rb
    CHANGED
    
    | 
         @@ -4,23 +4,31 @@ module UniMIDI 
     | 
|
| 
       4 
4 
     | 
    
         
             
              module Platform
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
                extend self
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
       8 
8 
     | 
    
         
             
                # Loads the proper MIDI library and adapter for the user's environment
         
     | 
| 
       9 
9 
     | 
    
         
             
                def bootstrap
         
     | 
| 
       10 
     | 
    
         
            -
                   
     | 
| 
      
 10 
     | 
    
         
            +
                  require("unimidi/adapter/#{platform_lib}")
         
     | 
| 
      
 11 
     | 
    
         
            +
                  Loader.use(platform_module::Loader)
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                private
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                def platform_lib
         
     | 
| 
      
 17 
     | 
    
         
            +
                  case RUBY_PLATFORM
         
     | 
| 
       11 
18 
     | 
    
         
             
                    when /darwin/ then "ffi-coremidi"
         
     | 
| 
       12 
19 
     | 
    
         
             
                    when /java/ then "midi-jruby"
         
     | 
| 
       13 
20 
     | 
    
         
             
                    when /linux/ then "alsa-rawmidi"
         
     | 
| 
       14 
21 
     | 
    
         
             
                    when /mingw/ then "midi-winmm"
         
     | 
| 
       15 
22 
     | 
    
         
             
                  end
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                def platform_module
         
     | 
| 
      
 26 
     | 
    
         
            +
                  case RUBY_PLATFORM
         
     | 
| 
       18 
27 
     | 
    
         
             
                    when /darwin/ then Adapter::CoreMIDI
         
     | 
| 
       19 
28 
     | 
    
         
             
                    when /java/ then Adapter::MIDIJRuby
         
     | 
| 
       20 
29 
     | 
    
         
             
                    when /linux/ then Adapter::AlsaRawMIDI
         
     | 
| 
       21 
30 
     | 
    
         
             
                    when /mingw/ then Adapter::MIDIWinMM
         
     | 
| 
       22 
31 
     | 
    
         
             
                  end
         
     | 
| 
       23 
     | 
    
         
            -
                  Loader.use(interface::Loader)
         
     | 
| 
       24 
32 
     | 
    
         
             
                end
         
     | 
| 
       25 
33 
     | 
    
         | 
| 
       26 
34 
     | 
    
         
             
              end
         
     | 
| 
         @@ -1,17 +1,17 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module UniMIDI
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       3 
3 
     | 
    
         
             
              # Utility for converting between different data formats
         
     | 
| 
       4 
4 
     | 
    
         
             
              module TypeConversion
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
                extend self
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
                # Convert an array of numeric bytes to string of hex bytes 
     | 
| 
       9 
     | 
    
         
            -
                # @param [Array< 
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                # Convert an array of numeric bytes to string of hex bytes
         
     | 
| 
      
 9 
     | 
    
         
            +
                # @param [Array<Integer>] byte An array of numeric bytes eg [0x90, 0x40, 0x40]
         
     | 
| 
       10 
10 
     | 
    
         
             
                # @return [String] A string of hex bytes eg "904040"
         
     | 
| 
       11 
11 
     | 
    
         
             
                def numeric_byte_array_to_hex_string(bytes)
         
     | 
| 
       12 
12 
     | 
    
         
             
                  bytes.map { |b| b.to_s(16) }.join
         
     | 
| 
       13 
13 
     | 
    
         
             
                end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
       15 
15 
     | 
    
         
             
              end
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
       17 
17 
     | 
    
         
             
            end
         
     | 
    
        data/test/helper.rb
    CHANGED
    
    | 
         @@ -1,5 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            dir = File.dirname(File.expand_path(__FILE__))
         
     | 
| 
       2 
     | 
    
         
            -
            $LOAD_PATH.unshift 
     | 
| 
      
 2 
     | 
    
         
            +
            $LOAD_PATH.unshift("#{dir}/../lib")
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            require "minitest/autorun"
         
     | 
| 
       5 
5 
     | 
    
         
             
            require "mocha/test_unit"
         
     | 
| 
         @@ -8,67 +8,4 @@ require "unimidi" 
     | 
|
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
            module TestHelper
         
     | 
| 
       10 
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 
11 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,76 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "helper"
         
     | 
| 
      
 2 
     | 
    
         
            +
            require "minitest/autorun"
         
     | 
| 
      
 3 
     | 
    
         
            +
            require "mocha/test_unit"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require "shoulda-context"
         
     | 
| 
      
 5 
     | 
    
         
            +
            require "unimidi"
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            module TestHelper
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              module Integration
         
     | 
| 
      
 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
         
     | 
| 
      
 75 
     | 
    
         
            +
              
         
     | 
| 
      
 76 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require  
     | 
| 
      
 1 
     | 
    
         
            +
            require "integration/helper"
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            class UniMIDI::InputTest < Minitest::Test
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
         @@ -8,9 +8,9 @@ class UniMIDI::InputTest < Minitest::Test 
     | 
|
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
                  setup do
         
     | 
| 
       10 
10 
     | 
    
         
             
                    sleep(1)
         
     | 
| 
       11 
     | 
    
         
            -
                    @input = TestHelper.devices[:input].open
         
     | 
| 
       12 
     | 
    
         
            -
                    @output = TestHelper.devices[:output].open
         
     | 
| 
       13 
     | 
    
         
            -
                    @messages = TestHelper.numeric_messages
         
     | 
| 
      
 11 
     | 
    
         
            +
                    @input = TestHelper::Integration.devices[:input].open
         
     | 
| 
      
 12 
     | 
    
         
            +
                    @output = TestHelper::Integration.devices[:output].open
         
     | 
| 
      
 13 
     | 
    
         
            +
                    @messages = TestHelper::Integration.numeric_messages
         
     | 
| 
       14 
14 
     | 
    
         
             
                    @bytes = []
         
     | 
| 
       15 
15 
     | 
    
         
             
                  end
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
         @@ -1,13 +1,13 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require "helper"
         
     | 
| 
      
 1 
     | 
    
         
            +
            require "integration/helper"
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            class UniMIDI:: 
     | 
| 
      
 3 
     | 
    
         
            +
            class UniMIDI::IoTest < Minitest::Test
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
              # ** these tests assume that TestOutput is connected to TestInput
         
     | 
| 
       6 
6 
     | 
    
         
             
              context "UniMIDI" do
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
                setup do
         
     | 
| 
       9 
     | 
    
         
            -
                  @input = TestHelper.devices[:input].open
         
     | 
| 
       10 
     | 
    
         
            -
                  @output = TestHelper.devices[:output].open
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @input = TestHelper::Integration.devices[:input].open
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @output = TestHelper::Integration.devices[:output].open
         
     | 
| 
       11 
11 
     | 
    
         
             
                end
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
                teardown do
         
     | 
| 
         @@ -20,7 +20,7 @@ class UniMIDI::FunctionalTest < Minitest::Test 
     | 
|
| 
       20 
20 
     | 
    
         
             
                  context "using numeric bytes" do
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
                    setup do
         
     | 
| 
       23 
     | 
    
         
            -
                      @messages = TestHelper.numeric_messages
         
     | 
| 
      
 23 
     | 
    
         
            +
                      @messages = TestHelper::Integration.numeric_messages
         
     | 
| 
       24 
24 
     | 
    
         
             
                      @messages_arr = @messages.inject(&:+).flatten
         
     | 
| 
       25 
25 
     | 
    
         
             
                      @received_arr = []
         
     | 
| 
       26 
26 
     | 
    
         
             
                      @pointer = 0
         
     | 
| 
         @@ -48,7 +48,7 @@ class UniMIDI::FunctionalTest < Minitest::Test 
     | 
|
| 
       48 
48 
     | 
    
         
             
                  context "using byte Strings" do
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
50 
     | 
    
         
             
                    setup do
         
     | 
| 
       51 
     | 
    
         
            -
                      @messages = TestHelper.string_messages
         
     | 
| 
      
 51 
     | 
    
         
            +
                      @messages = TestHelper::Integration.string_messages
         
     | 
| 
       52 
52 
     | 
    
         
             
                      @messages_str = @messages.join
         
     | 
| 
       53 
53 
     | 
    
         
             
                      @received_str = ""
         
     | 
| 
       54 
54 
     | 
    
         
             
                      @pointer = 0
         
     | 
| 
         @@ -78,7 +78,7 @@ class UniMIDI::FunctionalTest < Minitest::Test 
     | 
|
| 
       78 
78 
     | 
    
         
             
                  context "using MIDIMessages" do
         
     | 
| 
       79 
79 
     | 
    
         | 
| 
       80 
80 
     | 
    
         
             
                    setup do
         
     | 
| 
       81 
     | 
    
         
            -
                      @messages = TestHelper.message_objects
         
     | 
| 
      
 81 
     | 
    
         
            +
                      @messages = TestHelper::Integration.message_objects
         
     | 
| 
       82 
82 
     | 
    
         
             
                      @messages_arr = @messages.map(&:to_bytes).flatten
         
     | 
| 
       83 
83 
     | 
    
         
             
                      @received_arr = []
         
     | 
| 
       84 
84 
     | 
    
         
             
                      @pointer = 0
         
     | 
| 
         @@ -0,0 +1,197 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "unit/helper"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class UniMIDI::DeviceTest < Minitest::Test
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              context "Device" do
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                setup do
         
     | 
| 
      
 8 
     | 
    
         
            +
                  UniMIDI::Input.stubs(:all).returns(TestHelper::Unit.mock_devices[:input])
         
     | 
| 
      
 9 
     | 
    
         
            +
                  UniMIDI::Output.stubs(:all).returns(TestHelper::Unit.mock_devices[:output])
         
     | 
| 
      
 10 
     | 
    
         
            +
                end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                teardown do
         
     | 
| 
      
 13 
     | 
    
         
            +
                  UniMIDI::Input.unstub(:all)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  UniMIDI::Output.unstub(:all)
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                context "InstanceMethods" do
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                  context "Device#type" do
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                    context "input" do
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                      setup do
         
     | 
| 
      
 24 
     | 
    
         
            +
                        @input = UniMIDI::Input.all.sample
         
     | 
| 
      
 25 
     | 
    
         
            +
                      end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                      should "be an input" do
         
     | 
| 
      
 28 
     | 
    
         
            +
                        assert_equal(:input, @input.type)
         
     | 
| 
      
 29 
     | 
    
         
            +
                      end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                    end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                    context "output" do
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                      setup do
         
     | 
| 
      
 36 
     | 
    
         
            +
                        UniMIDI::Input.stubs(:all).returns(TestHelper::Unit.mock_devices[:input])
         
     | 
| 
      
 37 
     | 
    
         
            +
                        @output = UniMIDI::Output.all.sample
         
     | 
| 
      
 38 
     | 
    
         
            +
                      end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                      should "be an output" do
         
     | 
| 
      
 41 
     | 
    
         
            +
                        assert_equal(:output, @output.type)
         
     | 
| 
      
 42 
     | 
    
         
            +
                      end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                    end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                context "ClassMethods" do
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                  context ".find_by_name" do
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                    setup do
         
     | 
| 
      
 55 
     | 
    
         
            +
                      @name = UniMIDI::Output.all.map(&:name).sample
         
     | 
| 
      
 56 
     | 
    
         
            +
                      @output = UniMIDI::Output.find_by_name(@name)
         
     | 
| 
      
 57 
     | 
    
         
            +
                    end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                    should "select the correct input" do
         
     | 
| 
      
 60 
     | 
    
         
            +
                      assert_equal(@name, @output.name)
         
     | 
| 
      
 61 
     | 
    
         
            +
                    end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                  end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                  context ".first" do
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                    setup do
         
     | 
| 
      
 68 
     | 
    
         
            +
                      @output_to_test = UniMIDI::Output.all[0]
         
     | 
| 
      
 69 
     | 
    
         
            +
                      @output_to_test.expects(:open).returns(true)
         
     | 
| 
      
 70 
     | 
    
         
            +
                      @output_to_test.expects(:enabled?).returns(true)
         
     | 
| 
      
 71 
     | 
    
         
            +
                      @output = UniMIDI::Output.first
         
     | 
| 
      
 72 
     | 
    
         
            +
                    end
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                    teardown do
         
     | 
| 
      
 75 
     | 
    
         
            +
                      @output_to_test.unstub(:open)
         
     | 
| 
      
 76 
     | 
    
         
            +
                      @output_to_test.unstub(:enabled?)
         
     | 
| 
      
 77 
     | 
    
         
            +
                    end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                    should "return the first output" do
         
     | 
| 
      
 80 
     | 
    
         
            +
                      assert_equal(@output_to_test, @output)
         
     | 
| 
      
 81 
     | 
    
         
            +
                    end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                  end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                  context ".last" do
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
                    setup do
         
     | 
| 
      
 88 
     | 
    
         
            +
                      @output_to_test = UniMIDI::Output.all.last
         
     | 
| 
      
 89 
     | 
    
         
            +
                      @output_to_test.expects(:open).returns(true)
         
     | 
| 
      
 90 
     | 
    
         
            +
                      @output_to_test.expects(:enabled?).returns(true)
         
     | 
| 
      
 91 
     | 
    
         
            +
                      @output = UniMIDI::Output.last
         
     | 
| 
      
 92 
     | 
    
         
            +
                    end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
                    teardown do
         
     | 
| 
      
 95 
     | 
    
         
            +
                      @output_to_test.unstub(:open)
         
     | 
| 
      
 96 
     | 
    
         
            +
                      @output_to_test.unstub(:enabled?)
         
     | 
| 
      
 97 
     | 
    
         
            +
                    end
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                    should "return the last output" do
         
     | 
| 
      
 100 
     | 
    
         
            +
                      assert_equal @output_to_test, @output
         
     | 
| 
      
 101 
     | 
    
         
            +
                    end
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
                  end
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
                  context ".[]" do
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
                    setup do
         
     | 
| 
      
 108 
     | 
    
         
            +
                      @device_to_test = UniMIDI::Input.all[0]
         
     | 
| 
      
 109 
     | 
    
         
            +
                      @device_to_test.expects(:open).returns(true)
         
     | 
| 
      
 110 
     | 
    
         
            +
                      @device_to_test.expects(:enabled?).returns(true)
         
     | 
| 
      
 111 
     | 
    
         
            +
                      @device = UniMIDI::Input[0]
         
     | 
| 
      
 112 
     | 
    
         
            +
                    end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                    teardown do
         
     | 
| 
      
 115 
     | 
    
         
            +
                      @device_to_test.unstub(:open)
         
     | 
| 
      
 116 
     | 
    
         
            +
                      @device_to_test.unstub(:enabled?)
         
     | 
| 
      
 117 
     | 
    
         
            +
                    end
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
                    should "return correct input" do
         
     | 
| 
      
 120 
     | 
    
         
            +
                      assert_equal(@device_to_test, @device)
         
     | 
| 
      
 121 
     | 
    
         
            +
                    end
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
                  end
         
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
      
 125 
     | 
    
         
            +
                  context ".use" do
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
                    context "block given" do
         
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
      
 129 
     | 
    
         
            +
                      setup do
         
     | 
| 
      
 130 
     | 
    
         
            +
                        @device_to_test = UniMIDI::Input.all.sample
         
     | 
| 
      
 131 
     | 
    
         
            +
                        @index = UniMIDI::Input.all.index(@device_to_test)
         
     | 
| 
      
 132 
     | 
    
         
            +
                        @device_to_test.expects(:open).returns(true)
         
     | 
| 
      
 133 
     | 
    
         
            +
                        @device_to_test.expects(:enabled?).at_least_once.returns(true)
         
     | 
| 
      
 134 
     | 
    
         
            +
                      end
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
                      teardown do
         
     | 
| 
      
 137 
     | 
    
         
            +
                        @device_to_test.unstub(:open)
         
     | 
| 
      
 138 
     | 
    
         
            +
                        @device_to_test.unstub(:enabled?)
         
     | 
| 
      
 139 
     | 
    
         
            +
                      end
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
                      should "return and enable an input" do
         
     | 
| 
      
 142 
     | 
    
         
            +
                        @device = nil
         
     | 
| 
      
 143 
     | 
    
         
            +
                        UniMIDI::Input.use(@index) do |device|
         
     | 
| 
      
 144 
     | 
    
         
            +
                          @device = device
         
     | 
| 
      
 145 
     | 
    
         
            +
                          assert(@device.enabled?)
         
     | 
| 
      
 146 
     | 
    
         
            +
                        end
         
     | 
| 
      
 147 
     | 
    
         
            +
                        assert_equal(UniMIDI::Input.at(@index), @device)
         
     | 
| 
      
 148 
     | 
    
         
            +
                      end
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
                    end
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
                    context "with symbol" do
         
     | 
| 
      
 153 
     | 
    
         
            +
             
     | 
| 
      
 154 
     | 
    
         
            +
                      setup do
         
     | 
| 
      
 155 
     | 
    
         
            +
                        @device_to_test = UniMIDI::Output.all.sample
         
     | 
| 
      
 156 
     | 
    
         
            +
                        @index = UniMIDI::Output.all.index(@device_to_test)
         
     | 
| 
      
 157 
     | 
    
         
            +
                        @device_to_test.expects(:open).returns(true)
         
     | 
| 
      
 158 
     | 
    
         
            +
                        @device_to_test.expects(:enabled?).at_least_once.returns(true)
         
     | 
| 
      
 159 
     | 
    
         
            +
                      end
         
     | 
| 
      
 160 
     | 
    
         
            +
             
     | 
| 
      
 161 
     | 
    
         
            +
                      teardown do
         
     | 
| 
      
 162 
     | 
    
         
            +
                        @device_to_test.unstub(:open)
         
     | 
| 
      
 163 
     | 
    
         
            +
                        @device_to_test.unstub(:enabled?)
         
     | 
| 
      
 164 
     | 
    
         
            +
                      end
         
     | 
| 
      
 165 
     | 
    
         
            +
             
     | 
| 
      
 166 
     | 
    
         
            +
                      should "return an enabled input" do
         
     | 
| 
      
 167 
     | 
    
         
            +
                        @device = UniMIDI::Output.use(@index)
         
     | 
| 
      
 168 
     | 
    
         
            +
                        assert(@device.enabled?)
         
     | 
| 
      
 169 
     | 
    
         
            +
                        assert_equal(UniMIDI::Output.at(@index), @device)
         
     | 
| 
      
 170 
     | 
    
         
            +
                      end
         
     | 
| 
      
 171 
     | 
    
         
            +
             
     | 
| 
      
 172 
     | 
    
         
            +
                    end
         
     | 
| 
      
 173 
     | 
    
         
            +
             
     | 
| 
      
 174 
     | 
    
         
            +
                  end
         
     | 
| 
      
 175 
     | 
    
         
            +
             
     | 
| 
      
 176 
     | 
    
         
            +
                  context ".count" do
         
     | 
| 
      
 177 
     | 
    
         
            +
             
     | 
| 
      
 178 
     | 
    
         
            +
                    setup do
         
     | 
| 
      
 179 
     | 
    
         
            +
                      @inputs = UniMIDI::Input.all
         
     | 
| 
      
 180 
     | 
    
         
            +
                      @outputs = UniMIDI::Output.all
         
     | 
| 
      
 181 
     | 
    
         
            +
                    end
         
     | 
| 
      
 182 
     | 
    
         
            +
             
     | 
| 
      
 183 
     | 
    
         
            +
                    should "have the correct number of inputs" do
         
     | 
| 
      
 184 
     | 
    
         
            +
                      assert_equal(@inputs.count, UniMIDI::Input.count)
         
     | 
| 
      
 185 
     | 
    
         
            +
                    end
         
     | 
| 
      
 186 
     | 
    
         
            +
             
     | 
| 
      
 187 
     | 
    
         
            +
                    should "have the correct number of outputs" do
         
     | 
| 
      
 188 
     | 
    
         
            +
                      assert_equal(@outputs.count, UniMIDI::Output.count)
         
     | 
| 
      
 189 
     | 
    
         
            +
                    end
         
     | 
| 
      
 190 
     | 
    
         
            +
             
     | 
| 
      
 191 
     | 
    
         
            +
                  end
         
     | 
| 
      
 192 
     | 
    
         
            +
             
     | 
| 
      
 193 
     | 
    
         
            +
                end
         
     | 
| 
      
 194 
     | 
    
         
            +
             
     | 
| 
      
 195 
     | 
    
         
            +
              end
         
     | 
| 
      
 196 
     | 
    
         
            +
             
     | 
| 
      
 197 
     | 
    
         
            +
            end
         
     | 
    
        data/test/unit/helper.rb
    ADDED
    
    | 
         @@ -0,0 +1,40 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "helper"
         
     | 
| 
      
 2 
     | 
    
         
            +
            require "minitest/autorun"
         
     | 
| 
      
 3 
     | 
    
         
            +
            require "mocha/test_unit"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require "shoulda-context"
         
     | 
| 
      
 5 
     | 
    
         
            +
            require "unimidi"
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            module TestHelper
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              module Unit
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                extend self
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                def sysex_ok?
         
     | 
| 
      
 14 
     | 
    
         
            +
                  ENV["_system_name"] != "OSX" || !RUBY_PLATFORM.include?("java")
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                def mock_devices
         
     | 
| 
      
 18 
     | 
    
         
            +
                  if @mock_devices.nil?
         
     | 
| 
      
 19 
     | 
    
         
            +
                    @mock_devices = {
         
     | 
| 
      
 20 
     | 
    
         
            +
                      input: [],
         
     | 
| 
      
 21 
     | 
    
         
            +
                      output: []
         
     | 
| 
      
 22 
     | 
    
         
            +
                    }
         
     | 
| 
      
 23 
     | 
    
         
            +
                    2.times do |i|
         
     | 
| 
      
 24 
     | 
    
         
            +
                      input = Object.new
         
     | 
| 
      
 25 
     | 
    
         
            +
                      input.stubs(:type).returns(:input)
         
     | 
| 
      
 26 
     | 
    
         
            +
                      input.stubs(:name).returns("MIDI Input #{i}")
         
     | 
| 
      
 27 
     | 
    
         
            +
                      @mock_devices[:input] << input
         
     | 
| 
      
 28 
     | 
    
         
            +
                    end
         
     | 
| 
      
 29 
     | 
    
         
            +
                    3.times do |i|
         
     | 
| 
      
 30 
     | 
    
         
            +
                      input = Object.new
         
     | 
| 
      
 31 
     | 
    
         
            +
                      input.stubs(:type).returns(:output)
         
     | 
| 
      
 32 
     | 
    
         
            +
                      input.stubs(:name).returns("MIDI Output #{i}")
         
     | 
| 
      
 33 
     | 
    
         
            +
                      @mock_devices[:output] << input
         
     | 
| 
      
 34 
     | 
    
         
            +
                    end
         
     | 
| 
      
 35 
     | 
    
         
            +
                  end
         
     | 
| 
      
 36 
     | 
    
         
            +
                  @mock_devices
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
              end
         
     | 
| 
      
 40 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,37 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "unit/helper"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class UniMIDI::PlatformTest < Minitest::Test
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              context "Platform" do
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                context ".bootstrap" do
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                  if RUBY_PLATFORM.include?("java")
         
     | 
| 
      
 10 
     | 
    
         
            +
                    should "recognize java" do
         
     | 
| 
      
 11 
     | 
    
         
            +
                      assert_equal(UniMIDI::Adapter::MIDIJRuby::Loader, UniMIDI::Loader.instance_variable_get("@loader"))
         
     | 
| 
      
 12 
     | 
    
         
            +
                    end
         
     | 
| 
      
 13 
     | 
    
         
            +
                  end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                  if RUBY_PLATFORM.include?("linux")
         
     | 
| 
      
 16 
     | 
    
         
            +
                    should "recognize linux" do
         
     | 
| 
      
 17 
     | 
    
         
            +
                      assert_equal(UniMIDI::Adapter::AlsaRawMIDI::Loader, UniMIDI::Loader.instance_variable_get("@loader"))
         
     | 
| 
      
 18 
     | 
    
         
            +
                    end
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                  if RUBY_PLATFORM.include?("darwin")
         
     | 
| 
      
 22 
     | 
    
         
            +
                    should "recognize osx" do
         
     | 
| 
      
 23 
     | 
    
         
            +
                      assert_equal(UniMIDI::Adapter::CoreMIDI::Loader, UniMIDI::Loader.instance_variable_get("@loader"))
         
     | 
| 
      
 24 
     | 
    
         
            +
                    end
         
     | 
| 
      
 25 
     | 
    
         
            +
                  end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                  if RUBY_PLATFORM.include?("mingw")
         
     | 
| 
      
 28 
     | 
    
         
            +
                    should "recognize windows" do
         
     | 
| 
      
 29 
     | 
    
         
            +
                      assert_equal(UniMIDI::Adapter::MIDIWinMM::Loader, UniMIDI::Loader.instance_variable_get("@loader"))
         
     | 
| 
      
 30 
     | 
    
         
            +
                    end
         
     | 
| 
      
 31 
     | 
    
         
            +
                  end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: unimidi
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.4. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.4.8
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Ari Russo
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2017-06-07 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: minitest
         
     | 
| 
         @@ -193,16 +193,17 @@ files: 
     | 
|
| 
       193 
193 
     | 
    
         
             
            - lib/unimidi/output.rb
         
     | 
| 
       194 
194 
     | 
    
         
             
            - lib/unimidi/platform.rb
         
     | 
| 
       195 
195 
     | 
    
         
             
            - lib/unimidi/type_conversion.rb
         
     | 
| 
       196 
     | 
    
         
            -
            - test/adapter_test.rb
         
     | 
| 
       197 
     | 
    
         
            -
            - test/class_methods_test.rb
         
     | 
| 
       198 
     | 
    
         
            -
            - test/functional_test.rb
         
     | 
| 
       199 
196 
     | 
    
         
             
            - test/helper.rb
         
     | 
| 
       200 
     | 
    
         
            -
            - test/ 
     | 
| 
       201 
     | 
    
         
            -
            - test/ 
     | 
| 
       202 
     | 
    
         
            -
            - test/ 
     | 
| 
      
 197 
     | 
    
         
            +
            - test/integration/helper.rb
         
     | 
| 
      
 198 
     | 
    
         
            +
            - test/integration/input_test.rb
         
     | 
| 
      
 199 
     | 
    
         
            +
            - test/integration/io_test.rb
         
     | 
| 
      
 200 
     | 
    
         
            +
            - test/unit/device_test.rb
         
     | 
| 
      
 201 
     | 
    
         
            +
            - test/unit/helper.rb
         
     | 
| 
      
 202 
     | 
    
         
            +
            - test/unit/platform_test.rb
         
     | 
| 
      
 203 
     | 
    
         
            +
            - test/unit/type_conversion_test.rb
         
     | 
| 
       203 
204 
     | 
    
         
             
            homepage: http://github.com/arirusso/unimidi
         
     | 
| 
       204 
205 
     | 
    
         
             
            licenses:
         
     | 
| 
       205 
     | 
    
         
            -
            - Apache 
     | 
| 
      
 206 
     | 
    
         
            +
            - Apache-2.0
         
     | 
| 
       206 
207 
     | 
    
         
             
            metadata: {}
         
     | 
| 
       207 
208 
     | 
    
         
             
            post_install_message: 
         
     | 
| 
       208 
209 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
         @@ -220,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       220 
221 
     | 
    
         
             
                  version: 1.3.6
         
     | 
| 
       221 
222 
     | 
    
         
             
            requirements: []
         
     | 
| 
       222 
223 
     | 
    
         
             
            rubyforge_project: unimidi
         
     | 
| 
       223 
     | 
    
         
            -
            rubygems_version: 2. 
     | 
| 
      
 224 
     | 
    
         
            +
            rubygems_version: 2.6.8
         
     | 
| 
       224 
225 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       225 
226 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       226 
227 
     | 
    
         
             
            summary: Realtime MIDI IO for Ruby
         
     | 
    
        data/test/adapter_test.rb
    DELETED
    
    | 
         @@ -1,66 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require "helper"
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class UniMIDI::AdapterTest < Minitest::Test
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
              context "Adapter" do
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                context "Device#type" do
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
                  should "be an input" do
         
     | 
| 
       10 
     | 
    
         
            -
                    input = TestHelper.devices[:input]
         
     | 
| 
       11 
     | 
    
         
            -
                    assert_equal(:input, input.type)
         
     | 
| 
       12 
     | 
    
         
            -
                  end
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
                  should "be an output" do
         
     | 
| 
       15 
     | 
    
         
            -
                    output = TestHelper.devices[:output]
         
     | 
| 
       16 
     | 
    
         
            -
                    assert_equal(:output, output.type)
         
     | 
| 
       17 
     | 
    
         
            -
                  end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
                end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                context "Device.count" do
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                  setup do
         
     | 
| 
       24 
     | 
    
         
            -
                    @inputs = UniMIDI::Input.all
         
     | 
| 
       25 
     | 
    
         
            -
                  end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                  should "count all of the inputs" do
         
     | 
| 
       28 
     | 
    
         
            -
                    assert_equal @inputs.count, UniMIDI::Input.count
         
     | 
| 
       29 
     | 
    
         
            -
                  end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                end
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                context "Device.find_by_name" do
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                  setup do
         
     | 
| 
       36 
     | 
    
         
            -
                    index = rand(0..(UniMIDI::Output.count-1))
         
     | 
| 
       37 
     | 
    
         
            -
                    @output = UniMIDI::Output.all[index]
         
     | 
| 
       38 
     | 
    
         
            -
                  end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                  should "select the correct input" do
         
     | 
| 
       41 
     | 
    
         
            -
                    result = UniMIDI::Output.find_by_name(@output.name)
         
     | 
| 
       42 
     | 
    
         
            -
                    assert_equal @output, result
         
     | 
| 
       43 
     | 
    
         
            -
                  end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
                end
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
                context "Device.first" do
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
                  setup do
         
     | 
| 
       50 
     | 
    
         
            -
                    @output = UniMIDI::Output.all.first
         
     | 
| 
       51 
     | 
    
         
            -
                  end
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
                  should "open the output" do
         
     | 
| 
       54 
     | 
    
         
            -
                    @output.expects(:open)
         
     | 
| 
       55 
     | 
    
         
            -
                    output = UniMIDI::Output.first
         
     | 
| 
       56 
     | 
    
         
            -
                    @output.unstub(:open)
         
     | 
| 
       57 
     | 
    
         
            -
                  end
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
                  should "return the correct output" do
         
     | 
| 
       60 
     | 
    
         
            -
                    output = UniMIDI::Output.first
         
     | 
| 
       61 
     | 
    
         
            -
                    assert_equal @output, output
         
     | 
| 
       62 
     | 
    
         
            -
                  end
         
     | 
| 
       63 
     | 
    
         
            -
                end
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
              end
         
     | 
| 
       66 
     | 
    
         
            -
            end
         
     | 
    
        data/test/class_methods_test.rb
    DELETED
    
    | 
         @@ -1,95 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require "helper"
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class UniMIDI::ClassMethodsTest < Minitest::Test
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
              context "ClassMethods" do
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                context "#first" do
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
                  context "no block given" do
         
     | 
| 
       10 
     | 
    
         
            -
                    should "return first input" do
         
     | 
| 
       11 
     | 
    
         
            -
                      i = UniMIDI::Input.first
         
     | 
| 
       12 
     | 
    
         
            -
                      assert_equal(UniMIDI::Input.all.first, i)
         
     | 
| 
       13 
     | 
    
         
            -
                    end
         
     | 
| 
       14 
     | 
    
         
            -
                  end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                  context "block given" do
         
     | 
| 
       17 
     | 
    
         
            -
                    should "pass and return first input" do
         
     | 
| 
       18 
     | 
    
         
            -
                      sleep(1)
         
     | 
| 
       19 
     | 
    
         
            -
                      i = UniMIDI::Input.first do |i|
         
     | 
| 
       20 
     | 
    
         
            -
                        assert_equal(true, i.enabled?)
         
     | 
| 
       21 
     | 
    
         
            -
                      end
         
     | 
| 
       22 
     | 
    
         
            -
                      assert_equal(UniMIDI::Input.all.first, i)
         
     | 
| 
       23 
     | 
    
         
            -
                    end
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
                  end
         
     | 
| 
       26 
     | 
    
         
            -
                end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                context "#last" do
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
                  context "no block given" do
         
     | 
| 
       31 
     | 
    
         
            -
                    should "return last input" do
         
     | 
| 
       32 
     | 
    
         
            -
                      i = UniMIDI::Input.last
         
     | 
| 
       33 
     | 
    
         
            -
                      assert_equal(UniMIDI::Input.all.last, i)
         
     | 
| 
       34 
     | 
    
         
            -
                    end
         
     | 
| 
       35 
     | 
    
         
            -
                  end
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
                  context "block given" do
         
     | 
| 
       38 
     | 
    
         
            -
                    should "pass and return last input" do
         
     | 
| 
       39 
     | 
    
         
            -
                      sleep(1)
         
     | 
| 
       40 
     | 
    
         
            -
                      i = UniMIDI::Input.last do |i|
         
     | 
| 
       41 
     | 
    
         
            -
                        assert_equal(true, i.enabled?)
         
     | 
| 
       42 
     | 
    
         
            -
                      end
         
     | 
| 
       43 
     | 
    
         
            -
                      assert_equal(UniMIDI::Input.all.last, i)
         
     | 
| 
       44 
     | 
    
         
            -
                    end
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
                  end
         
     | 
| 
       47 
     | 
    
         
            -
                end
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
                context "#[]" do
         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                  should "return correct input" do
         
     | 
| 
       52 
     | 
    
         
            -
                    i = UniMIDI::Input[0]
         
     | 
| 
       53 
     | 
    
         
            -
                    assert_equal(UniMIDI::Input.first, i)
         
     | 
| 
       54 
     | 
    
         
            -
                    assert_equal(UniMIDI::Input.all.first, i)
         
     | 
| 
       55 
     | 
    
         
            -
                  end
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
                end
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
                context "#use" do
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
                  context "block given" do
         
     | 
| 
       62 
     | 
    
         
            -
                    should "return and enable an input" do
         
     | 
| 
       63 
     | 
    
         
            -
                      sleep(1)
         
     | 
| 
       64 
     | 
    
         
            -
                      i = UniMIDI::Input.use(0) do |i|
         
     | 
| 
       65 
     | 
    
         
            -
                        assert_equal(true, i.enabled?)
         
     | 
| 
       66 
     | 
    
         
            -
                      end
         
     | 
| 
       67 
     | 
    
         
            -
                      assert_equal(UniMIDI::Input.first, i)
         
     | 
| 
       68 
     | 
    
         
            -
                      assert_equal(UniMIDI::Input.all.first, i)
         
     | 
| 
       69 
     | 
    
         
            -
                    end
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
                  end
         
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
                  context "with symbol" do
         
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
                    should "return an enabled input" do
         
     | 
| 
       76 
     | 
    
         
            -
                      sleep(1)
         
     | 
| 
       77 
     | 
    
         
            -
                      input = UniMIDI::Input.use(:first)
         
     | 
| 
       78 
     | 
    
         
            -
                      assert_equal(true, input.enabled?)
         
     | 
| 
       79 
     | 
    
         
            -
                      assert_equal(UniMIDI::Input.first, input)
         
     | 
| 
       80 
     | 
    
         
            -
                      assert_equal(UniMIDI::Input.all.first, input)
         
     | 
| 
       81 
     | 
    
         
            -
                    end
         
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
                  end
         
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
                end
         
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
                context "#all" do
         
     | 
| 
       88 
     | 
    
         
            -
                  should "return all devices" do
         
     | 
| 
       89 
     | 
    
         
            -
                    assert_equal(UniMIDI::Loader.devices(:direction => :input), UniMIDI::Input.all)
         
     | 
| 
       90 
     | 
    
         
            -
                  end
         
     | 
| 
       91 
     | 
    
         
            -
                end
         
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
              end
         
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
            end
         
     | 
    
        data/test/platform_test.rb
    DELETED
    
    | 
         @@ -1,47 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'helper'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class UniMIDI::PlatformTest < Minitest::Test
         
     | 
| 
       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 
     | 
    
         
            -
                refute_equal(input_class, UniMIDI::Input)
         
     | 
| 
       10 
     | 
    
         
            -
                refute_equal(output_class, UniMIDI::Output)
         
     | 
| 
       11 
     | 
    
         
            -
                refute_equal(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 
     | 
    
         
            -
                refute_equal(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
         
     |