-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitors_test.go
More file actions
90 lines (75 loc) · 2.16 KB
/
monitors_test.go
File metadata and controls
90 lines (75 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"testing"
)
func TestDetectMonitors_ReturnsNonEmptySlice(t *testing.T) {
// Arrange: sistema com pelo menos 1 monitor
// Act
monitors := detectMonitors()
// Assert
if monitors == nil {
t.Fatal("Expected non-nil slice, got nil")
}
// Em um sistema sem monitores (CI/headless), retorna slice vazio
// Em sistema com GUI, retorna pelo menos 1
if len(monitors) > 0 {
t.Logf("Detected %d monitor(s)", len(monitors))
} else {
t.Log("No monitors detected (headless environment)")
}
}
func TestDetectMonitors_ValidatesMonitorInfo(t *testing.T) {
// Arrange & Act
monitors := detectMonitors()
// Assert: se há monitores, devem ter informações válidas
for i, mon := range monitors {
// Validate width and height are positive
if mon.Width <= 0 {
t.Errorf("Monitor %d has invalid width: %d", i, mon.Width)
}
if mon.Height <= 0 {
t.Errorf("Monitor %d has invalid height: %d", i, mon.Height)
}
// Name should not be empty
if mon.Name == "" {
t.Errorf("Monitor %d has empty name", i)
}
t.Logf("Monitor %d: %s (%dx%d at %d,%d)",
i, mon.Name, mon.Width, mon.Height, mon.X, mon.Y)
}
}
func TestDetectMonitors_HandlesGlfwFailureGracefully(t *testing.T) {
// Arrange: Este teste verifica que não há panic se GLFW falhar
// (difícil de simular sem mock, mas garante que função existe)
// Act & Assert: não deve causar panic
defer func() {
if r := recover(); r != nil {
t.Errorf("detectMonitors() panicked: %v", r)
}
}()
monitors := detectMonitors()
// Deve retornar slice vazio (não nil) em caso de falha
if monitors == nil {
t.Error("Expected empty slice on failure, got nil")
}
}
func TestMonitorInfo_StructFields(t *testing.T) {
// Arrange: criar MonitorInfo para validar estrutura
info := MonitorInfo{
Name: "Test Monitor",
X: 0,
Y: 0,
Width: 1920,
Height: 1080,
}
// Assert: verificar que campos estão acessíveis
if info.Name != "Test Monitor" {
t.Errorf("Expected name 'Test Monitor', got '%s'", info.Name)
}
if info.Width != 1920 {
t.Errorf("Expected width 1920, got %d", info.Width)
}
if info.Height != 1080 {
t.Errorf("Expected height 1080, got %d", info.Height)
}
}