Merge branch 'THRIFT-143'
authorKevin Clark <kclark@apache.org>
Fri, 14 Nov 2008 17:11:39 +0000 (17:11 +0000)
committerKevin Clark <kclark@apache.org>
Fri, 14 Nov 2008 17:11:39 +0000 (17:11 +0000)
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@714070 13f79535-47bb-0310-9956-ffa450edef68

compiler/cpp/src/generate/t_rb_generator.cc
lib/rb/Rakefile
lib/rb/lib/thrift/struct.rb
lib/rb/spec/ThriftSpec.thrift
lib/rb/spec/gen-rb/ThriftSpec_types.rb
lib/rb/spec/struct_spec.rb

index f878ad7..4d90b10 100644 (file)
@@ -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;
 
index 6ddca52..b5aa2ad 100644 (file)
@@ -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']
index 4b99168..d01b4ce 100644 (file)
@@ -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)
index e04662b..51758a3 100644 (file)
@@ -32,6 +32,11 @@ struct SimpleList {
   11: list<Hello> hellos
 }
 
+exception Xception {
+  1: string message,
+  2: i32 code = 1
+}
+
 service NonblockingService {
   Hello greeting(1:bool english)
   bool block()
index 6e5fed4..613c8de 100644 (file)
@@ -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
index 7c52d16..4dc8714 100644 (file)
@@ -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)