mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 21:36:29 +03:00
test: move dc_may_be_valid_addr tests to dc_contact.rs
This commit is contained in:
@@ -45,7 +45,7 @@ pub unsafe fn dc_marknoticed_contact(context: &dc_context_t, contact_id: uint32_
|
||||
);
|
||||
}
|
||||
|
||||
// handle contacts
|
||||
/// Returns false if addr is an invalid address, otherwise true.
|
||||
pub unsafe fn dc_may_be_valid_addr(addr: *const libc::c_char) -> bool {
|
||||
if addr.is_null() {
|
||||
return false;
|
||||
@@ -1259,3 +1259,59 @@ pub unsafe fn dc_scaleup_contact_origin(
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_dc_may_be_valid_addr() {
|
||||
unsafe {
|
||||
assert_eq!(dc_may_be_valid_addr(0 as *const libc::c_char), false);
|
||||
assert_eq!(
|
||||
dc_may_be_valid_addr(b"\x00" as *const u8 as *const libc::c_char),
|
||||
false
|
||||
);
|
||||
assert_eq!(
|
||||
dc_may_be_valid_addr(b"user@domain.tld\x00" as *const u8 as *const libc::c_char),
|
||||
true
|
||||
);
|
||||
assert_eq!(
|
||||
dc_may_be_valid_addr(b"uuu\x00" as *const u8 as *const libc::c_char),
|
||||
false
|
||||
);
|
||||
assert_eq!(
|
||||
dc_may_be_valid_addr(b"dd.tt\x00" as *const u8 as *const libc::c_char),
|
||||
false
|
||||
);
|
||||
assert_eq!(
|
||||
dc_may_be_valid_addr(b"tt.dd@uu\x00" as *const u8 as *const libc::c_char),
|
||||
false
|
||||
);
|
||||
assert_eq!(
|
||||
dc_may_be_valid_addr(b"u@d\x00" as *const u8 as *const libc::c_char),
|
||||
false
|
||||
);
|
||||
assert_eq!(
|
||||
dc_may_be_valid_addr(b"u@d.\x00" as *const u8 as *const libc::c_char),
|
||||
false
|
||||
);
|
||||
assert_eq!(
|
||||
dc_may_be_valid_addr(b"u@d.t\x00" as *const u8 as *const libc::c_char),
|
||||
false
|
||||
);
|
||||
assert_eq!(
|
||||
dc_may_be_valid_addr(b"u@d.tt\x00" as *const u8 as *const libc::c_char),
|
||||
true
|
||||
);
|
||||
assert_eq!(
|
||||
dc_may_be_valid_addr(b"u@.tt\x00" as *const u8 as *const libc::c_char),
|
||||
false
|
||||
);
|
||||
assert_eq!(
|
||||
dc_may_be_valid_addr(b"@d.tt\x00" as *const u8 as *const libc::c_char),
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
156
tests/stress.rs
156
tests/stress.rs
@@ -9,7 +9,6 @@ use tempfile::{tempdir, TempDir};
|
||||
use deltachat::constants::*;
|
||||
use deltachat::dc_array::*;
|
||||
use deltachat::dc_configure::*;
|
||||
use deltachat::dc_contact::*;
|
||||
use deltachat::dc_context::*;
|
||||
use deltachat::dc_hash::*;
|
||||
use deltachat::dc_imex::*;
|
||||
@@ -592,160 +591,7 @@ unsafe fn stress_functions(context: &dc_context_t) {
|
||||
} else {
|
||||
};
|
||||
free(s as *mut libc::c_void);
|
||||
if 0 != (dc_may_be_valid_addr(0 as *const libc::c_char)) as libc::c_int as libc::c_long {
|
||||
__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,
|
||||
380i32,
|
||||
b"!dc_may_be_valid_addr(NULL)\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
} else {
|
||||
};
|
||||
if 0 != (dc_may_be_valid_addr(b"\x00" as *const u8 as *const libc::c_char)) as libc::c_int
|
||||
as libc::c_long
|
||||
{
|
||||
__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,
|
||||
381i32,
|
||||
b"!dc_may_be_valid_addr(\"\")\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
} else {
|
||||
};
|
||||
if 0 != (!dc_may_be_valid_addr(b"user@domain.tld\x00" as *const u8 as *const libc::c_char))
|
||||
as libc::c_int as libc::c_long
|
||||
{
|
||||
__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,
|
||||
382i32,
|
||||
b"dc_may_be_valid_addr(\"user@domain.tld\")\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
} else {
|
||||
};
|
||||
if 0 != (dc_may_be_valid_addr(b"uuu\x00" as *const u8 as *const libc::c_char)) as libc::c_int
|
||||
as libc::c_long
|
||||
{
|
||||
__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,
|
||||
383i32,
|
||||
b"!dc_may_be_valid_addr(\"uuu\")\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
} else {
|
||||
};
|
||||
if 0 != (dc_may_be_valid_addr(b"dd.tt\x00" as *const u8 as *const libc::c_char)) as libc::c_int
|
||||
as libc::c_long
|
||||
{
|
||||
__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,
|
||||
384i32,
|
||||
b"!dc_may_be_valid_addr(\"dd.tt\")\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
} else {
|
||||
};
|
||||
if 0 != (dc_may_be_valid_addr(b"tt.dd@uu\x00" as *const u8 as *const libc::c_char))
|
||||
as libc::c_int as libc::c_long
|
||||
{
|
||||
__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,
|
||||
385i32,
|
||||
b"!dc_may_be_valid_addr(\"tt.dd@uu\")\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
} else {
|
||||
};
|
||||
if 0 != (dc_may_be_valid_addr(b"uu\x00" as *const u8 as *const libc::c_char)) as libc::c_int
|
||||
as libc::c_long
|
||||
{
|
||||
__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,
|
||||
386i32,
|
||||
b"!dc_may_be_valid_addr(\"uu\")\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
} else {
|
||||
};
|
||||
if 0 != (dc_may_be_valid_addr(b"u@d\x00" as *const u8 as *const libc::c_char)) as libc::c_int
|
||||
as libc::c_long
|
||||
{
|
||||
__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,
|
||||
387i32,
|
||||
b"!dc_may_be_valid_addr(\"u@d\")\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
} else {
|
||||
};
|
||||
if 0 != (dc_may_be_valid_addr(b"u@d.\x00" as *const u8 as *const libc::c_char)) as libc::c_int
|
||||
as libc::c_long
|
||||
{
|
||||
__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,
|
||||
388i32,
|
||||
b"!dc_may_be_valid_addr(\"u@d.\")\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
} else {
|
||||
};
|
||||
if 0 != (dc_may_be_valid_addr(b"u@d.t\x00" as *const u8 as *const libc::c_char)) as libc::c_int
|
||||
as libc::c_long
|
||||
{
|
||||
__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,
|
||||
389i32,
|
||||
b"!dc_may_be_valid_addr(\"u@d.t\")\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
} else {
|
||||
};
|
||||
if 0 != (!dc_may_be_valid_addr(b"u@d.tt\x00" as *const u8 as *const libc::c_char))
|
||||
as libc::c_int as libc::c_long
|
||||
{
|
||||
__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,
|
||||
390i32,
|
||||
b"dc_may_be_valid_addr(\"u@d.tt\")\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
} else {
|
||||
};
|
||||
if 0 != (dc_may_be_valid_addr(b"u@.tt\x00" as *const u8 as *const libc::c_char)) as libc::c_int
|
||||
as libc::c_long
|
||||
{
|
||||
__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,
|
||||
391i32,
|
||||
b"!dc_may_be_valid_addr(\"u@.tt\")\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
} else {
|
||||
};
|
||||
if 0 != (dc_may_be_valid_addr(b"@d.tt\x00" as *const u8 as *const libc::c_char)) as libc::c_int
|
||||
as libc::c_long
|
||||
{
|
||||
__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,
|
||||
392i32,
|
||||
b"!dc_may_be_valid_addr(\"@d.tt\")\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
} else {
|
||||
};
|
||||
|
||||
let mut str: *mut libc::c_char = strdup(b"aaa\x00" as *const u8 as *const libc::c_char);
|
||||
let replacements: libc::c_int = dc_str_replace(
|
||||
&mut str,
|
||||
|
||||
Reference in New Issue
Block a user