From b3fe3714052d3b90913471aef40b4149f38887e4 Mon Sep 17 00:00:00 2001 From: Victor Porof Date: Tue, 10 Sep 2019 10:00:12 +0200 Subject: [PATCH] Add test program from https://gist.github.com/mykmelez/ac75a7ab0a0d09a7d709be63806d01d7 Signed-off-by: Victor Porof --- lmdb-sys/tests/fixtures/testdb/data.mdb | Bin 0 -> 57344 bytes lmdb-sys/tests/fixtures/testdb/lock.mdb | Bin 0 -> 8192 bytes lmdb-sys/tests/simple.rs | 62 ++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 lmdb-sys/tests/fixtures/testdb/data.mdb create mode 100644 lmdb-sys/tests/fixtures/testdb/lock.mdb create mode 100644 lmdb-sys/tests/simple.rs diff --git a/lmdb-sys/tests/fixtures/testdb/data.mdb b/lmdb-sys/tests/fixtures/testdb/data.mdb new file mode 100644 index 0000000000000000000000000000000000000000..63d0fc8faa1d3c9bd4dceb318124d6c79a7fa8df GIT binary patch literal 57344 zcmeI5JFFE&7{`apxp1C$i6K-JQ&3P?%wr$39f=ke6ck30*xd7qg$c$-LU9X93kwU2 zTToC~P*_q}5MyCMVF(3P^yJs^z0r&CfoYHc36KB@kN^pg z011!)2|Nn{g@d-lw)o_;>3kZSz+d$u zr>$8`rB{(gq^sxBLPgnaYZmYqDpK9)gI&y|msTomGj8%WEv1FZtUGUZs$i>RnYJd| z@U^?Jg-YYvTv*$dxwKHJV{DObiFCE;PS-7^g-RX4%pqOK!H>@RfI4F#=eoyo%EP|Oq{e_(Ft~+MoP=6ijZ+G1>3k6#x z3){`X%&hb(R6B>z|L#ZhpB9gjC&{DaVe-`J&K)E`0wh2JBtQZrKmsH{0wh2JBtQa3 zfPjzZZLj>S;(NW?=dkv1!=<>;}3e@o;W|8 z9}8(*-o7~ad3&#SsrS{%TfHw%$iaoJkmd&`U$3&XfxirSHi!{ISz30+uoU8xUPXJD zr-{!glS?n#9>QvDwN0g$Rqe*XU*&eCm)?+YV~d!S@^Pv5P*dZBS|VM@WGaF~3J$5v z+ud!_)j52HY~CGvRP%-OGA66|nW$j_KwQV{>-ez(`II*$S_~Ty2 zwO5FyEb^sPkdBC}s&Xp5G~$n4aaD!#@f12WI4`}djqqU(zL42a7>&QE2nx~>eF%rSM$uMa>52aXhr`@2j+(7O|Cd)@bl(FG zWn1DLhVl(J?{E&866YF}=iTR~!FAdzkLXh}CHh^U9M`|Li*@6JL%L8N(Whk4ujZB8 z_6u;6ZUMefZrX2#jcpDepnStkc5MqEz#zvxqcd+A_(Hjgu(c>RC@W%Y;RE`dvzW55 z-~eTL`;D{7n*j$Xi?|2)XUW*-Nwd1Y;@Q)7-`@I@m_|u!}YWl$sb@JZtP)nMRz)8rMCqG@^f6mw4ua z(ui>d{+ZJ&Ro&Mp?Z6kZWyG_b%V3MX`iN&a?NG*$brI#}pP?Y@y3dQlv~dpiObZSf zIKmv>Bd(L$w?iPi;X1i)Ky&=R;6efnO|Mh(RTjGqko?K7v zCpVKv>)pNza3KK_AOR8}0TLhq5+DH*AOR8}0TOs70;g6-^+i~}Tc;8R<&5jkvbGEF z#S8QG4eRf#xAyto`)ZM^RbO1LKL`8pe!URv3;q7#c%Q-xfN%f5CLSk`Iro2EB3zLG36KB@kN^pg011!)36KB@kibzUP__I+`#+2$;QRlM za+%V15+DH*AOR8}0TLhq5+DH*AORAn2>AE^RlgB9`2N2z-hlo8tSKZw0wh2JBtQZr zKmsH{0wh2JB=9m3IN1LmejmX8|CgzZnHLfu0TLhq5+DH*AOR8}0TLjASCxS8|F7o! zJJ|mp<^}Zq|EI-1X8+&k{Qs|NC1JivfCNZ@1W14cNPq-LfCNZ@1pYGuVIIIRZ(o=P cFwEz7rT)udKEE(tzimE0xw7wz*!Kne4bDZz?*IS* literal 0 HcmV?d00001 diff --git a/lmdb-sys/tests/fixtures/testdb/lock.mdb b/lmdb-sys/tests/fixtures/testdb/lock.mdb new file mode 100644 index 0000000000000000000000000000000000000000..9df0ae2cf29d7e17dd70f3db77c491a0b67c96ab GIT binary patch literal 8192 zcmeIuu?d4v6a~=#S8xRf2$oiY+NPH*V6UJPxrSIdMpnoO2?0$Z7#!f-=J77v<~*0z z977DZdtG)_)^|lZG;JP^c^r%F|L(>=yOY_kes9@}Wm=QCKP~|R1PBlyK!5-N0t5&U aAV7cs0RjXF5FkK+009C72oNA}N#Fy??H3&Y literal 0 HcmV?d00001 diff --git a/lmdb-sys/tests/simple.rs b/lmdb-sys/tests/simple.rs new file mode 100644 index 0000000..ba774ba --- /dev/null +++ b/lmdb-sys/tests/simple.rs @@ -0,0 +1,62 @@ +extern crate lmdb_rkv_sys; + +use lmdb_rkv_sys::*; + +use std::ffi::{c_void, CString}; +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] +fn test_simple() { + 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!("./tests/fixtures/testdb"), 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)); + + mdb_dbi_close(env, dbi); + mdb_env_close(env); + } +}