blob: b85f096d4f6b6227ee0e8832b41b74d2d3eeee38 [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
David Reiss72754e12008-07-25 21:06:03 +000016 @prot.should_receive(:read_i32).and_return(protocol_class.const_get(:VERSION_1) | Thrift::MessageTypes::REPLY, 42)
Kevin Clark5ae03842008-06-18 01:07:37 +000017 @prot.should_receive(:read_string).and_return('testMessage')
David Reiss72754e12008-07-25 21:06:03 +000018 @prot.read_message_begin.should == ['testMessage', Thrift::MessageTypes::REPLY, 42]
Kevin Clark5ae03842008-06-18 01:07:37 +000019 end
20
Kevin Clarkc13c33b2008-06-18 01:12:48 +000021 it "should raise an exception if the message header has the wrong version" do
22 @prot.should_receive(:read_i32).and_return(42)
David Reiss72754e12008-07-25 21:06:03 +000023 lambda { @prot.read_message_begin }.should raise_error(Thrift::ProtocolException, 'Missing version identifier') do |e|
24 e.type == Thrift::ProtocolException::BAD_VERSION
Kevin Clark5ae03842008-06-18 01:07:37 +000025 end
26 end
Kevin Clarkf18b6432008-06-18 01:07:10 +000027 end
Kevin Clarke977a632008-06-18 01:07:50 +000028
29 describe BinaryProtocolFactory do
30 it "should create a BinaryProtocol" do
Kevin Clark90a2cbe2008-06-18 01:15:53 +000031 BinaryProtocolFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(BinaryProtocol)
Kevin Clarke977a632008-06-18 01:07:50 +000032 end
33 end
Kevin Clarkf18b6432008-06-18 01:07:10 +000034end