#[cfg(test)]
mod tests {
use super::super::*;
use crate::MAX_INLINE_SIZE;
#[test]
fn test_clipboard_content_serialization() {
let text_content = ClipboardContent::Text {
data: "Hello, world!".to_string(),
truncated: None,
};
let json = serde_json::to_string(&text_content).unwrap();
let deserialized: ClipboardContent = serde_json::from_str(&json).unwrap();
match deserialized {
ClipboardContent::Text { data, truncated } => {
assert_eq!(data, "Hello, world!");
assert_eq!(truncated, None);
}
_ => panic!("Wrong content type"),
}
}
#[test]
fn test_clipboard_content_truncation() {
let large_text = "a".repeat(MAX_INLINE_SIZE + 1000);
let content = ClipboardContent::Text {
data: large_text[..MAX_INLINE_SIZE].to_string(),
truncated: Some(true),
};
match content {
ClipboardContent::Text { data, truncated } => {
assert_eq!(data.len(), MAX_INLINE_SIZE);
assert_eq!(truncated, Some(true));
}
_ => panic!("Wrong content type"),
}
}
#[test]
fn test_image_content_with_metadata() {
let content = ClipboardContent::ImagePng {
data: Some("base64data".to_string()),
file: None,
width: 100,
height: 200,
size: 1024,
};
match content {
ClipboardContent::ImagePng { width, height, size, .. } => {
assert_eq!(width, 100);
assert_eq!(height, 200);
assert_eq!(size, 1024);
}
_ => panic!("Wrong content type"),
}
}
#[test]
#[ignore = "Clipboard access can cause segfaults in test environment"]
fn test_clipboard_change_detection() {
let manager = ClipboardManager::new().unwrap();
let initial_text = ClipboardContent::Text {
data: "Initial content".to_string(),
truncated: None,
};
manager.set_content(&initial_text).unwrap();
let _initial_content = manager.get_content().unwrap();
let new_content = ClipboardContent::Text {
data: "New content".to_string(),
truncated: None,
};
manager.set_content(&new_content).unwrap();
let updated_content = manager.get_content().unwrap();
match updated_content.content {
ClipboardContent::Text { ref data, .. } => {
assert_eq!(data, "New content");
}
_ => panic!("Expected text content"),
}
}
#[test]
fn test_text_clipboard_handling() {
let content = ClipboardContent::Text {
data: String::new(),
truncated: None,
};
let json = serde_json::to_string(&content).unwrap();
assert!(json.contains("text"));
}
#[test]
fn test_clipboard_data_metadata() {
let data = ClipboardData {
content: ClipboardContent::Text {
data: "Test".to_string(),
truncated: None,
},
metadata: ClipboardMetadata {
timestamp: chrono::Utc::now(),
source: Some("test".to_string()),
},
};
assert_eq!(data.metadata.source, Some("test".to_string()));
}
#[cfg(target_os = "macos")]
#[test]
#[ignore = "Clipboard access can cause segfaults in test environment"]
fn test_macos_image_conversion() {
let manager = ClipboardManager::new().unwrap();
let _ = manager.get_raw_image();
}
#[test]
fn test_error_handling() {
use crate::ClaudeUtilsError;
let error = ClaudeUtilsError::Clipboard("Test error".to_string());
assert_eq!(error.to_string(), "Clipboard error: Test error");
let error = ClaudeUtilsError::ImageProcessing(
image::ImageError::Unsupported(
image::error::UnsupportedError::from_format_and_kind(
image::error::ImageFormatHint::Unknown,
image::error::UnsupportedErrorKind::GenericFeature("test".to_string()),
)
)
);
assert!(error.to_string().contains("Image processing error"));
}
}