blob: 2d5b37513667b68a57d1174a4788d4e9241ad838 [file] [log] [blame]
Kevin Clarkf18b6432008-06-18 01:07:10 +00001require File.dirname(__FILE__) + '/spec_helper'
2require 'thrift/protocol/binaryprotocol'
David Reiss72754e12008-07-25 21:06:03 +00003require File.dirname(__FILE__) + '/binaryprotocol_spec_shared'
Kevin Clarkf18b6432008-06-18 01:07:10 +00004
Kevin Clark356f8612008-06-18 01:08:05 +00005class ThriftBinaryProtocolSpec < Spec::ExampleGroup
Kevin Clarkf18b6432008-06-18 01:07:10 +00006 include Thrift
7
8 describe BinaryProtocol do
David Reiss72754e12008-07-25 21:06:03 +00009 it_should_behave_like 'a binary protocol'
Kevin Clarkf18b6432008-06-18 01:07:10 +000010
David Reiss72754e12008-07-25 21:06:03 +000011 def protocol_class
12 BinaryProtocol
Kevin Clarkf18b6432008-06-18 01:07:10 +000013 end
Kevin Clark5ae03842008-06-18 01:07:37 +000014
15 it "should read a message header" do
Kevin Clarkead33822009-02-04 22:43:59 +000016 @trans.should_receive(:read_all).exactly(2).times.and_return(
17 [protocol_class.const_get(:VERSION_1) | Thrift::MessageTypes::REPLY].pack('N'),
18 [42].pack('N')
19 )
Kevin Clark5ae03842008-06-18 01:07:37 +000020 @prot.should_receive(:read_string).and_return('testMessage')
David Reiss72754e12008-07-25 21:06:03 +000021 @prot.read_message_begin.should == ['testMessage', Thrift::MessageTypes::REPLY, 42]
Kevin Clark5ae03842008-06-18 01:07:37 +000022 end
23
Kevin Clarkc13c33b2008-06-18 01:12:48 +000024 it "should raise an exception if the message header has the wrong version" do
Kevin Clarkead33822009-02-04 22:43:59 +000025 @prot.should_receive(:read_i32).and_return(-1)
David Reiss72754e12008-07-25 21:06:03 +000026 lambda { @prot.read_message_begin }.should raise_error(Thrift::ProtocolException, 'Missing version identifier') do |e|
27 e.type == Thrift::ProtocolException::BAD_VERSION
Kevin Clark5ae03842008-06-18 01:07:37 +000028 end
29 end
Kevin Clarkead33822009-02-04 22:43:59 +000030
31 it "should raise an exception if the message header does not exist and strict_read is enabled" do
32 @prot.should_receive(:read_i32).and_return(42)
33 @prot.should_receive(:strict_read).and_return(true)
34 lambda { @prot.read_message_begin }.should raise_error(Thrift::ProtocolException, 'No version identifier, old protocol client?') do |e|
35 e.type == Thrift::ProtocolException::BAD_VERSION
36 end
37 end
Kevin Clarkf18b6432008-06-18 01:07:10 +000038 end
Kevin Clarke977a632008-06-18 01:07:50 +000039
40 describe BinaryProtocolFactory do
41 it "should create a BinaryProtocol" do
Kevin Clark90a2cbe2008-06-18 01:15:53 +000042 BinaryProtocolFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(BinaryProtocol)
Kevin Clarke977a632008-06-18 01:07:50 +000043 end
44 end
Kevin Clarkf18b6432008-06-18 01:07:10 +000045end