mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 21:36:29 +03:00
wip try test that we see INFO events from the core
This commit is contained in:
@@ -20,6 +20,7 @@ def py_dc_callback(ctx, evt, data1, data2):
|
||||
CFFI only allows us to set one global event handler, so this one
|
||||
looks up the correct event handler for the given context.
|
||||
"""
|
||||
print("py_dc_callback", evt, data1, data2, ctx)
|
||||
try:
|
||||
callback = _DC_CALLBACK_MAP.get(ctx, lambda *a: 0)
|
||||
except AttributeError:
|
||||
@@ -54,6 +55,7 @@ def py_dc_callback(ctx, evt, data1, data2):
|
||||
|
||||
|
||||
def set_context_callback(dc_context, func):
|
||||
print("set_context_callback", dc_context, func)
|
||||
_DC_CALLBACK_MAP[dc_context] = func
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,26 @@
|
||||
from __future__ import print_function
|
||||
import pytest
|
||||
from deltachat import capi, Account, const
|
||||
from deltachat import capi, Account, const, set_context_callback
|
||||
from deltachat.cutil import as_dc_charpointer
|
||||
from queue import Queue
|
||||
|
||||
|
||||
def test_empty_context():
|
||||
ctx = capi.lib.dc_context_new(capi.ffi.NULL, capi.ffi.NULL, capi.ffi.NULL)
|
||||
capi.lib.dc_close(ctx)
|
||||
|
||||
def test_set_context():
|
||||
ctx = capi.lib.dc_context_new(capi.ffi.NULL, capi.ffi.NULL, capi.ffi.NULL)
|
||||
|
||||
q = Queue()
|
||||
set_context_callback(ctx, lambda *args: q.put(args))
|
||||
|
||||
name = as_dc_charpointer("ein")
|
||||
email = as_dc_charpointer("ein@kontakt.org")
|
||||
contact_id = capi.lib.dc_create_contact(ctx, name, email)
|
||||
capi.lib.dc_close(ctx)
|
||||
q.get(timeout=10)
|
||||
|
||||
|
||||
def test_wrong_db(tmpdir):
|
||||
tmpdir.join("hello.db").write("123")
|
||||
|
||||
@@ -70,6 +70,7 @@ impl Context {
|
||||
}
|
||||
|
||||
pub fn call_cb(&self, event: Event, data1: uintptr_t, data2: uintptr_t) -> uintptr_t {
|
||||
println!("call_cb: called");
|
||||
if let Some(cb) = self.cb {
|
||||
unsafe { cb(self, event, data1, data2) }
|
||||
} else {
|
||||
@@ -135,7 +136,7 @@ pub fn dc_context_new(
|
||||
userdata: *mut libc::c_void,
|
||||
os_name: *const libc::c_char,
|
||||
) -> Context {
|
||||
Context {
|
||||
let context = Context {
|
||||
blobdir: Arc::new(RwLock::new(std::ptr::null_mut())),
|
||||
dbfile: Arc::new(RwLock::new(std::ptr::null_mut())),
|
||||
inbox: Arc::new(RwLock::new({
|
||||
@@ -179,7 +180,12 @@ pub fn dc_context_new(
|
||||
))),
|
||||
probe_imap_network: Arc::new(RwLock::new(0)),
|
||||
perform_inbox_jobs_needed: Arc::new(RwLock::new(0)),
|
||||
}
|
||||
};
|
||||
println!("context created");
|
||||
info!(context, 0, "context created");
|
||||
context
|
||||
|
||||
|
||||
}
|
||||
|
||||
unsafe fn cb_receive_imf(
|
||||
@@ -284,13 +290,21 @@ pub unsafe fn dc_context_unref(context: &mut Context) {
|
||||
}
|
||||
|
||||
pub unsafe fn dc_close(context: &Context) {
|
||||
println!("disconnecting inbox watch yooaa");
|
||||
info!(
|
||||
context,
|
||||
0,
|
||||
"disconnecting INBOX-watch",
|
||||
);
|
||||
context.inbox.read().unwrap().disconnect(context);
|
||||
info!(context, 0, "disconnecting sentbox-thread",);
|
||||
context
|
||||
.sentbox_thread
|
||||
.read()
|
||||
.unwrap()
|
||||
.imap
|
||||
.disconnect(context);
|
||||
info!(context, 0, "disconnecting mvbox-thread",);
|
||||
context
|
||||
.mvbox_thread
|
||||
.read()
|
||||
@@ -298,8 +312,10 @@ pub unsafe fn dc_close(context: &Context) {
|
||||
.imap
|
||||
.disconnect(context);
|
||||
|
||||
info!(context, 0, "disconnecting SMTP");
|
||||
context.smtp.clone().lock().unwrap().disconnect();
|
||||
|
||||
info!(context, 0, "closing SQL");
|
||||
context.sql.close(context);
|
||||
let mut dbfile = context.dbfile.write().unwrap();
|
||||
free(*dbfile as *mut libc::c_void);
|
||||
|
||||
@@ -95,6 +95,7 @@ macro_rules! info {
|
||||
info!($ctx, $data1, $msg,)
|
||||
};
|
||||
($ctx:expr, $data1:expr, $msg:expr, $($args:expr),* $(,)?) => {{
|
||||
println!("xxx");
|
||||
let formatted = format!($msg, $($args),*);
|
||||
let formatted_c = $crate::dc_tools::to_cstring(formatted);
|
||||
$ctx.call_cb($crate::constants::Event::INFO, $data1 as uintptr_t,
|
||||
|
||||
@@ -467,6 +467,7 @@ impl Imap {
|
||||
}
|
||||
|
||||
fn unsetup_handle(&self, context: &Context) {
|
||||
info!(context, 0, "IMAP unsetup_handle starts");
|
||||
let session = self.session.lock().unwrap().0.take();
|
||||
if session.is_some() {
|
||||
match session.unwrap().close() {
|
||||
|
||||
Reference in New Issue
Block a user