update tests and bump version
This commit is contained in:
parent
c5e7eb6c73
commit
6d5a78fd98
|
@ -2,7 +2,7 @@ BDB_SPEC = Gem::Specification.new do |s|
|
||||||
s.platform = Gem::Platform::RUBY
|
s.platform = Gem::Platform::RUBY
|
||||||
s.required_ruby_version = '>=1.8.4'
|
s.required_ruby_version = '>=1.8.4'
|
||||||
s.name = "bdb"
|
s.name = "bdb"
|
||||||
s.version = "0.0.1"
|
s.version = "0.0.2"
|
||||||
s.authors = ["Matt Bauer", "Dan Janowski"]
|
s.authors = ["Matt Bauer", "Dan Janowski"]
|
||||||
s.email = "bauer@pedalbrain.com"
|
s.email = "bauer@pedalbrain.com"
|
||||||
s.summary = "A Ruby interface to BerkeleyDB"
|
s.summary = "A Ruby interface to BerkeleyDB"
|
||||||
|
|
10
ext/bdb.c
10
ext/bdb.c
|
@ -1259,14 +1259,14 @@ int bt_compare_callback(DB *db, const DBT* key1, const DBT* key2)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* db.set_bt_compare(proc)
|
* db.btree_compare = proc
|
||||||
*
|
*
|
||||||
* set the btree key comparison function to the callback proc.
|
* set the btree key comparison function to the callback proc.
|
||||||
*
|
*
|
||||||
* callback proc has signature:
|
* callback proc has signature:
|
||||||
* proc(db,key1,key2)
|
* proc(db,key1,key2)
|
||||||
*/
|
*/
|
||||||
VALUE db_set_bt_compare(VALUE obj, VALUE cb_proc)
|
VALUE db_btree_compare_set(VALUE obj, VALUE cb_proc)
|
||||||
{
|
{
|
||||||
t_dbh *dbh;
|
t_dbh *dbh;
|
||||||
int rv;
|
int rv;
|
||||||
|
@ -1283,10 +1283,10 @@ VALUE db_set_bt_compare(VALUE obj, VALUE cb_proc)
|
||||||
rv=dbh->db->set_bt_compare(dbh->db,bt_compare_callback);
|
rv=dbh->db->set_bt_compare(dbh->db,bt_compare_callback);
|
||||||
|
|
||||||
#ifdef DEBUG_DB
|
#ifdef DEBUG_DB
|
||||||
fprintf(stderr,"set_bt_compare done 0x%x\n",dbh);
|
fprintf(stderr,"btree_compare set 0x%x\n",dbh);
|
||||||
#endif
|
#endif
|
||||||
if (rv != 0) {
|
if (rv != 0) {
|
||||||
raise_error(rv, "db_set_bt_compare failure: %s",db_strerror(rv));
|
raise_error(rv, "db_btree_compare_set failure: %s",db_strerror(rv));
|
||||||
}
|
}
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
}
|
}
|
||||||
|
@ -2874,7 +2874,7 @@ void Init_bdb() {
|
||||||
rb_define_method(cDb,"del",db_del,3);
|
rb_define_method(cDb,"del",db_del,3);
|
||||||
rb_define_method(cDb,"cursor",db_cursor,2);
|
rb_define_method(cDb,"cursor",db_cursor,2);
|
||||||
rb_define_method(cDb,"associate",db_associate,4);
|
rb_define_method(cDb,"associate",db_associate,4);
|
||||||
rb_define_method(cDb,"set_btree_compare",db_set_bt_compare,1);
|
rb_define_method(cDb,"btree_compare=",db_btree_compare_set,1);
|
||||||
rb_define_method(cDb,"flags=",db_flags_set,1);
|
rb_define_method(cDb,"flags=",db_flags_set,1);
|
||||||
rb_define_method(cDb,"flags",db_flags_get,0);
|
rb_define_method(cDb,"flags",db_flags_get,0);
|
||||||
rb_define_method(cDb,"open",db_open,6);
|
rb_define_method(cDb,"open",db_open,6);
|
||||||
|
|
|
@ -22,6 +22,17 @@ class CursorTest < Test::Unit::TestCase
|
||||||
assert_equal 'data-0', value
|
assert_equal 'data-0', value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_get_range
|
||||||
|
keys = []
|
||||||
|
key, value = @cursor.get("4", nil, Bdb::DB_SET_RANGE)
|
||||||
|
while key and key <= "9"
|
||||||
|
keys << key
|
||||||
|
key, value = @cursor.get(nil, nil, Bdb::DB_NEXT)
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal (4..9).collect {|i| i.to_s}, keys
|
||||||
|
end
|
||||||
|
|
||||||
def test_pget
|
def test_pget
|
||||||
@db1 = Bdb::Db.new
|
@db1 = Bdb::Db.new
|
||||||
@db1.flags = Bdb::DB_DUPSORT
|
@db1.flags = Bdb::DB_DUPSORT
|
||||||
|
@ -71,9 +82,9 @@ class CursorTest < Test::Unit::TestCase
|
||||||
assert_equal (0..9).collect {|i| i.to_s}, all
|
assert_equal (0..9).collect {|i| i.to_s}, all
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_get_all_with_set_btree_compare
|
def test_get_all_with_btree_compare
|
||||||
@db1 = Bdb::Db.new
|
@db1 = Bdb::Db.new
|
||||||
@db1.set_btree_compare(proc {|db, key1, key2| key2 <=> key1})
|
@db1.btree_compare = proc {|db, key1, key2| key2 <=> key1}
|
||||||
@db1.open(nil, File.join(File.dirname(__FILE__), 'tmp', 'test1.db'), nil, Bdb::Db::BTREE, Bdb::DB_CREATE, 0)
|
@db1.open(nil, File.join(File.dirname(__FILE__), 'tmp', 'test1.db'), nil, Bdb::Db::BTREE, Bdb::DB_CREATE, 0)
|
||||||
10.times { |i| @db1.put(nil, i.to_s, "data-#{i}", 0)}
|
10.times { |i| @db1.put(nil, i.to_s, "data-#{i}", 0)}
|
||||||
@cursor1 = @db1.cursor(nil, 0)
|
@cursor1 = @db1.cursor(nil, 0)
|
||||||
|
@ -89,7 +100,7 @@ class CursorTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_btree_compare_raises_if_fixnum_not_returned
|
def test_btree_compare_raises_if_fixnum_not_returned
|
||||||
@db1 = Bdb::Db.new
|
@db1 = Bdb::Db.new
|
||||||
@db1.set_btree_compare(proc {|db, key1, key2| key1})
|
@db1.btree_compare = proc {|db, key1, key2| key1}
|
||||||
@db1.open(nil, File.join(File.dirname(__FILE__), 'tmp', 'test1.db'), nil, Bdb::Db::BTREE, Bdb::DB_CREATE, 0)
|
@db1.open(nil, File.join(File.dirname(__FILE__), 'tmp', 'test1.db'), nil, Bdb::Db::BTREE, Bdb::DB_CREATE, 0)
|
||||||
|
|
||||||
assert_raises(TypeError) do
|
assert_raises(TypeError) do
|
||||||
|
|
Loading…
Reference in a new issue