-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme_test.go
More file actions
220 lines (199 loc) · 4.89 KB
/
theme_test.go
File metadata and controls
220 lines (199 loc) · 4.89 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// theme_test.go
//go:build windows
// +build windows
package main
import (
"testing"
"golang.org/x/sys/windows/registry"
)
func TestThemeConstants(t *testing.T) {
tests := []struct {
name string
constant string
expected string
}{
{
name: "theme registry path",
constant: "themeRegistryPath",
expected: `Software\Microsoft\Windows\CurrentVersion\Themes\Personalize`,
},
{
name: "apps use light registry value",
constant: "regValAppsUseLight",
expected: "AppsUseLightTheme",
},
{
name: "system uses light registry value",
constant: "regValSystemUsesLight",
expected: "SystemUsesLightTheme",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
switch tt.constant {
case "themeRegistryPath":
if themeRegistryPath != tt.expected {
t.Errorf("themeRegistryPath = %s, want %s", themeRegistryPath, tt.expected)
}
case "regValAppsUseLight":
if regValAppsUseLight != tt.expected {
t.Errorf("regValAppsUseLight = %s, want %s", regValAppsUseLight, tt.expected)
}
case "regValSystemUsesLight":
if regValSystemUsesLight != tt.expected {
t.Errorf("regValSystemUsesLight = %s, want %s", regValSystemUsesLight, tt.expected)
}
}
})
}
}
func TestWithThemeRegistry(t *testing.T) {
tests := []struct {
name string
access uint32
shouldError bool
}{
{
name: "query access",
access: registry.QUERY_VALUE,
shouldError: false,
},
{
name: "read access",
access: registry.READ,
shouldError: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
called := false
err := withThemeRegistry(tt.access, func(key registry.Key) error {
called = true
return nil
})
if tt.shouldError && err == nil {
t.Error("Expected error but got none")
}
if !tt.shouldError && err != nil {
t.Errorf("Unexpected error: %v", err)
}
if !called && !tt.shouldError {
t.Error("Function was not called")
}
})
}
}
func TestGetCurrentAppThemeMode(t *testing.T) {
// This test attempts to read the actual theme registry
// It may fail if the registry key doesn't exist or access is denied
t.Run("read current app theme mode", func(t *testing.T) {
mode, err := getCurrentAppThemeMode()
if err != nil {
t.Logf("Expected behavior: could not read theme mode: %v", err)
return
}
// Valid values are 0 (dark) or 1 (light)
if mode != 0 && mode != 1 {
t.Errorf("getCurrentAppThemeMode() returned invalid mode: %d, expected 0 or 1", mode)
}
})
}
func TestSetBothThemeModes(t *testing.T) {
tests := []struct {
name string
lightMode bool
}{
{
name: "set to light mode",
lightMode: true,
},
{
name: "set to dark mode",
lightMode: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Note: This test may fail if we don't have write access to the registry
// or if we're not running with sufficient privileges
err := setBothThemeModes(tt.lightMode)
if err != nil {
t.Logf("Expected behavior on restricted systems: %v", err)
// Don't fail the test as this is expected behavior in many environments
return
}
// If successful, verify the values were set correctly
appMode, err := getCurrentAppThemeMode()
if err != nil {
t.Logf("Could not verify app mode after setting: %v", err)
return
}
expectedMode := uint64(0)
if tt.lightMode {
expectedMode = 1
}
if appMode != expectedMode {
t.Errorf("After setBothThemeModes(%v), app mode = %d, want %d", tt.lightMode, appMode, expectedMode)
}
})
}
}
func TestAppThemeMethods(t *testing.T) {
app := NewApp("test-version")
tests := []struct {
name string
testFunc func()
}{
{
name: "toggle app mode",
testFunc: func() {
app.toggleAppMode()
},
},
{
name: "toggle windows mode",
testFunc: func() {
app.toggleWindowsMode()
},
},
{
name: "toggle system mode",
testFunc: func() {
app.toggleSystemMode()
},
},
{
name: "update theme toggle titles",
testFunc: func() {
app.updateThemeToggleTitles()
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Skip these tests as they require systray initialization and registry write access
t.Skip("theme methods require systray initialization and registry access")
})
}
}
func TestToggleSingleTheme(t *testing.T) {
tests := []struct {
name string
registryKey string
}{
{
name: "toggle apps use light theme",
registryKey: regValAppsUseLight,
},
{
name: "toggle system uses light theme",
registryKey: regValSystemUsesLight,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Skip this test as it requires systray initialization and registry write access
t.Skip("toggleSingleTheme requires systray initialization and registry access")
})
}
}