use brlapi::ConnectionSettings;
mod common;
#[test]
fn test_connection_settings_validation() {
let mut settings = ConnectionSettings::localhost();
settings.set_auth("/etc/brlapi.key");
let (c_settings, auth_str, host_str) = settings
.to_c_settings()
.expect("Settings conversion should succeed for valid settings");
assert!(auth_str.is_some());
assert!(host_str.is_some());
assert!(!c_settings.auth.is_null());
assert!(!c_settings.host.is_null());
let default_settings = ConnectionSettings::default();
assert!(default_settings.auth().is_none());
assert!(default_settings.host().is_none());
let (c_default, auth_default, host_default) = default_settings
.to_c_settings()
.expect("Default settings conversion should always succeed");
assert!(auth_default.is_none());
assert!(host_default.is_none());
assert!(c_default.auth.is_null());
assert!(c_default.host.is_null());
}
#[test]
fn test_connection_settings_edge_cases() {
let mut empty_settings = ConnectionSettings::for_host("");
empty_settings.set_auth("");
let (c_settings, _, _) = empty_settings
.to_c_settings()
.expect("Empty string settings conversion should succeed");
assert!(!c_settings.auth.is_null());
assert!(!c_settings.host.is_null());
let long_path = "a".repeat(1000);
let mut long_settings = ConnectionSettings::for_host(&long_path);
long_settings.set_auth(&long_path);
let (c_long, _, _) = long_settings
.to_c_settings()
.expect("Long string settings conversion should succeed");
assert!(!c_long.auth.is_null());
assert!(!c_long.host.is_null());
let mut special_settings = ConnectionSettings::for_host("::1"); special_settings.set_auth("/etc/brltty-authkey:with:colons");
let (c_special, _, _) = special_settings
.to_c_settings()
.expect("Special character settings conversion should succeed");
assert!(!c_special.auth.is_null());
assert!(!c_special.host.is_null());
}
#[test]
fn test_connection_settings_null_byte_in_auth() {
let mut settings = ConnectionSettings::new();
settings.set_auth("/path/with\0null");
assert!(settings.to_c_settings().is_err());
}
#[test]
fn test_connection_settings_null_byte_in_host() {
let settings = ConnectionSettings::for_host("host\0name");
assert!(settings.to_c_settings().is_err());
}