mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-02-10 17:03:12 +00:00
Update tests
This commit is contained in:
parent
f2a394c41d
commit
fc343ff82e
@ -20,72 +20,31 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_ffi() {}
|
fn test_ffi() {}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_invite_convo() {
|
|
||||||
let mut ctx = create_context();
|
|
||||||
let mut bundle = vec![0u8; 200];
|
|
||||||
|
|
||||||
let bundle_len = create_intro_bundle(&mut ctx, (&mut bundle[..]).into());
|
|
||||||
unsafe {
|
|
||||||
bundle.set_len(bundle_len as usize);
|
|
||||||
}
|
|
||||||
|
|
||||||
assert!(bundle_len > 0, "bundle failed: {}", bundle_len);
|
|
||||||
let content = b"Hello";
|
|
||||||
let result = create_new_private_convo(&mut ctx, bundle[..].into(), content[..].into());
|
|
||||||
|
|
||||||
assert!(result.error_code == 0, "Error: {}", result.error_code);
|
|
||||||
|
|
||||||
destroy_context(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_message_roundtrip() {
|
fn test_message_roundtrip() {
|
||||||
let mut saro = create_context();
|
let mut saro = create_context();
|
||||||
let mut raya = create_context();
|
let mut raya = create_context();
|
||||||
let mut raya_bundle = vec![0u8; 200];
|
|
||||||
|
|
||||||
let bundle_len = create_intro_bundle(&mut raya, (&mut raya_bundle[..]).into());
|
// Raya Creates Bundle and Sends to Saro
|
||||||
unsafe {
|
let intro_result = create_intro_bundle(&mut raya);
|
||||||
raya_bundle.set_len(bundle_len as usize);
|
assert!(is_ok(intro_result.error_code));
|
||||||
}
|
|
||||||
|
|
||||||
assert!(bundle_len > 0, "bundle failed: {}", bundle_len);
|
let raya_bundle = intro_result.intro_bytes.as_ref();
|
||||||
let content = String::from_str("Hello").unwrap();
|
|
||||||
let result = create_new_private_convo(
|
|
||||||
&mut saro,
|
|
||||||
raya_bundle.as_slice().into(),
|
|
||||||
content.as_bytes().into(),
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(result.error_code == 0, "Error: {}", result.error_code);
|
// Saro creates a new conversation with Raya
|
||||||
|
let content: &[u8] = "hello".as_bytes();
|
||||||
|
|
||||||
// Handle payloads on raya's side
|
let convo_result = create_new_private_convo(&mut saro, raya_bundle, content.into());
|
||||||
let mut conversation_id_out = vec![0u8; 256];
|
assert!(is_ok(convo_result.error_code));
|
||||||
let mut conversation_id_out_len: u32 = 0;
|
|
||||||
let mut content_out = vec![0u8; 256];
|
|
||||||
|
|
||||||
for p in result.payloads.iter() {
|
// Raya recieves initial message
|
||||||
let bytes_written = handle_payload(
|
let payload = convo_result.payloads.first().unwrap();
|
||||||
&mut raya,
|
|
||||||
p.data[..].into(),
|
|
||||||
(&mut conversation_id_out[..]).into(),
|
|
||||||
(&mut conversation_id_out_len).into(),
|
|
||||||
(&mut content_out[..]).into(),
|
|
||||||
);
|
|
||||||
|
|
||||||
unsafe {
|
let handle_result = handle_payload(&mut raya, payload.data.as_ref());
|
||||||
content_out.set_len(bytes_written as usize);
|
assert!(is_ok(handle_result.error_code));
|
||||||
}
|
|
||||||
|
|
||||||
assert!(
|
// Check that the Content sent was the content received
|
||||||
bytes_written >= 0,
|
assert!(handle_result.content.as_ref().as_slice() == content);
|
||||||
"handle_payload failed: {}",
|
|
||||||
bytes_written
|
|
||||||
);
|
|
||||||
|
|
||||||
//TODO: Verify output match
|
|
||||||
}
|
|
||||||
|
|
||||||
destroy_context(saro);
|
destroy_context(saro);
|
||||||
destroy_context(raya);
|
destroy_context(raya);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user