robotgo/robotgo_test.go

197 lines
3.3 KiB
Go
Raw Permalink Normal View History

2019-04-23 17:35:39 +00:00
// Copyright 2016 The go-vgo Project Developers. 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> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
2019-04-23 17:44:59 +00:00
// +build darwin windows
2019-04-23 17:35:39 +00:00
package robotgo
import (
"testing"
"github.com/vcaesar/tt"
)
2020-02-13 13:40:43 +00:00
func TestColor(t *testing.T) {
s := GetPixelColor(10, 10)
tt.IsType(t, "string", s)
tt.NotEmpty(t, s)
c := GetPxColor(10, 10)
s1 := PadHex(c)
tt.Equal(t, s, s1)
}
func TestSize(t *testing.T) {
x, y := GetScreenSize()
tt.NotZero(t, x)
tt.NotZero(t, y)
x, y = GetScaleSize()
tt.NotZero(t, x)
tt.NotZero(t, y)
2020-02-13 13:40:43 +00:00
}
2019-11-24 11:18:04 +00:00
func TestMoveMouse(t *testing.T) {
MoveMouse(20, 20)
2019-11-24 11:28:38 +00:00
MilliSleep(10)
2019-04-23 17:35:39 +00:00
x, y := GetMousePos()
tt.Equal(t, 20, x)
tt.Equal(t, 20, y)
2019-04-23 17:35:39 +00:00
}
2019-11-24 11:18:04 +00:00
func TestMoveMouseSmooth(t *testing.T) {
2020-02-18 16:34:10 +00:00
b := MoveMouseSmooth(100, 100)
2019-11-24 11:28:38 +00:00
MilliSleep(10)
2019-11-24 11:18:04 +00:00
x, y := GetMousePos()
2020-02-18 16:34:10 +00:00
tt.True(t, b)
2019-11-24 11:18:04 +00:00
tt.Equal(t, 100, x)
tt.Equal(t, 100, y)
}
2019-11-24 11:28:38 +00:00
func TestDragMouse(t *testing.T) {
DragMouse(500, 500)
2019-11-24 11:28:38 +00:00
MilliSleep(10)
x, y := GetMousePos()
tt.Equal(t, 500, x)
tt.Equal(t, 500, y)
}
func TestScrollMouse(t *testing.T) {
ScrollMouse(120, "up")
MilliSleep(100)
Scroll(210, 210)
2019-11-24 11:28:38 +00:00
}
func TestMoveRelative(t *testing.T) {
Move(200, 200)
MilliSleep(10)
MoveRelative(10, -10)
MilliSleep(10)
x, y := GetMousePos()
tt.Equal(t, 210, x)
tt.Equal(t, 190, y)
}
func TestMoveSmoothRelative(t *testing.T) {
Move(200, 200)
MilliSleep(10)
MoveSmoothRelative(10, -10)
MilliSleep(10)
x, y := GetMousePos()
tt.Equal(t, 210, x)
tt.Equal(t, 190, y)
}
func TestMouseToggle(t *testing.T) {
e := MouseToggle("up", "right")
tt.Zero(t, e)
}
2020-02-12 14:01:43 +00:00
func TestKey(t *testing.T) {
e := KeyTap("v", "cmd")
tt.Empty(t, e)
e = KeyToggle("v", "up")
tt.Empty(t, e)
}
func TestClip(t *testing.T) {
err := WriteAll("s")
tt.Nil(t, err)
s, e := ReadAll()
tt.Equal(t, "s", s)
tt.Nil(t, e)
}
2020-02-12 14:01:43 +00:00
func TestTypeStr(t *testing.T) {
c := CharCodeAt("s", 0)
tt.Equal(t, 115, c)
2020-02-18 16:37:13 +00:00
e := PasteStr("s")
tt.Empty(t, e)
uc := toUC("s")
tt.Equal(t, "[s]", uc)
2020-02-12 14:01:43 +00:00
}
2020-02-25 15:48:28 +00:00
func TestKeyCode(t *testing.T) {
m := MouseMap["left"]
tt.Equal(t, 1, m)
k := Keycode["1"]
tt.Equal(t, 2, k)
}
func TestBitmap(t *testing.T) {
bit := CaptureScreen()
tt.NotNil(t, bit)
e := SaveBitmap(bit, "robot_test.png")
tt.Empty(t, e)
2020-01-26 16:49:44 +00:00
bit1 := OpenBitmap("robot_test.png")
b := tt.TypeOf(bit, bit1)
tt.True(t, b)
tt.NotNil(t, bit1)
}
2020-03-23 19:34:33 +00:00
2020-04-17 15:34:23 +00:00
func TestPs(t *testing.T) {
id, err := Pids()
tt.Not(t, "[]", id)
tt.IsType(t, "[]int32", id)
tt.Nil(t, err)
2020-04-18 18:20:25 +00:00
ps, e := Process()
tt.Not(t, "[]", ps)
tt.IsType(t, "[]robotgo.Nps", ps)
2020-05-01 15:40:41 +00:00
tt.Nil(t, e)
2020-04-18 18:20:25 +00:00
2020-04-17 15:34:23 +00:00
b, e := PidExists(id[0])
tt.Bool(t, b)
tt.Nil(t, e)
n, e := FindName(id[0])
tt.NotEmpty(t, n)
tt.Nil(t, e)
2020-04-18 18:21:53 +00:00
n1, e := FindNames()
tt.Not(t, "[]", n1)
tt.IsType(t, "[]string", n1)
tt.Nil(t, e)
id, err = FindIds(n1[0])
tt.Not(t, "[]", id)
tt.IsType(t, "[]int32", id)
tt.Nil(t, err)
2020-04-30 15:30:21 +00:00
// n, e = FindPath(id[0])
// tt.NotEmpty(t, n)
// tt.Nil(t, e)
2020-04-17 15:34:23 +00:00
}
// func TestAlert(t *testing.T) {
// go func() {
// MilliSleep(200)
// KeyTap("enter")
// log.Println("tap...")
// }()
2020-03-23 19:34:33 +00:00
// i := ShowAlert("t", "msg")
// tt.Zero(t, i)
// }