David Reiss | 72754e1 | 2008-07-25 21:06:03 +0000 | [diff] [blame] | 1 | require File.dirname(__FILE__) + '/spec_helper' |
| 2 | require 'thrift/protocol/binaryprotocolaccelerated' |
| 3 | require File.dirname(__FILE__) + '/binaryprotocol_spec_shared' |
| 4 | require File.dirname(__FILE__) + '/gen-rb/ThriftSpec_types' |
| 5 | |
| 6 | class ThriftBinaryProtocolAcceleratedSpec < Spec::ExampleGroup |
| 7 | include Thrift |
| 8 | |
Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 9 | describe Thrift::BinaryProtocolAccelerated do |
| 10 | # since BinaryProtocolAccelerated should be directly equivalent to |
| 11 | # BinaryProtocol, we don't need any custom specs! |
David Reiss | 72754e1 | 2008-07-25 21:06:03 +0000 | [diff] [blame] | 12 | it_should_behave_like 'a binary protocol' |
| 13 | |
| 14 | def protocol_class |
| 15 | BinaryProtocolAccelerated |
| 16 | end |
| 17 | |
Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 18 | # before(:each) do |
| 19 | # @buffer = "" |
| 20 | # @trans.stub!(:borrow).and_return { @buffer } |
| 21 | # @trans.stub!(:consume!).and_return do |*args| |
| 22 | # n = args.first || 0 |
| 23 | # @buffer.slice!(0,n) |
| 24 | # end |
| 25 | # end |
| 26 | # |
| 27 | # |
| 28 | # it "should raise an exception if the message header has the wrong version" do |
| 29 | # @buffer = "\000\000\000\v" |
| 30 | # # @prot.should_receive(:read_i32).and_return(42) |
| 31 | # lambda { @prot.read_message_begin }.should raise_error(Thrift::ProtocolException, 'Missing version identifier') do |e| |
| 32 | # e.type == Thrift::ProtocolException::BAD_VERSION |
| 33 | # end |
| 34 | # end |
| 35 | # |
| 36 | # it "should encode a string with null bytes in it" do |
| 37 | # foo = SpecNamespace::Hello.new(:greeting => "Hello\000World!") |
| 38 | # @prot.encode_binary(foo).should == "\v\000\001\000\000\000\fHello\000World!\000" |
| 39 | # end |
| 40 | # |
| 41 | # it "should decode a string with null bytes in it" do |
| 42 | # trans = Thrift::MemoryBuffer.new("\v\000\001\000\000\000\fHello\000World!\000") |
| 43 | # @prot.decode_binary(SpecNamespace::Hello.new, trans).should == SpecNamespace::Hello.new(:greeting => "Hello\000World!") |
| 44 | # end |
| 45 | # |
| 46 | # it "should error when encoding a struct with a nil value in a list" do |
| 47 | # Thrift.type_checking = false |
| 48 | # sl = SpecNamespace::SimpleList |
| 49 | # hello = SpecNamespace::Hello |
| 50 | # # nil counts as false for bools |
| 51 | # # lambda { @prot.encode_binary(sl.new(:bools => [true, false, nil, false])) }.should raise_error |
| 52 | # lambda { @prot.encode_binary(sl.new(:bytes => [1, 2, nil, 3])) }.should raise_error |
| 53 | # lambda { @prot.encode_binary(sl.new(:i16s => [1, 2, nil, 3])) }.should raise_error |
| 54 | # lambda { @prot.encode_binary(sl.new(:i32s => [1, 2, nil, 3])) }.should raise_error |
| 55 | # lambda { @prot.encode_binary(sl.new(:i64s => [1, 2, nil, 3])) }.should raise_error |
| 56 | # lambda { @prot.encode_binary(sl.new(:doubles => [1.0, 2.0, nil, 3.0])) }.should raise_error |
| 57 | # lambda { @prot.encode_binary(sl.new(:strings => ["one", "two", nil, "three"])) }.should raise_error |
| 58 | # lambda { @prot.encode_binary(sl.new(:lists => [[1, 2], nil, [3, 4]])) }.should raise_error |
| 59 | # lambda { @prot.encode_binary(sl.new(:maps => [{1 => 2}, nil, {3 => 4}])) }.should raise_error |
| 60 | # lambda { @prot.encode_binary(sl.new(:sets => [Set.new([1, 2]), nil, Set.new([3, 4])])) }.should raise_error |
| 61 | # lambda { @prot.encode_binary(sl.new(:structs => [hello.new, nil, hello.new(:greeting => "hi")])) }.should raise_error |
| 62 | # end |
| 63 | # |
| 64 | # it "should error when encoding a non-nil, non-correctly-typed value in a list" do |
| 65 | # Thrift.type_checking = false |
| 66 | # sl = SpecNamespace::SimpleList |
| 67 | # hello = SpecNamespace::Hello |
| 68 | # # bool should accept any value |
| 69 | # # lambda { @prot.encode_binary(sl.new(:bools => [true, false, 3])) }.should raise_error |
| 70 | # lambda { @prot.encode_binary(sl.new(:bytes => [1, 2, "3", 5])) }.should raise_error |
| 71 | # lambda { @prot.encode_binary(sl.new(:i16s => ["one", 2, 3])) }.should raise_error |
| 72 | # lambda { @prot.encode_binary(sl.new(:i32s => [[1,2], 3, 4])) }.should raise_error |
| 73 | # lambda { @prot.encode_binary(sl.new(:i64s => [{1 => 2}, 3, 4])) }.should raise_error |
| 74 | # lambda { @prot.encode_binary(sl.new(:doubles => ["one", 2.3, 3.4])) }.should raise_error |
| 75 | # lambda { @prot.encode_binary(sl.new(:strings => ["one", "two", 3, 4])) }.should raise_error |
| 76 | # lambda { @prot.encode_binary(sl.new(:lists => [{1 => 2}, [3, 4]])) }.should raise_error |
| 77 | # lambda { @prot.encode_binary(sl.new(:maps => [{1 => 2}, [3, 4]])) }.should raise_error |
| 78 | # lambda { @prot.encode_binary(sl.new(:sets => [Set.new([1, 2]), 3, 4])) }.should raise_error |
| 79 | # lambda { @prot.encode_binary(sl.new(:structs => [3, "four"])) }.should raise_error |
| 80 | # end |
| 81 | # |
| 82 | # it "should error when encoding an improper object where a container is expected" do |
| 83 | # Thrift.type_checking = false |
| 84 | # sl = SpecNamespace::SimpleList |
| 85 | # lambda { @prot.encode_binary(sl.new(:strings => {"one" => "two", nil => "three"})) }.should raise_error |
| 86 | # lambda { @prot.encode_binary(sl.new(:maps => [[1, 2]])) }.should raise_error |
| 87 | # end |
| 88 | # |
| 89 | # it "should accept arrays and hashes as sets" do |
| 90 | # Thrift.type_checking = false |
| 91 | # sl = SpecNamespace::SimpleList |
| 92 | # lambda { @prot.encode_binary(sl.new(:sets => [[1, 2], {3 => true, 4 => true}])) }.should_not raise_error |
| 93 | # end |
David Reiss | 72754e1 | 2008-07-25 21:06:03 +0000 | [diff] [blame] | 94 | end |
| 95 | |
| 96 | describe BinaryProtocolAcceleratedFactory do |
| 97 | it "should create a BinaryProtocolAccelerated" do |
| 98 | BinaryProtocolAcceleratedFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(BinaryProtocolAccelerated) |
| 99 | end |
| 100 | end |
| 101 | end |