tengri/Content/Input/Tests/FT_InputDeviceDetection.ts

126 lines
5.6 KiB
TypeScript

// Input/Tests/FT_InputDeviceDetection.ts
import { AC_InputDevice } from '#root/Input/Components/AC_InputDevice.ts';
import { AC_ToastSystem } from '#root/Toasts/Components/AC_ToastSystem.ts';
import { EFunctionalTestResult } from '#root/UE/EFunctionalTestResult.ts';
import { EHardwareDevicePrimaryType } from '#root/UE/EHardwareDevicePrimaryType.ts';
import { FunctionalTest } from '#root/UE/FunctionalTest.ts';
/**
* Functional Test: Input Device Detection System
* Tests event-driven device detection with minimal wrapper approach
* Validates initialization, device queries, and delegate events
*/
export class FT_InputDeviceDetection extends FunctionalTest {
// ════════════════════════════════════════════════════════════════════════════════════════
// GRAPHS
// ════════════════════════════════════════════════════════════════════════════════════════
// ────────────────────────────────────────────────────────────────────────────────────────
// EventGraph
// ────────────────────────────────────────────────────────────────────────────────────────
/**
* Test entry point - validates complete device detection workflow
* Tests initialization, device queries, and simulated device changes
*/
EventStartTest(): void {
// Initialize components
this.ToastSystemComponent.InitializeToastSystem();
this.InputDeviceComponent.InitializeDeviceDetection(
this.ToastSystemComponent
);
this.TestInitialization();
this.TestDeviceQueries();
this.FinishTest(EFunctionalTestResult.Succeeded);
}
// ════════════════════════════════════════════════════════════════════════════════════════
// TEST METHODS
// ════════════════════════════════════════════════════════════════════════════════════════
/**
* Test initialization and initial device detection
* @returns True if test passed
*/
private TestInitialization(): void {
// Validate initialization
if (this.InputDeviceComponent.IsInitialized) {
if (
this.InputDeviceComponent.GetCurrentInputDevice() !==
EHardwareDevicePrimaryType.Unspecified
) {
// Test passed
} else {
this.FinishTest(
EFunctionalTestResult.Failed,
'No initial device detected'
);
}
} else {
this.FinishTest(
EFunctionalTestResult.Failed,
'Input Device Detection failed to initialize'
);
}
}
/**
* Test device query functions consistency
* @returns True if test passed
*/
private TestDeviceQueries(): void {
const currentDevice = this.InputDeviceComponent.GetCurrentInputDevice();
const isKeyboard = this.InputDeviceComponent.IsKeyboard();
const isGamepad = this.InputDeviceComponent.IsGamepad();
// Validate that exactly one device type is active
if (!(isKeyboard && isGamepad)) {
if (isKeyboard || isGamepad) {
const expectedIsKeyboard =
currentDevice === EHardwareDevicePrimaryType.KeyboardAndMouse;
const expectedIsGamepad =
currentDevice === EHardwareDevicePrimaryType.Gamepad;
if (
isKeyboard === expectedIsKeyboard &&
isGamepad === expectedIsGamepad
) {
// Test passed
} else {
this.FinishTest(
EFunctionalTestResult.Failed,
'Device query functions inconsistent with GetCurrentInputDevice()'
);
}
} else {
this.FinishTest(
EFunctionalTestResult.Failed,
'Neither keyboard nor gamepad detected'
);
}
} else {
this.FinishTest(
EFunctionalTestResult.Failed,
'Both keyboard and gamepad detected simultaneously'
);
}
}
// ════════════════════════════════════════════════════════════════════════════════════════
// VARIABLES
// ════════════════════════════════════════════════════════════════════════════════════════
/**
* Input device detection system - component under test
* @category Components
*/
private InputDeviceComponent = new AC_InputDevice();
/**
* Toast notification system - required for device detection initialization
* @category Components
*/
private ToastSystemComponent = new AC_ToastSystem();
}