diff options
Diffstat (limited to 'actionwebservice/test')
-rw-r--r-- | actionwebservice/test/abstract_dispatcher.rb | 12 | ||||
-rw-r--r-- | actionwebservice/test/api_test.rb | 4 | ||||
-rw-r--r-- | actionwebservice/test/casting_test.rb | 4 |
3 files changed, 18 insertions, 2 deletions
diff --git a/actionwebservice/test/abstract_dispatcher.rb b/actionwebservice/test/abstract_dispatcher.rb index 7d02943d0a..78243ee497 100644 --- a/actionwebservice/test/abstract_dispatcher.rb +++ b/actionwebservice/test/abstract_dispatcher.rb @@ -56,6 +56,8 @@ module DispatcherTest api_method :hash_struct_return, :returns => [[Person]] api_method :thrower api_method :void + api_method :hex, :expects => [:base64], :returns => [:string] + api_method :unhex, :expects => [:string], :returns => [:base64] end class VirtualAPI < ActionWebService::API::Base @@ -216,6 +218,14 @@ module DispatcherTest @void_called = @method_params end + def hex(s) + return s.unpack("H*")[0] + end + + def unhex(s) + return [s].pack("H*") + end + protected def alwaysfail @before_filter_called = true @@ -248,6 +258,8 @@ module DispatcherCommonTests result = do_method_call(@direct_controller, 'BaseStructReturn') assert(result[0].is_a?(DispatcherTest::Person)) assert(result[1].is_a?(DispatcherTest::Person)) + assert_equal("cafe", do_method_call(@direct_controller, 'Hex', "\xca\xfe")) + assert_equal("\xca\xfe", do_method_call(@direct_controller, 'Unhex', "cafe")) end def test_direct_entrypoint diff --git a/actionwebservice/test/api_test.rb b/actionwebservice/test/api_test.rb index 83d7196273..0e58d84864 100644 --- a/actionwebservice/test/api_test.rb +++ b/actionwebservice/test/api_test.rb @@ -7,7 +7,7 @@ module APITest api_method :expects, :expects => [:int, :bool] api_method :returns, :returns => [:int, [:string]] api_method :named_signature, :expects => [{:appkey=>:int}, {:publish=>:bool}] - api_method :string_types, :expects => ['int', 'string', 'bool'] + api_method :string_types, :expects => ['int', 'string', 'bool', 'base64'] api_method :class_types, :expects => [TrueClass, Bignum, String] end end @@ -45,7 +45,7 @@ class TC_API < Test::Unit::TestCase assert_equal([Integer, [String]], API.api_methods[:returns].returns.map{|x| x.array?? [x.element_type.type_class] : x.type_class}) assert_equal([[:appkey, Integer], [:publish, TrueClass]], API.api_methods[:named_signature].expects.map{|x| [x.name, x.type_class]}) assert_equal(nil, API.api_methods[:named_signature].returns) - assert_equal([Integer, String, TrueClass], API.api_methods[:string_types].expects.map{|x| x.type_class}) + assert_equal([Integer, String, TrueClass, ActionWebService::Base64], API.api_methods[:string_types].expects.map{|x| x.type_class}) assert_equal(nil, API.api_methods[:string_types].returns) assert_equal([TrueClass, Integer, String], API.api_methods[:class_types].expects.map{|x| x.type_class}) assert_equal(nil, API.api_methods[:class_types].returns) diff --git a/actionwebservice/test/casting_test.rb b/actionwebservice/test/casting_test.rb index aa8941da17..34bad07d5b 100644 --- a/actionwebservice/test/casting_test.rb +++ b/actionwebservice/test/casting_test.rb @@ -4,6 +4,7 @@ module CastingTest class API < ActionWebService::API::Base api_method :int, :expects => [:int] api_method :str, :expects => [:string] + api_method :base64, :expects => [:base64] api_method :bool, :expects => [:bool] api_method :float, :expects => [:float] api_method :time, :expects => [:time] @@ -22,6 +23,9 @@ class TC_Casting < Test::Unit::TestCase def test_base_type_casting_valid assert_equal 10000, cast_expects(:int, '10000')[0] assert_equal '10000', cast_expects(:str, 10000)[0] + base64 = cast_expects(:base64, 10000)[0] + assert_equal '10000', base64 + assert_instance_of ActionWebService::Base64, base64 [1, '1', 'true', 'y', 'yes'].each do |val| assert_equal true, cast_expects(:bool, val)[0] end |