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
// SPDX-License-Identifier: LGPL-2.1
//! TTY mode operations tests
use brlapi::{BrlApiError, TtyMode};
mod common;
#[test]
fn test_tty_mode_operations() {
// Test TTY mode operations based on BrlAPI patterns
let conn_result = common::try_connect();
if let Ok(conn) = conn_result {
// Test entering TTY mode (may fail without proper braille device)
match TtyMode::try_from(&conn) {
Ok(_tty_mode) => {
println!("TTY mode entered successfully");
// TTY mode automatically left when _tty_mode drops
println!("TTY mode left successfully");
}
Err(e) => {
println!("Enter TTY mode failed (expected without braille device): {e}");
// Test that we get appropriate error types
match e {
BrlApiError::TTYBusy
| BrlApiError::DeviceBusy
| BrlApiError::OperationNotSupported => {
// These are expected error types
}
_ => {
println!("Unexpected error type: {e}");
}
}
}
}
// Test TTY mode with specific TTY number
match TtyMode::with_tty(&conn, Some(1), None) {
Ok(_tty_mode) => {
println!("TTY mode with TTY 1 entered successfully");
// TTY mode automatically cleaned up when _tty_mode drops
}
Err(e) => {
println!("Enter TTY mode with TTY 1 failed: {e}");
}
}
} else {
println!("No connection available for TTY mode testing");
}
}
#[test]
fn test_tty_mode_specific_ttys() {
// Test TTY mode with various TTY numbers
if let Some(_) = common::with_connection(|conn| {
let tty_numbers = vec![None, Some(0), Some(1), Some(7)];
for tty in tty_numbers {
match TtyMode::with_tty(&conn, tty, None) {
Ok(_tty_mode) => {
println!("TTY mode entered for TTY {:?}", tty);
// TTY mode automatically left when _tty_mode drops
println!("TTY mode left for TTY {:?}", tty);
}
Err(e) => {
println!("Failed to enter TTY mode for TTY {:?}: {e}", tty);
}
}
}
}) {
// Connection was available for testing
} else {
println!("No connection available for specific TTY testing");
}
}