-
-
Notifications
You must be signed in to change notification settings - Fork 99
test: add failing test for selfavatar #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e97f6ac
a1e790b
fd4de4d
e7afcc3
bc521a2
acc4805
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
//! Stress some functions for testing; if used as a lib, this file is obsolete. | ||
|
||
use std::collections::HashSet; | ||
use std::ffi::{CStr, CString}; | ||
use std::env::current_dir; | ||
use std::ffi::CString; | ||
use std::path::PathBuf; | ||
|
||
use mmime::mailimf_types::*; | ||
use tempfile::{tempdir, TempDir}; | ||
|
@@ -121,21 +123,15 @@ unsafe fn stress_functions(context: &Context) { | |
context.get_blobdir(), | ||
b"foobar\x00" as *const u8 as *const libc::c_char, | ||
); | ||
assert_ne!(0, dc_is_blobdir_path(context, abs_path)); | ||
assert_ne!( | ||
0, | ||
dc_is_blobdir_path( | ||
context, | ||
b"$BLOBDIR/fofo\x00" as *const u8 as *const libc::c_char, | ||
) | ||
); | ||
assert_eq!( | ||
0, | ||
dc_is_blobdir_path( | ||
context, | ||
b"/BLOBDIR/fofo\x00" as *const u8 as *const libc::c_char, | ||
) | ||
); | ||
assert!(dc_is_blobdir_path(context, abs_path)); | ||
assert!(dc_is_blobdir_path( | ||
context, | ||
b"$BLOBDIR/fofo\x00" as *const u8 as *const libc::c_char, | ||
)); | ||
assert!(!dc_is_blobdir_path( | ||
context, | ||
b"/BLOBDIR/fofo\x00" as *const u8 as *const libc::c_char, | ||
)); | ||
assert_ne!(0, dc_file_exist(context, abs_path)); | ||
free(abs_path as *mut libc::c_void); | ||
assert_ne!( | ||
|
@@ -946,23 +942,60 @@ fn test_dc_get_oauth2_token() { | |
} | ||
|
||
#[test] | ||
fn test_stress_tests() { | ||
fn test_dc_get_abs_path() { | ||
let ctx = unsafe { create_test_context() }; | ||
|
||
let blobdir_c = unsafe { dc_get_blobdir(&ctx.ctx) }; | ||
let mut image_path = PathBuf::from(to_string(blobdir_c)); | ||
image_path.push("image.png"); | ||
|
||
let mut image_path_2 = PathBuf::from("$BLOBDIR"); | ||
image_path_2.push("image.png"); | ||
|
||
let image_c = CString::new(image_path_2.to_str().unwrap()).unwrap(); | ||
let abs_path = unsafe { dc_get_abs_path(&ctx.ctx, image_c.as_ptr()) }; | ||
|
||
assert_eq!(to_string(abs_path), image_path.to_str().unwrap()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test works on windows and *nix. |
||
} | ||
|
||
#[test] | ||
fn test_selfavatar_config() { | ||
let ctx = unsafe { create_test_context() }; | ||
|
||
let mut logo_path = current_dir().unwrap(); | ||
logo_path.push("tests"); | ||
logo_path.push("fixtures"); | ||
logo_path.push("delta-logo.png"); | ||
assert!(logo_path.as_path().exists()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only asserting that we do have a real file in the test. |
||
|
||
let logo_path_c = CString::new(logo_path.to_str().unwrap()).unwrap(); | ||
unsafe { | ||
let context = create_test_context(); | ||
stress_functions(&context.ctx); | ||
dc_set_config( | ||
&ctx.ctx, | ||
b"selfavatar\x00" as *const u8 as *const libc::c_char, | ||
logo_path_c.as_ptr(), | ||
); | ||
} | ||
|
||
let selfavatar = unsafe { | ||
dc_get_config( | ||
&ctx.ctx, | ||
b"selfavatar\x00" as *const u8 as *const libc::c_char, | ||
) | ||
}; | ||
|
||
let blobdir_c = unsafe { dc_get_blobdir(&ctx.ctx) }; | ||
let mut image_path = PathBuf::from(to_string(blobdir_c)); | ||
image_path.push("delta-logo.png"); | ||
|
||
assert!(image_path.as_path().exists()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The resulting file in the blobdir should exist. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems windows manages to copy the file to the blobdir at least. This is good to know. |
||
assert_eq!(to_string(selfavatar), image_path.to_str().unwrap()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should fail on windows. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no totally sure, but dc_set_config() tries to copy the given file physically to the blob directory. i assume the file described by logo_path_c normally does not exist? maybe the behavior of copying unexistent files is slightly different at some level (dc_set_config() uses the source file when copying failed) to have a reliable test, maybe ensure that the given file exists before calling dc_get_config()? no need to be a valid image, an empty file should do the job. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's what the test is doing, |
||
} | ||
|
||
#[test] | ||
fn test_arr_to_string() { | ||
let arr2: [uint32_t; 4] = [ | ||
0i32 as uint32_t, | ||
12i32 as uint32_t, | ||
133i32 as uint32_t, | ||
1999999i32 as uint32_t, | ||
]; | ||
|
||
let str_0 = unsafe { dc_arr_to_string(arr2.as_ptr(), 4i32) }; | ||
assert_eq!(to_string(str_0), "0,12,133,1999999"); | ||
unsafe { free(str_0 as *mut _) }; | ||
fn test_stress_tests() { | ||
unsafe { | ||
let context = create_test_context(); | ||
stress_functions(&context.ctx); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing to do with these tests, but it came in my way and was easy to fix.