From: Kevin Clark Date: Fri, 14 Nov 2008 17:11:39 +0000 (+0000) Subject: Merge branch 'THRIFT-143' X-Git-Tag: 0.2.0~409 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=031baf70860ade4096953d1c0838408ca0ecee96;p=common%2Fthrift.git Merge branch 'THRIFT-143' git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@714070 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/src/generate/t_rb_generator.cc b/compiler/cpp/src/generate/t_rb_generator.cc index f878ad7c..4d90b108 100644 --- a/compiler/cpp/src/generate/t_rb_generator.cc +++ b/compiler/cpp/src/generate/t_rb_generator.cc @@ -448,7 +448,7 @@ void t_rb_generator::generate_rb_struct(std::ofstream& out, t_struct* tstruct, b generate_rdoc(out, tstruct); indent(out) << "class " << type_name(tstruct); if (is_exception) { - out << " < StandardError"; + out << " < Thrift::Exception"; } out << endl; diff --git a/lib/rb/Rakefile b/lib/rb/Rakefile index 6ddca522..b5aa2ad8 100644 --- a/lib/rb/Rakefile +++ b/lib/rb/Rakefile @@ -4,7 +4,7 @@ require 'spec/rake/spectask' THRIFT = '../../compiler/cpp/thrift' -task :default => [:spec, :test] +task :default => [:'gen-rb', :spec, :test] Spec::Rake::SpecTask.new do |t| t.spec_files = FileList['spec/**/*_spec.rb'] diff --git a/lib/rb/lib/thrift/struct.rb b/lib/rb/lib/thrift/struct.rb index 4b991680..d01b4ce0 100644 --- a/lib/rb/lib/thrift/struct.rb +++ b/lib/rb/lib/thrift/struct.rb @@ -82,6 +82,7 @@ module Thrift end def read(iprot) + validate # TODO(kevinclark): Make sure transport is C readable if iprot.respond_to?(:decode_binary) iprot.decode_binary(self, iprot.trans) diff --git a/lib/rb/spec/ThriftSpec.thrift b/lib/rb/spec/ThriftSpec.thrift index e04662b5..51758a3e 100644 --- a/lib/rb/spec/ThriftSpec.thrift +++ b/lib/rb/spec/ThriftSpec.thrift @@ -32,6 +32,11 @@ struct SimpleList { 11: list hellos } +exception Xception { + 1: string message, + 2: i32 code = 1 +} + service NonblockingService { Hello greeting(1:bool english) bool block() diff --git a/lib/rb/spec/gen-rb/ThriftSpec_types.rb b/lib/rb/spec/gen-rb/ThriftSpec_types.rb index 6e5fed42..613c8de8 100644 --- a/lib/rb/spec/gen-rb/ThriftSpec_types.rb +++ b/lib/rb/spec/gen-rb/ThriftSpec_types.rb @@ -96,6 +96,24 @@ module SpecNamespace SETS => {:type => Thrift::Types::LIST, :name => 'sets', :element => {:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I16}}}, HELLOS => {:type => Thrift::Types::LIST, :name => 'hellos', :element => {:type => Thrift::Types::STRUCT, :class => Hello}} } + def validate + end + + end + + class Xception < Thrift::Exception + include Thrift::Struct + MESSAGE = 1 + CODE = 2 + + Thrift::Struct.field_accessor self, :message, :code + FIELDS = { + MESSAGE => {:type => Thrift::Types::STRING, :name => 'message'}, + CODE => {:type => Thrift::Types::I32, :name => 'code', :default => 1} + } + def validate + end + end end diff --git a/lib/rb/spec/struct_spec.rb b/lib/rb/spec/struct_spec.rb index 7c52d160..4dc8714a 100644 --- a/lib/rb/spec/struct_spec.rb +++ b/lib/rb/spec/struct_spec.rb @@ -5,15 +5,6 @@ class ThriftStructSpec < Spec::ExampleGroup include Thrift include SpecNamespace - class Xception < Thrift::Exception - include Thrift::Struct - attr_accessor :message, :code - FIELDS = { - 1 => {:type => Thrift::Types::STRING, :name => 'message'}, - 2 => {:type => Thrift::Types::I32, :name => 'code', :default => 1} - } - end - describe Struct do it "should iterate over all fields properly" do fields = {} @@ -209,7 +200,7 @@ class ThriftStructSpec < Spec::ExampleGroup e.code.should == 1 # ensure it gets serialized properly, this is the really important part prot = mock("Protocol") - prot.should_receive(:write_struct_begin).with("ThriftStructSpec::Xception") + prot.should_receive(:write_struct_begin).with("SpecNamespace::Xception") prot.should_receive(:write_struct_end) prot.should_receive(:write_field).with('message', Types::STRING, 1, "something happened") prot.should_receive(:write_field).with('code', Types::I32, 2, 1) @@ -226,7 +217,7 @@ class ThriftStructSpec < Spec::ExampleGroup e.message.should == "something happened" e.code.should == 5 prot = mock("Protocol") - prot.should_receive(:write_struct_begin).with("ThriftStructSpec::Xception") + prot.should_receive(:write_struct_begin).with("SpecNamespace::Xception") prot.should_receive(:write_struct_end) prot.should_receive(:write_field).with('message', Types::STRING, 1, "something happened") prot.should_receive(:write_field).with('code', Types::I32, 2, 5)