diff --git a/src/request.rs b/src/request.rs index d23fed6..d82b06b 100644 --- a/src/request.rs +++ b/src/request.rs @@ -549,7 +549,12 @@ pub mod alloc_mod { #[cfg(test)] mod tests { - use spacepackets::util::UbfU16; + use std::string::String; + + use spacepackets::{ + cfdp::tlv::{msg_to_user::MsgToUserTlv, ReadableTlv}, + util::UbfU16, + }; use super::*; @@ -557,6 +562,53 @@ mod tests { #[test] fn test_put_request_basic() { + let src_file = "/tmp/hello.txt"; + let dest_file = "/tmp/hello2.txt"; + let put_request = PutRequest::new( + DEST_ID.into(), + Some(src_file), + Some(dest_file), + None, + None, + None, + None, + None, + None, + None, + ) + .unwrap(); + let identical_request = + PutRequest::new_regular_request(DEST_ID.into(), src_file, dest_file, None, None) + .unwrap(); + assert_eq!(put_request, identical_request); + } + + #[test] + fn test_put_request_path_checks() { + let mut invalid_path = String::from("/tmp/"); + invalid_path += "a".repeat(u8::MAX as usize).as_str(); + let dest_file = "/tmp/hello2.txt"; + let error = + PutRequest::new_regular_request(DEST_ID.into(), &invalid_path, dest_file, None, None); + assert!(error.is_err()); + let error = error.unwrap_err(); + assert_eq!(u8::MAX as usize + 5, error.0); + } + + #[test] + fn test_put_request_path_checks_dest_file() { + let mut invalid_path = String::from("/tmp/"); + invalid_path += "a".repeat(u8::MAX as usize).as_str(); + let source_file = "/tmp/hello2.txt"; + let error = + PutRequest::new_regular_request(DEST_ID.into(), source_file, &invalid_path, None, None); + assert!(error.is_err()); + let error = error.unwrap_err(); + assert_eq!(u8::MAX as usize + 5, error.0); + } + + #[test] + fn test_put_request_basic_small_ctor() { let src_file = "/tmp/hello.txt"; let dest_file = "/tmp/hello2.txt"; let put_request = @@ -641,4 +693,18 @@ mod tests { assert_eq!(put_request_cached.static_fields.dest_file_len, 0); assert_eq!(put_request_cached.opts_len(), 0); } + + #[test] + fn test_messages_to_user_ctor() { + let msg_to_user = MsgToUserTlv::new(&[1, 2, 3]).expect("creating message to user failed"); + let put_request = PutRequestOwned::new_msgs_to_user_only(DEST_ID.into(), &[msg_to_user]) + .expect("creating msgs to user only put request failed"); + let msg_to_user_iter = put_request.msgs_to_user(); + assert!(msg_to_user_iter.is_some()); + let msg_to_user_iter = msg_to_user_iter.unwrap(); + for msg_to_user_tlv in msg_to_user_iter { + assert_eq!(msg_to_user_tlv.value(), msg_to_user.value()); + assert_eq!(msg_to_user_tlv.tlv_type().unwrap(), TlvType::MsgToUser); + } + } }