patch 0.4.13

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.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +13 -0
  3. data/README.md +176 -0
  4. data/bin/patchrb +40 -0
  5. data/lib/patch/config.rb +124 -0
  6. data/lib/patch/em_patch.rb +47 -0
  7. data/lib/patch/hub.rb +68 -0
  8. data/lib/patch/io/midi/action.rb +42 -0
  9. data/lib/patch/io/midi/input.rb +110 -0
  10. data/lib/patch/io/midi/message.rb +112 -0
  11. data/lib/patch/io/midi/output.rb +58 -0
  12. data/lib/patch/io/midi.rb +45 -0
  13. data/lib/patch/io/module.rb +35 -0
  14. data/lib/patch/io/osc/action.rb +43 -0
  15. data/lib/patch/io/osc/client.rb +60 -0
  16. data/lib/patch/io/osc/message.rb +109 -0
  17. data/lib/patch/io/osc/server.rb +159 -0
  18. data/lib/patch/io/osc.rb +43 -0
  19. data/lib/patch/io/websocket/node.rb +103 -0
  20. data/lib/patch/io/websocket/socket.rb +103 -0
  21. data/lib/patch/io/websocket.rb +27 -0
  22. data/lib/patch/io.rb +15 -0
  23. data/lib/patch/log.rb +97 -0
  24. data/lib/patch/message.rb +67 -0
  25. data/lib/patch/node/container.rb +69 -0
  26. data/lib/patch/node/map.rb +71 -0
  27. data/lib/patch/node.rb +10 -0
  28. data/lib/patch/patch.rb +59 -0
  29. data/lib/patch/report.rb +132 -0
  30. data/lib/patch/thread.rb +19 -0
  31. data/lib/patch.rb +42 -0
  32. data/test/config/nodes.yml +16 -0
  33. data/test/config/patches.yml +41 -0
  34. data/test/config_test.rb +216 -0
  35. data/test/helper.rb +20 -0
  36. data/test/hub_test.rb +49 -0
  37. data/test/io/midi/action_test.rb +82 -0
  38. data/test/io/midi/input_test.rb +130 -0
  39. data/test/io/midi/message_test.rb +54 -0
  40. data/test/io/midi/output_test.rb +44 -0
  41. data/test/io/midi_test.rb +94 -0
  42. data/test/io/module_test.rb +21 -0
  43. data/test/io/osc/action_test.rb +76 -0
  44. data/test/io/osc/client_test.rb +49 -0
  45. data/test/io/osc/message_test.rb +53 -0
  46. data/test/io/osc/server_test.rb +116 -0
  47. data/test/io/osc_test.rb +111 -0
  48. data/test/io/websocket/node_test.rb +96 -0
  49. data/test/io/websocket_test.rb +37 -0
  50. data/test/js/logger.js +67 -0
  51. data/test/js/message.js +62 -0
  52. data/test/js/qunit-1.18.0.js +3828 -0
  53. data/test/js/qunit.css +291 -0
  54. data/test/js/test.html +15 -0
  55. data/test/js/websocket.js +12 -0
  56. data/test/log_test.rb +96 -0
  57. data/test/message_test.rb +109 -0
  58. data/test/node/container_test.rb +104 -0
  59. data/test/node/map_test.rb +50 -0
  60. data/test/node_test.rb +14 -0
  61. data/test/patch_test.rb +57 -0
  62. data/test/report_test.rb +37 -0
  63. metadata +320 -0
data/test/js/qunit.css ADDED
@@ -0,0 +1,291 @@
1
+ /*!
2
+ * QUnit 1.18.0
3
+ * http://qunitjs.com/
4
+ *
5
+ * Copyright jQuery Foundation and other contributors
6
+ * Released under the MIT license
7
+ * http://jquery.org/license
8
+ *
9
+ * Date: 2015-04-03T10:23Z
10
+ */
11
+
12
+ /** Font Family and Sizes */
13
+
14
+ #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
15
+ font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
16
+ }
17
+
18
+ #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
19
+ #qunit-tests { font-size: smaller; }
20
+
21
+
22
+ /** Resets */
23
+
24
+ #qunit-tests, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter {
25
+ margin: 0;
26
+ padding: 0;
27
+ }
28
+
29
+
30
+ /** Header */
31
+
32
+ #qunit-header {
33
+ padding: 0.5em 0 0.5em 1em;
34
+
35
+ color: #8699A4;
36
+ background-color: #0D3349;
37
+
38
+ font-size: 1.5em;
39
+ line-height: 1em;
40
+ font-weight: 400;
41
+
42
+ border-radius: 5px 5px 0 0;
43
+ }
44
+
45
+ #qunit-header a {
46
+ text-decoration: none;
47
+ color: #C2CCD1;
48
+ }
49
+
50
+ #qunit-header a:hover,
51
+ #qunit-header a:focus {
52
+ color: #FFF;
53
+ }
54
+
55
+ #qunit-testrunner-toolbar label {
56
+ display: inline-block;
57
+ padding: 0 0.5em 0 0.1em;
58
+ }
59
+
60
+ #qunit-banner {
61
+ height: 5px;
62
+ }
63
+
64
+ #qunit-testrunner-toolbar {
65
+ padding: 0.5em 1em 0.5em 1em;
66
+ color: #5E740B;
67
+ background-color: #EEE;
68
+ overflow: hidden;
69
+ }
70
+
71
+ #qunit-userAgent {
72
+ padding: 0.5em 1em 0.5em 1em;
73
+ background-color: #2B81AF;
74
+ color: #FFF;
75
+ text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
76
+ }
77
+
78
+ #qunit-modulefilter-container {
79
+ float: right;
80
+ padding: 0.2em;
81
+ }
82
+
83
+ .qunit-url-config {
84
+ display: inline-block;
85
+ padding: 0.1em;
86
+ }
87
+
88
+ .qunit-filter {
89
+ display: block;
90
+ float: right;
91
+ margin-left: 1em;
92
+ }
93
+
94
+ /** Tests: Pass/Fail */
95
+
96
+ #qunit-tests {
97
+ list-style-position: inside;
98
+ }
99
+
100
+ #qunit-tests li {
101
+ padding: 0.4em 1em 0.4em 1em;
102
+ border-bottom: 1px solid #FFF;
103
+ list-style-position: inside;
104
+ }
105
+
106
+ #qunit-tests > li {
107
+ display: none;
108
+ }
109
+
110
+ #qunit-tests li.running,
111
+ #qunit-tests li.pass,
112
+ #qunit-tests li.fail,
113
+ #qunit-tests li.skipped {
114
+ display: list-item;
115
+ }
116
+
117
+ #qunit-tests.hidepass li.running,
118
+ #qunit-tests.hidepass li.pass {
119
+ visibility: hidden;
120
+ position: absolute;
121
+ width: 0px;
122
+ height: 0px;
123
+ padding: 0;
124
+ border: 0;
125
+ margin: 0;
126
+ }
127
+
128
+ #qunit-tests li strong {
129
+ cursor: pointer;
130
+ }
131
+
132
+ #qunit-tests li.skipped strong {
133
+ cursor: default;
134
+ }
135
+
136
+ #qunit-tests li a {
137
+ padding: 0.5em;
138
+ color: #C2CCD1;
139
+ text-decoration: none;
140
+ }
141
+
142
+ #qunit-tests li p a {
143
+ padding: 0.25em;
144
+ color: #6B6464;
145
+ }
146
+ #qunit-tests li a:hover,
147
+ #qunit-tests li a:focus {
148
+ color: #000;
149
+ }
150
+
151
+ #qunit-tests li .runtime {
152
+ float: right;
153
+ font-size: smaller;
154
+ }
155
+
156
+ .qunit-assert-list {
157
+ margin-top: 0.5em;
158
+ padding: 0.5em;
159
+
160
+ background-color: #FFF;
161
+
162
+ border-radius: 5px;
163
+ }
164
+
165
+ .qunit-collapsed {
166
+ display: none;
167
+ }
168
+
169
+ #qunit-tests table {
170
+ border-collapse: collapse;
171
+ margin-top: 0.2em;
172
+ }
173
+
174
+ #qunit-tests th {
175
+ text-align: right;
176
+ vertical-align: top;
177
+ padding: 0 0.5em 0 0;
178
+ }
179
+
180
+ #qunit-tests td {
181
+ vertical-align: top;
182
+ }
183
+
184
+ #qunit-tests pre {
185
+ margin: 0;
186
+ white-space: pre-wrap;
187
+ word-wrap: break-word;
188
+ }
189
+
190
+ #qunit-tests del {
191
+ background-color: #E0F2BE;
192
+ color: #374E0C;
193
+ text-decoration: none;
194
+ }
195
+
196
+ #qunit-tests ins {
197
+ background-color: #FFCACA;
198
+ color: #500;
199
+ text-decoration: none;
200
+ }
201
+
202
+ /*** Test Counts */
203
+
204
+ #qunit-tests b.counts { color: #000; }
205
+ #qunit-tests b.passed { color: #5E740B; }
206
+ #qunit-tests b.failed { color: #710909; }
207
+
208
+ #qunit-tests li li {
209
+ padding: 5px;
210
+ background-color: #FFF;
211
+ border-bottom: none;
212
+ list-style-position: inside;
213
+ }
214
+
215
+ /*** Passing Styles */
216
+
217
+ #qunit-tests li li.pass {
218
+ color: #3C510C;
219
+ background-color: #FFF;
220
+ border-left: 10px solid #C6E746;
221
+ }
222
+
223
+ #qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
224
+ #qunit-tests .pass .test-name { color: #366097; }
225
+
226
+ #qunit-tests .pass .test-actual,
227
+ #qunit-tests .pass .test-expected { color: #999; }
228
+
229
+ #qunit-banner.qunit-pass { background-color: #C6E746; }
230
+
231
+ /*** Failing Styles */
232
+
233
+ #qunit-tests li li.fail {
234
+ color: #710909;
235
+ background-color: #FFF;
236
+ border-left: 10px solid #EE5757;
237
+ white-space: pre;
238
+ }
239
+
240
+ #qunit-tests > li:last-child {
241
+ border-radius: 0 0 5px 5px;
242
+ }
243
+
244
+ #qunit-tests .fail { color: #000; background-color: #EE5757; }
245
+ #qunit-tests .fail .test-name,
246
+ #qunit-tests .fail .module-name { color: #000; }
247
+
248
+ #qunit-tests .fail .test-actual { color: #EE5757; }
249
+ #qunit-tests .fail .test-expected { color: #008000; }
250
+
251
+ #qunit-banner.qunit-fail { background-color: #EE5757; }
252
+
253
+ /*** Skipped tests */
254
+
255
+ #qunit-tests .skipped {
256
+ background-color: #EBECE9;
257
+ }
258
+
259
+ #qunit-tests .qunit-skipped-label {
260
+ background-color: #F4FF77;
261
+ display: inline-block;
262
+ font-style: normal;
263
+ color: #366097;
264
+ line-height: 1.8em;
265
+ padding: 0 0.5em;
266
+ margin: -0.4em 0.4em -0.4em 0;
267
+ }
268
+
269
+ /** Result */
270
+
271
+ #qunit-testresult {
272
+ padding: 0.5em 1em 0.5em 1em;
273
+
274
+ color: #2B81AF;
275
+ background-color: #D2E0E6;
276
+
277
+ border-bottom: 1px solid #FFF;
278
+ }
279
+ #qunit-testresult .module-name {
280
+ font-weight: 700;
281
+ }
282
+
283
+ /** Fixture */
284
+
285
+ #qunit-fixture {
286
+ position: absolute;
287
+ top: -10000px;
288
+ left: -10000px;
289
+ width: 1000px;
290
+ height: 1000px;
291
+ }
data/test/js/test.html ADDED
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Patch Tests</title>
6
+ <link rel="stylesheet" href="qunit.css">
7
+ <script src="../../js/patch.Websocket.js"></script>
8
+ </head>
9
+ <body>
10
+ <div id="qunit"></div>
11
+ <div id="qunit-fixture"></div>
12
+ <script src="qunit-1.18.0.js"></script>
13
+ <script src="logger.js"></script>
14
+ </body>
15
+ </html>
@@ -0,0 +1,12 @@
1
+ var config;
2
+
3
+ module("VZ.Config", {
4
+ setup: function() {
5
+ config = new VZ.Config();
6
+ }, teardown: function() {
7
+ delete config;
8
+ }
9
+ });
10
+ test( "new", function() {
11
+ ok( (config !== undefined && config !== null), "config is initialized" );
12
+ });
data/test/log_test.rb ADDED
@@ -0,0 +1,96 @@
1
+ require "helper"
2
+
3
+ class Patch::LogTest < Minitest::Test
4
+
5
+ context "Log" do
6
+
7
+ setup do
8
+ @out = Object.new
9
+ end
10
+
11
+ context "#exception" do
12
+
13
+ should "display exception" do
14
+ message = "blah blah"
15
+ @out.expects(:puts).once
16
+ @log = Patch::Log.new(@out)
17
+ begin
18
+ raise(message)
19
+ rescue Exception => e
20
+ @log.exception(e)
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ context "#info" do
27
+
28
+ should "display message" do
29
+ message = "blah blah"
30
+ @out.expects(:puts).once
31
+ @log = Patch::Log.new(@out)
32
+ @log.info(message)
33
+ end
34
+
35
+ end
36
+
37
+ context "#populate_level" do
38
+
39
+ setup do
40
+ @message = "blah blah"
41
+ @error = "error!"
42
+ end
43
+
44
+ should "only output info" do
45
+ @log = Patch::Log.new(@out, :show => :info)
46
+ refute @log.instance_variable_get("@exception")
47
+ assert @log.instance_variable_get("@info")
48
+ @out.expects(:puts).once
49
+ output = Object.new
50
+ output.expects(:colorize).once.with(:blue)
51
+ @log.expects(:format).once.with(@message, :type => :info).returns(output)
52
+ @log.info(@message)
53
+ begin
54
+ raise(@error)
55
+ rescue Exception => e
56
+ @log.exception(e)
57
+ end
58
+ end
59
+
60
+ should "only output exception" do
61
+ @log = Patch::Log.new(@out, :show => :exception)
62
+ assert @log.instance_variable_get("@exception")
63
+ refute @log.instance_variable_get("@info")
64
+ @out.expects(:puts).once
65
+ output = Object.new
66
+ output.expects(:colorize).once.with(:red)
67
+ @log.expects(:format).once.with(@error, :type => :exception).returns(output)
68
+ begin
69
+ raise(@error)
70
+ rescue Exception => e
71
+ @log.exception(e)
72
+ end
73
+ end
74
+
75
+ should "show everything" do
76
+ @log = Patch::Log.new(@out)
77
+ assert @log.instance_variable_get("@exception")
78
+ assert @log.instance_variable_get("@info")
79
+ @out.expects(:puts).twice
80
+ output = Object.new
81
+ output.expects(:colorize).once.with(:red)
82
+ output.expects(:colorize).once.with(:blue)
83
+ @log.expects(:format).once.with(@error, :type => :exception).returns(output)
84
+ @log.expects(:format).once.with(@message, :type => :info).returns(output)
85
+ begin
86
+ raise(@error)
87
+ rescue Exception => e
88
+ @log.exception(e)
89
+ end
90
+ end
91
+
92
+ end
93
+
94
+ end
95
+
96
+ end
@@ -0,0 +1,109 @@
1
+ require "helper"
2
+
3
+ class Patch::MessageTest < Minitest::Test
4
+
5
+ context "Message" do
6
+
7
+ setup do
8
+ @message = Patch::Message.new
9
+ end
10
+
11
+ context "#to_h" do
12
+
13
+ setup do
14
+ @message.index = 1
15
+ @message.value = 100
16
+ @message.patch_name = :test
17
+ end
18
+
19
+ should "have basic properties" do
20
+ @result = @message.to_h
21
+ refute_nil @result
22
+ refute_empty @result
23
+ refute_nil @result[:index]
24
+ refute_nil @result[:value]
25
+ refute_nil @result[:patch_name]
26
+ refute_nil @result[:timestamp]
27
+ assert_equal 1, @result[:index]
28
+ assert_equal 100, @result[:value]
29
+ assert_equal :test, @result[:patch_name]
30
+ end
31
+
32
+ should "have properties from hash" do
33
+ @message.send(:populate_from_properties, { :a_property => "hello!" })
34
+ @result = @message.to_h
35
+ refute_nil @result
36
+ refute_nil @result[:a_property]
37
+ assert_equal "hello!", @result[:a_property]
38
+ end
39
+
40
+ end
41
+
42
+ context "#to_json" do
43
+
44
+ setup do
45
+ @message.index = 10
46
+ @message.value = 200
47
+ @message.patch_name = :test
48
+ end
49
+
50
+ should "have all of the message properties" do
51
+ hash = @message.to_h
52
+ json = @message.to_json
53
+ hash.each do |key, value|
54
+ assert json.include?(key.to_s)
55
+ assert json.include?(value.to_s)
56
+ end
57
+ end
58
+
59
+ end
60
+
61
+ context "#timestamp" do
62
+
63
+ should "return js int time format" do
64
+ result = @message.timestamp
65
+ refute_nil result
66
+ assert_equal Fixnum, result.class
67
+ assert result.to_s.size > Time.new.to_i.to_s.size
68
+ assert_equal (result / 1000).to_s.size, Time.new.to_i.to_s.size
69
+ end
70
+
71
+ end
72
+
73
+ context "#timestamp_to_time" do
74
+
75
+ should "return Ruby time format" do
76
+ result = @message.send(:timestamp_to_time, 1413332943271)
77
+ refute_nil result
78
+ assert_equal Time, result.class
79
+ assert_equal 2014, result.year
80
+ end
81
+
82
+ end
83
+
84
+ context "#populate_from_properties" do
85
+
86
+ setup do
87
+ @hash = {
88
+ :index => 2,
89
+ :value => "blah",
90
+ :patch_name => :test,
91
+ :another_property => "something"
92
+ }
93
+ @message.send(:populate_from_properties, @hash)
94
+ end
95
+
96
+ should "have properties from hash" do
97
+ refute_nil @message.index
98
+ refute_nil @message.value
99
+ refute_nil @message.patch_name
100
+ assert_equal 2, @message.index
101
+ assert_equal "blah", @message.value
102
+ assert_equal :test, @message.patch_name
103
+ end
104
+
105
+ end
106
+
107
+ end
108
+
109
+ end
@@ -0,0 +1,104 @@
1
+ require "helper"
2
+
3
+ class Patch::Node::ContainerTest < Minitest::Test
4
+
5
+ context "Container" do
6
+
7
+ setup do
8
+ @nodes_hash = {
9
+ :nodes => [
10
+ {
11
+ :id => 1,
12
+ :type => "websocket",
13
+ :host => "localhost",
14
+ :port => 9006
15
+ },
16
+ {
17
+ :id => 2,
18
+ :type => "midi",
19
+ :direction => "input",
20
+ :name => "Apple Inc. IAC Driver"
21
+ },
22
+ {
23
+ :id => 3,
24
+ :type => "osc",
25
+ :server => {
26
+ :port => 8000
27
+ },
28
+ :client => {
29
+ :host => "192.168.1.118",
30
+ :port => 9000
31
+ }
32
+ }
33
+ ]
34
+ }.freeze
35
+ @nodes = Patch::Config.to_nodes(@nodes_hash)
36
+ end
37
+
38
+ context "#find_all_by_type" do
39
+
40
+ should "return osc nodes" do
41
+ nodes = @nodes.find_all_by_type(:osc)
42
+ refute_nil nodes
43
+ refute_empty nodes
44
+ assert nodes.all? { |node| node.class.name.match(/\APatch\:\:IO\:\:OSC/) }
45
+ end
46
+
47
+ should "return midi nodes" do
48
+ nodes = @nodes.find_all_by_type(:midi)
49
+ refute_nil nodes
50
+ refute_empty nodes
51
+ assert nodes.all? { |node| node.class.name.match(/\APatch\:\:IO\:\:MIDI/) }
52
+ end
53
+
54
+ should "return websocket nodes" do
55
+ nodes = @nodes.find_all_by_type(:websocket)
56
+ refute_nil nodes
57
+ refute_empty nodes
58
+ assert nodes.all? { |node| node.class.name.match(/\APatch\:\:IO\:\:Websocket/) }
59
+ end
60
+
61
+ should "not return non existant nodes" do
62
+ nodes = @nodes.find_all_by_type(:http)
63
+ refute_nil nodes
64
+ assert_empty nodes
65
+ end
66
+
67
+ end
68
+
69
+ context "#enable" do
70
+
71
+ setup do
72
+ @node_classes = [Patch::IO::MIDI::Input, Patch::IO::OSC::Server, Patch::IO::Websocket::Node]
73
+ @node_classes.each { |c| c.any_instance.expects(:start).once }
74
+ end
75
+
76
+ teardown do
77
+ @node_classes.each { |c| c.any_instance.unstub(:start) }
78
+ end
79
+
80
+ should "enable nodes" do
81
+ assert @nodes.enable
82
+ end
83
+
84
+ end
85
+
86
+ context "#find_by_id" do
87
+
88
+ should "return node with id" do
89
+ node = @nodes.find_by_id(2)
90
+ refute_nil node
91
+ refute_nil node.id
92
+ assert_equal 2, node.id
93
+ end
94
+
95
+ should "return nil if not found" do
96
+ node = @nodes.find_by_id(99)
97
+ assert_nil node
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+
104
+ end
@@ -0,0 +1,50 @@
1
+ require "helper"
2
+
3
+ class Patch::Node::MapTest < Minitest::Test
4
+
5
+ context "Map" do
6
+
7
+ setup do
8
+ load_test_data
9
+ @nodes = Patch::Config.to_nodes(@nodes_path)
10
+ @patches = Patch::Config.to_patches(@nodes, @patches_path)
11
+ end
12
+
13
+ context "#nodes" do
14
+
15
+ setup do
16
+ @map = @patches.first.maps.first
17
+ end
18
+
19
+ should "return all from and to nodes" do
20
+ @nodes = @map.nodes
21
+ refute_nil @nodes
22
+ refute_empty @nodes
23
+ assert @map.from.all? { |node| @nodes.include?(node) }
24
+ assert @map.to.all? { |node| @nodes.include?(node) }
25
+ end
26
+
27
+ end
28
+
29
+ context "#enable" do
30
+
31
+ setup do
32
+ @maps = @patches.first.maps
33
+ refute_empty @nodes
34
+ assert [Patch::IO::MIDI::Input, Patch::IO::OSC::Server, Patch::IO::Websocket::Node].all? { |klass| @nodes.map(&:class).include?(klass) }
35
+ ::Patch::Thread.expects(:new).times(@nodes.count)
36
+ end
37
+
38
+ teardown do
39
+ ::Patch::Thread.unstub(:new)
40
+ end
41
+
42
+ should "create node start threads" do
43
+ assert @maps.first.enable(@patches.first)
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
50
+ end
data/test/node_test.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "helper"
2
+
3
+ class Patch::NodeTest < Minitest::Test
4
+
5
+ context "Node" do
6
+
7
+ should "load classes" do
8
+ refute_nil Patch::Node::Container
9
+ refute_nil Patch::Node::Map
10
+ end
11
+
12
+ end
13
+
14
+ end