StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | /// Windows-specific clipboard tests. |
| 2 | /// |
| 3 | /// Note: Most image processing functionality is tested in ui/src/clipboard_utils_tests.rs |
| 4 | /// to avoid duplication. These tests focus on Windows-specific clipboard behavior. |
| 5 | #[cfg(target_os = "windows")] |
| 6 | mod clipboard_tests { |
| 7 | use crate::windowing::winit::windows::clipboard::WindowsClipboard; |
| 8 | use crate::{clipboard::ClipboardContent, Clipboard}; |
| 9 | |
| 10 | fn create_test_clipboard() -> Option<WindowsClipboard> { |
| 11 | WindowsClipboard::new().ok() |
| 12 | } |
| 13 | |
| 14 | #[test] |
| 15 | fn test_clipboard_round_trip() { |
| 16 | let mut clipboard = match create_test_clipboard() { |
| 17 | Some(clipboard) => clipboard, |
| 18 | None => { |
| 19 | eprintln!("Skipping test - no clipboard available (headless environment)"); |
| 20 | return; |
| 21 | } |
| 22 | }; |
| 23 | |
| 24 | let test_content = ClipboardContent::plain_text("Windows clipboard test".to_string()); |
| 25 | |
| 26 | // Write content |
| 27 | clipboard.write(test_content.clone()); |
| 28 | |
| 29 | // Read it back |
| 30 | let read_content = clipboard.read(); |
| 31 | |
| 32 | // Should get the same text back (in environments where clipboard works) |
| 33 | if !read_content.plain_text.is_empty() { |
| 34 | assert_eq!(read_content.plain_text, test_content.plain_text); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | #[test] |
| 39 | fn test_html_content_handling() { |
| 40 | let mut clipboard = match create_test_clipboard() { |
| 41 | Some(clipboard) => clipboard, |
| 42 | None => { |
| 43 | eprintln!("Skipping test - no clipboard available (headless environment)"); |
| 44 | return; |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | let test_content = ClipboardContent { |
| 49 | plain_text: "Test text".to_string(), |
| 50 | html: Some("<div>Test HTML</div>".to_string()), |
| 51 | images: None, |
| 52 | paths: None, |
| 53 | }; |
| 54 | |
| 55 | // Write HTML content |
| 56 | clipboard.write(test_content.clone()); |
| 57 | |
| 58 | // Read it back |
| 59 | let read_content = clipboard.read(); |
| 60 | |
| 61 | // In environments where clipboard works, we should get content back |
| 62 | // (the exact HTML may not be preserved depending on the system) |
| 63 | if !read_content.is_empty() { |
| 64 | assert!(!read_content.plain_text.is_empty()); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | #[test] |
| 69 | fn test_empty_content_handling() { |
| 70 | let mut clipboard = match create_test_clipboard() { |
| 71 | Some(clipboard) => clipboard, |
| 72 | None => { |
| 73 | eprintln!("Skipping test - no clipboard available (headless environment)"); |
| 74 | return; |
| 75 | } |
| 76 | }; |
| 77 | |
| 78 | let empty_content = ClipboardContent::plain_text("".to_string()); |
| 79 | |
| 80 | // Writing empty content should not panic |
| 81 | clipboard.write(empty_content); |
| 82 | |
| 83 | // Reading should return valid ClipboardContent (may be empty or have previous content) |
| 84 | let read_content = clipboard.read(); |
| 85 | |
| 86 | // Should always return a valid ClipboardContent struct |
| 87 | // Test that the structure itself is valid, not the content |
| 88 | assert!(matches!(read_content.images, None | Some(_))); |
| 89 | } |
| 90 | } |
| 91 |