proc env003 { } {
global env
source ./include.tcl
puts "Env003: DB_TMP_DIR test."
puts "\tEnv003: Running with -home argument to berkdb_env."
env003_body "-home $testdir"
puts "\tEnv003: Running with environment variable DB_HOME set."
set env(DB_HOME) $testdir
env003_body "-use_environ"
unset env(DB_HOME)
puts "\tEnv003: Running with both DB_HOME and -home set."
set env(DB_HOME) $testdir/bogus_home
env003_body "-use_environ -home $testdir"
unset env(DB_HOME)
}
proc env003_body { home_arg } {
source ./include.tcl
env_cleanup $testdir
set tmpdir "tmpfiles_in_here"
file mkdir $testdir/$tmpdir
set curdir [pwd]
cd $testdir/$tmpdir
set fulltmpdir [pwd]
cd $curdir
env003_make_config $tmpdir
env003_run_test a 1 "relative path, config file" $home_arg \
$testdir/$tmpdir
env003_make_config $fulltmpdir
env003_run_test a 2 "absolute path, config file" $home_arg \
$fulltmpdir
env003_run_test b 1 "relative path, db_config" "$home_arg \
-tmp_dir $tmpdir -data_dir ." \
$testdir/$tmpdir
env003_run_test b 2 "absolute path, db_config" "$home_arg \
-tmp_dir $fulltmpdir -data_dir ." \
$fulltmpdir
file mkdir $testdir/bogus
env003_make_config $tmpdir
env003_run_test c 1 "relative path, both db_config and file" \
"$home_arg -tmp_dir $testdir/bogus -data_dir ." \
$testdir/$tmpdir
file mkdir $fulltmpdir/bogus
env003_make_config $fulltmpdir
env003_run_test c 2 "absolute path, both db_config and file" \
"$home_arg -tmp_dir $fulltmpdir/bogus -data_dir ." \
$fulltmpdir
}
proc env003_run_test { major minor msg env_args tmp_path} {
global testdir
global alphabet
global errorCode
puts "\t\tEnv003.$major.$minor: $msg"
set dbenv [eval {berkdb_env -create -home $testdir} $env_args \
{-cachesize {0 50000 1}}]
error_check_good env_open [is_valid_env $dbenv] TRUE
set db [berkdb_open -env $dbenv -create -btree]
error_check_good db_open [is_valid_db $db] TRUE
set key "key"
set data [repeat $alphabet 2000]
error_check_good db_put [$db put $key $data] 0
set ret [glob -nocomplain $tmp_path/BDB*]
error_check_good temp_file_exists [llength $ret] 1
error_check_good db_close [$db close] 0
fileremove -f $ret
error_check_good env_close [$dbenv close] 0
}
proc env003_make_config { tmpdir } {
global testdir
set cid [open $testdir/DB_CONFIG w]
puts $cid "set_data_dir ."
puts $cid "set_tmp_dir $tmpdir"
close $cid
}