a9b3c8e7a5
- changed the BSON constant to BSON_CODER and scoped it inside of a module - changed the directory layout for all of the BSON related files - updated the C extension to find the BSON files at their new directory locations - updated the C extension to use better/safer macros for accessing the C API; extension now compiles cleanly under rubinius/rbx - changed directory layout for BSON related tests - modified the Rakefile to understand the new layout
84 lines
1.7 KiB
Ruby
84 lines
1.7 KiB
Ruby
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
require 'test/test_helper'
|
|
require 'mongo/gridfs'
|
|
|
|
class ChunkTest < Test::Unit::TestCase
|
|
|
|
include Mongo
|
|
include GridFS
|
|
|
|
@@db = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
|
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-utils-test')
|
|
@@files = @@db.collection('gridfs.files')
|
|
@@chunks = @@db.collection('gridfs.chunks')
|
|
|
|
def setup
|
|
@@chunks.remove
|
|
@@files.remove
|
|
|
|
@f = GridStore.new(@@db, 'foobar', 'w')
|
|
@c = @f.instance_variable_get('@curr_chunk')
|
|
end
|
|
|
|
def teardown
|
|
@@chunks.remove
|
|
@@files.remove
|
|
@@db.error
|
|
end
|
|
|
|
def test_pos
|
|
assert_equal 0, @c.pos
|
|
assert @c.eof? # since data is empty
|
|
|
|
b = ByteBuffer.new
|
|
3.times { |i| b.put(i) }
|
|
c = Chunk.new(@f, 'data' => b)
|
|
assert !c.eof?
|
|
end
|
|
|
|
def test_getc
|
|
b = ByteBuffer.new
|
|
3.times { |i| b.put(i) }
|
|
c = Chunk.new(@f, 'data' => b)
|
|
|
|
assert !c.eof?
|
|
assert_equal 0, c.getc
|
|
assert !c.eof?
|
|
assert_equal 1, c.getc
|
|
assert !c.eof?
|
|
assert_equal 2, c.getc
|
|
assert c.eof?
|
|
end
|
|
|
|
def test_putc
|
|
3.times { |i| @c.putc(i) }
|
|
@c.pos = 0
|
|
|
|
assert !@c.eof?
|
|
assert_equal 0, @c.getc
|
|
assert !@c.eof?
|
|
assert_equal 1, @c.getc
|
|
assert !@c.eof?
|
|
assert_equal 2, @c.getc
|
|
assert @c.eof?
|
|
end
|
|
|
|
def test_truncate
|
|
10.times { |i| @c.putc(i) }
|
|
assert_equal 10, @c.size
|
|
@c.pos = 3
|
|
@c.truncate
|
|
assert_equal 3, @c.size
|
|
|
|
@c.pos = 0
|
|
assert !@c.eof?
|
|
assert_equal 0, @c.getc
|
|
assert !@c.eof?
|
|
assert_equal 1, @c.getc
|
|
assert !@c.eof?
|
|
assert_equal 2, @c.getc
|
|
assert @c.eof?
|
|
end
|
|
|
|
end
|