Kevin Clark | f18b643 | 2008-06-18 01:07:10 +0000 | [diff] [blame] | 1 | require File.dirname(__FILE__) + '/spec_helper' |
| 2 | require 'thrift/protocol/binaryprotocol' |
David Reiss | 72754e1 | 2008-07-25 21:06:03 +0000 | [diff] [blame] | 3 | require File.dirname(__FILE__) + '/binaryprotocol_spec_shared' |
Kevin Clark | f18b643 | 2008-06-18 01:07:10 +0000 | [diff] [blame] | 4 | |
Kevin Clark | 356f861 | 2008-06-18 01:08:05 +0000 | [diff] [blame] | 5 | class ThriftBinaryProtocolSpec < Spec::ExampleGroup |
Kevin Clark | f18b643 | 2008-06-18 01:07:10 +0000 | [diff] [blame] | 6 | include Thrift |
| 7 | |
| 8 | describe BinaryProtocol do |
David Reiss | 72754e1 | 2008-07-25 21:06:03 +0000 | [diff] [blame] | 9 | it_should_behave_like 'a binary protocol' |
Kevin Clark | f18b643 | 2008-06-18 01:07:10 +0000 | [diff] [blame] | 10 | |
David Reiss | 72754e1 | 2008-07-25 21:06:03 +0000 | [diff] [blame] | 11 | def protocol_class |
| 12 | BinaryProtocol |
Kevin Clark | f18b643 | 2008-06-18 01:07:10 +0000 | [diff] [blame] | 13 | end |
Kevin Clark | 5ae0384 | 2008-06-18 01:07:37 +0000 | [diff] [blame] | 14 | |
| 15 | it "should read a message header" do |
David Reiss | 72754e1 | 2008-07-25 21:06:03 +0000 | [diff] [blame] | 16 | @prot.should_receive(:read_i32).and_return(protocol_class.const_get(:VERSION_1) | Thrift::MessageTypes::REPLY, 42) |
Kevin Clark | 5ae0384 | 2008-06-18 01:07:37 +0000 | [diff] [blame] | 17 | @prot.should_receive(:read_string).and_return('testMessage') |
David Reiss | 72754e1 | 2008-07-25 21:06:03 +0000 | [diff] [blame] | 18 | @prot.read_message_begin.should == ['testMessage', Thrift::MessageTypes::REPLY, 42] |
Kevin Clark | 5ae0384 | 2008-06-18 01:07:37 +0000 | [diff] [blame] | 19 | end |
| 20 | |
Kevin Clark | c13c33b | 2008-06-18 01:12:48 +0000 | [diff] [blame] | 21 | it "should raise an exception if the message header has the wrong version" do |
| 22 | @prot.should_receive(:read_i32).and_return(42) |
David Reiss | 72754e1 | 2008-07-25 21:06:03 +0000 | [diff] [blame] | 23 | lambda { @prot.read_message_begin }.should raise_error(Thrift::ProtocolException, 'Missing version identifier') do |e| |
| 24 | e.type == Thrift::ProtocolException::BAD_VERSION |
Kevin Clark | 5ae0384 | 2008-06-18 01:07:37 +0000 | [diff] [blame] | 25 | end |
| 26 | end |
Kevin Clark | f18b643 | 2008-06-18 01:07:10 +0000 | [diff] [blame] | 27 | end |
Kevin Clark | e977a63 | 2008-06-18 01:07:50 +0000 | [diff] [blame] | 28 | |
| 29 | describe BinaryProtocolFactory do |
| 30 | it "should create a BinaryProtocol" do |
Kevin Clark | 90a2cbe | 2008-06-18 01:15:53 +0000 | [diff] [blame] | 31 | BinaryProtocolFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(BinaryProtocol) |
Kevin Clark | e977a63 | 2008-06-18 01:07:50 +0000 | [diff] [blame] | 32 | end |
| 33 | end |
Kevin Clark | f18b643 | 2008-06-18 01:07:10 +0000 | [diff] [blame] | 34 | end |