Skip to content

Commit

Permalink
Test Pio::Hello13.new().
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuhito committed Apr 6, 2015
1 parent 6f1e9c9 commit 9ecd4f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/pio/hello13.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ class HelloElement < BinData::Record
class Hello13 < BinData::Record
endian :big

uint8 :ofp_version, value: 4
uint8 :ofp_version, initial_value: 4
uint8 :message_type
uint16 :message_length
uint16 :message_length, value: 8
uint32 :transaction_id
array :elements, type: :hello_element, length: 0

def xid
transaction_id
end

alias_method :to_binary, :to_binary_s
end
end
16 changes: 15 additions & 1 deletion spec/pio/hello13_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
When(:result) { Pio::Hello13.read(binary) }

context 'with a hello message' do
Given(:binary) { [3, 0, 0, 8, 0, 0, 0, 0].pack('C*') }
Given(:binary) { [4, 0, 0, 8, 0, 0, 0, 0].pack('C*') }

Then { result.class == Pio::Hello13 }
Then { result.ofp_version == 4 }
Expand All @@ -16,4 +16,18 @@
Then { result.elements.empty? }
end
end

describe '.new' do
context 'with no arguments' do
When(:result) { Pio::Hello13.new }

Then { result.ofp_version == 4 }
Then { result.message_type == 0 }
Then { result.message_length == 8 }
Then { result.transaction_id == 0 }
Then { result.xid == 0 }
Then { result.elements.empty? }
Then { result.to_binary == [4, 0, 0, 8, 0, 0, 0, 0].pack('C*') }
end
end
end

0 comments on commit 9ecd4f1

Please sign in to comment.