You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by mc...@apache.org on 2013/06/21 17:28:14 UTC

svn commit: r1495479 - in /qpid/proton/trunk: proton-c/bindings/ruby/lib/qpid_proton/ tests/ruby/proton_tests/

Author: mcpierce
Date: Fri Jun 21 15:28:14 2013
New Revision: 1495479

URL: http://svn.apache.org/r1495479
Log:
PROTON-341: Update the Ruby interop tests.

Added a new helper function to Data to return an instance of Described.

Added new helper methods to the interop.rb file for testing Arrays.

Modified:
    qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/array.rb
    qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/data.rb
    qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/described.rb
    qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/hash.rb
    qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/mapping.rb
    qpid/proton/trunk/tests/ruby/proton_tests/interop.rb

Modified: qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/array.rb
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/array.rb?rev=1495479&r1=1495478&r2=1495479&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/array.rb (original)
+++ qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/array.rb Fri Jun 21 15:28:14 2013
@@ -132,7 +132,8 @@ class Array
       raise TypeError, "not a list" unless data.enter
       elements = []
       (0...size).each do
-        type = data.next
+        data.next
+        type = data.type
         raise TypeError, "missing next element in list" unless type
         elements << type.get(data)
       end
@@ -155,10 +156,12 @@ class Array
 
       elements.proton_array_header = Qpid::Proton::ArrayHeader.new(type, descriptor)
       (0...count).each do |which|
-        etype = data.next
-        raise TypeError, "missing next element in array" unless etype
-        raise TypeError, "invalid array element: #{etype}" unless etype == type
-        elements << type.get(data)
+        if data.next
+          etype = data.type
+          raise TypeError, "missing next element in array" unless etype
+          raise TypeError, "invalid array element: #{etype}" unless etype == type
+          elements << type.get(data)
+        end
       end
       data.exit
       return elements

Modified: qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/data.rb
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/data.rb?rev=1495479&r1=1495478&r2=1495479&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/data.rb (original)
+++ qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/data.rb Fri Jun 21 15:28:14 2013
@@ -128,8 +128,8 @@ module Qpid
       #
       # If there is no next sibling the current node remains unchanged
       # and nil is returned.
-      def next
-        return Cproton.pn_data_next(@data) ? type : nil
+      def next(print = false)
+        Cproton.pn_data_next(@data)
       end
 
       # Advances the current node to its previous sibling and returns its type.
@@ -267,6 +267,10 @@ module Qpid
         Cproton.pn_data_get_map(@data)
       end
 
+      def get_map # :nodoc:
+        ::Hash.proton_data_get(self)
+      end
+
       # Puts an array value.
       #
       # Elements may be filled by entering the array node and putting the
@@ -334,6 +338,10 @@ module Qpid
         [count, described, Mapping.for_code(array_type) ]
       end
 
+      def get_array # :nodoc:
+        ::Array.proton_get(self)
+      end
+
       # Puts a described value.
       #
       # A described node has two children, the descriptor and the value.
@@ -353,6 +361,19 @@ module Qpid
         check(Cproton.pn_data_put_described(@data))
       end
 
+      def get_described # :nodoc:
+        raise TypeError, "not a described type" unless self.described?
+        self.enter
+        self.next
+        type = self.type
+        descriptor = type.get(self)
+        self.next
+        type = self.type
+        value = type.get(self)
+        self.exit
+        Described.new(descriptor, value)
+      end
+
       # Checks if the current node is a described value.
       #
       # The described and value may be accessed by entering the described value.

Modified: qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/described.rb
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/described.rb?rev=1495479&r1=1495478&r2=1495479&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/described.rb (original)
+++ qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/described.rb Fri Jun 21 15:28:14 2013
@@ -31,22 +31,6 @@ module Qpid # :nodoc:
         @value = value
       end
 
-      # Retrieves the descriptor and value from the supplied Data object.
-      #
-      # ==== Arguments
-      #
-      # * data - the Qpid::Proton::Data instance
-      #
-      def self.get(data)
-        type = data.next
-        raise TypeError, "not a described type" unless type == Mapping.SYMBOL
-        descriptor = data.symbol
-        type = data.next
-        raise TypeError, "not a described type" unless type == Mapping.STRING
-        value = data.string
-        Described.new(descriptor, value)
-      end
-
       # Puts the description into the Data object.
       #
       # ==== Arguments
@@ -65,6 +49,16 @@ module Qpid # :nodoc:
         data.string = @value
       end
 
+      def ==(that) # :nodoc:
+        (that.is_a?(Qpid::Proton::Described) &&
+         (self.descriptor == that.descriptor) &&
+         (self.value == that.value))
+      end
+
+      def to_s # :nodoc:
+        "descriptor=#{descriptor} value=#{value}"
+      end
+
     end
 
   end

Modified: qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/hash.rb
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/hash.rb?rev=1495479&r1=1495478&r2=1495479&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/hash.rb (original)
+++ qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/hash.rb Fri Jun 21 15:28:14 2013
@@ -67,9 +67,11 @@ class Hash
       data.enter
 
       (0...(count/2)).each do
-        type = data.next
+        data.next
+        type = data.type
         key = type.get(data)
-        type = data.next
+        data.next
+        type = data.type
         value = type.get(data)
         result[key] = value
       end

Modified: qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/mapping.rb
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/mapping.rb?rev=1495479&r1=1495478&r2=1495479&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/mapping.rb (original)
+++ qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/mapping.rb Fri Jun 21 15:28:14 2013
@@ -38,6 +38,9 @@ module Qpid # :nodoc:
       # * klasses - the Ruby classes for this type
       # * getter  - overrides the get method for the type
       def initialize(code, name, klasses = nil, getter = nil)
+
+        @debug = (name == "bool")
+
         @code = code
         @name = name
 
@@ -85,7 +88,7 @@ module Qpid # :nodoc:
     end
 
     NULL       = Mapping.new(Cproton::PN_NULL, "null", [NilClass], "nil?")
-    BOOL       = Mapping.new(Cproton::PN_BOOL, "bool", [TrueClass, FalseClass])
+    BOOL       = Mapping.new(Cproton::PN_BOOL, "bool", [TrueClass, FalseClass], "bool")
     UBYTE      = Mapping.new(Cproton::PN_UBYTE, "ubyte")
     BYTE       = Mapping.new(Cproton::PN_BYTE, "byte")
     USHORT     = Mapping.new(Cproton::PN_USHORT, "ushort")
@@ -105,10 +108,10 @@ module Qpid # :nodoc:
     BINARY     = Mapping.new(Cproton::PN_BINARY, "binary")
     STRING     = Mapping.new(Cproton::PN_STRING, "string", [String])
     SYMBOL     = Mapping.new(Cproton::PN_SYMBOL, "symbol")
-    DESCRIBED  = Mapping.new(Cproton::PN_DESCRIBED, "described", [Qpid::Proton::Described])
-    ARRAY      = Mapping.new(Cproton::PN_ARRAY, "array")
-    LIST       = Mapping.new(Cproton::PN_LIST, "list", [::Array])
-    MAP        = Mapping.new(Cproton::PN_MAP, "map", [::Hash])
+    DESCRIBED  = Mapping.new(Cproton::PN_DESCRIBED, "described", [Qpid::Proton::Described], "get_described")
+    ARRAY      = Mapping.new(Cproton::PN_ARRAY, "array", nil, "get_array")
+    LIST       = Mapping.new(Cproton::PN_LIST, "list", [::Array], "get_array")
+    MAP        = Mapping.new(Cproton::PN_MAP, "map", [::Hash], "get_map")
 
   end
 

Modified: qpid/proton/trunk/tests/ruby/proton_tests/interop.rb
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/tests/ruby/proton_tests/interop.rb?rev=1495479&r1=1495478&r2=1495479&view=diff
==============================================================================
--- qpid/proton/trunk/tests/ruby/proton_tests/interop.rb (original)
+++ qpid/proton/trunk/tests/ruby/proton_tests/interop.rb Fri Jun 21 15:28:14 2013
@@ -58,73 +58,84 @@ class InteropTest < Test::Unit::TestCase
     assert_equal(value, type.get(@data))
   end
 
+  def assert_array_next(expected, header)
+    assert_next(Qpid::Proton::ARRAY, expected)
+    result = @data.type.get(@data)
+    assert_equal(result.proton_array_header, header)
+  end
+
   def test_message
     decode_message_file("message")
-    assert_next(Data::STRING, "hello")
-    assert !@data.next()
+    assert_next(Qpid::Proton::STRING, "hello")
+    assert !@data.next
   end
 
   def test_primitives
     decode_data_file("primitives")
-    assert_next(Data::BOOL, true)
-    assert_next(Data::BOOL, false)
-    assert_next(Data::UBYTE, 42)
-    assert_next(Data::USHORT, 42)
-    assert_next(Data::SHORT, -42)
-    assert_next(Data::UINT, 12345)
-    assert_next(Data::INT, -12345)
-    assert_next(Data::ULONG, 12345)
-    assert_next(Data::LONG, -12345)
-    assert_next(Data::FLOAT, 0.125)
-    assert_next(Data::DOUBLE, 0.125)
-    assert !@data.next()
+    assert_next(Qpid::Proton::BOOL, true)
+    assert_next(Qpid::Proton::BOOL, false)
+    assert_next(Qpid::Proton::UBYTE, 42)
+    assert_next(Qpid::Proton::USHORT, 42)
+    assert_next(Qpid::Proton::SHORT, -42)
+    assert_next(Qpid::Proton::UINT, 12345)
+    assert_next(Qpid::Proton::INT, -12345)
+    assert_next(Qpid::Proton::ULONG, 12345)
+    assert_next(Qpid::Proton::LONG, -12345)
+    assert_next(Qpid::Proton::FLOAT, 0.125)
+    assert_next(Qpid::Proton::DOUBLE, 0.125)
+    assert !@data.next
   end
 
   def test_strings
     decode_data_file("strings")
-    assert_next(Data::BINARY, "abc\0defg")
-    assert_next(Data::STRING, "abcdefg")
-    assert_next(Data::SYMBOL, "abcdefg")
-    assert_next(Data::BINARY, "")
-    assert_next(Data::STRING, "")
-    assert_next(Data::SYMBOL, "")
-    assert !@data.next()
+    assert_next(Qpid::Proton::BINARY, "abc\0defg")
+    assert_next(Qpid::Proton::STRING, "abcdefg")
+    assert_next(Qpid::Proton::SYMBOL, "abcdefg")
+    assert_next(Qpid::Proton::BINARY, "")
+    assert_next(Qpid::Proton::STRING, "")
+    assert_next(Qpid::Proton::SYMBOL, "")
+    assert !@data.next
   end
 
   def test_described
     decode_data_file("described")
-    assert_next(Data::DESCRIBED, Data::Described.new("foo-descriptor", "foo-value"))
+    assert_next(Qpid::Proton::DESCRIBED, Qpid::Proton::Described.new("foo-descriptor", "foo-value"))
     assert(@data.described?)
-    assert_next(Data::DESCRIBED, Data::Described.new(12, 13))
+    assert_next(Qpid::Proton::DESCRIBED, Qpid::Proton::Described.new(12, 13))
     assert(@data.described?)
     assert !@data.next
   end
 
   def test_described_array
     decode_data_file("described_array")
-    assert_next(Data::ARRAY, Data::Array.new("int-array", Data::INT, 0...10))
+    assert_array_next((0...10).to_a,
+                       Qpid::Proton::ArrayHeader.new(Qpid::Proton::INT,
+                                                     "int-array"))
   end
 
   def test_arrays
     decode_data_file("arrays")
-    assert_next(Data::ARRAY, Data::Array.new(false, Data::INT, 0...100))
-    assert_next(Data::ARRAY, Data::Array.new(false, Data::STRING, ["a", "b", "c"]))
-    assert_next(Data::ARRAY, Data::Array.new(false, Data::INT))
+    assert_array_next((0...100).to_a,
+                      Qpid::Proton::ArrayHeader.new(Qpid::Proton::INT))
+    assert_array_next(["a", "b", "c"],
+                      Qpid::Proton::ArrayHeader.new(Qpid::Proton::STRING))
+    assert_array_next([],
+                      Qpid::Proton::ArrayHeader.new(Qpid::Proton::INT))
     assert !@data.next
   end
 
   def test_lists
     decode_data_file("lists")
-    assert_next(Data::LIST, [32, "foo", true])
-    assert_next(Data::LIST, [])
+    assert_next(Qpid::Proton::LIST, [32, "foo", true])
+    assert_next(Qpid::Proton::LIST, [])
     assert !@data.next
   end
 
   def test_maps
     decode_data_file("maps")
-    assert_next(Data::MAP, {"one" => 1, "two" => 2, "three" => 3 })
-    assert_next(Data::MAP, {1 => "one", 2 => "two", 3 => "three"})
-    assert_next(Data::MAP, {})
-    assert !@data.next()
+    assert_next(Qpid::Proton::MAP, {"one" => 1, "two" => 2, "three" => 3 })
+    assert_next(Qpid::Proton::MAP, {1 => "one", 2 => "two", 3 => "three"})
+    assert_next(Qpid::Proton::MAP, {})
+    assert !@data.next
   end
 end



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org