From 4cffa496a5deba17d84af93509d1b37eb4ccd243 Mon Sep 17 00:00:00 2001 From: Alexander Kulikov Date: Sun, 8 Apr 2018 15:43:14 +0300 Subject: windows: improved tests --- systray_windows_test.go | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file 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) +} -- cgit v1.2.3