Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de2062d
commit 26de92a
Showing
10 changed files
with
360 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use super::*; | ||
|
||
mod with_atom_name; | ||
|
||
#[test] | ||
fn with_local_reference_name_errors_badarg() { | ||
with_name_errors_badarg(|process| Term::local_reference(&process)); | ||
} | ||
|
||
#[test] | ||
fn with_empty_list_right_errors_badarg() { | ||
with_name_errors_badarg(|_| Term::EMPTY_LIST); | ||
} | ||
|
||
#[test] | ||
fn with_list_right_errors_badarg() { | ||
with_name_errors_badarg(|process| { | ||
Term::cons(0.into_process(&process), 1.into_process(&process), &process) | ||
}); | ||
} | ||
|
||
#[test] | ||
fn with_small_integer_right_errors_badarg() { | ||
with_name_errors_badarg(|process| 0.into_process(&process)); | ||
} | ||
|
||
#[test] | ||
fn with_big_integer_right_errors_badarg() { | ||
with_name_errors_badarg(|process| (crate::integer::small::MAX + 1).into_process(&process)); | ||
} | ||
|
||
#[test] | ||
fn with_float_right_errors_badarg() { | ||
with_name_errors_badarg(|process| 0.0.into_process(&process)); | ||
} | ||
|
||
#[test] | ||
fn with_local_pid_right_errors_badarg() { | ||
with_name_errors_badarg(|_| Term::local_pid(0, 1).unwrap()); | ||
} | ||
|
||
#[test] | ||
fn with_external_pid_right_errors_badarg() { | ||
with_name_errors_badarg(|process| Term::external_pid(1, 2, 3, &process).unwrap()); | ||
} | ||
|
||
#[test] | ||
fn with_tuple_right_errors_badarg() { | ||
with_name_errors_badarg(|process| Term::slice_to_tuple(&[], &process)); | ||
} | ||
|
||
#[test] | ||
fn with_map_right_errors_badarg() { | ||
with_name_errors_badarg(|process| Term::slice_to_map(&[], &process)); | ||
} | ||
|
||
#[test] | ||
fn with_heap_binary_right_errors_badarg() { | ||
with_name_errors_badarg(|process| Term::slice_to_binary(&[], &process)); | ||
} | ||
|
||
#[test] | ||
fn with_subbinary_right_errors_badarg() { | ||
with_name_errors_badarg(|process| bitstring!(1 :: 1, &process)); | ||
} | ||
|
||
fn with_name_errors_badarg<N>(name: N) | ||
where | ||
N: FnOnce(&Process) -> Term, | ||
{ | ||
with_process_arc(|process_arc| { | ||
let pid = Term::local_pid(0, 0).unwrap(); | ||
|
||
assert_badarg!(erlang::register_2(name(&process_arc), pid, process_arc)); | ||
}); | ||
} |
31 changes: 31 additions & 0 deletions
31
lumen_runtime/src/otp/erlang/tests/register_2/with_atom_name.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use super::*; | ||
|
||
mod without_registered_name; | ||
|
||
#[test] | ||
fn with_undefined_atom_errors_badarg() { | ||
with_name_errors_badarg(|_| Term::str_to_atom("undefined", DoNotCare).unwrap()) | ||
} | ||
|
||
#[test] | ||
fn with_registered_name_errors_badarg() { | ||
let registered_name = Term::str_to_atom("registered_name", DoNotCare).unwrap(); | ||
let registered_process_arc = process::local::new(); | ||
|
||
assert_eq!( | ||
erlang::register_2( | ||
registered_name, | ||
registered_process_arc.pid, | ||
registered_process_arc | ||
), | ||
Ok(true.into()) | ||
); | ||
|
||
let unregistered_process_arc = process::local::new(); | ||
|
||
assert_badarg!(erlang::register_2( | ||
registered_name, | ||
unregistered_process_arc.pid, | ||
unregistered_process_arc | ||
)); | ||
} |
91 changes: 91 additions & 0 deletions
91
lumen_runtime/src/otp/erlang/tests/register_2/with_atom_name/without_registered_name.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
use super::*; | ||
|
||
use std::sync::atomic::AtomicUsize; | ||
|
||
mod with_local_pid; | ||
|
||
#[test] | ||
fn with_atom_pid_or_process_errors_badarg() { | ||
with_pid_or_port_errors_badarg(|_| Term::str_to_atom("pid_or_port", DoNotCare).unwrap()) | ||
} | ||
|
||
#[test] | ||
fn with_empty_list_pid_or_process_errors_badarg() { | ||
with_pid_or_port_errors_badarg(|_| Term::EMPTY_LIST); | ||
} | ||
|
||
#[test] | ||
fn with_list_pid_or_process_errors_badarg() { | ||
with_pid_or_port_errors_badarg(|process| { | ||
Term::cons(0.into_process(&process), 1.into_process(&process), &process) | ||
}); | ||
} | ||
|
||
#[test] | ||
fn with_small_integer_pid_or_process_errors_badarg() { | ||
with_pid_or_port_errors_badarg(|process| 0.into_process(&process)); | ||
} | ||
|
||
#[test] | ||
fn with_big_integer_pid_or_process_errors_badarg() { | ||
with_pid_or_port_errors_badarg(|process| { | ||
(crate::integer::small::MAX + 1).into_process(&process) | ||
}); | ||
} | ||
|
||
#[test] | ||
fn with_float_pid_or_process_errors_badarg() { | ||
with_pid_or_port_errors_badarg(|process| 0.0.into_process(&process)); | ||
} | ||
|
||
#[test] | ||
fn with_external_pid_pid_or_process_errors_badarg() { | ||
with_pid_or_port_errors_badarg(|process| Term::external_pid(1, 2, 3, &process).unwrap()); | ||
} | ||
|
||
#[test] | ||
fn with_tuple_pid_or_process_errors_badarg() { | ||
with_pid_or_port_errors_badarg(|process| Term::slice_to_tuple(&[], &process)); | ||
} | ||
|
||
#[test] | ||
fn with_map_pid_or_process_errors_badarg() { | ||
with_pid_or_port_errors_badarg(|process| Term::slice_to_map(&[], &process)); | ||
} | ||
|
||
#[test] | ||
fn with_heap_binary_pid_or_process_errors_badarg() { | ||
with_pid_or_port_errors_badarg(|process| Term::slice_to_binary(&[], &process)); | ||
} | ||
|
||
#[test] | ||
fn with_subbinary_pid_or_process_errors_badarg() { | ||
with_pid_or_port_errors_badarg(|process| bitstring!(1 :: 1, &process)); | ||
} | ||
|
||
static REGISTERED_NAME_COUNTER: AtomicUsize = AtomicUsize::new(0); | ||
|
||
fn registered_name() -> Term { | ||
Term::str_to_atom( | ||
format!( | ||
"registered{}", | ||
REGISTERED_NAME_COUNTER.fetch_add(1, std::sync::atomic::Ordering::SeqCst) | ||
) | ||
.as_ref(), | ||
DoNotCare, | ||
) | ||
.unwrap() | ||
} | ||
|
||
fn with_pid_or_port_errors_badarg<P>(pid_or_port: P) | ||
where | ||
P: FnOnce(&Process) -> Term, | ||
{ | ||
with_process_arc(|process_arc| { | ||
assert_badarg!(erlang::register_2( | ||
registered_name(), | ||
pid_or_port(&process_arc), | ||
process_arc | ||
)); | ||
}) | ||
} |
63 changes: 63 additions & 0 deletions
63
.../src/otp/erlang/tests/register_2/with_atom_name/without_registered_name/with_local_pid.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use super::*; | ||
|
||
use crate::registry::Registered; | ||
|
||
#[test] | ||
fn without_process() { | ||
with_process_arc(|process_arc| { | ||
let pid_or_port = process::identifier::local::next(); | ||
|
||
assert_badarg!(erlang::register_2( | ||
registered_name(), | ||
pid_or_port, | ||
process_arc | ||
)); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn with_same_process() { | ||
with_process_arc(|process_arc| { | ||
let name = registered_name(); | ||
let pid_or_port = process_arc.pid; | ||
|
||
assert_eq!( | ||
erlang::register_2(name, pid_or_port, process_arc.clone()), | ||
Ok(true.into()) | ||
); | ||
assert_eq!(*process_arc.registered_name.lock().unwrap(), Some(name)); | ||
assert_eq!( | ||
registry::RW_LOCK_REGISTERED_BY_NAME | ||
.read() | ||
.unwrap() | ||
.get(&name), | ||
Some(&Registered::Process(process_arc)) | ||
); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn with_different_process() { | ||
with_process_arc(|process_arc| { | ||
let name = registered_name(); | ||
|
||
let another_process_arc = process::local::new(); | ||
let pid_or_port = another_process_arc.pid; | ||
|
||
assert_eq!( | ||
erlang::register_2(name, pid_or_port, process_arc), | ||
Ok(true.into()) | ||
); | ||
assert_eq!( | ||
*another_process_arc.registered_name.lock().unwrap(), | ||
Some(name) | ||
); | ||
assert_eq!( | ||
registry::RW_LOCK_REGISTERED_BY_NAME | ||
.read() | ||
.unwrap() | ||
.get(&name), | ||
Some(&Registered::Process(another_process_arc)) | ||
); | ||
}); | ||
} |
Oops, something went wrong.