diff --git a/src/tests/test_db_env_open_nocreate.c b/src/tests/test_db_env_open_nocreate.c new file mode 100644 index 00000000000..08f05ee9a19 --- /dev/null +++ b/src/tests/test_db_env_open_nocreate.c @@ -0,0 +1,36 @@ +// Try to open an environment where the directory does not exist +// Try when the dir exists but is not an initialized env + +#include +#include +#include +#include +#include +#include +#include + +// DIR is defined in the Makefile +#define CKERR(r) if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, db_strerror(r)); assert(r==0); + +int main() { + DB_ENV *dbenv; + int r; + + system("rm -rf " DIR); + + r = db_env_create(&dbenv, 0); + assert(r == 0); + r = dbenv->open(dbenv, DIR, DB_PRIVATE|DB_INIT_MPOOL, 0); + assert(r==ENOENT); + dbenv->close(dbenv,0); // free memory + + system("rm -rf " DIR); + mkdir(DIR, 0777); + r = db_env_create(&dbenv, 0); + assert(r == 0); + r = dbenv->open(dbenv, DIR, DB_PRIVATE|DB_INIT_MPOOL, 0); + assert(r==ENOENT); + dbenv->close(dbenv,0); // free memory + + return 0; +} diff --git a/src/tests/test_db_env_set_data_dir.c b/src/tests/test_db_env_set_data_dir.c index c80dbe3eb7b..c69b8182757 100644 --- a/src/tests/test_db_env_set_data_dir.c +++ b/src/tests/test_db_env_set_data_dir.c @@ -2,6 +2,8 @@ #include #include +// DIR is defined in the Makefile + int main() { DB_ENV *dbenv; int r; @@ -9,16 +11,16 @@ int main() { r = db_env_create(&dbenv, 0); assert(r == 0); - r = dbenv->set_data_dir(dbenv, "."); + r = dbenv->set_data_dir(dbenv, DIR); assert(r == 0); - r = dbenv->set_data_dir(dbenv, "."); + r = dbenv->set_data_dir(dbenv, DIR); assert(r == 0); - r = dbenv->open(dbenv, ".", DB_PRIVATE+DB_INIT_MPOOL, 0); + r = dbenv->open(dbenv, DIR, DB_PRIVATE+DB_INIT_MPOOL, 0); assert(r == 0); - r = dbenv->set_data_dir(dbenv, "."); + r = dbenv->set_data_dir(dbenv, DIR); assert(r != 0); r = dbenv->close(dbenv, 0); diff --git a/src/tests/test_db_env_set_errpfx.c b/src/tests/test_db_env_set_errpfx.c index d928f940ee3..ff2369b180a 100644 --- a/src/tests/test_db_env_set_errpfx.c +++ b/src/tests/test_db_env_set_errpfx.c @@ -2,6 +2,8 @@ #include #include +// DIR is defined in the Makefile + int main() { DB_ENV *dbenv; int r; @@ -11,7 +13,7 @@ int main() { dbenv->set_errpfx(dbenv, "houdy partners: "); - r = dbenv->open(dbenv, ".", DB_PRIVATE+DB_INIT_MPOOL, 0); + r = dbenv->open(dbenv, DIR, DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL, 0); assert(r == 0); r = dbenv->close(dbenv, 0);