Files
NimPulse/tests/test_tray_integration.nim
T

56 lines
2.0 KiB
Nim

## test_tray_integration.nim
## ==========================
## Test d'intégration Win32 : crée une vraie fenêtre cachée, puis exerce les
## interfaces publiques de `tray.nim` et `notifications.nim` contre les API
## réelles (user32/shell32) en vérifiant leurs codes de retour.
##
## Note : ce test fait brièvement apparaître une icône tray et une notification
## sur le bureau, puis nettoie tout à la fin.
import std/unittest
import winim/lean
import ../src/tray
import ../src/notifications
import ../src/timer
proc createTestWindow(): HWND =
let hInstance = GetModuleHandleW(nil)
var wc: WNDCLASSW
wc.lpfnWndProc = cast[WNDPROC](DefWindowProcW)
wc.hInstance = hInstance
wc.lpszClassName = L"NimPulseTestClass"
discard RegisterClass(&wc)
result = CreateWindowExW(0, L"NimPulseTestClass", L"", WS_OVERLAPPED,
0, 0, 0, 0, 0, 0, hInstance, nil)
suite "tray integration":
test "tray icon, dynamic icon, toast and hotkey succeed":
let hwnd = createTestWindow()
check hwnd != 0
# Génération des icônes dynamiques (GDI) pour les 5 états.
for phase in [phIdle, phWorking, phShortBreak, phLongBreak, phPaused]:
check phaseIcon(phase) != 0
# Ajout de l'icône dans le tray (Shell_NotifyIcon NIM_ADD -> bool).
check addTrayIcon(hwnd, phaseIcon(phIdle), "NimPulse") == true
# Mise à jour de l'icône et du tooltip.
updateTrayIcon(hwnd, phaseIcon(phWorking), "Travail: 25:00")
# Notification (NIF_INFO).
showToast(hwnd, "Test", "Notification d'intégration")
# Raccourci global (RegisterHotKey / UnregisterHotKey). Clé de test peu
# susceptible d'être déjà réservée (Ctrl+Alt+F10).
check RegisterHotKey(hwnd, 1'i32, MOD_CONTROL or MOD_ALT, 0x79) != 0
check UnregisterHotKey(hwnd, 1'i32) != 0
# Son de fin de période (alias système valide -> PlaySound retourne true).
check playSound("SystemAsterisk") == true
# Suppression de l'icône et de la fenêtre.
removeTrayIcon(hwnd)
discard DestroyWindow(hwnd)