mongo-ruby-driver/tests/test_message.rb

36 lines
838 B
Ruby
Raw Normal View History

2008-11-22 01:00:51 +00:00
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
require 'test/unit'
class MessageTest < Test::Unit::TestCase
include XGen::Mongo::Driver
2008-11-22 01:00:51 +00:00
def setup
@msg = Message.new(42)
2008-11-22 01:00:51 +00:00
end
def test_initial_info
assert_equal Message::HEADER_SIZE, @msg.buf.length
2008-11-22 01:00:51 +00:00
@msg.write_long(1029)
@msg.buf.rewind
assert_equal Message::HEADER_SIZE + 8, @msg.buf.get_int
2008-11-22 01:00:51 +00:00
@msg.buf.get_int # skip message id
assert_equal 0, @msg.buf.get_int
assert_equal 42, @msg.buf.get_int
assert_equal 1029, @msg.buf.get_long
end
def test_update_length
@msg.update_message_length
@msg.buf.rewind
assert_equal Message::HEADER_SIZE, @msg.buf.get_int
2008-11-22 01:00:51 +00:00
end
def test_long_length
@msg.write_long(1027)
assert_equal Message::HEADER_SIZE + 8, @msg.buf.length
2008-11-22 01:00:51 +00:00
end
end