From 9ecd4f12f1672c965427260c828efa94dbc84628 Mon Sep 17 00:00:00 2001 From: Yasuhito Takamiya Date: Mon, 6 Apr 2015 13:37:57 +0900 Subject: [PATCH] Test Pio::Hello13.new(). --- lib/pio/hello13.rb | 6 ++++-- spec/pio/hello13_spec.rb | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/pio/hello13.rb b/lib/pio/hello13.rb index 5515e236..e41cabca 100644 --- a/lib/pio/hello13.rb +++ b/lib/pio/hello13.rb @@ -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 diff --git a/spec/pio/hello13_spec.rb b/spec/pio/hello13_spec.rb index 43a66d61..b9f008c8 100644 --- a/spec/pio/hello13_spec.rb +++ b/spec/pio/hello13_spec.rb @@ -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 } @@ -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