brlapi 0.4.1

Safe Rust bindings for the BrlAPI library
// 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");
    }
}