1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! Proves the default error-reporting safety harness: it is on by default, and
//! a user-installed handler replaces it and receives embree's asynchronous
//! errors.
//!
//! The `log`-routed default reporter itself is proven in `default_error_log.rs`
//! (which needs `--features log` and a capturing logger). Here we prove the
//! wiring: the harness defaults on, and `set_error_function` overrides it.
mod common;
use std::sync::{Arc, Mutex};
use embree3::{Config, Error};
#[test]
fn report_errors_is_on_by_default() {
assert!(
Config::default().report_errors,
"the default error reporter must be installed by default"
);
}
#[test]
fn custom_handler_replaces_default_and_receives_errors() {
// The device is created with the default reporter installed (report_errors =
// true). Replacing it must redirect embree's errors to our closure instead of
// stderr/log, so the capture filling proves both that the override works and
// that the error channel is live.
let device = common::device();
let captured: Arc<Mutex<Vec<Error>>> = Arc::new(Mutex::new(Vec::new()));
let sink = captured.clone();
device.set_error_function(move |error, _msg| sink.lock().unwrap().push(error));
common::trigger_embree_error(&device);
let got = captured.lock().unwrap();
assert!(
!got.is_empty(),
"the installed handler must replace the default and receive embree's error"
);
assert_eq!(
got[0],
Error::INVALID_ARGUMENT,
"the out-of-range buffer slot should report INVALID_ARGUMENT"
);
}