-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplatform_linux_test.go
More file actions
90 lines (74 loc) · 2.26 KB
/
platform_linux_test.go
File metadata and controls
90 lines (74 loc) · 2.26 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
//go:build linux
package main
import (
"testing"
)
func TestDetectInputMethod(t *testing.T) {
method := detectInputMethod()
validMethods := []string{"ibus", "fcitx", "fcitx5", "xkb"}
found := false
for _, valid := range validMethods {
if method == valid {
found = true
break
}
}
if !found {
t.Errorf("detectInputMethod() returned invalid method: %s", method)
}
}
func TestIsProcessRunning(t *testing.T) {
result := isProcessRunning("nonexistent-process-12345")
if result {
t.Error("isProcessRunning() should return false for non-existent process")
}
result = isProcessRunning("init")
if !result {
t.Error("isProcessRunning() should return true for init process")
}
}
func TestLinuxInputMethods(t *testing.T) {
testCases := []struct {
method string
getter func() string
lister func() []string
setter func(string) bool
}{
{"ibus", getCurrentInputSourceIBus, getAllInputSourcesIBus, setInputSourceIBus},
{"fcitx", getCurrentInputSourceFcitx, getAllInputSourcesFcitx, setInputSourceFcitx},
{"fcitx5", getCurrentInputSourceFcitx5, getAllInputSourcesFcitx5, setInputSourceFcitx5},
{"xkb", getCurrentInputSourceXKB, getAllInputSourcesXKB, setInputSourceXKB},
}
for _, tc := range testCases {
t.Run(tc.method, func(t *testing.T) {
current := tc.getter()
t.Logf("%s current input source: %s", tc.method, current)
sources := tc.lister()
if sources == nil {
t.Errorf("%s getAllInputSources returned nil", tc.method)
return
}
if len(sources) == 0 {
t.Errorf("%s getAllInputSources returned empty slice", tc.method)
return
}
validSource := sources[0]
result := tc.setter(validSource)
if tc.method != "xkb" && !result {
t.Logf("%s setInputSource may have failed (this is expected if %s is not running)", tc.method, tc.method)
}
})
}
}
func TestXKBInputSources(t *testing.T) {
sources := getAllInputSourcesXKB()
expectedSources := []string{"us", "gb", "de", "fr", "es", "it", "ru", "cn", "jp", "kr"}
if len(sources) != len(expectedSources) {
t.Errorf("Expected %d sources, got %d", len(expectedSources), len(sources))
}
for i, expected := range expectedSources {
if i >= len(sources) || sources[i] != expected {
t.Errorf("Expected source %s at index %d, got %s", expected, i, sources[i])
}
}
}