You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by sc...@apache.org on 2009/04/24 18:05:57 UTC
svn commit: r768343 [1/4] - in /incubator/etch/branches/ruby/binding-ruby:
./ src/ src/main/ src/main/ruby/ src/main/ruby/idl/ src/main/ruby/idl/test/
src/main/ruby/msg/ src/main/ruby/msg/test/ src/main/ruby/support/
src/main/ruby/support/test/ src/mai...
Author: sccomer
Date: Fri Apr 24 16:05:55 2009
New Revision: 768343
URL: http://svn.apache.org/viewvc?rev=768343&view=rev
Log:
initial contribution of etch ruby binding from cisco.
Added:
incubator/etch/branches/ruby/binding-ruby/
incubator/etch/branches/ruby/binding-ruby/src/
incubator/etch/branches/ruby/binding-ruby/src/main/
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/Test.etch (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/fake_test.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_remote_test_server.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_stub_test_server.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_test.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_value_factory_test.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/array_element.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/array_value.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/field.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/id_name.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/mailbox.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/message.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/struct_element.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/struct_value.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/tagged_data_input.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/tagged_data_output.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_array_value.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_id_name.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_message.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_struct_value.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/type.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/value_factory.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/close.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/converter.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/default_value_factory.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/delivery_service.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/element.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/enum.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch__auth_exception.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch__runtime_exception.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch_enum.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/etch_mutex.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/id_name_map.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/mailbox.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/message_handler.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/message_source.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/pool.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/remote_base.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/stub_base.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_default_value_factory.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_id_name_map.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_remote_base.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/test/test_stub_base.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/unwanted.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/support/who.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/abstract_startable.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/client_socket_connection.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/connection.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_handler.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_source.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/data_type_values.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/default_message_handler.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/examples.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/flex_buffer.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data_input.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/binary_tagged_data_output.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/byte_array_output_stream.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/tagged_data.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/fmt/type_code.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/listener.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/listener_handler.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/monitor.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packet_handler.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packet_source.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/packetizer.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/runner.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/runner_handler.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/socket_prog.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/source.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/source_handler.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/startable.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/stream_input.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/tcp_connection.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/test/
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/test/test_packetizer.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/test/test_tcp_connection.rb (with props)
incubator/etch/branches/ruby/binding-ruby/src/main/ruby/transport/who.rb (with props)
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/Test.etch
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/Test.etch?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/Test.etch (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/Test.etch Fri Apr 24 16:05:55 2009
@@ -0,0 +1,33 @@
+module etch.bindings.ruby.test
+@Direction(Both)
+@Timeout(4000)
+service Test
+{
+ const int FOO = 23
+
+ enum E1 ( A, B, C )
+ void nothing()
+
+ struct S1( int x, int y, int z )
+ struct S2( S1 a, S1 b, E1 c )
+
+ int incr( int x )
+ int sum( int[] x )
+ int trans( E1 e, int x )
+ double dist( S1 a, S1 b )
+ int[] fill( int n, int x )
+
+ exception Excp1( string msg, int code )
+ void blow( string msg, int code ) throws Excp1
+
+ @Unchecked(true)
+ exception Excp3()
+ @Unchecked(false)
+ exception Excp4()
+ int beets( E1 e ) throws Excp3, Excp4
+
+ exception X( int g, int h, int i )
+ exception Y( int g, int h, int i )
+ int add( int x, int y ) throws X
+ int sub( int x, int y ) throws X, Y
+}
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/Test.etch
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/Test.etch
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/fake_test.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/fake_test.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/fake_test.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/fake_test.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,66 @@
+require 'etch/bindings/ruby/idl/test/Test'
+
+# silly implementation of test used for testing
+class FakeTest
+ include Test
+
+ def beets( e )
+
+ if ( e == nil )
+ return nil
+ end
+
+ case ( e )
+ when Test::E1::A then return 5
+ when Test::E1::B then raise Test::Excp3.new
+ when Test::E1::C then raise Test::Excp4.new
+ else return nil
+ end
+ end
+
+ def blow( msg, code )
+ raise Test::Excp1.new( msg, code )
+ end
+
+ def dist( a, b )
+ c = Test::S1.new( a.x - b.x, a.y - b.y, a.z - b.z )
+ return Math.sqrt( c.x * c.x + c.y * c.y + c.z * c.z )
+ end
+
+ def incr( x )
+ return ( x+1 )
+ end
+
+ def nothing()
+ # nothing
+ end
+
+ def sub( x, y )
+ return ( x - y )
+ end
+
+ def sum( x )
+ sumVar = 0
+ x.each { |value| sumVar += value }
+ return sumVar
+ end
+
+ def trans( e, x )
+ case ( e )
+ when Test::E1::A then return ( x/2 )
+ when Test::E1::B then return ( x*2 )
+ when Test::E1::C then return ( x+7 )
+ end
+ end
+
+ def fill( n, x )
+ y = Array.new( n )
+ for i in 0...n
+ y[i] = x
+ end
+ return y
+ end
+
+
+
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/fake_test.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/fake_test.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_remote_test_server.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_remote_test_server.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_remote_test_server.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_remote_test_server.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,382 @@
+require 'test/unit'
+require 'etch/bindings/ruby/support/delivery_service'
+require 'etch/bindings/ruby/idl/test/RemoteTest'
+require 'etch/bindings/ruby/idl/test/ValueFactoryTest'
+
+class TestRemoteTestServer < Test::Unit::TestCase
+
+ attr :svc, true
+ attr :test, true
+
+ def setup
+ @svc = MyDeliveryService.new
+ @test = RemoteTest.new( svc )
+ end
+
+ def test_method_nothing
+ @test.nothing()
+ check( :VOIDCALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_nothing,
+ Array.new, Array.new, ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_nothing,
+ 4000 )
+ end
+
+ def test_method_incr1
+ @svc.xresult = 2
+ assert_equal( 2, @test.incr( 1 ) )
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_incr,
+ Array[ ValueFactoryTest::MF_x ], Array[ 1 ],
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_incr,
+ 4000 )
+ end
+
+ def test_method_incr2
+ @svc.xresult = 3
+ assert_equal( 3, @test.incr( 2 ) )
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_incr,
+ Array[ ValueFactoryTest::MF_x ], Array[ 2 ],
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_incr,
+ 4000 )
+ end
+
+ def test_method_incr3
+ @svc.xresult = -1
+ assert_equal( -1, @test.incr( -2 ) )
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_incr,
+ Array[ ValueFactoryTest::MF_x ], Array[ -2 ],
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_incr,
+ 4000 )
+ end
+
+ def test_method_sub1
+ @svc.xresult = 5
+ assert_equal( 5, @test.sub( 7, 2 ) )
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_sub,
+ Array[ ValueFactoryTest::MF_x, ValueFactoryTest::MF_y ],
+ Array[ 7, 2 ],
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_sub,
+ 4000 )
+ end
+
+ def test_method_sub2
+ @svc.xresult = 8
+ assert_equal( 8, @test.sub( 23, 15 ) )
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_sub,
+ Array[ ValueFactoryTest::MF_x, ValueFactoryTest::MF_y ],
+ Array[ 23, 15 ],
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_sub,
+ 4000 )
+ end
+
+ def test_method_sub3
+ @svc.xresult = -5
+ assert_equal( -5, @test.sub( 2, 7 ) )
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_sub,
+ Array[ ValueFactoryTest::MF_x, ValueFactoryTest::MF_y ],
+ Array[ 2, 7 ],
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_sub,
+ 4000 )
+ end
+
+ def test_method_sum
+ @svc.xresult = 24
+ args = Array[ 1, 2, 3, 7, 11 ]
+ assert_equal( 24, @test.sum( args ) )
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_sum,
+ Array[ ValueFactoryTest::MF_x ],
+ Array[ args ] ,
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_sum,
+ 4000 )
+ end
+
+ def test_method_trans1
+ @svc.xresult = 2
+ assert_equal( 2, @test.trans( Test::E1::A, 5 ) )
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_trans,
+ Array[ ValueFactoryTest::MF_e, ValueFactoryTest::MF_x ],
+ Array[ Test::E1::A, 5 ] ,
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_trans,
+ 4000 )
+ end
+
+ def test_method_trans2
+ @svc.xresult = 10
+ assert_equal( 10, @test.trans( Test::E1::B, 5 ) )
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_trans,
+ Array[ ValueFactoryTest::MF_e, ValueFactoryTest::MF_x ],
+ Array[ Test::E1::B, 5 ] ,
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_trans,
+ 4000 )
+ end
+
+
+ def test_method_trans3
+ @svc.xresult = 12
+ assert_equal( 12, @test.trans( Test::E1::C, 5 ) )
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_trans,
+ Array[ ValueFactoryTest::MF_e, ValueFactoryTest::MF_x ],
+ Array[ Test::E1::C, 5 ] ,
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_trans,
+ 4000 )
+ end
+
+ def test_method_dist1
+ @svc.xresult = Math.sqrt( 3 )
+ arg1 = Test::S1.new( 1, 1, 1 )
+ arg2 = Test::S1.new( 0, 0, 0 )
+ assert_equal( Math.sqrt( 3 ), @test.dist( arg1, arg2 ) )
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_dist,
+ Array[ ValueFactoryTest::MF_a, ValueFactoryTest::MF_b ],
+ Array[ arg1, arg2 ] ,
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_dist,
+ 4000 )
+ end
+
+ def test_method_dist2
+ @svc.xresult = Math.sqrt( 35 )
+ arg1 = Test::S1.new( 1, 2, 3 )
+ arg2 = Test::S1.new( 6, 5, 4 )
+ assert_equal( Math.sqrt( 35 ), @test.dist( arg1, arg2 ) )
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_dist,
+ Array[ ValueFactoryTest::MF_a, ValueFactoryTest::MF_b ],
+ Array[ arg1, arg2 ] ,
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_dist,
+ 4000 )
+ end
+
+ def test_method_dist3
+ @svc.xresult = Math.sqrt( 56 )
+ arg1 = Test::S1.new( 1, 2, 3 )
+ arg2 = Test::S1.new( -1, -2, -3 )
+ assert_equal( Math.sqrt( 56 ), @test.dist( arg1, arg2 ) )
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_dist,
+ Array[ ValueFactoryTest::MF_a, ValueFactoryTest::MF_b ],
+ Array[ arg1, arg2 ] ,
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_dist,
+ 4000 )
+ end
+
+ def test_method_fill1
+ @svc.xresult = Array.new
+ x = @test.fill( 0, 1 )
+ assert_equal( 0, x.length )
+
+ x.each { |value| assert_equal( 1, value ) }
+
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_fill,
+ Array[ ValueFactoryTest::MF_n, ValueFactoryTest::MF_x ],
+ Array[ 0, 1 ] ,
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_fill,
+ 4000 )
+ end
+
+ def test_method_fill2
+ @svc.xresult = Array[ 2 ]
+ x = @test.fill( 1, 2 )
+ assert_equal( 1, x.length )
+ x.each { |value| assert_equal( 2, value ) }
+
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_fill,
+ Array[ ValueFactoryTest::MF_n, ValueFactoryTest::MF_x ],
+ Array[ 1, 2 ] ,
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_fill,
+ 4000 )
+ end
+
+ def test_method_fill3
+ @svc.xresult = Array[ 3, 3 ]
+ x = @test.fill( 2, 3 )
+ assert_equal( 2, x.length )
+ x.each { |value| assert_equal( 3, value ) }
+
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_fill,
+ Array[ ValueFactoryTest::MF_n, ValueFactoryTest::MF_x ],
+ Array[ 2, 3 ] ,
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_fill,
+ 4000 )
+ end
+
+ def test_method_blow1
+ begin
+ @svc.xresult = Test::Excp1.new( "foo", 2 )
+ @test.blow( "foo", 2 )
+ flunk( "did not throw ! " )
+ rescue Test::Excp1 => e
+ assert_equal( "foo", e.msg )
+ assert_equal( 2, e.code )
+ end
+ check( :VOIDCALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_blow,
+ Array[ ValueFactoryTest::MF_msg, ValueFactoryTest::MF_code ],
+ Array[ "foo", 2 ] ,
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_blow,
+ 4000 )
+ end
+
+ def test_method_blow2
+ begin
+ @svc.xresult = Test::Excp1.new( "bar", 3 )
+ @test.blow( "bar", 3 )
+ flunk( "did not throw ! " )
+ rescue Test::Excp1 => e
+ assert_equal( "bar", e.msg )
+ assert_equal( 3, e.code )
+ end
+ check( :VOIDCALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_blow,
+ Array[ ValueFactoryTest::MF_msg, ValueFactoryTest::MF_code ],
+ Array[ "bar", 3 ] ,
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_blow,
+ 4000 )
+ end
+
+ def test_method_beets1
+ @svc.xresult = 5
+ assert_equal( 5, @test.beets( Test::E1::A ) )
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_beets,
+ Array[ ValueFactoryTest::MF_e ],
+ Array[ Test::E1::A ] ,
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_beets,
+ 4000 )
+ end
+
+ def test_method_beets2
+
+ begin
+
+ @svc.xresult = Test::Excp3.new
+ @test.beets( Test::E1::B )
+ flunk( "beets did not throw" )
+
+ rescue Test::Excp3 => e
+ assert( true )
+ end
+
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_beets,
+ Array[ ValueFactoryTest::MF_e ],
+ Array[ Test::E1::B ] ,
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_beets,
+ 4000 )
+ end
+
+ def test_method_beets3
+
+ begin
+
+ @svc.xresult = Test::Excp4.new
+ @test.beets( Test::E1::C )
+ flunk( "beets did not throw" )
+
+ rescue Test::Excp4 => e
+ assert( true )
+ end
+
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_beets,
+ Array[ ValueFactoryTest::MF_e ],
+ Array[ Test::E1::C ] ,
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_beets,
+ 4000 )
+ end
+
+ def test_method_beets4
+
+ @svc.xresult = nil
+ assert_nil( @test.beets( nil ) )
+ check( :CALL, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_beets,
+ Array[ ValueFactoryTest::MF_e ],
+ Array[ nil ] ,
+ ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_beets,
+ 4000 )
+ end
+
+
+
+ def check( what, type, fields, objects, resultType, timeout )
+ assert_same( what, @svc.what )
+ assert_same( type, @svc.xmsg.getType() )
+
+ n = fields.length
+ assert_equal( n, objects.length )
+ assert_equal( n, @svc.xmsg.size )
+
+ for i in 0...n
+ f = fields[i]
+ assert_equal( objects[i], @svc.xmsg[f] )
+ end
+
+ assert_same( resultType, @svc.xresponseType )
+ assert_same( ValueFactoryTest::MF_result, @svc.xresponseField )
+ assert_equal( timeout, @svc.xtimeout )
+ end
+
+ class MyDeliveryService
+ include DeliveryService
+ include Test::Unit::Assertions
+
+ attr :what, true
+ attr :xmsg, true
+ attr :xresponseType, true
+ attr :xresponseField, true
+ attr :xtimeout, true
+ attr :xresult, true
+ attr :xmb, true
+
+ def initialize()
+ @what = EtchEnum.enum2
+ end
+
+ def clear()
+
+ end
+
+ def send( msg )
+ assert_nil( @what )
+ @what = :SEND
+ @xmsg = msg
+ end
+
+ def begincall( msg )
+
+ assert_nil( @what )
+ @what = :BEGINCALL
+ @xmsg = msg
+ # TODO: Uncomment this when PlainMailbox is done !
+ # @xmb = PlainMailbox.new( nil, 0, 0, 0, 1)
+ return @xmb
+ end
+
+ def endvoidcall( mb, responseType, responseField, timeout )
+
+ assert_same( :BEGINCALL, @what )
+ assert_same( mb, @xmb )
+ @what = :VOIDCALL
+ @xmb = nil
+ @xresponseType = responseType
+ @xresponseField = responseField
+ @xtimeout = timeout
+ if ( @xresult != nil && @xresult.kind_of?( Exception ) )
+ raise @xresult
+ end
+ assert_nil( @xresult )
+ end
+
+ def endcall( mb, responseType, responseField, timeout )
+
+ assert_same( :BEGINCALL, @what )
+ assert_same( mb, @xmb )
+ @what = :CALL
+ @xmb = nil
+ @xresponseType = responseType
+ @xresponseField = responseField
+ @xtimeout = timeout
+ if ( @xresult.kind_of?( Exception ) )
+ raise @xresult
+ end
+ return @xresult
+ end
+
+ def shutdownOutput()
+ assert_nil( @what )
+ what = :SHUTDOWNOUTPUT
+ end
+
+ end
+
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_remote_test_server.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_remote_test_server.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_stub_test_server.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_stub_test_server.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_stub_test_server.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_stub_test_server.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,196 @@
+require 'test/unit'
+require 'etch/bindings/ruby/support/delivery_service'
+require 'etch/bindings/ruby/idl/test/RemoteTest'
+require 'etch/bindings/ruby/idl/test/StubTest'
+require 'etch/bindings/ruby/idl/test/ValueFactoryTest'
+require 'etch/bindings/ruby/idl/test/fake_test'
+require 'etch/bindings/ruby/support/message_source'
+require 'etch/bindings/ruby/msg/message'
+
+class TestStubTestServer < Test::Unit::TestCase
+
+
+ def setup
+ @test = FakeTest.new
+ @vf = ValueFactoryTest.new
+ @stub = StubTest.new( @test, nil, nil )
+ @src = MyMessageSource.new
+ end
+
+ def test_method_nothing
+ msg = Message.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_nothing, @vf )
+ @stub.message( @src, nil, msg )
+ @src.xreply.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_nothing )
+ assert_equal( 0, @src.xreply.size )
+ end
+
+ def test_method_incr1
+ msg = Message.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_incr, @vf )
+ msg.store( ValueFactoryTest::MF_x, 3 )
+ @stub.message( @src, nil, msg )
+ @src.xreply.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_incr )
+ assert_equal( 1, @src.xreply.size )
+ assert_equal( 4, @src.xreply[ ValueFactoryTest::MF_result ] )
+ end
+
+ def test_method_incr2
+ msg = Message.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_incr, @vf )
+ # msg.store( ValueFactoryTest::MF_x, 3 )
+ @stub.message( @src, nil, msg )
+ @src.xreply.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_incr )
+ assert_equal( 1, @src.xreply.size )
+ o = @src.xreply[ ValueFactoryTest::MF_result ]
+ assert( o.kind_of?( Exception ) )
+ end
+
+ def test_method_sub
+ msg = Message.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_sub, @vf )
+ msg.store( ValueFactoryTest::MF_x, 7 )
+ msg.store( ValueFactoryTest::MF_y, 3 )
+ @stub.message( @src, nil, msg )
+ @src.xreply.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_sub )
+ assert_equal( 1, @src.xreply.size )
+ assert_equal( 4, @src.xreply[ ValueFactoryTest::MF_result ] )
+ end
+
+ def test_method_sum
+ msg = Message.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_sum, @vf )
+ msg.store( ValueFactoryTest::MF_x, Array[ 1, 2, 3, 7, 11 ] )
+ @stub.message( @src, nil, msg )
+ @src.xreply.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_sum )
+ assert_equal( 1, @src.xreply.size )
+ assert_equal( 24, @src.xreply[ ValueFactoryTest::MF_result ] )
+ end
+
+ def test_method_trans1
+ msg = Message.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_trans, @vf )
+ msg.store( ValueFactoryTest::MF_e, Test::E1::A )
+ msg.store( ValueFactoryTest::MF_x, 5 )
+ @stub.message( @src, nil, msg )
+ @src.xreply.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_trans )
+ assert_equal( 1, @src.xreply.size )
+ assert_equal( 2, @src.xreply[ ValueFactoryTest::MF_result ] )
+ end
+
+ def test_method_trans2
+ msg = Message.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_trans, @vf )
+ msg.store( ValueFactoryTest::MF_e, Test::E1::B )
+ msg.store( ValueFactoryTest::MF_x, 5 )
+ @stub.message( @src, nil, msg )
+ @src.xreply.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_trans )
+ assert_equal( 1, @src.xreply.size )
+ assert_equal( 10, @src.xreply[ ValueFactoryTest::MF_result ] )
+ end
+
+ def test_method_trans3
+ msg = Message.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_trans, @vf )
+ msg.store( ValueFactoryTest::MF_e, Test::E1::C )
+ msg.store( ValueFactoryTest::MF_x, 5 )
+ @stub.message( @src, nil, msg )
+ @src.xreply.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_trans )
+ assert_equal( 1, @src.xreply.size )
+ assert_equal( 12, @src.xreply[ ValueFactoryTest::MF_result ] )
+ end
+
+ def test_method_dist1
+ msg = Message.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_dist, @vf )
+ msg.store( ValueFactoryTest::MF_a, Test::S1.new( 1, 1, 1 ) )
+ msg.store( ValueFactoryTest::MF_b, Test::S1.new( 0, 0, 0 ) )
+ @stub.message( @src, nil, msg )
+ @src.xreply.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_dist )
+ assert_equal( 1, @src.xreply.size )
+ assert_equal( Math.sqrt( 3 ), @src.xreply[ ValueFactoryTest::MF_result ] )
+ end
+
+ def test_method_dist2
+ msg = Message.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_dist, @vf )
+ msg.store( ValueFactoryTest::MF_a, Test::S1.new( 1, 2, 3 ) )
+ msg.store( ValueFactoryTest::MF_b, Test::S1.new( 6, 5, 4 ) )
+ @stub.message( @src, nil, msg )
+ @src.xreply.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_dist )
+ assert_equal( 1, @src.xreply.size )
+ assert_equal( Math.sqrt( 35 ), @src.xreply[ ValueFactoryTest::MF_result ] )
+ end
+
+ def test_method_fill
+ msg = Message.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_fill, @vf )
+ msg.store( ValueFactoryTest::MF_n, 4 )
+ msg.store( ValueFactoryTest::MF_x, 3 )
+ @stub.message( @src, nil, msg )
+ @src.xreply.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_fill )
+ assert_equal( 1, @src.xreply.size )
+ x = @src.xreply[ ValueFactoryTest::MF_result ]
+ assert_not_nil( x )
+ assert_equal( 4, x.length )
+ x.each { |value| assert_equal( 3, value ) }
+ end
+
+ def test_method_blow
+ msg = Message.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_blow, @vf )
+ msg.store( ValueFactoryTest::MF_msg, "foo" )
+ msg.store( ValueFactoryTest::MF_code, 23 )
+ @stub.message( @src, nil, msg )
+ @src.xreply.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_blow )
+ assert_equal( 1, @src.xreply.size )
+ e = @src.xreply[ ValueFactoryTest::MF_result ]
+ assert_not_nil( e )
+ assert_equal( "foo", e.msg )
+ assert_equal( 23, e.code )
+ end
+
+ def test_method_beets1
+ msg = Message.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_beets, @vf )
+ msg.store( ValueFactoryTest::MF_e, Test::E1::A )
+ @stub.message( @src, nil, msg )
+ @src.xreply.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_beets )
+ assert_equal( 1, @src.xreply.size )
+ o = @src.xreply[ ValueFactoryTest::MF_result ]
+ assert_equal( 5, o )
+ end
+
+ def test_method_beets2
+ msg = Message.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_beets, @vf )
+ msg.store( ValueFactoryTest::MF_e, Test::E1::B )
+ @stub.message( @src, nil, msg )
+ @src.xreply.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_beets )
+ assert_equal( 1, @src.xreply.size )
+ o = @src.xreply[ ValueFactoryTest::MF_result ]
+ assert_equal( Test::Excp3, o.class )
+ end
+
+ def test_method_beets3
+ msg = Message.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_beets, @vf )
+ msg.store( ValueFactoryTest::MF_e, Test::E1::C )
+ @stub.message( @src, nil, msg )
+ @src.xreply.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_beets )
+ assert_equal( 1, @src.xreply.size )
+ o = @src.xreply[ ValueFactoryTest::MF_result ]
+ assert_equal( Test::Excp4, o.class )
+ end
+
+
+ def test_method_beets4
+ msg = Message.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_beets, @vf )
+ msg.store( ValueFactoryTest::MF_e, nil )
+ @stub.message( @src, nil, msg )
+ @src.xreply.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_beets )
+ assert_equal( 1, @src.xreply.size )
+ o = @src.xreply[ ValueFactoryTest::MF_result ]
+ assert_nil( o )
+ end
+
+
+
+ class MyMessageSource
+ include MessageSource
+ include Test::Unit::Assertions
+
+ attr :xreply, true
+
+ def message( recipient, msg )
+ assert_nil( recipient)
+ assert_nil( @xreply )
+ @xreply = msg
+ end
+ end
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_stub_test_server.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_stub_test_server.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_test.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_test.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_test.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_test.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,214 @@
+require 'test/unit'
+require 'etch/bindings/ruby/support/delivery_service'
+require 'etch/bindings/ruby/idl/test/RemoteTest'
+require 'etch/bindings/ruby/idl/test/fake_test'
+require 'etch/bindings/ruby/idl/test/ValueFactoryTest'
+require 'etch/bindings/ruby/msg/type'
+require 'etch/bindings/ruby/msg/field'
+
+class TestTest < Test::Unit::TestCase
+
+ def setup
+ @test = FakeTest.new
+ end
+
+ def test_enum_E1
+ # see implementation of EtchEnum
+ assert_equal( 3, Test::E1.constants.length )
+ assert_not_nil( Test::E1::A )
+ assert_not_nil( Test::E1::B )
+ assert_not_nil( Test::E1::C )
+ end
+
+ def test_struct_S1
+ s = Test::S1.new( 1, 2, 3 )
+ assert_equal( 1, s.x )
+ assert_equal( 2, s.y )
+ assert_equal( 3, s.z )
+
+ s = Test::S1.new( nil, nil, nil )
+ assert_nil( s.x )
+ assert_nil( s.y )
+ assert_nil( s.z )
+
+ s = Test::S1.new()
+ assert_nil( s.x )
+ assert_nil( s.y )
+ assert_nil( s.z )
+
+ s.x = 4
+ s.y = 5
+ s.z = 6
+
+ assert_equal( 4, s.x )
+ assert_equal( 5, s.y )
+ assert_equal( 6, s.z )
+
+ s.x = nil
+ assert_nil( s.x )
+
+ s.x = 7
+ assert_equal( 7, s.x )
+ end
+
+ def test_excp_Excp1
+ e = Test::Excp1.new( "foo", 23 )
+ assert_equal( "foo", e.msg )
+ assert_equal( 23, e.code )
+
+ e = Test::Excp1.new( nil, nil )
+ assert_nil( e.msg )
+ assert_nil( e.code )
+
+ e = Test::Excp1.new()
+ assert_nil( e.msg )
+ assert_nil( e.code )
+
+ e.msg = "bar"
+ e.code = 24
+ assert_equal( "bar", e.msg )
+ assert_equal( 24, e.code )
+
+ e.msg = nil
+ e.code = nil
+ assert_nil( e.msg )
+ assert_nil( e.code )
+
+ assert( e.kind_of?( Exception ) )
+
+ end
+
+ def test_excp_Excp3
+
+ e = Test::Excp3.new
+ assert( e.kind_of?( Exception ) )
+ end
+
+ def test_excp_Excp4
+
+ e = Test::Excp4.new
+ assert( e.kind_of?( Exception ) )
+ end
+
+ def test_method_nothing
+ @test.nothing
+ end
+
+ def test_method_incr1
+ assert_equal( 2, @test.incr( 1 ) )
+ end
+
+ def test_method_incr2
+ assert_equal( 3, @test.incr( 2 ) )
+ end
+
+ def test_method_incr3
+ assert_equal( -1, @test.incr( -2 ) )
+ end
+
+ def test_method_sub1
+ assert_equal( 5, @test.sub( 7, 2 ) )
+ end
+
+ def test_method_sub2
+ assert_equal( 8, @test.sub( 23, 15 ) )
+ end
+
+ def test_method_sub3
+ assert_equal( -5, @test.sub( 2, 7 ) )
+ end
+
+ def test_method_sum
+ assert_equal( 24, @test.sum( Array[ 1, 2, 3, 7, 11 ] ) )
+ end
+
+ def test_method_trans1
+ assert_equal( 2, @test.trans( Test::E1::A, 5 ) )
+ end
+
+ def test_method_trans2
+ assert_equal( 10, @test.trans( Test::E1::B, 5 ) )
+ end
+
+ def test_method_trans3
+ assert_equal( 12, @test.trans( Test::E1::C, 5 ) )
+ end
+
+ def test_method_dist1
+ assert_equal( Math.sqrt( 3 ), @test.dist( Test::S1.new( 1, 1, 1 ), Test::S1.new( 0, 0, 0 ) ) )
+ end
+
+ def test_method_dist2
+ assert_equal( Math.sqrt( 35 ), @test.dist( Test::S1.new( 1, 2, 3 ), Test::S1.new( 6, 5, 4 ) ) )
+ end
+
+ def test_method_dist3
+ assert_equal( Math.sqrt( 56 ), @test.dist( Test::S1.new( 1, 2, 3 ), Test::S1.new( -1, -2, -3 ) ) )
+ end
+
+ def test_method_fill1
+ x = @test.fill( 0, 1 )
+ assert_equal( 0, x.length )
+ x.each { |value| assert_equal( 1, value ) }
+ end
+
+ def test_method_fill2
+ x = @test.fill( 1, 2 )
+ assert_equal( 1, x.length )
+ x.each { |value| assert_equal( 2, value ) }
+ end
+
+ def test_method_fill3
+ x = @test.fill( 2, 3 )
+ assert_equal( 2, x.length )
+ x.each { |value| assert_equal( 3, value ) }
+ end
+
+ def test_method_blow1
+ begin
+ @test.blow( "foo", 2 )
+ flunk( "did not throw" )
+ rescue Test::Excp1 => e
+ assert_equal( "foo", e.msg )
+ assert_equal( 2, e.code )
+ end
+ end
+
+ def test_method_blow2
+ begin
+ @test.blow( "bar", 3 )
+ flunk( "did not throw" )
+ rescue Test::Excp1 => e
+ assert_equal( "bar", e.msg )
+ assert_equal( 3, e.code )
+ end
+ end
+
+ def test_method_beets1
+ assert_equal( 5, @test.beets( Test::E1::A ) )
+ end
+
+ def test_method_beets2
+ begin
+ @test.beets( Test::E1::B )
+ flunk( "did not throw" )
+ rescue Test::Excp3 => e
+ assert( true )
+ end
+ end
+
+
+ def test_method_beets3
+ begin
+ @test.beets( Test::E1::C )
+ flunk( "did not throw" )
+ rescue Test::Excp4 => e
+ assert( true )
+ end
+ end
+
+ def test_method_beets4
+ assert_nil( @test.beets( nil ) )
+ end
+
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_test.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_test.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_value_factory_test.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_value_factory_test.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_value_factory_test.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_value_factory_test.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,253 @@
+require 'test/unit'
+require 'etch/bindings/ruby/support/delivery_service'
+require 'etch/bindings/ruby/idl/test/RemoteTest'
+require 'etch/bindings/ruby/idl/test/ValueFactoryTest'
+require 'etch/bindings/ruby/msg/type'
+require 'etch/bindings/ruby/msg/field'
+
+class TestValueFactoryTest < Test::Unit::TestCase
+
+
+ def setup
+ @vf = ValueFactoryTest.new
+ end
+
+ def test_E1
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_E1 )
+
+ checkField( ValueFactoryTest::MF_A )
+ checkField( ValueFactoryTest::MF_B )
+ checkField( ValueFactoryTest::MF_C )
+ end
+
+ def test_E1_export
+ testEnumExport( Test::E1::A, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_E1,
+ ValueFactoryTest::MF_A )
+ testEnumExport( Test::E1::B, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_E1,
+ ValueFactoryTest::MF_B )
+ testEnumExport( Test::E1::C, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_E1,
+ ValueFactoryTest::MF_C )
+ end
+
+ def test_E1_import
+ testEnumImport( Test::E1::A, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_E1,
+ ValueFactoryTest::MF_A )
+ testEnumImport( Test::E1::B, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_E1,
+ ValueFactoryTest::MF_B )
+ testEnumImport( Test::E1::C, ValueFactoryTest::MT_etch_bindings_ruby_test_Test_E1,
+ ValueFactoryTest::MF_C )
+ end
+
+ def test_S1
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_S1 )
+
+ checkField( ValueFactoryTest::MF_x )
+ checkField( ValueFactoryTest::MF_y )
+ checkField( ValueFactoryTest::MF_z )
+ end
+
+ def test_S1_export
+ sv = @vf.exportCustomValue( Test::S1.new( 19, 23, 29 ) )
+ sv.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_S1 )
+ assert_equal( 3, sv.size )
+ assert_equal( 19, sv[ ValueFactoryTest::MF_x ] )
+ assert_equal( 23, sv[ ValueFactoryTest::MF_y ] )
+ assert_equal( 29, sv[ ValueFactoryTest::MF_z ] )
+ end
+
+ def test_S1_import
+
+ sv = StructValue.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_S1 )
+ sv.store( ValueFactoryTest::MF_x, 101 )
+ sv.store( ValueFactoryTest::MF_y, 103 )
+ sv.store( ValueFactoryTest::MF_z, 107 )
+ s = @vf.importCustomValue( sv )
+ assert_equal( 101, s.x )
+ assert_equal( 103, s.y )
+ assert_equal( 107, s.z )
+ end
+
+ def test_S2
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_S2 )
+
+ checkField( ValueFactoryTest::MF_a )
+ checkField( ValueFactoryTest::MF_b )
+ checkField( ValueFactoryTest::MF_c )
+ end
+
+ def test_S2_export
+
+ a = Test::S1.new( 21, 22, 23 )
+ b = Test::S1.new( 31, 32, 33 )
+ c = Test::E1::A
+
+ sv = @vf.exportCustomValue( Test::S2.new( a, b, c ) )
+ sv.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_S2 )
+ assert_equal( 3, sv.size )
+ assert_equal( a, sv[ ValueFactoryTest::MF_a ] )
+ assert_equal( b, sv[ ValueFactoryTest::MF_b ] )
+ assert_equal( c, sv[ ValueFactoryTest::MF_c ] )
+ end
+
+ def test_S2_import
+
+ sv = StructValue.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_S2 )
+
+ sv.store( ValueFactoryTest::MF_a, Test::S1.new( 21, 22, 23 ) )
+ sv.store( ValueFactoryTest::MF_b, Test::S1.new( 31, 32, 33 ) )
+ sv.store( ValueFactoryTest::MF_c, Test::E1::A )
+
+ s = @vf.importCustomValue( sv )
+ assert_equal( 21, s.a.x )
+ assert_equal( 22, s.a.y )
+ assert_equal( 23, s.a.z )
+ assert_equal( 31, s.b.x )
+ assert_equal( 32, s.b.y )
+ assert_equal( 33, s.b.z )
+ assert_equal( Test::E1::A, s.c )
+ end
+
+ def test_excps
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_Excp1 )
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_Excp3 )
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_Excp4 )
+
+ checkField( ValueFactoryTest::MF_msg )
+ checkField( ValueFactoryTest::MF_code )
+ end
+
+ def test_excps_export
+ sv = @vf.exportCustomValue( Test::Excp1.new( "abc", 23 ) )
+ sv.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_Excp1 )
+ assert_equal( 2, sv.size )
+ assert_equal( "abc", sv[ ValueFactoryTest::MF_msg ] )
+ assert_equal( 23, sv[ ValueFactoryTest::MF_code ] )
+
+ sv = @vf.exportCustomValue( Test::Excp3.new() )
+ sv.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_Excp3 )
+ assert_equal( 0, sv.size )
+
+ sv = @vf.exportCustomValue( Test::Excp4.new() )
+ sv.checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_Excp4 )
+ assert_equal( 0, sv.size )
+
+ end
+
+ def test_expcs_import
+ sv = StructValue.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_Excp1 )
+ sv.store( ValueFactoryTest::MF_msg, "def" )
+ sv.store( ValueFactoryTest::MF_code, 29 )
+ e1 = @vf.importCustomValue( sv )
+ assert_equal( "def", e1.msg )
+ assert_equal( 29, e1.code )
+ e1 = nil
+
+ sv = StructValue.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_Excp3 )
+ e3 = @vf.importCustomValue( sv )
+ assert_not_nil( e3 )
+ e3 = nil
+
+ sv = StructValue.new( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_Excp4 )
+ e4 = @vf.importCustomValue( sv )
+ assert_not_nil( e4 )
+ e4 = nil
+ end
+
+ def test_method_nothing
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_nothing )
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_nothing )
+ checkField( ValueFactoryTest::MF_result )
+ end
+
+ def test_method_incr
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_incr )
+ checkField( ValueFactoryTest::MF_x )
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_incr )
+ checkField( ValueFactoryTest::MF_result )
+ end
+
+ def test_method_sub
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_sub )
+ checkField( ValueFactoryTest::MF_x )
+ checkField( ValueFactoryTest::MF_y )
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_sub )
+ checkField( ValueFactoryTest::MF_result )
+ end
+
+ def test_method_sum
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_sum )
+ checkField( ValueFactoryTest::MF_x )
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_sum )
+ checkField( ValueFactoryTest::MF_result )
+ end
+
+ def test_method_trans
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_trans )
+ checkField( ValueFactoryTest::MF_e )
+ checkField( ValueFactoryTest::MF_y )
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_trans )
+ checkField( ValueFactoryTest::MF_result )
+ end
+
+ def test_method_dist
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_dist )
+ checkField( ValueFactoryTest::MF_a )
+ checkField( ValueFactoryTest::MF_b )
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_dist )
+ checkField( ValueFactoryTest::MF_result )
+ end
+
+ def test_method_fill
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_fill )
+ checkField( ValueFactoryTest::MF_n )
+ checkField( ValueFactoryTest::MF_x )
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_fill )
+ checkField( ValueFactoryTest::MF_result )
+ end
+
+ def test_method_blow
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_blow )
+ checkField( ValueFactoryTest::MF_msg )
+ checkField( ValueFactoryTest::MF_code )
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_blow )
+ checkField( ValueFactoryTest::MF_result )
+ end
+
+ def test_method_beets
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test_beets )
+ checkField( ValueFactoryTest::MF_e )
+ checkType( ValueFactoryTest::MT_etch_bindings_ruby_test_Test__result_beets )
+ checkField( ValueFactoryTest::MF_result )
+ end
+
+
+
+ #
+ # utility methods
+ #
+ def checkType( t )
+ assert_not_nil( t )
+ assert_same( Type, t.class )
+ assert_same( t, @vf.getType( t.xid ) )
+ end
+
+ def checkField( f )
+ assert_not_nil( f )
+ assert_same( Field, f.class )
+ assert_same( f, @vf.getField( f.xid ) )
+ end
+
+ def testEnumExport( e, t, f )
+ sv = @vf.exportCustomValue( e )
+ sv.checkType( t )
+ assert_equal( 1, sv.size )
+ assert( sv[f] )
+ end
+
+ def testEnumImport( e, t, f )
+ sv = StructValue.new( t )
+ sv.store( f, true )
+ a = @vf.importCustomValue( sv )
+ assert_same( e, a )
+ end
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_value_factory_test.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/idl/test/test_value_factory_test.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/array_element.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/array_element.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/array_element.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/array_element.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,9 @@
+# package 'etch/bindings/ruby/msg'
+
+# Holder for a value from an array element sequence.
+class ArrayElement
+
+ # The array element value (Object)
+ attr :value, true
+
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/array_element.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/array_element.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/array_value.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/array_value.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/array_value.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/array_value.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,68 @@
+# package 'etch/bindings/ruby/msg'
+
+class ArrayValue < Array
+
+ # Adds many values to the array value
+ # param -> values = set of values as varargs
+
+ def addMany( *values )
+ values.each { |value| self << value }
+ end
+
+ # Constructs a new array value and adds it to the end of
+ # this array value.
+ # returns -> newly constructed array value
+
+ def addArrayValue
+ av = ArrayValue.new
+ self << av
+ return av
+ end
+
+ # Constructs a new struct value and adds it to the end of
+ # this array value.
+ # param -> type = the type of the structure
+ # returns -> a newly constructed structvalue
+
+ def addStructValue( type )
+ sv = StructValue.new( type )
+ self << sv
+ return sv
+ end
+
+ # Reads an array and all of its values.
+ # param -> tdi = the tagged data input to read from.
+ # return -> an array value read from the tagged data input.
+
+ def self.read( tdi )
+ array = tdi.startArray
+ array.readValues( tdi )
+ tdi.endArray( array )
+ return array
+ end
+
+ # Writes an array and all of its values.
+ # param -> tdo the tagged data output to write to.
+
+ def write( tdo )
+ tdo.startArray( self )
+ writeValues( tdo )
+ tdo.endArray( self )
+ end
+
+ # Reads the values of the array. Does not clear the array first.
+ # param -> tdi = the tagged data input to read from.
+
+ def readValues( tdi )
+ ae = ArrayElement.new
+ while tdi.readArrayElement( ae )
+ self << ae.value
+ end
+ end
+
+ # Writes the values of the array.
+ # param -> tdo = the tagged data output to write to.
+ def writeValues( tdo )
+ each {|value| tdo.writeArrayElement( value )}
+ end
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/array_value.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/array_value.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/field.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/field.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/field.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/field.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,25 @@
+# package 'etch/bindings/ruby/msg'
+require 'etch/bindings/ruby/msg/id_name'
+
+# Field is an IdName which denotes a field of a struct
+# or message (i.e., a key for a value).
+
+class Field < IdName
+
+ # Constructs the Field.
+ # @param id the id of the field.
+ # @param name the name of the field.
+
+ def initialize(id, name)
+ super(id, name)
+ end
+
+ # Constructs the Field, computing the appropriate value
+ # for the id.
+ # @param name the name of the field.
+
+ # def initialize(name)
+ # super(name)
+ # end
+
+end
\ No newline at end of file
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/field.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/field.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/id_name.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/id_name.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/id_name.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/id_name.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,80 @@
+# package 'etch/bindings/ruby/msg'
+
+# An IdName is a base class for Field or Type. It is used
+# to bind together a type or field name with the associated id. The id
+# is used for certain operations, such as the key in a Map, comparisons,
+# and binary encoding on the wire, while the name is used for display.
+
+class IdName
+ attr :xid, true
+ attr :name, true
+
+ # Constructs the IdName.
+ # @param id the id for the name
+ # @param name the name of the item.
+ def initialize( xid, name )
+ xid = IdName.hashit( name ) if xid.nil?
+ @xid = xid
+ @name = name
+ end
+
+ # def initialize( name )
+ # initialize( name, hashit( name ) )
+ # end
+
+ def to_s
+ return @name
+ end
+
+ def hash
+ return @xid.hash
+ end
+
+ def ==(o)
+
+ # check for nil first
+ if ( o == nil )
+ if ( self.class == NilClass )
+ return true
+ else
+ return false
+ end
+ return true
+ end
+
+ # overload ==
+ return @xid == o.xid
+ end
+
+ def eql?( o )
+
+ # check for nil first
+ if ( o == nil )
+ if ( self.class == NilClass )
+ return true
+ else
+ return false
+ end
+ return true
+ end
+
+ return @xid.eql?( o.xid )
+ end
+
+ # Computes the hash value of the name to be used as the id when
+ # constructing an IdName.
+ # @param name the name of the type or field.
+ # @return a hash of name in the unicode character encoding which is
+ # very likely to be unique over reasonable name spaces. Collisions
+ # should be very unlikely as they will force the user to change the
+ # name.
+ def self.hashit( name )
+ r = 5381
+ name.each_byte {|c| r = c + (r << 6) + (r << 16) - r }
+ r = r % 4294967296
+ if r > 2147483647 then
+ r = r - 4294967296
+ end
+ return r
+ end
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/id_name.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/id_name.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/mailbox.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/mailbox.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/mailbox.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/mailbox.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,27 @@
+# package 'etch/bindings/ruby/msg'
+
+module Mailbox
+ def getMessageId
+ raise "subclasser responsibility"
+ end
+
+ def deliver( msg )
+ raise "subclasser responsibility"
+ end
+
+ def deliver( msg, maxDelay )
+ raise "subclasser responsibility"
+ end
+
+ def read
+ raise "subclasser responsibility"
+ end
+
+ def read( maxDelay )
+ raise "subclasser responsibility"
+ end
+
+ def close
+ raise "subclasser responsibility"
+ end
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/mailbox.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/mailbox.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/message.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/message.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/message.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/message.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,89 @@
+# package 'etch/bindings/ruby/msg'
+
+require 'etch/bindings/ruby/msg/struct_value'
+
+# A message is modeled as a command and some argments.
+# The command is an arbitrary integer value, and the
+# arguments are key / value pairs, where the key is an
+# arbitrary integer value and the value is any one of the
+# standard java objects, an ArrayValue, a StructValue,
+# or any type which may be serialized by the ValueFactory.
+
+class Message < StructValue
+ attr :vf
+
+ # Constructs the Message.
+ # @param vf the value factory
+ #
+ def initialize( stype, vf )
+ super( stype )
+ @vf = vf
+ end
+
+ def vf()
+ return @vf
+ end
+
+ # Reads a Message from the tagged data input.
+ # @param tdi the tagged data input to read from.
+ # @return a Message read from the tagged data input.
+
+ def self.read( tdi )
+ msg = tdi.startMessage()
+ msg.readKeysAndValues( tdi )
+ tdi.endMessage( msg )
+ return msg
+ end
+
+ # Writes a message to the tagged data output
+ # @param tdo the tagged data output to write to.
+ # @throws IOException if there is a problem with the tagged data output.
+
+ def writeMessage( tdo )
+ tdo.startMessage( self )
+ writeKeysAndValues( tdo )
+ tdo.endMessage( self )
+ end
+
+ # Creates a message which is a reply to the current message.
+ # The current message's value factory is copied to the new
+ # message. The message-id of the current message (if any) is
+ # copied into the in-reply-to field of the new message.
+ # @param rType the type of the reply.
+ # @return a reply message.
+ #
+ def reply( rType ) # return Message
+ rmsg = Message.new( rType, @vf)
+ rmsg.setInReplyTo( getMessageId() )
+ return rmsg
+ end
+
+
+ # @return the connection specific unique identifier of this
+ # message, or null if there was no such identifier.
+ def getMessageId()
+ return @vf.getMessageId( self )
+ end
+
+ # Sets the message-id field of this message.
+ # @param msgid the connection specific unique identifier of this
+ # message. Null if the message has not been sent yet.
+ # NOTE: the send process overwrites any value the user might set
+ # here. So don't bother trying to set it.
+ def setMessageId( msgid )
+ vf.setMessageId( self, msgid )
+ end
+
+ # @return the message-id of the message that this is a response to.
+ # Null if this is an original message or if the original message did
+ # not have a message-id.
+ def getInReplyTo()
+ return vf.getInReplyTo( self )
+ end
+
+ # Sets the in-reply-to field of this message.
+ # @param msgid the message-id of the message that this is a response to.
+ def setInReplyTo( msgid )
+ vf.setInReplyTo( self, msgid )
+ end
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/message.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/struct_element.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/struct_element.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/struct_element.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/struct_element.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,11 @@
+# package 'etch/bindings/ruby/msg'
+
+# Holder for a key / value pair from a struct element sequence.
+class StructElement
+
+ # Description of key (Field).
+ attr :key, true
+
+ # Description of value (Object).
+ attr :value, true
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/struct_element.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/struct_element.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/struct_value.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/struct_value.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/struct_value.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/struct_value.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,108 @@
+# package 'etch/bindings/ruby/msg'
+
+require 'etch/bindings/ruby/msg/struct_element'
+
+# A typed map of key/value pairs, where the type is a Type,
+# each key is a Field, and each value is of arbitrary type
+# chosen from the basic java types boolean, byte, short, int, long,
+# float, double, String, an array of those, the extended types
+# ArrayValue and StructValue, and specific types supported by
+# ValueFactory.
+
+# StructValue is not protected against concurrent access.
+#
+class StructValue < Hash
+
+ attr :stype
+
+ def initialize( stype )
+ @stype = stype
+ end
+
+ def getType()
+ return @stype
+ end
+
+ # Compares the type of this struct to another type.
+ # @param otherType the type to compare this type to.
+ # @return true if this struct is of the specified type.
+ def stype?( otherStype )
+ return @stype.eql?( otherStype )
+ end
+
+ # Checks a struct for having the expected type.
+ # @param expectedType the expected type of this struct.
+ # @throws IllegalArgumentException if the type is not as expected.
+ #
+ def checkType( otherStype )
+ if !stype?( otherStype )
+ raise "type mismatch (got #{stype} wanted #{otherStype})"
+ else
+ return true
+ end
+ end
+
+ # Constructs a new array value and puts it into this struct value
+ # with the specified key.
+ # @param key the key of the newly constructed array value.
+ # @return a newly constructed array value.
+ #
+ def putArrayValue( key )
+ av = ArrayValue.new
+ store( key, av )
+ return av
+ end
+
+ # Constructs a new struct value and puts it into this struct value
+ # with the specified key.
+ # @param key the key of the newly constructed struct value.
+ # @param sType the type of the structure.
+ # @return a newly constructed struct value.
+ #
+ def putStructValue( key, type )
+ sv = StructValue.new( type )
+ store( key, sv )
+ return sv
+ end
+
+ # Reads the struct from the tagged data input.
+ # @param tdi the tagged data input to read from.
+ # @return a struct value read from the tagged data input.
+ #
+ def self.read( tdi )
+ sv = tdi.startStruct
+ sv.readKeysAndValues( tdi )
+ tdi.endStruct( sv )
+ return sv
+ end
+
+ # Writes a struct to the tagged data output.
+ # @param tdo the tagged data output to write to.
+ #
+ def writeStruct( tdo )
+ tdo.startStruct( self )
+ writeKeysAndValues( tdo )
+ tdo.endStruct( self )
+ end
+
+ # Reads the key / value pairs and puts them in the struct.
+ # @param tdi the tagged data input to read from.
+ #
+ def readKeysAndValues( tdi )
+ se = StructElement.new
+ while tdi.readStructElement( se )
+ store( se.key, se.value )
+ end
+ end
+
+ # Writes the key / value pairs.
+ # @param tdo the tagged data output to write to.
+ #
+ def writeKeysAndValues( tdo )
+ each{ |key, value| tdo.writeStructElement( key, value ) }
+ end
+
+ def to_s
+ return "#{@stype}: "+to_a.join( ", " )
+ end
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/struct_value.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/struct_value.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/tagged_data_input.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/tagged_data_input.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/tagged_data_input.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/tagged_data_input.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,71 @@
+# package 'etch/bindings/ruby/msg'
+
+# A TaggedDataInputStream reads type tagged values from an input stream.
+module TaggedDataInput
+
+ # Starts reading a message from the stream.
+ # @return the message that we are reading.
+ #
+ def startMessage( ms ) # returns Message
+ raise "subclasser responsibility"
+ end
+
+ # Ends a message that we are reading.
+ # @param msg the message that has been read.
+ #
+ def endMessage( msg )
+ raise "subclasser responsibility"
+ end
+
+ # Starts reading a struct from the stream.
+ # @return the struct that we are reading.
+ #
+ def startStruct # returns StructValue
+ raise "subclasser responsibility"
+ end
+
+ # Reads the next key and value in the sequence of struct
+ # elements by stuffing the fields of the passed in StructElement.
+ # @param se place to store the read key and value.
+ # @return true if a key and value were read, false if there aren't any more
+ # key / value pairs.
+ #
+ def readStructElement( se ) # returns boolean
+ raise "subclasser responsibility"
+ end
+
+ # Ends a struct that we are reading.
+ # @param struct the struct that we read.
+ #
+ def endStruct( struct )
+ raise "subclasser responsibility"
+ end
+
+ # Starts reading an array from the stream.
+ # @return the array that we are reading.
+ #
+ def startArray # returns ArrayValue
+ raise "subclasser responsibility"
+ end
+
+ # Reads the next value in the sequence of array elements by
+ # stuffing the fields of the passed in ArrayElement.
+ # @param ae place to store the read value.
+ # @return true if a value was read, false if there aren't any more.
+ #
+ def readArrayElement( ae ) # returns boolean
+ raise "subclasser responsibility"
+ end
+
+ # Ends an array that we are reading.
+ # @param array the array that we read.
+ #
+ def endArray( array )
+ raise "subclasser responsibility"
+ end
+
+ # Closes and discards any underlying resources.
+ def close()
+ raise "subclasser responsibility"
+ end
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/tagged_data_input.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/tagged_data_input.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/tagged_data_output.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/tagged_data_output.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/tagged_data_output.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/tagged_data_output.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,76 @@
+# package 'etch/bindings/ruby/msg'
+
+# A TaggedDataOutputStream writes type tagged data values to
+# an output stream.
+#
+module TaggedDataOutput
+
+ # Writes the beginning of message data. A message is also a struct,
+ # and so the type of the struct is written. The fields and
+ # values of the struct should be written using
+ # writeStructElement(key, value)
+ # @param msg the message being written out.
+ #
+ def startMessage( msg )
+ raise "subclasser responsibility"
+ end
+
+ # Writes the end of message data.
+ # @param msg the message that was written.
+ #
+ def endMessage ( msg )
+ raise "subclasser responsibility"
+ end
+
+ # Writes the beginning of struct data. The type of the struct is
+ # written. The fields and values of the struct are written
+ # using writeStructElement(key, value).
+ # @param struct the struct being written out.
+ #
+ def startStruct( struct )
+ raise "subclasser responsibility"
+ end
+
+ # Writes a struct element with the specified key and value.
+ # @param key
+ # @param value
+ #
+ def writeStructElement( key, value )
+ raise "subclasser responsibility"
+ end
+
+ # Writes the end of struct data.
+ # @param struct the struct that was written.
+ #
+ def endStruct( struct )
+ raise "subclasser responsibility"
+ end
+
+ # Writes the beginning of array data. The values of the array
+ # should be written using writeArrayElement(value)
+ # @param array the array to be written.
+ #
+ def startArray( array )
+ raise "subclasser responsibility"
+ end
+
+ # Writes an array element with the specified value.
+ # @param value
+ #
+ def writeArrayElement( value )
+ raise "subclasser responsibility"
+ end
+
+ # Writes the end of array data.
+ # @param array the array that was written.
+ #
+ def endArray( array )
+ raise "subclasser responsibility"
+ end
+
+ # Closes and releases any resources.
+ #
+ def close
+ raise "subclasser responsibility"
+ end
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/tagged_data_output.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/tagged_data_output.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_array_value.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_array_value.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_array_value.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_array_value.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,193 @@
+require 'test/unit'
+require 'etch/bindings/ruby/msg/array_element'
+require 'etch/bindings/ruby/msg/array_value'
+require 'etch/bindings/ruby/msg/id_name'
+require 'etch/bindings/ruby/msg/struct_value'
+require 'etch/bindings/ruby/msg/tagged_data_input'
+require 'etch/bindings/ruby/msg/tagged_data_output'
+
+class TestArrayValue < Test::Unit::TestCase
+ def testAddArrayValue
+ av = ArrayValue.new
+ assert( av.empty? )
+ assert_equal( 0, av.length )
+
+ av1 = av.addArrayValue
+ assert_not_nil( av1 )
+ assert_not_same( av, av1 )
+ assert_instance_of( ArrayValue, av1 )
+ assert( !av.empty? )
+ assert_equal( 1, av.length )
+ assert_same( av1, av[0] )
+
+ av2 = av.addArrayValue
+ assert_not_nil( av2 )
+ assert_not_same( av, av2 )
+ assert_not_same( av1, av2 )
+ assert_instance_of( ArrayValue, av2 )
+ assert( !av.empty? )
+ assert_equal( 2, av.length )
+ assert_same( av1, av[0] )
+ assert_same( av2, av[1] )
+ end
+
+ def testAddStructValue
+ av = ArrayValue.new
+ assert_equal( 0, av.length )
+
+ mt1 = IdName.new( 1, "foo" )
+ mt2 = IdName.new( 2, "bar" )
+
+ sv1 = av.addStructValue( mt1 )
+ assert_not_nil( sv1 )
+ assert_not_same( av, sv1 )
+ assert_instance_of( StructValue, sv1 )
+ assert_same( mt1, sv1.stype )
+ assert( !av.empty? )
+ assert_equal( 1, av.length )
+ assert_same( sv1, av[0] )
+
+ sv2 = av.addStructValue( mt2 )
+ assert_not_nil( sv2 )
+ assert_not_same( av, sv2 )
+ assert_not_same( sv1, sv2 )
+ assert_instance_of( StructValue, sv2 )
+ assert_same( mt2, sv2.stype )
+ assert( !av.empty? )
+ assert_equal( 2, av.length )
+ assert_same( sv1, av[0] )
+ assert_same( sv2, av[1] )
+ end
+
+ def testRead
+ readHelper
+ readHelper( 1 )
+ readHelper( 2, 3.3 )
+ readHelper( 4, true, 6 )
+ readHelper( "a", "b", "c", "d" )
+ end
+
+ def testWrite
+ writeHelper
+ writeHelper( 1 )
+ writeHelper( 2, 3.3 )
+ writeHelper( 4, true, 6 )
+ writeHelper( "a", "b", "c", "d" )
+ end
+
+ def readHelper( *vals )
+ tdi = FakeTdi.new( vals )
+ av = ArrayValue.read( tdi )
+ assert_instance_of( ArrayValue, av )
+ tdi.close
+ end
+
+ def writeHelper( *vals )
+ av = ArrayValue.new
+ vals.each {|v| av << v}
+ tdo = FakeTdo.new( vals )
+ av.write( tdo )
+ tdo.close()
+ end
+end
+
+class FakeTdo
+ include TaggedDataOutput
+ include Test::Unit::Assertions
+
+ def initialize( vals )
+ @vals = vals
+ @started = false
+ @ended = false
+ end
+
+ def startArray( array )
+ assert( !@started )
+ assert( !@ended )
+ assert_not_nil( array )
+
+ @started = true
+ @xarray = array
+ @list = Array.new
+ end
+
+ def writeArrayElement( value )
+ assert( @started )
+ assert( !@ended )
+
+ @list << value
+ end
+
+ def endArray( array )
+ assert( @started )
+ assert( !@ended )
+ assert_same( @xarray, array )
+
+ @ended = true
+ end
+
+ def close
+ assert( @started )
+ assert( @ended )
+ assert_equal( @vals.length, @list.length )
+ assert_equal( @vals, @list )
+ end
+end
+
+class FakeTdi
+ include TaggedDataInput
+ include Test::Unit::Assertions
+
+ def initialize( vals )
+ @vals = vals
+ @started = false
+ @done = false
+ @ended = false
+ end
+
+ def startArray
+ assert( !@started )
+ assert( !@done )
+ assert( !@ended )
+
+ @started = true
+ @xarray = ArrayValue.new
+ @index = 0
+
+ return @xarray
+ end
+
+ def readArrayElement( ae )
+ assert( @started )
+ assert( !@done )
+ assert( !@ended )
+ assert( @index <= @vals.length )
+
+ if @index < @vals.length
+ ae.value = @vals[@index]
+ @index += 1
+ return true
+ end
+
+ @done = true
+ return false
+ end
+
+ def endArray( array )
+ assert( @started )
+ assert( @done )
+ assert( !@ended )
+ assert_same( @xarray, array )
+
+ @ended = true
+ end
+
+ def close
+ assert( @started )
+ assert( @done )
+ assert( @ended )
+
+ assert_equal( @vals.length, @xarray.length )
+ assert_equal( @vals, @xarray )
+ end
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_array_value.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_array_value.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_id_name.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_id_name.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_id_name.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_id_name.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,58 @@
+require 'test/unit'
+require 'etch/bindings/ruby/msg/id_name'
+
+class TestIdName < Test::Unit::TestCase
+ def testGetId()
+ assert_equal( 1, IdName.new( 1, "foo" ).xid )
+ assert_equal( 1, IdName.new( 1, "bar" ).xid )
+ assert_equal( 2, IdName.new( 2, "foo" ).xid )
+ assert_equal( 2, IdName.new( 2, "bar" ).xid )
+ end
+
+ def testGetName
+ assert_equal( "foo", IdName.new( 1, "foo" ).name )
+ assert_equal( "bar", IdName.new( 1, "bar" ).name )
+ assert_equal( "foo", IdName.new( 2, "foo" ).name )
+ assert_equal( "bar", IdName.new( 2, "bar" ).name )
+ end
+
+ def testToString
+ assert_equal( "foo", IdName.new( 1, "foo" ).to_s )
+ assert_equal( "bar", IdName.new( 1, "bar" ).to_s )
+ assert_equal( "foo", IdName.new( 2, "foo" ).to_s )
+ assert_equal( "bar", IdName.new( 2, "bar" ).to_s )
+ end
+
+ def testEqual
+ assert( IdName.new( 1, "foo" ).eql?( IdName.new( 1, "foo" ) ) )
+ assert( IdName.new( 1, "foo" ).eql?( IdName.new( 1, "bar" ) ) )
+ assert( IdName.new( 2, "foo" ).eql?( IdName.new( 2, "foo" ) ) )
+ assert( IdName.new( 2, "foo" ).eql?( IdName.new( 2, "bar" ) ) )
+
+ assert( !IdName.new( 1, "foo" ).eql?( IdName.new( 2, "foo" ) ) )
+ assert( !IdName.new( 1, "foo" ).eql?( IdName.new( 2, "bar" ) ) )
+ assert( !IdName.new( 2, "foo" ).eql?( IdName.new( 1, "foo" ) ) )
+ assert( !IdName.new( 2, "foo" ).eql?( IdName.new( 1, "bar" ) ) )
+ end
+
+ def testHash
+ assert_equal( IdName.new( 1, "foo" ).hash, IdName.new( 1, "foo" ).hash );
+ assert_equal( IdName.new( 1, "foo" ).hash, IdName.new( 1, "bar" ).hash );
+ assert_equal( IdName.new( 2, "foo" ).hash, IdName.new( 2, "foo" ).hash );
+ assert_equal( IdName.new( 2, "foo" ).hash, IdName.new( 2, "bar" ).hash );
+ end
+
+ def testHashIt
+ assert_equal( 5381, IdName.hashit( "" ) );
+ assert_equal( 352988316, IdName.hashit( "a" ) );
+ assert_equal( 1511848646, IdName.hashit( "ab" ) );
+ assert_equal( 669497117, IdName.hashit( "abc" ) );
+ assert_equal( -1994190713, IdName.hashit( "abcd" ) );
+ assert_equal( -802680418, IdName.hashit( "abcde" ) );
+ assert_equal( 1266308680, IdName.hashit( "abcdef" ) );
+ assert_equal( -379372513, IdName.hashit( "abcdefg" ) );
+ assert_equal( -1416967159, IdName.hashit( "abcdefgh" ) );
+ assert_equal( 53556896, IdName.hashit( "abcdefghi" ) );
+ assert_equal( -4427318, IdName.hashit( "abcdefghij" ) );
+ end
+end
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_id_name.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_id_name.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_message.rb
URL: http://svn.apache.org/viewvc/incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_message.rb?rev=768343&view=auto
==============================================================================
--- incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_message.rb (added)
+++ incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_message.rb Fri Apr 24 16:05:55 2009
@@ -0,0 +1,260 @@
+require 'test/unit'
+require 'etch/bindings/ruby/msg/id_name'
+require 'etch/bindings/ruby/msg/field'
+require 'etch/bindings/ruby/msg/type'
+require 'etch/bindings/ruby/msg/message'
+require 'etch/bindings/ruby/msg/mailbox'
+require 'etch/bindings/ruby/msg/tagged_data_input'
+require 'etch/bindings/ruby/msg/tagged_data_output'
+require 'etch/bindings/ruby/msg/value_factory'
+
+class TestMessage < Test::Unit::TestCase
+
+ attr :vf, true
+ attr :mt1, true
+ attr :rmt, true
+ attr :mf1, true
+ attr :mf2, true
+
+ def setup
+ @vf = MyValueFactory.new()
+ @mt1 = Type.new(1, "mt")
+ @rmt = Type.new(2, "rmt")
+ @mf1 = Field.new(1, "x")
+ @mf2 = Field.new(2, "y")
+ end
+
+ # Tests
+ #
+
+ def testgetVf
+ msg = Message.new(@mt1, @vf)
+ assert_equal(@vf, msg.vf())
+ end
+
+ def testread
+ readHelper(@mt1)
+ readHelper(@mt1, @mf1, 3)
+ readHelper(@mt1, @mf1, 3, @mf2, 4)
+ end
+
+ def readHelper(mt, *keyVals)
+ tdi = FakeTdi.new(@vf, mt, keyVals)
+ #puts tdi
+ msg = Message.read(tdi)
+ assert_not_nil(msg)
+ tdi.close()
+ end
+
+ def testwriteMessage
+ msg = Message.new(@mt1, @vf)
+ writeHelper(msg)
+
+ msg.store(@mf1, 123)
+ writeHelper(msg)
+
+ msg.store(@mf2, 234)
+ writeHelper(msg)
+ end
+
+ def writeHelper(msg)
+ tdo = FakeTdo.new(msg)
+ msg.writeMessage(tdo)
+ tdo.close()
+ end
+
+ def testreply
+ msg = Message.new(@mt1, @vf)
+ msg.setMessageId(12345)
+
+ rmsg = msg.reply(@rmt)
+ assert_equal(@rmt, rmsg.getType())
+ assert_equal(@vf, rmsg.vf())
+ assert_equal(12345, rmsg.getInReplyTo())
+ end
+
+ def testgetMessageId
+ msg = Message.new(@mt1, @vf)
+ assert_nil(msg.getMessageId())
+ msg.setMessageId(234)
+ assert_equal(234, msg.getMessageId)
+ msg.setMessageId(345)
+ assert_equal(345, msg.getMessageId)
+ end
+
+ def testgetInReplyTo
+ msg = Message.new(@mt1, @vf)
+ assert_nil(msg.getInReplyTo)
+ msg.setInReplyTo(234)
+ assert_equal(234, msg.getInReplyTo)
+ end
+
+
+ # Helper (mostly dummy) classes
+ #
+ class MyValueFactory
+ include ValueFactory
+
+ attr :mf_messageId, true
+ attr :mf_inReplyTo, true
+ def initialize()
+ @mf_messageId = Field.new(nil, "_messageId")
+ @mf_inReplyTo = Field.new(nil, "_inReplyTo")
+ end
+
+ # Return message id of message.
+ def getMessageId(msg)
+ return msg[@mf_messageId]
+ end
+
+ # Set message Id. of the message
+ def setMessageId(msg, msgId)
+ msg.store(@mf_messageId, msgId)
+ end
+
+ def getInReplyTo(msg)
+ return msg[@mf_inReplyTo]
+ end
+
+ def setInReplyTo(msg, msgId)
+ msg.store(@mf_inReplyTo, msgId)
+ end
+ end
+
+ class FakeTdo
+ include TaggedDataOutput
+ include Test::Unit::Assertions
+
+ attr :xmsg, true
+ attr :started, true
+ attr :ended, true
+ attr :items, true
+
+ def initialize(msg)
+ @xmsg = msg
+ @started = false
+ @ended = false
+ @items = Hash.new()
+ end
+
+ def startMessage(msg)
+ assert_equal(@xmsg, msg)
+ assert_same(@xmsg, msg)
+ assert(!@started)
+ assert(!@ended)
+
+ @started = true
+ end
+
+ def writeStructElement(key, value)
+ assert(@started)
+ assert(!@ended)
+ @items.store(key, value)
+ end
+
+ def endMessage(msg)
+ assert_equal(@xmsg, msg)
+ assert_same(@xmsg, msg) # testing ...
+ assert(!@ended)
+ @ended = true
+ end
+
+ def close
+ assert(@started)
+ assert(@ended)
+ assert_equal(@xmsg.size(), @items.size())
+ assert_equal(@xmsg, @items)
+
+ end
+ end
+
+ class FakeTdi
+ include TaggedDataInput
+ include Test::Unit::Assertions
+
+ attr :vf, true
+ attr :mt, true
+ attr :fieldsandvalues, true
+ attr :started, true
+ attr :ended, true
+ attr :done, true
+ attr :xmsg, true
+
+ def initialize(vf, mt, *fieldsandvalues)
+ @vf = vf
+ @mt = mt
+ @fieldsandvalues = fieldsandvalues
+ end
+
+ def startMessage()
+
+ assert(!@started)
+ assert(!@ended)
+ assert(!@done)
+
+ @started = true
+ @xmsg = Message.new(@mt, @vf)
+ @index = 0
+
+ return @xmsg
+ end
+
+ def readStructElement(se)
+ assert(@started)
+ assert(!@done)
+ assert(!@ended)
+
+ index = 0
+ while (@keyVals != nil) and (index < @keyVals.length)
+ key = @keyVals[index]
+ value = @keyVals[index+1]
+ assert_same( value, @xmsg[key] )
+ index += 2
+ end
+
+ @done = true
+ return false
+ end
+
+ def endMessage(msg)
+ assert_equal(@xmsg, msg)
+ assert(@started)
+ assert(@done)
+ assert( !@ended )
+ @ended = true
+ end
+
+ def close()
+ assert(@started)
+ assert(@done)
+ assert(@ended)
+
+ assert_equal(@mt, @xmsg.getType())
+ assert_equal(@fieldsandvalues.length/2, @xmsg.length/2)
+
+ index = 0
+ while index < @fieldsandvalues.length
+ key = @fieldsandvalues[index]
+ value = @fieldsandvalues[index+1]
+ assert_equal( value, @xmsg[key] )
+ index += 2
+ end
+ end
+
+ end
+
+end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_message.rb
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/ruby/binding-ruby/src/main/ruby/msg/test/test_message.rb
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"