Wrap dc_context_t and TempDir in a struct

This commit is contained in:
Lars-Magnus Skog
2019-05-13 11:45:55 +02:00
parent e3e56d9f7e
commit 3813a219e0

View File

@@ -6,7 +6,7 @@ use mmime::mailimf_types::*;
use mmime::mailmime_content::*; use mmime::mailmime_content::*;
use mmime::mailmime_types::*; use mmime::mailmime_types::*;
use mmime::other::*; use mmime::other::*;
use tempfile::tempdir; use tempfile::{tempdir, TempDir};
use deltachat::constants::*; use deltachat::constants::*;
use deltachat::dc_array::*; use deltachat::dc_array::*;
@@ -4476,7 +4476,13 @@ unsafe extern "C" fn cb(
0 0
} }
unsafe fn create_context() -> dc_context_t { #[allow(dead_code)]
struct TestContext {
ctx: dc_context_t,
dir: TempDir,
}
unsafe fn create_test_context() -> TestContext {
let mut ctx = dc_context_new(cb, std::ptr::null_mut(), std::ptr::null_mut()); let mut ctx = dc_context_new(cb, std::ptr::null_mut(), std::ptr::null_mut());
let dir = tempdir().unwrap(); let dir = tempdir().unwrap();
let dbfile = CString::new(dir.path().join("db.sqlite").to_str().unwrap()).unwrap(); let dbfile = CString::new(dir.path().join("db.sqlite").to_str().unwrap()).unwrap();
@@ -4489,13 +4495,13 @@ unsafe fn create_context() -> dc_context_t {
.unwrap() .unwrap()
); );
ctx TestContext { ctx: ctx, dir: dir }
} }
#[test] #[test]
fn run_stress_tests() { fn run_stress_tests() {
unsafe { unsafe {
let ctx = create_context(); let context = create_test_context();
stress_functions(&ctx); stress_functions(&context.ctx);
} }
} }