/
osc_simple_packets_spec.rb
118 lines (79 loc) · 3.23 KB
/
osc_simple_packets_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
require File.join( File.dirname(__FILE__) , '..', 'spec_helper' )
describe OSC::OSCPacket do
before :each do
@address = "/hi"
@first_int = 42
@second_int = 33
@first_float = 42.01
@second_float = 33.01
@first_string = "greetings"
@second_string = "how are you?"
@first_blob = "this is a fake blob"
@second_blob = "tis another fake blob"
@builder = MessageBuilder.new
@builder.with_address( @address )
end
it "should decode the address of a simple message from the network data" do
sent_msg = @builder.build
msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
msg.first.address.must_equal @address
end
it "should decode the int arg of a simple message from the network data" do
sent_msg = @builder.with_int( @first_int ).build
msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
msg.first.to_a.must_equal [@first_int]
end
it "should decode two int args" do
sent_msg = @builder.with_int( @first_int ).with_int( @second_int ).build
msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
msg.first.to_a.must_equal [@first_int, @second_int]
end
it "should decode address with float arg" do
sent_msg = @builder.with_float( @first_float ).build
msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
msg.first.to_a[0].must_be_close_to( @first_float, 0.001 )
end
it "should decode address with two float args" do
sent_msg = @builder.with_float( @first_float ).with_float( @second_float ).build
msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
args = msg.first.to_a
args.first.must_be_close_to( @first_float, 0.001 )
args[1].must_be_close_to( @second_float, 0.001 )
end
it "should decode address with string arg" do
sent_msg = @builder.with_string( @first_string ).build
msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
msg.first.to_a.must_equal [@first_string]
end
it "should decode address with multiple string args" do
sent_msg = @builder.with_string( @first_string ).with_string( @second_string).build
msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
args = msg.first.to_a
args[0].must_equal @first_string
args[1].must_equal @second_string
end
it "should decode messages with three different types of args" do
sent_msg = @builder.with_int( @first_int ).
with_float( @second_float ).
with_string( @first_string ).
build
msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
args = msg.first.to_a
args[0].must_equal( @first_int )
args[1].must_be_close_to( @second_float, 0.001 )
args[2].must_equal( @first_string )
end
it "should decode messages with blobs" do
sent_msg = @builder.with_blob( @first_blob ).build
msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
args = msg.first.to_a
args.first.must_equal( @first_blob )
end
it "should decode messages with double64 types" do
pi = 3.14159
sent_msg = @builder.with_double( pi ).build
msg = OSC::OSCPacket.messages_from_network( sent_msg.encode )
args = msg.first.to_a
args.first.must_be_close_to( pi, 0.001 )
end
end