Back to Repositories

Testing APC Sequence Processing in Termux-App Terminal Emulator

A test suite validating Application Program Command (APC) handling in the Termux terminal emulator, focusing on graphics protocol support and non-printable character processing.

Test Coverage Overview

The test suite provides comprehensive coverage of APC sequence handling in terminal operations.

Key areas tested include:
  • Kitty graphics protocol support probing
  • APC sequence consumption behavior
  • Non-printable character handling within APC strings
  • Terminal display integrity after APC processing

Implementation Analysis

The testing approach employs JUnit framework features for terminal emulation verification. The implementation uses a fluent interface pattern with chained assertions to validate terminal state and output.

Technical patterns include:
  • Terminal size configuration testing
  • Escape sequence processing validation
  • String display verification
  • State maintenance checking

Technical Details

Testing infrastructure includes:
  • JUnit test framework
  • TerminalTestCase base class for emulation testing
  • Custom assertion methods for terminal state verification
  • Terminal size manipulation utilities
  • Escape sequence handling verification tools

Best Practices Demonstrated

The test suite exemplifies high-quality testing practices through isolated test cases and comprehensive state verification.

Notable practices include:
  • Clear test case documentation with reference links
  • Explicit test scenarios for edge cases
  • Comprehensive output validation
  • Real-world use case testing

termux/termux-app

terminal-emulator/src/test/java/com/termux/terminal/ApcTest.java

            
package com.termux.terminal;

public class ApcTest extends TerminalTestCase {

    public void testApcConsumed() {
        // At time of writing this is part of what yazi sends for probing for kitty graphics protocol support:
        // https://github.com/sxyazi/yazi/blob/0cdaff98d0b3723caff63eebf1974e7907a43a2c/yazi-adapter/src/emulator.rs#L129
        // This should not result in anything being written to the screen: If kitty graphics protocol support
        // is implemented it should instead result in an error code on stdin, and if not it should be consumed
        // silently just as xterm does. See https://sw.kovidgoyal.net/kitty/graphics-protocol/.
        withTerminalSized(2, 2)
            .enterString("\033_Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA\033\\")
            .assertLinesAre("  ", "  ");

        // It is ok for the APC content to be non printable characters:
        withTerminalSized(12, 2)
            .enterString("hello \033_some\023\033_\\apc#end\033\\ world")
            .assertLinesAre("hello  world", "            ");
    }

}