--- t/10-xs.t 2008/08/17 22:54:02 7 +++ t/10-xs.t 2008/08/18 18:53:39 22 @@ -5,7 +5,7 @@ use blib; -use Test::More tests => 9; +use Test::More tests => 27; use Test::Exception; use Data::Dump qw/dump/; @@ -13,18 +13,58 @@ use_ok( 'Search::TokyoDystopia' ); } +my $path = 'casket'; + cmp_ok( $Search::TokyoDystopia::debug, '==', 0, '$debug' ); -cmp_ok( Search::TokyoDystopia::errmsg(0), 'eq', 'success', 'errmsg' ); +cmp_ok( tcidberrmsg(0), 'eq', 'success', 'tcidberrmsg' ); + +ok( my $idb = tcidbnew, 'tcidbnew' ); # FIXME check better + +ok( ! tcidbdel( $idb ), 'tcidbdel' ); + +ok( $idb = tcidbnew, 'tcidbnew again' ); + +is( tcidbecode( $idb ), 0, 'tcidbecode' ); + +ok( tcidbtune( $idb, 0, 0, 0, IDBTLARGE | IDBTDEFLATE ), 'tcidbtune' ); + +ok( tcidbsetcache( $idb, 0, 0 ), 'tcidbsetcache' ); + +ok( tcidbsetfwmmax( $idb, 0 ), 'tcidbsetfwmmax' ); + +ok( tcidbopen( $idb, $path, IDBOWRITER | IDBOCREAT | IDBOTRUNC ), "tcidbopen $path" ); -ok( my $db = Search::TokyoDystopia::new, 'new' ); # FIXME check better +ok( tcidbclose( $idb ), 'tcidbclose' ); -ok( ! Search::TokyoDystopia::del( $db ), 'del' ); +ok( tcidbopen( $idb, $path, IDBOWRITER | IDBOCREAT ), "tcidbopen $path again" ); -ok( $db = Search::TokyoDystopia::new, 'new again' ); +ok( tcidbput( $idb, 1, 'foobar' ), 'tcidbput' ); + +ok( tcidbout( $idb, 1, ), 'tcidbout' ); + +ok( tcidbput( $idb, 42, 'some data' ), 'tcidbput again' ); +is( tcidbget( $idb, 42 ), 'some data', 'tcidbget' ); +ok( ! tcidbget( $idb, 1 ), 'tcidbget non-existing' ); + +is_deeply( tcidbsearch( $idb, 'some', IDBSSUBSTR ), [ 42 ], 'tcidbsearch' ); +ok( tcidbput( $idb, 65536, 'some more data' ), 'tcidbput more data' ); +is_deeply( tcidbsearch( $idb, 'some', IDBSSUBSTR ), [ 42, 65536 ], 'tcidbsearch' ); + +is_deeply( tcidbsearch2( $idb, 'some' ), [ 42, 65536 ], 'tcidbsearch2' ); + +ok( tcidbiterinit( $idb ), 'tcidbiterinit' ); + +my @ids; + +while ( my $id = tcidbiternext( $idb ) ) { + ok( $id, "tcidbiternext $id" ); + push @ids, $id; +} -is( Search::TokyoDystopia::ecode( $db ), 0, 'ecode' ); +# order is not defined, so we need to sort it +is_deeply( [ sort @ids ], [ 42, 65536 ], 'all records' ); -is( Search::TokyoDystopia::tune( $db, 0, 0, 0, 0 ), 1, 'tune' ); +ok( tcidbsync( $idb ), 'tcidbsync' ); -is( Search::TokyoDystopia::setcache( $db, 0, 0 ), 1, 'setcache' ); +diag tcidberrmsg( tcidbecode( $idb ) );