Repository navigation
Expand file tree
/
Copy pathrobotgo_purego_test.go
More file actions
91 lines (80 loc) · 2.65 KB
/
Copy pathrobotgo_purego_test.go
File metadata and controls
91 lines (80 loc) · 2.65 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
//go:build wayland || win || libei || mac || x11 || purego
// +build wayland win libei mac x11 purego
// Copyright (c) 2016-2026 AtomAI, All rights reserved.
//
// See the COPYRIGHT file at the top-level directory of this distribution and at
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0>
//
// This file may not be copied, modified, or distributed
// except according to those terms.
package robotgo
import (
"strconv"
"testing"
"github.com/go-vgo/robotgo/pub"
)
func TestIs64Bit(t *testing.T) {
if Is64Bit() != (strconv.IntSize == 64) {
t.Errorf("Is64Bit: got %v, want %v", Is64Bit(), strconv.IntSize == 64)
}
}
// Invalid code points must error before any key event is posted.
func TestUnicodeTypeInvalid(t *testing.T) {
for _, r := range []uint32{0xD800, 0x110000} {
if err := UnicodeType(r); err == nil {
t.Errorf("UnicodeType(%#x): want error", r)
}
}
}
// Handle mode follows Cgo: any extra arg or NotPid.
func TestIsHandle(t *testing.T) {
old := NotPid
defer func() { NotPid = old }()
NotPid = false
if isHandle(nil) || !isHandle([]int{1}) {
t.Error("isHandle: wrong result with NotPid=false")
}
NotPid = true
if !isHandle(nil) {
t.Error("isHandle: want true with NotPid=true")
}
}
// A non-positive count must not post any click.
func TestMultiClickNoop(t *testing.T) {
for _, n := range []int{0, -1} {
if err := MultiClick("left", n); err != nil {
t.Errorf("MultiClick(%d): got %v, want nil", n, err)
}
if err := clickTimes("left", n); err != nil {
t.Errorf("clickTimes(%d): got %v, want nil", n, err)
}
}
}
func TestRgbToHex(t *testing.T) {
if got := RgbToHex(0x12, 0xab, 0xff); got != 0x12abff {
t.Errorf("RgbToHex: got %#x, want 0x12abff", got)
}
if got := PadHex(RgbToHex(0, 0, 1)); got != "000001" {
t.Errorf("PadHex(RgbToHex(0, 0, 1)): got %q", got)
}
}
// TestDelaySync checks init copied the robotgo_pub.go config into pub;
// SetDelay keeping both in sync is covered by TestSetDelay.
func TestDelaySync(t *testing.T) {
if pub.DisplayID != DisplayID {
t.Fatalf("pub.DisplayID = %d, want %d", pub.DisplayID, DisplayID)
}
}
// KeyPress must dispatch to the backend's atomic KeyTap (via keyPress),
// not the shared down/sleep/up sequence: an unknown key fails exactly
// like KeyTap, before any key-down is posted.
func TestKeyPressUsesBackendTap(t *testing.T) {
const bad = "no_such_key"
errTap, errPress := KeyTap(bad), KeyPress(bad)
if errTap == nil || errPress == nil || errTap.Error() != errPress.Error() {
t.Fatalf("KeyPress(%q) = %v, want KeyTap error %v", bad, errPress, errTap)
}
}