osc-ruby 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'rr'
4
+
5
+ $:.unshift( File.join( File.dirname( __FILE__), '..', 'lib' ) )
6
+ $:.unshift( File.dirname( __FILE__ ) )
7
+
8
+ require 'osc-ruby'
9
+ require 'builders/message_builder'
10
+
11
+ Spec::Runner.configure do |config|
12
+ config.mock_with RR::Adapters::Rspec
13
+ end
@@ -0,0 +1,83 @@
1
+ require File.join( File.dirname(__FILE__) , '..', 'spec_helper' )
2
+
3
+ describe OSC::AddressPattern do
4
+ it "should match anything if the pattern is nil" do
5
+ ap = OSC::AddressPattern.new( nil )
6
+
7
+ ap.match?( "/some/nonsense").should be_true
8
+ ap.match?( "/completely.different").should be_true
9
+ end
10
+
11
+ it "should match based on a regex" do
12
+ ap = OSC::AddressPattern.new( /hi/ )
13
+
14
+ ap.match?( '/hi' ).should be_true
15
+ ap.match?( '/hidden' ).should be_true
16
+
17
+ ap.match?( '/bye' ).should be_false
18
+ end
19
+
20
+ it "should return a regex if the pattern is a string" do
21
+ ap = OSC::AddressPattern.new( "/hi" )
22
+
23
+ ap.match?('/hi').should be_true
24
+
25
+ ap.match?(' /hi').should be_false
26
+ ap.match?('/ahi').should be_false
27
+ ap.match?( '/hidden' ).should be_false
28
+ ap.match?( '/bye' ).should be_false
29
+ end
30
+
31
+ it "should match with question mark" do
32
+ ap = OSC::AddressPattern.new( "/h?l" )
33
+
34
+ ap.match?('/hal').should be_true
35
+ ap.match?('/hel').should be_true
36
+ ap.match?('/hil').should be_true
37
+ ap.match?('/hol').should be_true
38
+ ap.match?('/hul').should be_true
39
+ ap.match?('/hub').should be_false
40
+ end
41
+
42
+ it "should match with *" do
43
+ ap = OSC::AddressPattern.new( "/believ*d" )
44
+
45
+ ap.match?('/believd').should be_true
46
+ ap.match?('/believed').should be_true
47
+ ap.match?('/believeeed').should be_true
48
+ ap.match?('/believaeeeioud').should be_true
49
+ ap.match?('/believaeeeioud').should be_true
50
+ end
51
+
52
+ it "should match with []" do
53
+ ap = OSC::AddressPattern.new( "/believ[aeiou]d" )
54
+
55
+ ap.match?('/believad').should be_true
56
+ ap.match?('/believed').should be_true
57
+ ap.match?('/believid').should be_true
58
+ ap.match?('/believod').should be_true
59
+ ap.match?('/believud').should be_true
60
+ ap.match?('/believkd').should be_false
61
+ end
62
+
63
+ it "should match with [!]" do
64
+ ap = OSC::AddressPattern.new( "/believ[!aeiou]d" )
65
+
66
+ ap.match?('/believad').should be_false
67
+ ap.match?('/believed').should be_false
68
+ ap.match?('/believid').should be_false
69
+ ap.match?('/believod').should be_false
70
+ ap.match?('/believud').should be_false
71
+ ap.match?('/believkd').should be_true
72
+ ap.match?('/believzd').should be_true
73
+ end
74
+
75
+ it "should match with {}" do
76
+ ap = OSC::AddressPattern.new( "/{hi,bye}" )
77
+
78
+ ap.match?('/hi').should be_true
79
+ ap.match?('/bye').should be_true
80
+ ap.match?('/greetings').should be_false
81
+ end
82
+
83
+ end
@@ -0,0 +1,6 @@
1
+ require File.join( File.dirname(__FILE__) , '..', 'spec_helper' )
2
+
3
+
4
+ describe OSC::Bundle do
5
+
6
+ end
@@ -0,0 +1,34 @@
1
+ # some test data for when i unit test this
2
+ # @simple_packet = "/hi\000,\000\000\000"
3
+ # @simple_with_integer_arg = "/hi\000,i\000\000\000\000\000*"
4
+ # @simple_with_two_integer_args = "/hi\000,ii\000\000\000\000*\000\000\000!"
5
+ # @simple_with_float_arg = "/hi\000,f\000\000B(\n="
6
+ # @simple_with_two_float_args = "/hi\000,ff\000B(\n=B\004\n="
7
+ # @simple_with_string_arg = "/hi\000,s\000\000greetings\000\000\000"
8
+ # @simple_with_two_string_args = "/hi\000,ss\000greetings\000\000\000how are you?\000\000\000\000"
9
+ # @simple_with_int_float_string = "/hi\000,ifs\000\000\000\000\000\000\000*B\004\n=greetings\000\000\000"
10
+
11
+ require File.join( File.dirname(__FILE__) , '..', 'spec_helper' )
12
+
13
+
14
+ describe OSC::Message do
15
+ before :each do
16
+ @builder = MessageBuilder.new
17
+ @builder.with_int( 42 ).
18
+ with_int( 33 )
19
+
20
+ @message = @builder.build
21
+ end
22
+
23
+ it "should have no arguments if you define none" do
24
+ m = OSC::Message.new( "/hi" )
25
+ m.to_a.should == []
26
+ end
27
+
28
+ it "should have accept int arguments" do
29
+ m = OSC::Message.new( "/hi", 42 )
30
+ m.to_a.should == [42]
31
+ m.tags.should == "i"
32
+ end
33
+
34
+ end
@@ -0,0 +1,33 @@
1
+ require File.join( File.dirname(__FILE__) , '..', 'spec_helper' )
2
+
3
+
4
+ describe OSC::NetworkPacket do
5
+ before :each do
6
+ @empty = OSC::NetworkPacket.new( "" )
7
+ @simple = OSC::NetworkPacket.new( "abc" )
8
+ end
9
+
10
+ it "should know if it's at the end of the stream" do
11
+ @empty.eof?.should be_true
12
+ end
13
+
14
+ it "should know the remainder in the stream" do
15
+ @simple.rem.should == 3
16
+ end
17
+
18
+ it "should be able to skip positions" do
19
+ @simple.skip( 1 )
20
+ @simple.rem.should == 2
21
+ end
22
+
23
+ it "should be able to get a character from the stream" do
24
+ @simple.getc.should == ?a
25
+ @simple.getc.should == ?b
26
+ @simple.getc.should == ?c
27
+ @simple.eof?.should be_true
28
+ end
29
+
30
+ it "should be able to get a number of characters from the stream" do
31
+ @simple.getn(3).should == "abc"
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ require File.join( File.dirname(__FILE__) , '..', 'spec_helper' )
2
+
3
+ describe OSC::OSCArgument do
4
+ it "should not blow up" do
5
+ OSC::OSCArgument.new 1
6
+ end
7
+ end
@@ -0,0 +1,39 @@
1
+ require File.join( File.dirname(__FILE__) , '..', 'spec_helper' )
2
+
3
+
4
+ describe OSC::OSCPacket do
5
+ before :each do
6
+ @complex_packet = "#bundle\000\316\034\315T\000\003\030\370\000\000\000$/tuio/2Dobj\000,ss\000source\000\000simulator\000\000\000\000\000\000\030/tuio/2Dobj\000,s\000\000alive\000\000\000\000\000\000\034/tuio/2Dobj\000,si\000fseq\000\000\000\000\377\377\377\377"
7
+
8
+ @messages = OSC::OSCPacket.messages_from_network( @complex_packet )
9
+ end
10
+
11
+ it "should have three messages" do
12
+ @messages.should have(3).items
13
+ end
14
+
15
+ it "should have the propper address for the messages" do
16
+ 3.times do |i|
17
+ @messages[i].address.should eql("/tuio/2Dobj")
18
+ end
19
+ end
20
+
21
+ it "should have a first message with two strings" do
22
+ args = @messages[0].to_a
23
+
24
+ args[0].should eql( "source" )
25
+ args[1].should eql( "simulator" )
26
+ end
27
+
28
+ it "should have a second message with one string" do
29
+ args = @messages[1].to_a
30
+ args[0].should eql( "alive" )
31
+ end
32
+
33
+ it "should have a third message with a string and an int" do
34
+ args = @messages[2].to_a
35
+
36
+ args[0].should eql( "fseq" )
37
+ args[1].should eql(-1)
38
+ end
39
+ end
@@ -0,0 +1,108 @@
1
+ require File.join( File.dirname(__FILE__) , '..', 'spec_helper' )
2
+
3
+
4
+ describe OSC::OSCPacket do
5
+ before :each do
6
+ @address = "/hi"
7
+ @first_int = 42
8
+ @second_int = 33
9
+
10
+ @first_float = 42.01
11
+ @second_float = 33.01
12
+
13
+ @first_string = "greetings"
14
+ @second_string = "how are you?"
15
+
16
+ @first_blob = "this is a fake blob"
17
+ @second_blob = "tis another fake blob"
18
+
19
+ @builder = MessageBuilder.new
20
+ @builder.with_address( @address )
21
+ end
22
+
23
+ it "should decode the address of a simple message from the network data" do
24
+ sent_msg = @builder.build
25
+
26
+ msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
27
+
28
+ msg.first.address.should == @address
29
+ end
30
+
31
+ it "should decode the int arg of a simple message from the network data" do
32
+ sent_msg = @builder.with_int( @first_int ).build
33
+
34
+ msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
35
+
36
+ msg.first.to_a.should == [@first_int]
37
+ end
38
+
39
+ it "should decode two int args" do
40
+ sent_msg = @builder.with_int( @first_int ).with_int( @second_int ).build
41
+
42
+ msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
43
+
44
+ msg.first.to_a.should == [@first_int, @second_int]
45
+ end
46
+
47
+ it "shold decode address with float arg" do
48
+ sent_msg = @builder.with_float( @first_float ).build
49
+
50
+ msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
51
+
52
+ msg.first.to_a[0].should be_close( @first_float, 0.001 )
53
+ end
54
+
55
+
56
+ it "shold decode address with two float args" do
57
+ sent_msg = @builder.with_float( @first_float ).with_float( @second_float).build
58
+
59
+ msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
60
+
61
+ args = msg.first.to_a
62
+ args.first.should be_close( @first_float, 0.001 )
63
+ args[1].should be_close( @second_float, 0.0001 )
64
+ end
65
+
66
+ it "should decode address with string arg" do
67
+ sent_msg = @builder.with_string( @first_string ).build
68
+
69
+ msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
70
+
71
+ msg.first.to_a.should == [@first_string]
72
+ end
73
+
74
+ it "should decode address with multiple string args" do
75
+ sent_msg = @builder.with_string( @first_string ).with_string( @second_string).build
76
+ msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
77
+
78
+ args = msg.first.to_a
79
+ args[0].should == @first_string
80
+ args[1].should == @second_string
81
+ end
82
+
83
+
84
+ it "should decode messages with three different types of args" do
85
+ sent_msg = @builder.with_int( @first_int ).
86
+ with_float( @second_float ).
87
+ with_string( @first_string ).
88
+ build
89
+
90
+ msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
91
+
92
+ args = msg.first.to_a
93
+
94
+ args[0].should eql( @first_int )
95
+ args[1].should be_close( @second_float, 0.0001 )
96
+ args[2].should eql( @first_string )
97
+ end
98
+
99
+ it "should decode messages with blobs" do
100
+ sent_msg = @builder.with_blob( @first_blob ).build
101
+
102
+
103
+ msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
104
+
105
+ args = msg.first.to_a
106
+ args.first.should eql( @first_blob )
107
+ end
108
+ end
@@ -0,0 +1,25 @@
1
+ require File.join( File.dirname(__FILE__) , '..', 'spec_helper' )
2
+
3
+ describe OSC::OSCInt32 do
4
+ it "should not blow up" do
5
+ OSC::OSCInt32.new 1
6
+ end
7
+ end
8
+
9
+ describe OSC::OSCFloat32 do
10
+ it "should not blow up" do
11
+ OSC::OSCFloat32.new 1.0
12
+ end
13
+ end
14
+
15
+ describe OSC::OSCString do
16
+ it "should not blow up" do
17
+ OSC::OSCString.new "1"
18
+ end
19
+ end
20
+
21
+ describe OSC::OSCBlob do
22
+ it "should not blow up" do
23
+ OSC::OSCBlob.new 1
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: osc-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - aberant
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-16 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: qzzzq1@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - Rakefile
26
+ - examples/classic_server.rb
27
+ - examples/event_machine_server.rb
28
+ - lib/osc-ruby.rb
29
+ - lib/osc-ruby/address_pattern.rb
30
+ - lib/osc-ruby/bundle.rb
31
+ - lib/osc-ruby/client.rb
32
+ - lib/osc-ruby/core_ext/numeric.rb
33
+ - lib/osc-ruby/core_ext/object.rb
34
+ - lib/osc-ruby/core_ext/time.rb
35
+ - lib/osc-ruby/em_server.rb
36
+ - lib/osc-ruby/message.rb
37
+ - lib/osc-ruby/network_packet.rb
38
+ - lib/osc-ruby/osc_argument.rb
39
+ - lib/osc-ruby/osc_packet.rb
40
+ - lib/osc-ruby/osc_types.rb
41
+ - lib/osc-ruby/packet.rb
42
+ - lib/osc-ruby/server.rb
43
+ - README.rdoc
44
+ has_rdoc: true
45
+ homepage: http://github.com/aberant/osc-ruby
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --charset=UTF-8
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project: osc-ruby
66
+ rubygems_version: 1.3.1
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: inital gem
70
+ test_files:
71
+ - spec/builders/message_builder.rb
72
+ - spec/spec_helper.rb
73
+ - spec/unit/address_pattern_spec.rb
74
+ - spec/unit/message_bundle_spec.rb
75
+ - spec/unit/message_spec.rb
76
+ - spec/unit/network_packet_spec.rb
77
+ - spec/unit/osc_argument_spec.rb
78
+ - spec/unit/osc_complex_packets_spec.rb
79
+ - spec/unit/osc_simple_packets_spec.rb
80
+ - spec/unit/osc_types_spec.rb