minor: update mongo-qa tests for new bson api

This commit is contained in:
Mike Dirolf 2009-12-02 15:49:45 -05:00
parent c893b9269f
commit bfb26b3426
2 changed files with 15 additions and 11 deletions

View File

@ -76,6 +76,10 @@ class BSON_RUBY
@buf.to_a @buf.to_a
end end
def to_s
@buf.to_s
end
# Serializes an object. # Serializes an object.
# Implemented to ensure an API compatible with BSON extension. # Implemented to ensure an API compatible with BSON extension.
def self.serialize(obj, check_keys=false) def self.serialize(obj, check_keys=false)

View File

@ -74,18 +74,18 @@ EOS
# Read the BSON from the file # Read the BSON from the file
bson = f.read bson = f.read
bson = if RUBY_VERSION >= '1.9' bson = if RUBY_VERSION >= '1.9'
bson.bytes.to_a bson.bytes
else else
bson.split(//).collect { |c| c[0] } bson
end end
# Turn the Ruby object into BSON bytes and compare with the BSON bytes # Turn the Ruby object into BSON bytes and compare with the BSON bytes
# from the file. # from the file.
bson_from_ruby = BSON.new.serialize(obj).to_a bson_from_ruby = BSON.serialize(obj)
begin begin
assert_equal bson.length, bson_from_ruby.length assert_equal bson.length, bson_from_ruby.to_s.length
assert_equal bson, bson_from_ruby assert_equal bson, bson_from_ruby.to_s
rescue => ex rescue => ex
# File.open(File.join(dir, "#{name}_out_a.bson"), 'wb') { |f| # DEBUG # File.open(File.join(dir, "#{name}_out_a.bson"), 'wb') { |f| # DEBUG
# bson_from_ruby.each { |b| f.putc(b) } # bson_from_ruby.each { |b| f.putc(b) }
@ -98,15 +98,15 @@ EOS
# We're passing a nil db to the contructor here, but that's OK because # We're passing a nil db to the contructor here, but that's OK because
# the BSON DBRef bytes don't contain the db object in any case, and we # the BSON DBRef bytes don't contain the db object in any case, and we
# don't care what the database is. # don't care what the database is.
obj_from_bson = BSON.new.deserialize(ByteBuffer.new(bson_from_ruby)) obj_from_bson = BSON.deserialize(bson_from_ruby)
assert_kind_of OrderedHash, obj_from_bson assert_kind_of OrderedHash, obj_from_bson
# Turn that Ruby object into BSON and compare it to the original BSON # Turn that Ruby object into BSON and compare it to the original BSON
# bytes. # bytes.
bson_from_ruby = BSON.new.serialize(obj_from_bson).to_a bson_from_ruby = BSON.serialize(obj_from_bson)
begin begin
assert_equal bson.length, bson_from_ruby.length assert_equal bson.length, bson_from_ruby.to_s.length
assert_equal bson, bson_from_ruby assert_equal bson, bson_from_ruby.to_s
rescue => ex rescue => ex
# File.open(File.join(dir, "#{name}_out_b.bson"), 'wb') { |f| # DEBUG # File.open(File.join(dir, "#{name}_out_b.bson"), 'wb') { |f| # DEBUG
# bson_from_ruby.each { |b| f.putc(b) } # bson_from_ruby.each { |b| f.putc(b) }