curtain/Tests/CurtainSharedTests/RevealComboTests.swift
Aric Camarata 8c19e960d2 Detection root-cause fix + audit batch: netstat path, UDP activator, settings coherence, refactor, docs
Detection: netstat lives at /usr/sbin/netstat, not /usr/bin — the hardcoded wrong
path silently killed the ESTABLISHED-TCP activator (root cause of the failed live
test). Fixed and live-verified. Added peered-UDP activator (5900-5902) for
High-Performance sessions, per-signal transition logging, unconditional error
logging for dead probe helpers, and probe v2 with full CGSession dictionary
diffing. 7 new parser tests (32 total).

Fixes from a full audit + adversarial review: idle source setting honored
(default now Remote session activity), cover scope reduced to a coherent
two-mode model with legacy migration (per-display toggle was inverted in
onlyMarked and dead in all), curtain test no longer schedules a teardown over a
live session, specific-display password box placement gets a real picker,
refuse-to-arm enforced, activation notification posts a real banner, menu
password gate bypassed when the event tap is dead, shared single-decoder aerial
player with stale-task guard and async playability check, password buffer zeroed
on successful unlock and Esc, XPC interruption/invalidation handlers, modern
Accessibility settings URL, launchPath modernized, codesign failures now abort
release.sh, monotonic CFBundleVersion, install.sh temp cleanup, dead
armDisarmHotkey setting removed.

Refactor: Curtain.swift and PreferencesWindow.swift split into focused files
(largest now 479 lines). Wiki, README, and contributing docs updated to match.
Build clean at 0 warnings, 32/32 tests pass.
2026-06-09 20:36:30 -04:00

84 lines
3.1 KiB
Swift

import XCTest
@testable import CurtainShared
final class RevealComboTests: XCTestCase {
// Documented CGEventFlags raw masks.
private let cmd: UInt64 = 0x100000
private let shift: UInt64 = 0x20000
private let control: UInt64 = 0x40000
private let option: UInt64 = 0x80000
private let capsLock: UInt64 = 0x10000
private let fn: UInt64 = 0x800000
// The "L" key: keycode 37, char "l".
private let lKeycode = 37
func testMatchesCmdShiftL() {
XCTAssertTrue(RevealCombo.matches(
combo: "cmd+shift+l", keycode: lKeycode, chars: "l", flagsRawValue: cmd | shift))
}
func testRejectsWrongKey() {
XCTAssertFalse(RevealCombo.matches(
combo: "cmd+shift+l", keycode: 0, chars: "a", flagsRawValue: cmd | shift))
}
func testRejectsMissingModifier() {
// Only cmd held, shift required too.
XCTAssertFalse(RevealCombo.matches(
combo: "cmd+shift+l", keycode: lKeycode, chars: "l", flagsRawValue: cmd))
}
func testRejectsExtraModifier() {
// control is held but not part of the combo: exact-match rejects it.
XCTAssertFalse(RevealCombo.matches(
combo: "cmd+shift+l", keycode: lKeycode, chars: "l", flagsRawValue: cmd | shift | control))
}
func testNamedKeySpace() {
XCTAssertTrue(RevealCombo.matches(
combo: "cmd+space", keycode: 49, chars: " ", flagsRawValue: cmd))
XCTAssertFalse(RevealCombo.matches(
combo: "cmd+space", keycode: 36, chars: nil, flagsRawValue: cmd))
}
func testNamedKeysReturnEscDelete() {
XCTAssertTrue(RevealCombo.matches(
combo: "ctrl+return", keycode: 36, chars: nil, flagsRawValue: control))
XCTAssertTrue(RevealCombo.matches(
combo: "cmd+esc", keycode: 53, chars: nil, flagsRawValue: cmd))
XCTAssertTrue(RevealCombo.matches(
combo: "cmd+delete", keycode: 51, chars: nil, flagsRawValue: cmd))
}
func testIgnoresCapsLockAndFnBits() {
XCTAssertTrue(RevealCombo.matches(
combo: "cmd+shift+l", keycode: lKeycode, chars: "l",
flagsRawValue: cmd | shift | capsLock | fn))
}
func testCaseInsensitiveChar() {
XCTAssertTrue(RevealCombo.matches(
combo: "cmd+shift+l", keycode: lKeycode, chars: "L", flagsRawValue: cmd | shift))
XCTAssertTrue(RevealCombo.matches(
combo: "CMD+SHIFT+L", keycode: lKeycode, chars: "l", flagsRawValue: cmd | shift))
}
func testOptionAndControlNames() {
XCTAssertTrue(RevealCombo.matches(
combo: "opt+a", keycode: 0, chars: "a", flagsRawValue: option))
XCTAssertTrue(RevealCombo.matches(
combo: "alt+a", keycode: 0, chars: "a", flagsRawValue: option))
}
func testEmptyComboIsFalse() {
XCTAssertFalse(RevealCombo.matches(
combo: "", keycode: 0, chars: "a", flagsRawValue: 0))
}
func testModifierOnlyComboIsFalse() {
// No final key part, so nothing to match.
XCTAssertFalse(RevealCombo.matches(
combo: "cmd+shift", keycode: 0, chars: "a", flagsRawValue: cmd | shift))
}
}