From b1f89a2aea00a473f7ccac26390c2e8e2c2a1c36 Mon Sep 17 00:00:00 2001 From: Arthur LE MOIGNE Date: Mon, 11 Dec 2023 17:11:44 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Add=20tests=20with=20invalid=20valu?= =?UTF-8?q?e=20in=20Dictionary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- quickfix/tests/test_dictionary.rs | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/quickfix/tests/test_dictionary.rs b/quickfix/tests/test_dictionary.rs index 840bb7f..848b27d 100644 --- a/quickfix/tests/test_dictionary.rs +++ b/quickfix/tests/test_dictionary.rs @@ -1,5 +1,37 @@ use quickfix::*; +#[test] +fn test_new_invalid_text() { + assert_eq!( + Dictionary::with_name("in\0valid").unwrap_err(), + QuickFixError::invalid_argument("nul byte found in provided data at position: 2") + ); +} + +#[test] +fn test_get_invalid_text() { + let dict = Dictionary::new(); + + assert_eq!( + dict.get::("in\0valid").unwrap_err(), + QuickFixError::invalid_argument("nul byte found in provided data at position: 2") + ); +} + +#[test] +fn test_set_invalid_text() { + let mut dict = Dictionary::new(); + + assert_eq!( + dict.set("\0invalid", "foo".to_string()).unwrap_err(), + QuickFixError::invalid_argument("nul byte found in provided data at position: 0") + ); + assert_eq!( + dict.set("key", "\0invalid".to_string()).unwrap_err(), + QuickFixError::invalid_argument("nul byte found in provided data at position: 0") + ); +} + #[test] fn test_text() { let mut dict = Dictionary::with_name("HELLO").unwrap(); @@ -121,6 +153,11 @@ fn test_contains() { let mut dict = Dictionary::with_name("HELLO").unwrap(); assert!(!dict.contains("foo").unwrap()); + assert_eq!( + dict.contains("in\0valid").unwrap_err(), + QuickFixError::invalid_argument("nul byte found in provided data at position: 2") + ); + dict.set("foo", "bar".to_string()).unwrap(); assert!(dict.contains("foo").unwrap()); }