mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 17:06:35 +03:00
test: move to dc_param
This commit is contained in:
@@ -372,3 +372,68 @@ pub unsafe fn dc_param_set_float(param: *mut dc_param_t, key: libc::c_int, value
|
|||||||
dc_param_set(param, key, value_str);
|
dc_param_set(param, key, value_str);
|
||||||
free(value_str as *mut libc::c_void);
|
free(value_str as *mut libc::c_void);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use std::ffi::CStr;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_dc_param() {
|
||||||
|
unsafe {
|
||||||
|
let p1: *mut dc_param_t = dc_param_new();
|
||||||
|
dc_param_set_packed(
|
||||||
|
p1,
|
||||||
|
b"\r\n\r\na=1\nb=2\n\nc = 3 \x00" as *const u8 as *const libc::c_char,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(dc_param_get_int(p1, 'a' as i32, 0), 1);
|
||||||
|
assert_eq!(dc_param_get_int(p1, 'b' as i32, 0), 2);
|
||||||
|
assert_eq!(dc_param_get_int(p1, 'c' as i32, 0), 0);
|
||||||
|
assert_eq!(dc_param_exists(p1, 'c' as i32), 0);
|
||||||
|
|
||||||
|
dc_param_set_int(p1, 'd' as i32, 4i32);
|
||||||
|
|
||||||
|
assert_eq!(dc_param_get_int(p1, 'd' as i32, 0), 4);
|
||||||
|
|
||||||
|
dc_param_empty(p1);
|
||||||
|
dc_param_set(
|
||||||
|
p1,
|
||||||
|
'a' as i32,
|
||||||
|
b"foo\x00" as *const u8 as *const libc::c_char,
|
||||||
|
);
|
||||||
|
dc_param_set_int(p1, 'b' as i32, 2i32);
|
||||||
|
dc_param_set(p1, 'c' as i32, 0 as *const libc::c_char);
|
||||||
|
dc_param_set_int(p1, 'd' as i32, 4i32);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
CStr::from_ptr((*p1).packed as *const libc::c_char)
|
||||||
|
.to_str()
|
||||||
|
.unwrap(),
|
||||||
|
"a=foo\nb=2\nd=4"
|
||||||
|
);
|
||||||
|
|
||||||
|
dc_param_set(p1, 'b' as i32, 0 as *const libc::c_char);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
CStr::from_ptr((*p1).packed as *const libc::c_char)
|
||||||
|
.to_str()
|
||||||
|
.unwrap(),
|
||||||
|
"a=foo\nd=4",
|
||||||
|
);
|
||||||
|
|
||||||
|
dc_param_set(p1, 'a' as i32, 0 as *const libc::c_char);
|
||||||
|
dc_param_set(p1, 'd' as i32, 0 as *const libc::c_char);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
CStr::from_ptr((*p1).packed as *const libc::c_char)
|
||||||
|
.to_str()
|
||||||
|
.unwrap(),
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
|
||||||
|
dc_param_unref(p1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
101
tests/stress.rs
101
tests/stress.rs
@@ -412,107 +412,6 @@ unsafe fn stress_functions(context: &Context) {
|
|||||||
free(fn0 as *mut libc::c_void);
|
free(fn0 as *mut libc::c_void);
|
||||||
free(fn1 as *mut libc::c_void);
|
free(fn1 as *mut libc::c_void);
|
||||||
}
|
}
|
||||||
let p1: *mut dc_param_t = dc_param_new();
|
|
||||||
dc_param_set_packed(
|
|
||||||
p1,
|
|
||||||
b"\r\n\r\na=1\nb=2\n\nc = 3 \x00" as *const u8 as *const libc::c_char,
|
|
||||||
);
|
|
||||||
if 0 != !(dc_param_get_int(p1, 'a' as i32, 0i32) == 1i32) as usize {
|
|
||||||
__assert_rtn(
|
|
||||||
(*::std::mem::transmute::<&[u8; 17], &[libc::c_char; 17]>(b"stress_functions\x00"))
|
|
||||||
.as_ptr(),
|
|
||||||
b"../cmdline/stress.c\x00" as *const u8 as *const libc::c_char,
|
|
||||||
690i32,
|
|
||||||
b"dc_param_get_int(p1, \'a\', 0)==1\x00" as *const u8 as *const libc::c_char,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
};
|
|
||||||
if 0 != !(dc_param_get_int(p1, 'b' as i32, 0i32) == 2i32) as usize {
|
|
||||||
__assert_rtn(
|
|
||||||
(*::std::mem::transmute::<&[u8; 17], &[libc::c_char; 17]>(b"stress_functions\x00"))
|
|
||||||
.as_ptr(),
|
|
||||||
b"../cmdline/stress.c\x00" as *const u8 as *const libc::c_char,
|
|
||||||
691i32,
|
|
||||||
b"dc_param_get_int(p1, \'b\', 0)==2\x00" as *const u8 as *const libc::c_char,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
};
|
|
||||||
if 0 != !(dc_param_get_int(p1, 'c' as i32, 0i32) == 0i32) as usize {
|
|
||||||
__assert_rtn(
|
|
||||||
(*::std::mem::transmute::<&[u8; 17], &[libc::c_char; 17]>(b"stress_functions\x00"))
|
|
||||||
.as_ptr(),
|
|
||||||
b"../cmdline/stress.c\x00" as *const u8 as *const libc::c_char,
|
|
||||||
692i32,
|
|
||||||
b"dc_param_get_int(p1, \'c\', 0)==0\x00" as *const u8 as *const libc::c_char,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
};
|
|
||||||
if 0 != !(dc_param_exists(p1, 'c' as i32) == 0i32) as usize {
|
|
||||||
__assert_rtn(
|
|
||||||
(*::std::mem::transmute::<&[u8; 17], &[libc::c_char; 17]>(b"stress_functions\x00"))
|
|
||||||
.as_ptr(),
|
|
||||||
b"../cmdline/stress.c\x00" as *const u8 as *const libc::c_char,
|
|
||||||
693i32,
|
|
||||||
b"dc_param_exists (p1, \'c\')==0\x00" as *const u8 as *const libc::c_char,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
};
|
|
||||||
dc_param_set_int(p1, 'd' as i32, 4i32);
|
|
||||||
if 0 != !(dc_param_get_int(p1, 'd' as i32, 0i32) == 4i32) as usize {
|
|
||||||
__assert_rtn(
|
|
||||||
(*::std::mem::transmute::<&[u8; 17], &[libc::c_char; 17]>(b"stress_functions\x00"))
|
|
||||||
.as_ptr(),
|
|
||||||
b"../cmdline/stress.c\x00" as *const u8 as *const libc::c_char,
|
|
||||||
696i32,
|
|
||||||
b"dc_param_get_int(p1, \'d\', 0)==4\x00" as *const u8 as *const libc::c_char,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
};
|
|
||||||
dc_param_empty(p1);
|
|
||||||
dc_param_set(
|
|
||||||
p1,
|
|
||||||
'a' as i32,
|
|
||||||
b"foo\x00" as *const u8 as *const libc::c_char,
|
|
||||||
);
|
|
||||||
dc_param_set_int(p1, 'b' as i32, 2i32);
|
|
||||||
dc_param_set(p1, 'c' as i32, 0 as *const libc::c_char);
|
|
||||||
dc_param_set_int(p1, 'd' as i32, 4i32);
|
|
||||||
if 0 != !(strcmp(
|
|
||||||
(*p1).packed,
|
|
||||||
b"a=foo\nb=2\nd=4\x00" as *const u8 as *const libc::c_char,
|
|
||||||
) == 0i32) as usize
|
|
||||||
{
|
|
||||||
__assert_rtn(
|
|
||||||
(*::std::mem::transmute::<&[u8; 17], &[libc::c_char; 17]>(b"stress_functions\x00"))
|
|
||||||
.as_ptr(),
|
|
||||||
b"../cmdline/stress.c\x00" as *const u8 as *const libc::c_char,
|
|
||||||
703i32,
|
|
||||||
b"strcmp(p1->packed, \"a=foo\\nb=2\\nd=4\")==0\x00" as *const u8 as *const libc::c_char,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
};
|
|
||||||
|
|
||||||
dc_param_set(p1, 'b' as i32, 0 as *const libc::c_char);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
CStr::from_ptr((*p1).packed as *const libc::c_char)
|
|
||||||
.to_str()
|
|
||||||
.unwrap(),
|
|
||||||
"a=foo\nd=4",
|
|
||||||
);
|
|
||||||
|
|
||||||
dc_param_set(p1, 'a' as i32, 0 as *const libc::c_char);
|
|
||||||
dc_param_set(p1, 'd' as i32, 0 as *const libc::c_char);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
CStr::from_ptr((*p1).packed as *const libc::c_char)
|
|
||||||
.to_str()
|
|
||||||
.unwrap(),
|
|
||||||
"",
|
|
||||||
);
|
|
||||||
|
|
||||||
dc_param_unref(p1);
|
|
||||||
|
|
||||||
let mut keys: *mut libc::c_char = dc_get_config(
|
let mut keys: *mut libc::c_char = dc_get_config(
|
||||||
context,
|
context,
|
||||||
b"sys.config_keys\x00" as *const u8 as *const libc::c_char,
|
b"sys.config_keys\x00" as *const u8 as *const libc::c_char,
|
||||||
|
|||||||
Reference in New Issue
Block a user