1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// SPDX-License-Identifier: LGPL-2.1
//! Text writing operations tests
use brlapi::{BrlApiError, TtyMode};
mod common;
#[test]
fn test_text_writing_operations() {
// Test text writing operations based on Python apitest.py patterns
let conn_result = common::try_connect();
if let Ok(conn) = conn_result {
// First try to enter TTY mode
match TtyMode::try_from(&conn) {
Ok(tty_mode) => {
println!("TTY mode entered, testing text operations");
// Skip text operations for NoBraille driver
match conn.display_driver() {
Ok(driver) if driver == "NoBraille" => {
println!("Skipping text write tests for NoBraille driver (not supported)");
}
_ => {
// Test basic text writing with sample texts
for text in common::test_data::sample_texts() {
match tty_mode.write_text(text) {
Ok(()) => println!(
"Text write succeeded: '{}'",
text.chars().take(20).collect::<String>()
),
Err(e) => println!(
"Text write failed for '{}': {e}",
text.chars().take(20).collect::<String>()
),
}
}
}
}
// Test text writing with cursor positioning (skip for NoBraille)
match conn.display_driver() {
Ok(driver) if driver == "NoBraille" => {
println!("Skipping cursor positioning tests for NoBraille driver");
}
_ => {
for cursor_pos in common::test_data::cursor_positions() {
let cursor = if cursor_pos == brlapi_sys::BRLAPI_CURSOR_LEAVE {
brlapi::text::CursorPosition::Leave
} else if cursor_pos == brlapi_sys::BRLAPI_CURSOR_OFF as i32 {
brlapi::text::CursorPosition::Off
} else {
brlapi::text::CursorPosition::At(cursor_pos as u32)
};
match tty_mode
.write_text_with_cursor(&format!("Cursor at {cursor_pos}"), cursor)
{
Ok(()) => println!("Text write with cursor {cursor_pos} succeeded"),
Err(e) => {
println!("Text write with cursor {cursor_pos} failed: {e}")
}
}
}
}
}
// TTY mode automatically cleaned up when tty_mode drops
}
Err(e) => {
println!("TTY mode entry failed, testing text operations without TTY mode: {e}");
// Skip text operations for NoBraille driver
match conn.display_driver() {
Ok(driver) if driver == "NoBraille" => {
println!("Skipping text write without TTY mode test for NoBraille driver");
}
_ => {
// Test text operations without TTY mode (should fail appropriately)
match brlapi::text::util::write_message(&conn, "No TTY mode") {
Ok(()) => {
println!("Text write without TTY mode succeeded (unexpected)")
}
Err(e) => {
println!("Text write without TTY mode failed (expected): {e}");
// Should get appropriate error type
match e {
BrlApiError::IllegalInstruction
| BrlApiError::InvalidParameter
| BrlApiError::OperationNotSupported => {
// Expected error types
}
_ => println!("Unexpected error type for no TTY mode: {e}"),
}
}
}
}
}
}
}
} else {
println!("No connection available for text writing testing");
}
}
#[test]
fn test_text_writing_with_tty_helper() {
// Test text writing using the helper function
if let Some(_) = common::with_tty_mode(|conn| {
// Skip text operations for NoBraille driver
match conn.display_driver() {
Ok(driver) if driver == "NoBraille" => {
println!("Skipping text write helper tests for NoBraille driver");
return Ok(());
}
_ => {}
}
// Test various text samples
for text in common::test_data::sample_texts() {
brlapi::text::util::write_message(conn, text)?;
println!(
"Successfully wrote: '{}'",
text.chars().take(30).collect::<String>()
);
}
Ok(())
}) {
println!("Text writing tests completed with TTY mode");
} else {
println!("TTY mode not available for text writing tests");
}
}
#[test]
fn test_cursor_positioning() {
// Test cursor positioning specifically
if let Some(_) = common::with_tty_mode(|conn| {
// Skip cursor positioning for NoBraille driver
match conn.display_driver() {
Ok(driver) if driver == "NoBraille" => {
println!("Skipping cursor positioning tests for NoBraille driver");
return Ok(());
}
_ => {}
}
let test_text = "Cursor test";
for cursor_pos in common::test_data::cursor_positions() {
let cursor = if cursor_pos == brlapi_sys::BRLAPI_CURSOR_LEAVE {
brlapi::text::CursorPosition::Leave
} else if cursor_pos == brlapi_sys::BRLAPI_CURSOR_OFF as i32 {
brlapi::text::CursorPosition::Off
} else {
brlapi::text::CursorPosition::At(cursor_pos as u32)
};
brlapi::text::util::write_message_with_cursor(conn, test_text, cursor)?;
println!("Cursor positioning test passed for position: {cursor_pos}");
}
Ok(())
}) {
println!("Cursor positioning tests completed");
} else {
println!("Cursor positioning tests skipped - no TTY mode available");
}
}