ruby-player 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/client_spec.rb CHANGED
@@ -5,7 +5,7 @@ describe Player::Client do
5
5
  before do
6
6
  @socket = mock("Socket")
7
7
 
8
- TCPSocket.stub!(:new).with("localhost", 6665).and_return(@socket)
8
+ TCPSocket.should_receive(:new).with("localhost", 6665).and_return(@socket)
9
9
  @socket.stub! :flush
10
10
  Time.stub!(:now).and_return(0)
11
11
 
@@ -19,10 +19,12 @@ describe Player::Client do
19
19
  @cl = Player::Client.new("localhost", log_level: "debug")
20
20
  end
21
21
 
22
- # it "should raise error if connection doesn't success" do
23
- # lambda{ Player::Client.new(host: "localhost", post: 6666) }.should raise_error(StandardError,
24
- # "connect call on [localhost:6666] failed with error [111:Connection refused]")
25
- # end
22
+ =begin
23
+ it "should raise error if connection doesn't success" do
24
+ lambda{ Player::Client.new("localhost", port: 6666) }.should raise_error(StandardError,
25
+ "connect call on [localhost:6666] failed with error [111:Connection refused]")
26
+ end
27
+ =end
26
28
 
27
29
  it "should have close method" do
28
30
  @socket.should_receive(:closed?).and_return(false)
@@ -35,7 +37,8 @@ describe Player::Client do
35
37
  end
36
38
 
37
39
  it "should have block for connection" do
38
- @socket.stub!(:read)
40
+ TCPSocket.should_receive(:new).with("localhost", 6665).and_return(@socket)
41
+ @socket.should_receive(:read).with(PLAYER_IDENT_STRLEN).and_return("Mock player for 3.1-svn")
39
42
  @socket.stub!(:write)
40
43
  @socket.should_receive(:closed?).and_return(false)
41
44
  @socket.should_receive(:close)
@@ -45,6 +48,25 @@ describe Player::Client do
45
48
  end
46
49
  end
47
50
 
51
+ it "should write header to socket" do
52
+ hdr = Header.new
53
+ @socket.should_receive(:write).with(hdr.encode)
54
+ @socket.should_receive(:write).with("")
55
+
56
+ @cl.send_message_with_hdr(hdr, "")
57
+ end
58
+
59
+ it "shoul write message with header to socket" do
60
+ msg = "Hello"
61
+ hdr = Header.new(size: msg.bytesize)
62
+
63
+ @cl.should_receive(:send_header).with(hdr)
64
+ @socket.should_receive(:write).with(msg)
65
+ @socket.should_receive(:flush)
66
+
67
+ @cl.send_message_with_hdr(hdr, msg)
68
+ end
69
+
48
70
  describe "Device manage" do
49
71
  before do
50
72
  #subscribe two position2d
@@ -118,6 +140,15 @@ describe Player::Client do
118
140
  should_recive_sync
119
141
  end
120
142
 
143
+ it 'should for unique devices' do
144
+ mock_subscribe(PLAYER_POSITION2D_CODE)
145
+ @cl.subscribe("position2d")
146
+
147
+
148
+ mock_subscribe(PLAYER_POSITION2D_CODE)
149
+ @cl.subscribe("position2d").should be_nil
150
+ end
151
+
121
152
  it "should describe to position2d:0" do
122
153
  mock_subscribe(PLAYER_POSITION2D_CODE)
123
154
 
@@ -162,6 +193,16 @@ describe Player::Client do
162
193
  actarray.addr.interface_name.should eql("actarray")
163
194
  actarray.addr.index.should eql(4)
164
195
  end
196
+
197
+ it "should describe to actarray:5" do
198
+ mock_subscribe(PLAYER_BLOBFINDER_CODE, 5)
199
+
200
+ bf = @cl.subscribe(:blobfinder, index: 5)
201
+ bf.should be_an_instance_of(Player::BlobFinder)
202
+ bf.addr.interface_name.should eql("blobfinder")
203
+ bf.addr.index.should eql(5)
204
+ end
205
+
165
206
  end
166
207
 
167
208
  private
@@ -0,0 +1,51 @@
1
+ require "ruby-player"
2
+
3
+ include Player
4
+
5
+ describe Player::DevAddr do
6
+ before do
7
+ @data = [0, 0, PLAYER_PLAYER_CODE, 0]
8
+ @dev = make_dev_addr
9
+ end
10
+
11
+ it "should have attrs" do
12
+ @dev.host.should eql(0)
13
+ @dev.robot.should eql(0)
14
+ @dev.interface.should eql(PLAYER_PLAYER_CODE)
15
+ @dev.index.should eql(0)
16
+ end
17
+
18
+ it "should have interface_name" do
19
+ @dev.interface_name.should eql("player")
20
+ end
21
+
22
+ it "should be compare with other dev addr" do
23
+ other = DevAddr.new
24
+ @dev.should_not == other
25
+
26
+ other = make_dev_addr
27
+ @dev.should == other
28
+ end
29
+
30
+ it "should be made from string" do
31
+ DevAddr.decode(@data.pack("NNNN")).should == @dev
32
+ end
33
+
34
+ it "should encode itself to string for sending" do
35
+ @dev.encode.should eql(@data.pack("NNNN"))
36
+ end
37
+
38
+ it "should convert to array" do
39
+ @dev.to_a.should eql(@data)
40
+ end
41
+
42
+ private
43
+ def make_dev_addr
44
+ DevAddr.new(
45
+ host: @data[0],
46
+ robot: @data[1],
47
+ interface: @data[2],
48
+ index: @data[3]
49
+ )
50
+ end
51
+ end
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + "/spec_helper"
2
+
3
+ include Player
4
+ describe Player::Device do
5
+ before do
6
+ @dev_addr = DevAddr.new(interface: PLAYER_POSITION2D_CODE)
7
+ @client = mock_client
8
+ @dev = Device.new(@dev_addr, @client)
9
+ end
10
+
11
+ it "should have addr" do
12
+ @dev.addr.should == @dev_addr
13
+ end
14
+
15
+ it "should send message" do
16
+ Time.stub!(:now).and_return(0)
17
+ @client.should_receive(:send_message_with_hdr).with(
18
+ Header.new(
19
+ dev_addr: @dev_addr,
20
+ type: PLAYER_MSGTYPE_REQ,
21
+ subtype: PLAYER_POSITION2D_REQ_MOTOR_POWER,
22
+ size: 4
23
+ ), [0].pack("N")
24
+ )
25
+ @dev.send_message(PLAYER_MSGTYPE_REQ, PLAYER_POSITION2D_REQ_MOTOR_POWER, "\x0\x0\x0\x0")
26
+ end
27
+ end
data/spec/gripper_spec.rb CHANGED
@@ -22,7 +22,7 @@ describe Player::Position2d do
22
22
  )
23
23
  end
24
24
 
25
- it 'should have open? attribute' do
25
+ it 'should have #open? method' do
26
26
  @gripper.should_receive(:state).and_return(state: PLAYER_GRIPPER_STATE_OPEN)
27
27
  @gripper.open?.should be_true
28
28
 
@@ -30,7 +30,7 @@ describe Player::Position2d do
30
30
  @gripper.open?.should be_false
31
31
  end
32
32
 
33
- it 'should have closed? attribute' do
33
+ it 'should have #closed? method' do
34
34
  @gripper.should_receive(:state).and_return(state: PLAYER_GRIPPER_STATE_CLOSED)
35
35
  @gripper.closed?.should be_true
36
36
 
@@ -38,7 +38,7 @@ describe Player::Position2d do
38
38
  @gripper.closed?.should be_false
39
39
  end
40
40
 
41
- it 'should have moving? attribute' do
41
+ it 'should have #moving? method' do
42
42
  @gripper.should_receive(:state).and_return(state: PLAYER_GRIPPER_STATE_MOVING)
43
43
  @gripper.moving?.should be_true
44
44
 
@@ -46,7 +46,7 @@ describe Player::Position2d do
46
46
  @gripper.moving?.should be_false
47
47
  end
48
48
 
49
- it 'should have error? attribute' do
49
+ it 'should have #error? method' do
50
50
  @gripper.should_receive(:state).and_return(state: PLAYER_GRIPPER_STATE_ERROR)
51
51
  @gripper.error?.should be_true
52
52
 
@@ -54,6 +54,16 @@ describe Player::Position2d do
54
54
  @gripper.error?.should be_false
55
55
  end
56
56
 
57
+ it 'should have #beams attr' do
58
+ @gripper.should_receive(:state).and_return(beams: 4)
59
+ @gripper.beams.should eql(4)
60
+ end
61
+
62
+ it 'should have #stored attr' do
63
+ @gripper.should_receive(:state).and_return(stored: 2)
64
+ @gripper.stored.should eql(2)
65
+ end
66
+
57
67
  it 'should open gripper' do
58
68
  should_send_message(PLAYER_MSGTYPE_CMD, PLAYER_GRIPPER_CMD_OPEN)
59
69
  @gripper.open!
@@ -0,0 +1,61 @@
1
+ require "ruby-player"
2
+
3
+ include Player
4
+
5
+ describe Player::Header do
6
+ before do
7
+ @data = [
8
+ 0, 0, PLAYER_PLAYER_CODE, 0,
9
+ PLAYER_MSGTYPE_REQ, PLAYER_PLAYER_REQ_DEV, 0.1, 0, 10
10
+ ]
11
+
12
+ @hdr = make_header
13
+ end
14
+
15
+ it "should have attrs" do
16
+ @hdr.dev_addr.should == Player::DevAddr.new(host: 0, robot: 0, interface: PLAYER_PLAYER_CODE, index: 0)
17
+ @hdr.type.should eql(PLAYER_MSGTYPE_REQ)
18
+ @hdr.subtype.should eql(PLAYER_PLAYER_REQ_DEV)
19
+ @hdr.size.should eql(10)
20
+ end
21
+
22
+ it "should have type_name" do
23
+ @hdr.type_name.should eql("MSGTYPE_REQ")
24
+ end
25
+
26
+ it "should have subtype_name" do
27
+ @hdr.subtype_name.should eql("PLAYER_REQ_DEV")
28
+ end
29
+
30
+ it "should comapre with other header" do
31
+ other = Header.new
32
+ @hdr.should_not == other
33
+
34
+ other = make_header
35
+ @hdr.should == other
36
+ end
37
+
38
+ it "should decode itself from string " do
39
+ Header.decode(@data.pack("NNNNNNGNN")).should == @hdr
40
+ end
41
+
42
+ it "should be made form array" do
43
+ Header.from_a(@data).should == @hdr
44
+ end
45
+
46
+ it "should encode string for sending" do
47
+ @hdr.encode.should eql(@data.pack("NNNNNNGNN"))
48
+ end
49
+
50
+ private
51
+ def make_header
52
+ Player::Header.new(
53
+ dev_addr: Player::DevAddr.new(host: @data[0], robot: @data[1], interface: @data[2], index: @data[3]),
54
+ type: @data[4],
55
+ subtype: @data[5],
56
+ time: @data[6],
57
+ seq: @data[7],
58
+ size: @data[8]
59
+ )
60
+ end
61
+ end
@@ -17,6 +17,44 @@ describe Player::Position2d do
17
17
  @pos2d.geom.should eql(px:0.0, py:0.0, pz:0.0, proll:0.0, ppitch:0.0, pyaw:0.0, sw:0.0, sl:0.0, sh:0.0)
18
18
  end
19
19
 
20
+ it 'should have #px attributes' do
21
+ @pos2d.should_receive(:state).and_return(px: 2.2)
22
+ @pos2d.px.should eql(2.2)
23
+ end
24
+
25
+ it 'should have #py attributes' do
26
+ @pos2d.should_receive(:state).and_return(py: 2.9)
27
+ @pos2d.py.should eql(2.9)
28
+ end
29
+
30
+ it 'should have #pa attributes' do
31
+ @pos2d.should_receive(:state).and_return(pa: 0.2)
32
+ @pos2d.pa.should eql(0.2)
33
+ end
34
+
35
+ it 'should have #vx attributes' do
36
+ @pos2d.should_receive(:state).and_return(vx: 0.1)
37
+ @pos2d.vx.should eql(0.1)
38
+ end
39
+
40
+ it 'should have #vy attributes' do
41
+ @pos2d.should_receive(:state).and_return(vy: 0.9)
42
+ @pos2d.vy.should eql(0.9)
43
+ end
44
+
45
+ it 'should have #va attributes' do
46
+ @pos2d.should_receive(:state).and_return(va: 4.2)
47
+ @pos2d.va.should eql(4.2)
48
+ end
49
+
50
+ it 'should have #power? method' do
51
+ @pos2d.should_receive(:state).and_return(stall: 0)
52
+ @pos2d.power?.should be_false
53
+
54
+ @pos2d.should_receive(:state).and_return(stall: 1)
55
+ @pos2d.power?.should be_true
56
+ end
57
+
20
58
  it 'should query geometry' do
21
59
  should_send_message(PLAYER_MSGTYPE_REQ, PLAYER_POSITION2D_REQ_GET_GEOM)
22
60
  @pos2d.query_geom
data/spec/power_spec.rb CHANGED
@@ -17,6 +17,26 @@ describe Player::Power do
17
17
  @power.state.should eql(valid: 0, volts: 0.0, percent: 0.0, joules: 0.0, watts: 0.0, charging: 0)
18
18
  end
19
19
 
20
+ it 'should have #volts attr' do
21
+ @power.should_receive(:state).and_return(volts: 3.3)
22
+ @power.volts.should eql(3.3)
23
+ end
24
+
25
+ it 'should have #percent attr' do
26
+ @power.should_receive(:state).and_return(percent: 90.0)
27
+ @power.percent.should eql(90.0)
28
+ end
29
+
30
+ it 'should have #joules attr' do
31
+ @power.should_receive(:state).and_return(joules: 23.2)
32
+ @power.joules.should eql(23.2)
33
+ end
34
+
35
+ it 'should have #watts attr' do
36
+ @power.should_receive(:state).and_return(watts: 9.4)
37
+ @power.watts.should eql(9.4)
38
+ end
39
+
20
40
  it 'should have volts_valid? attribute' do
21
41
  @power.should_receive(:state).and_return(valid: 1)
22
42
  @power.volts_valid?.should be_true
data/spec/ranger_spec.rb CHANGED
@@ -13,8 +13,6 @@ describe Player::Ranger do
13
13
  end
14
14
 
15
15
  it 'should have default values' do
16
- @ranger.rangers.should eql([])
17
- @ranger.intensities.should eql([])
18
16
  @ranger.geom.should eql(px:0.0, py:0.0, pz:0.0, proll:0.0, ppitch:0.0, pyaw:0.0, sw:0.0, sl:0.0, sh:0.0)
19
17
  @ranger.config.should eql(min_angle: 0.0, max_angle: 0.0, angular_res: 0.0, min_range: 0.0, max_range: 0.0, range_res: 0.0, frequecy: 0.0)
20
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-player
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-06 00:00:00.000000000 Z
12
+ date: 2012-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: isna
16
- requirement: &10656420 !ruby/object:Gem::Requirement
16
+ requirement: &9997220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.0.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *10656420
24
+ version_requirements: *9997220
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &10655940 !ruby/object:Gem::Requirement
27
+ requirement: &9996380 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '2.7'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *10655940
35
+ version_requirements: *9996380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &10655440 !ruby/object:Gem::Requirement
38
+ requirement: &9995860 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.9'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *10655440
46
+ version_requirements: *9995860
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pry
49
- requirement: &10655040 !ruby/object:Gem::Requirement
49
+ requirement: &9994940 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *10655040
57
+ version_requirements: *9994940
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: yard
60
- requirement: &10654440 !ruby/object:Gem::Requirement
60
+ requirement: &9994240 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *10654440
68
+ version_requirements: *9994240
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: redcarpet
71
- requirement: &10653560 !ruby/object:Gem::Requirement
71
+ requirement: &9993500 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *10653560
79
+ version_requirements: *9993500
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: guard-rspec
82
- requirement: &10652440 !ruby/object:Gem::Requirement
82
+ requirement: &9993080 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *10652440
90
+ version_requirements: *9993080
91
91
  description: Ruby Player - Ruby client library for Player (tools for robots)
92
92
  email:
93
93
  - atimin@gmail.com
@@ -110,6 +110,8 @@ files:
110
110
  - lib/ruby-player.rb
111
111
  - lib/ruby-player/actarray.rb
112
112
  - lib/ruby-player/actuator.rb
113
+ - lib/ruby-player/blob.rb
114
+ - lib/ruby-player/blob_finder.rb
113
115
  - lib/ruby-player/client.rb
114
116
  - lib/ruby-player/common.rb
115
117
  - lib/ruby-player/constants.rb
@@ -125,8 +127,13 @@ files:
125
127
  - ruby-player.gemspec
126
128
  - spec/actarray_spec.rb
127
129
  - spec/actuator_spec.rb
130
+ - spec/blob_finder_spec.rb
131
+ - spec/blob_spec.rb
128
132
  - spec/client_spec.rb
133
+ - spec/dev_addr_spec.rb
134
+ - spec/device_spec.rb
129
135
  - spec/gripper_spec.rb
136
+ - spec/header_spec.rb
130
137
  - spec/position2d_spec.rb
131
138
  - spec/power_spec.rb
132
139
  - spec/ranger_spec.rb
@@ -151,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
158
  version: '0'
152
159
  requirements: []
153
160
  rubyforge_project:
154
- rubygems_version: 1.8.15
161
+ rubygems_version: 1.8.17
155
162
  signing_key:
156
163
  specification_version: 3
157
164
  summary: Ruby Player - Ruby client library for Player (tools for robots)