• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! This file contains unit tests for `rusqlite::trace::config_log`. This
2 //! function affects SQLite process-wide and so is not safe to run as a normal
3 //! #[test] in the library.
4 
5 #[cfg(feature = "trace")]
main()6 fn main() {
7     use lazy_static::lazy_static;
8     use std::os::raw::c_int;
9     use std::sync::Mutex;
10 
11     lazy_static! {
12         static ref LOGS_RECEIVED: Mutex<Vec<(c_int, String)>> = Mutex::new(Vec::new());
13     }
14 
15     fn log_handler(err: c_int, message: &str) {
16         let mut logs_received = LOGS_RECEIVED.lock().unwrap();
17         logs_received.push((err, message.to_owned()));
18     }
19 
20     use rusqlite::trace;
21 
22     unsafe { trace::config_log(Some(log_handler)) }.unwrap();
23     trace::log(10, "First message from rusqlite");
24     unsafe { trace::config_log(None) }.unwrap();
25     trace::log(11, "Second message from rusqlite");
26 
27     let logs_received = LOGS_RECEIVED.lock().unwrap();
28     assert_eq!(logs_received.len(), 1);
29     assert_eq!(logs_received[0].0, 10);
30     assert_eq!(logs_received[0].1, "First message from rusqlite");
31 }
32 
33 #[cfg(not(feature = "trace"))]
main()34 fn main() {}
35