# encoding: utf-8 require 'pio' describe Pio::Features do describe '.read' do context 'with a Features Request message' do Given(:features_request_dump) { [1, 5, 0, 8, 0, 0, 0, 0].pack('C*') } When(:features_request) { Pio::Features.read(features_request_dump) } Then { features_request.class == Pio::Features::Request } Then { features_request.version == 1 } Then { features_request.message_type == Pio::Features::REQUEST } Then { features_request.message_length == 8 } Then { features_request.transaction_id == 0 } Then { features_request.xid == 0 } Then { features_request.body.empty? } end context 'with a Features Reply message' do Given(:features_reply_dump) do [0x01, 0x06, 0x01, 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0xe2, 0xfc, 0x0f, 0xae, 0x66, 0x4d, 0x00, 0x00, 0x01, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc7, 0x00, 0x00, 0x0f, 0xff, 0x00, 0x03, 0x82, 0xb0, 0xff, 0x6e, 0x51, 0x44, 0x76, 0x65, 0x74, 0x68, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x9e, 0x49, 0x7d, 0x7c, 0x06, 0x8d, 0x76, 0x65, 0x74, 0x68, 0x32, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x12, 0x13, 0xb4, 0x13, 0x4c, 0x19, 0x76, 0x65, 0x74, 0x68, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x86, 0xbd, 0xe3, 0xad, 0x3d, 0x73, 0x76, 0x65, 0x74, 0x68, 0x31, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfe, 0xe2, 0xfc, 0x0f, 0xae, 0x66, 0x4d, 0x62, 0x72, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00].pack('C*') end When(:features_reply) { Pio::Features.read(features_reply_dump) } Then { features_reply.class == Pio::Features::Reply } Then { features_reply.version == 1 } Then { features_reply.message_type == Pio::Features::REPLY } Then { features_reply.message_length == 272 } Then { features_reply.transaction_id == 2 } Then { features_reply.xid == 2 } Then { !features_reply.body.empty? } Then { features_reply.datapath_id == 0xe2fc0fae664d } Then { features_reply.n_buffers == 0x100 } Then { features_reply.n_tables == 0xfe } Then { features_reply.capabilities == 0xc7 } Then { features_reply.actions == 0xfff } Then { features_reply.ports.size == 7 } end context 'with a Hello message' do Given(:hello_dump) { [1, 0, 0, 8, 0, 0, 0, 0].pack('C*') } When(:result) { Pio::Features.read(hello_dump) } Then { result == Failure(Pio::ParseError) } end end end