-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplatform_test.go
More file actions
261 lines (235 loc) · 7.08 KB
/
Copy pathplatform_test.go
File metadata and controls
261 lines (235 loc) · 7.08 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
// Copyright 2026 The gogpu Authors
// SPDX-License-Identifier: MIT
package gpucontext
import "testing"
func TestNullPlatformProvider_ClipboardRead(t *testing.T) {
var pp PlatformProvider = NullPlatformProvider{}
text, err := pp.ClipboardRead()
if text != "" {
t.Errorf("ClipboardRead() text = %q, want empty", text)
}
if err != nil {
t.Errorf("ClipboardRead() err = %v, want nil", err)
}
}
func TestNullPlatformProvider_ClipboardWrite(t *testing.T) {
var pp PlatformProvider = NullPlatformProvider{}
err := pp.ClipboardWrite("hello")
if err != nil {
t.Errorf("ClipboardWrite() err = %v, want nil", err)
}
}
func TestNullPlatformProvider_SetCursor(t *testing.T) {
var pp PlatformProvider = NullPlatformProvider{}
// All cursor shapes should be accepted without panic
cursors := []CursorShape{
CursorDefault, CursorPointer, CursorText, CursorCrosshair,
CursorMove, CursorResizeNS, CursorResizeEW, CursorResizeNWSE,
CursorResizeNESW, CursorNotAllowed, CursorWait, CursorNone,
}
for _, c := range cursors {
pp.SetCursor(c)
}
}
func TestNullPlatformProvider_Defaults(t *testing.T) {
var pp PlatformProvider = NullPlatformProvider{}
if pp.DarkMode() {
t.Error("DarkMode() should return false")
}
if pp.ReduceMotion() {
t.Error("ReduceMotion() should return false")
}
if pp.HighContrast() {
t.Error("HighContrast() should return false")
}
if got := pp.FontScale(); got != 1.0 {
t.Errorf("FontScale() = %f, want 1.0", got)
}
if got := pp.SubpixelLayout(); got != SubpixelNone {
t.Errorf("SubpixelLayout() = %v, want SubpixelNone", got)
}
if got := pp.FontSmoothing(); got != FontSmoothingGrayscale {
t.Errorf("FontSmoothing() = %v, want FontSmoothingGrayscale", got)
}
}
func TestCursorShape_String(t *testing.T) {
tests := []struct {
cursor CursorShape
want string
}{
{CursorDefault, "Default"},
{CursorPointer, "Pointer"},
{CursorText, "Text"},
{CursorCrosshair, "Crosshair"},
{CursorMove, "Move"},
{CursorResizeNS, "ResizeNS"},
{CursorResizeEW, "ResizeEW"},
{CursorResizeNWSE, "ResizeNWSE"},
{CursorResizeNESW, "ResizeNESW"},
{CursorNotAllowed, "NotAllowed"},
{CursorWait, "Wait"},
{CursorNone, "None"},
{CursorShape(99), "Unknown"},
}
for _, tt := range tests {
t.Run(tt.want, func(t *testing.T) {
if got := tt.cursor.String(); got != tt.want {
t.Errorf("CursorShape(%d).String() = %q, want %q", tt.cursor, got, tt.want)
}
})
}
}
func TestCursorShape_Values(t *testing.T) {
// Verify cursor shape constants are sequential starting from 0
if CursorDefault != 0 {
t.Errorf("CursorDefault = %d, want 0", CursorDefault)
}
if CursorPointer != 1 {
t.Errorf("CursorPointer = %d, want 1", CursorPointer)
}
if CursorText != 2 {
t.Errorf("CursorText = %d, want 2", CursorText)
}
if CursorCrosshair != 3 {
t.Errorf("CursorCrosshair = %d, want 3", CursorCrosshair)
}
if CursorMove != 4 {
t.Errorf("CursorMove = %d, want 4", CursorMove)
}
if CursorResizeNS != 5 {
t.Errorf("CursorResizeNS = %d, want 5", CursorResizeNS)
}
if CursorResizeEW != 6 {
t.Errorf("CursorResizeEW = %d, want 6", CursorResizeEW)
}
if CursorResizeNWSE != 7 {
t.Errorf("CursorResizeNWSE = %d, want 7", CursorResizeNWSE)
}
if CursorResizeNESW != 8 {
t.Errorf("CursorResizeNESW = %d, want 8", CursorResizeNESW)
}
if CursorNotAllowed != 9 {
t.Errorf("CursorNotAllowed = %d, want 9", CursorNotAllowed)
}
if CursorWait != 10 {
t.Errorf("CursorWait = %d, want 10", CursorWait)
}
if CursorNone != 11 {
t.Errorf("CursorNone = %d, want 11", CursorNone)
}
}
// mockPlatformProvider verifies the interface can be implemented by custom types.
type mockPlatformProvider struct {
clipboard string
cursor CursorShape
darkMode bool
reduceMotion bool
highContrast bool
fontScale float32
}
func (m *mockPlatformProvider) ClipboardRead() (string, error) { return m.clipboard, nil }
func (m *mockPlatformProvider) ClipboardWrite(text string) error {
m.clipboard = text
return nil
}
func (m *mockPlatformProvider) SetCursor(cursor CursorShape) { m.cursor = cursor }
func (m *mockPlatformProvider) DarkMode() bool { return m.darkMode }
func (m *mockPlatformProvider) ReduceMotion() bool { return m.reduceMotion }
func (m *mockPlatformProvider) HighContrast() bool { return m.highContrast }
func (m *mockPlatformProvider) FontScale() float32 { return m.fontScale }
func (m *mockPlatformProvider) SubpixelLayout() SubpixelLayout { return SubpixelRGB }
func (m *mockPlatformProvider) FontSmoothing() FontSmoothing { return FontSmoothingSubpixel }
// Ensure mockPlatformProvider implements PlatformProvider.
var _ PlatformProvider = &mockPlatformProvider{}
func TestPlatformProvider_CustomImplementation(t *testing.T) {
mock := &mockPlatformProvider{
darkMode: true,
reduceMotion: true,
highContrast: true,
fontScale: 1.5,
}
var pp PlatformProvider = mock
// Test clipboard round-trip
err := pp.ClipboardWrite("test clipboard")
if err != nil {
t.Fatalf("ClipboardWrite() err = %v", err)
}
text, err := pp.ClipboardRead()
if err != nil {
t.Fatalf("ClipboardRead() err = %v", err)
}
if text != "test clipboard" {
t.Errorf("ClipboardRead() = %q, want \"test clipboard\"", text)
}
// Test cursor
pp.SetCursor(CursorPointer)
if mock.cursor != CursorPointer {
t.Errorf("cursor = %v, want CursorPointer", mock.cursor)
}
// Test system preferences
if !pp.DarkMode() {
t.Error("DarkMode() should return true")
}
if !pp.ReduceMotion() {
t.Error("ReduceMotion() should return true")
}
if !pp.HighContrast() {
t.Error("HighContrast() should return true")
}
if got := pp.FontScale(); got != 1.5 {
t.Errorf("FontScale() = %f, want 1.5", got)
}
// Test font smoothing delegation
if got := pp.FontSmoothing(); got != FontSmoothingSubpixel {
t.Errorf("FontSmoothing() = %v, want FontSmoothingSubpixel", got)
}
}
func TestFontSmoothing_String(t *testing.T) {
tests := []struct {
fs FontSmoothing
want string
}{
{FontSmoothingNone, "None"},
{FontSmoothingGrayscale, "Grayscale"},
{FontSmoothingSubpixel, "Subpixel"},
{FontSmoothing(99), "Unknown"},
}
for _, tt := range tests {
t.Run(tt.want, func(t *testing.T) {
if got := tt.fs.String(); got != tt.want {
t.Errorf("FontSmoothing(%d).String() = %q, want %q", tt.fs, got, tt.want)
}
})
}
}
func TestFontSmoothing_Values(t *testing.T) {
if FontSmoothingNone != 0 {
t.Errorf("FontSmoothingNone = %d, want 0", FontSmoothingNone)
}
if FontSmoothingGrayscale != 1 {
t.Errorf("FontSmoothingGrayscale = %d, want 1", FontSmoothingGrayscale)
}
if FontSmoothingSubpixel != 2 {
t.Errorf("FontSmoothingSubpixel = %d, want 2", FontSmoothingSubpixel)
}
}
func TestSubpixelLayout_String(t *testing.T) {
tests := []struct {
sl SubpixelLayout
want string
}{
{SubpixelNone, "None"},
{SubpixelRGB, "RGB"},
{SubpixelBGR, "BGR"},
{SubpixelVRGB, "VRGB"},
{SubpixelVBGR, "VBGR"},
{SubpixelLayout(99), "Unknown"},
}
for _, tt := range tests {
t.Run(tt.want, func(t *testing.T) {
if got := tt.sl.String(); got != tt.want {
t.Errorf("SubpixelLayout(%d).String() = %q, want %q", tt.sl, got, tt.want)
}
})
}
}