diff options
Diffstat (limited to 'third_party/rust/lmdb-rkv-sys/tests')
-rw-r--r-- | third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb-32/data.mdb | bin | 0 -> 24576 bytes | |||
-rw-r--r-- | third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb-32/lock.mdb | bin | 0 -> 8192 bytes | |||
-rw-r--r-- | third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb/data.mdb | bin | 0 -> 57344 bytes | |||
-rw-r--r-- | third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb/lock.mdb | bin | 0 -> 8192 bytes | |||
-rw-r--r-- | third_party/rust/lmdb-rkv-sys/tests/lmdb.rs | 28 | ||||
-rw-r--r-- | third_party/rust/lmdb-rkv-sys/tests/simple.rs | 93 |
6 files changed, 121 insertions, 0 deletions
diff --git a/third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb-32/data.mdb b/third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb-32/data.mdb Binary files differnew file mode 100644 index 0000000000..c1a0bff0f4 --- /dev/null +++ b/third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb-32/data.mdb diff --git a/third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb-32/lock.mdb b/third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb-32/lock.mdb Binary files differnew file mode 100644 index 0000000000..7219256523 --- /dev/null +++ b/third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb-32/lock.mdb diff --git a/third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb/data.mdb b/third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb/data.mdb Binary files differnew file mode 100644 index 0000000000..63d0fc8faa --- /dev/null +++ b/third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb/data.mdb diff --git a/third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb/lock.mdb b/third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb/lock.mdb Binary files differnew file mode 100644 index 0000000000..9df0ae2cf2 --- /dev/null +++ b/third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb/lock.mdb diff --git a/third_party/rust/lmdb-rkv-sys/tests/lmdb.rs b/third_party/rust/lmdb-rkv-sys/tests/lmdb.rs new file mode 100644 index 0000000000..2acb97d81b --- /dev/null +++ b/third_party/rust/lmdb-rkv-sys/tests/lmdb.rs @@ -0,0 +1,28 @@ +extern crate lmdb_sys; + +use std::env; +use std::path::PathBuf; +use std::process::Command; + +#[test] +fn test_lmdb() { + let mut lmdb = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap()); + lmdb.push("lmdb"); + lmdb.push("libraries"); + lmdb.push("liblmdb"); + + let make_cmd = Command::new("make") + .current_dir(&lmdb) + .status() + .expect("failed to execute process"); + + assert_eq!(make_cmd.success(), true); + + let make_test_cmd = Command::new("make") + .arg("test") + .current_dir(&lmdb) + .status() + .expect("failed to execute process"); + + assert_eq!(make_test_cmd.success(), true); +} diff --git a/third_party/rust/lmdb-rkv-sys/tests/simple.rs b/third_party/rust/lmdb-rkv-sys/tests/simple.rs new file mode 100644 index 0000000000..f15cc84c2d --- /dev/null +++ b/third_party/rust/lmdb-rkv-sys/tests/simple.rs @@ -0,0 +1,93 @@ +extern crate lmdb_sys; + +use lmdb_sys::*; + +use std::ffi::{c_void, CString}; +use std::fs::File; +use std::ptr; + +// https://github.com/victorporof/lmdb/blob/mdb.master/libraries/liblmdb/moz-test.c + +macro_rules! E { + ($expr:expr) => {{ + match $expr { + ::MDB_SUCCESS => (), + err_code => assert!(false, "Failed with code {}", err_code), + } + }}; +} + +macro_rules! str { + ($expr:expr) => { + ::CString::new($expr).unwrap().as_ptr() + }; +} + +#[test] +#[cfg(target_pointer_width = "32")] +fn test_simple_32() { + test_simple("./tests/fixtures/testdb-32") +} + +#[test] +#[cfg(target_pointer_width = "64")] +fn test_simple_64() { + test_simple("./tests/fixtures/testdb") +} + +#[cfg(windows)] +fn get_file_fd(file: &File) -> std::os::windows::io::RawHandle { + use std::os::windows::io::AsRawHandle; + file.as_raw_handle() +} + +#[cfg(unix)] +fn get_file_fd(file: &File) -> std::os::unix::io::RawFd { + use std::os::unix::io::AsRawFd; + file.as_raw_fd() +} + +fn test_simple(env_path: &str) { + let mut env: *mut MDB_env = ptr::null_mut(); + let mut dbi: MDB_dbi = 0; + let mut key = MDB_val { + mv_size: 0, + mv_data: ptr::null_mut(), + }; + let mut data = MDB_val { + mv_size: 0, + mv_data: ptr::null_mut(), + }; + let mut txn: *mut MDB_txn = ptr::null_mut(); + let sval = str!("foo") as *mut c_void; + let dval = str!("bar") as *mut c_void; + + unsafe { + E!(mdb_env_create(&mut env)); + E!(mdb_env_set_maxdbs(env, 2)); + E!(mdb_env_open(env, str!(env_path), 0, 0664)); + + E!(mdb_txn_begin(env, ptr::null_mut(), 0, &mut txn)); + E!(mdb_dbi_open(txn, str!("subdb"), MDB_CREATE, &mut dbi)); + E!(mdb_txn_commit(txn)); + + key.mv_size = 3; + key.mv_data = sval; + data.mv_size = 3; + data.mv_data = dval; + + E!(mdb_txn_begin(env, ptr::null_mut(), 0, &mut txn)); + E!(mdb_put(txn, dbi, &mut key, &mut data, 0)); + E!(mdb_txn_commit(txn)); + } + + let file = File::create("./tests/fixtures/copytestdb.mdb").unwrap(); + + unsafe { + let fd = get_file_fd(&file); + E!(mdb_env_copyfd(env, fd)); + + mdb_dbi_close(env, dbi); + mdb_env_close(env); + } +} |