aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kulikov2018-04-08 15:43:14 +0300
committerAlexander Kulikov2018-04-08 15:43:14 +0300
commit4cffa496a5deba17d84af93509d1b37eb4ccd243 (patch)
tree59cd6325d1b3b1fe9865854cfa936a54801ef072
parent9db10538d29eaf16e2f2c3033e73b007865e11a6 (diff)
downloadsystray-4cffa496a5deba17d84af93509d1b37eb4ccd243.tar.bz2
windows: improved tests
-rw-r--r--systray_windows_test.go47
1 files changed, 41 insertions, 6 deletions
diff --git a/systray_windows_test.go b/systray_windows_test.go
index 0fcb1e5..7cb6c75 100644
--- a/systray_windows_test.go
+++ b/systray_windows_test.go
@@ -3,15 +3,22 @@
package systray
import (
- "testing"
+ "io/ioutil"
+ "runtime"
"sync/atomic"
+ "testing"
"time"
- "golang.org/x/sys/windows"
"unsafe"
- "runtime"
+
+ "golang.org/x/sys/windows"
)
+const iconFilePath = "example/icon/iconwin.ico"
+
func TestBaseWindowsTray(t *testing.T) {
+ systrayReady = func() {}
+ systrayExit = func() {}
+
runtime.LockOSThread()
if err := wt.initInstance(); err != nil {
@@ -24,10 +31,10 @@ func TestBaseWindowsTray(t *testing.T) {
defer func() {
pDestroyWindow.Call(uintptr(wt.window))
- wt.wcex.Unregister()
+ wt.wcex.unregister()
}()
- if err := wt.setIcon("example/icon/iconwin.ico"); err != nil {
+ if err := wt.setIcon(iconFilePath); err != nil {
t.Errorf("SetIcon failed: %s", err)
}
@@ -72,7 +79,7 @@ func TestBaseWindowsTray(t *testing.T) {
t.Errorf("mergeMenuItem failed: %s", err)
}
- time.AfterFunc(3*time.Second, quit)
+ time.AfterFunc(1*time.Second, quit)
m := struct {
WindowHandle windows.Handle
@@ -95,3 +102,31 @@ func TestBaseWindowsTray(t *testing.T) {
pDispatchMessage.Call(uintptr(unsafe.Pointer(&m)))
}
}
+
+func TestWindowsRun(t *testing.T) {
+ onReady := func() {
+ b, err := ioutil.ReadFile(iconFilePath)
+ if err != nil {
+ t.Fatalf("Can't load icon file: %v", err)
+ }
+ SetIcon(b)
+ SetTitle("Test title с кириллицей")
+
+ bSomeBtn := AddMenuItem("Йа кнопко", "")
+ bSomeBtn.Check()
+ AddSeparator()
+ bQuit := AddMenuItem("Quit", "Quit the whole app")
+ go func() {
+ <-bQuit.ClickedCh
+ t.Log("Quit reqested")
+ Quit()
+ }()
+ time.AfterFunc(1*time.Second, Quit)
+ }
+
+ onExit := func() {
+ t.Log("Exit success")
+ }
+
+ Run(onReady, onExit)
+}