Replace silent error discards with logged warnings during X11 cleanup and D-Bus channel operations. Add structured error handling in the main event loop, configurable TRAY_ICON_SIZE env var, and remove unused xembed_info atom.
61 lines
1.9 KiB
Rust
61 lines
1.9 KiB
Rust
// Basic unit tests for xembed-sni-proxy
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use x11rb::protocol::xproto::Atom;
|
|
|
|
#[test]
|
|
fn test_icon_size_parsing() {
|
|
// Test the icon size parsing logic from main.rs
|
|
fn parse_icon_size(env_var: Option<&str>) -> u16 {
|
|
env_var
|
|
.map(|s| s.to_string())
|
|
.and_then(|s| s.parse().ok())
|
|
.filter(|&s| s > 0)
|
|
.unwrap_or(64)
|
|
}
|
|
|
|
// Test valid sizes
|
|
assert_eq!(parse_icon_size(Some("32")), 32);
|
|
assert_eq!(parse_icon_size(Some("128")), 128);
|
|
assert_eq!(parse_icon_size(Some("64")), 64);
|
|
|
|
// Test invalid sizes (should fall back to default)
|
|
assert_eq!(parse_icon_size(Some("0")), 64);
|
|
assert_eq!(parse_icon_size(Some("-1")), 64);
|
|
assert_eq!(parse_icon_size(Some("invalid")), 64);
|
|
assert_eq!(parse_icon_size(None), 64);
|
|
}
|
|
|
|
#[test]
|
|
fn test_error_handling_patterns() {
|
|
// Test that our error handling patterns work correctly
|
|
let result: Result<(), Box<dyn std::error::Error>> = Ok(());
|
|
assert!(result.is_ok());
|
|
|
|
let err_result: Result<(), Box<dyn std::error::Error>> = Err("test error".into());
|
|
assert!(err_result.is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn test_atoms_struct() {
|
|
// This will be expanded once we have a way to test X11 connection
|
|
// For now, just verify the struct compiles
|
|
|
|
#[allow(dead_code)]
|
|
struct Atoms {
|
|
net_system_tray_s0: Atom,
|
|
net_system_tray_opcode: Atom,
|
|
manager: Atom,
|
|
xembed: Atom,
|
|
}
|
|
|
|
// Struct should compile without xembed_info field
|
|
let _atoms = Atoms {
|
|
net_system_tray_s0: 0,
|
|
net_system_tray_opcode: 0,
|
|
manager: 0,
|
|
xembed: 0,
|
|
};
|
|
}
|
|
} |