Merge pull request #22 from jonas-schievink/droptest
Add a test ensuring that userdata is dropped
This commit is contained in:
commit
d5ec09614c
32
src/tests.rs
32
src/tests.rs
|
@ -833,14 +833,36 @@ fn test_expired_userdata() {
|
|||
hatch = self.userdata
|
||||
end })
|
||||
|
||||
print("userdata = ", userdata)
|
||||
print("hatch = ", hatch)
|
||||
print "collecting..."
|
||||
tbl = nil
|
||||
userdata = nil -- make table and userdata collectable
|
||||
collectgarbage("collect")
|
||||
print("userdata = ", userdata)
|
||||
print("hatch = ", hatch)
|
||||
hatch:access()
|
||||
"#, None).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn detroys_userdata() {
|
||||
use std::sync::atomic::{Ordering, AtomicBool, ATOMIC_BOOL_INIT};
|
||||
|
||||
static DROPPED: AtomicBool = ATOMIC_BOOL_INIT;
|
||||
|
||||
struct Userdata;
|
||||
|
||||
impl LuaUserDataType for Userdata {}
|
||||
|
||||
impl Drop for Userdata {
|
||||
fn drop(&mut self) {
|
||||
DROPPED.store(true, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
let lua = Lua::new();
|
||||
{
|
||||
let globals = lua.globals();
|
||||
globals.set("userdata", Userdata).unwrap();
|
||||
}
|
||||
|
||||
assert_eq!(DROPPED.load(Ordering::SeqCst), false);
|
||||
drop(lua); // should destroy all objects
|
||||
assert_eq!(DROPPED.load(Ordering::SeqCst), true);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue