diff options
Diffstat (limited to 'systray_windows_test.go')
| -rw-r--r-- | systray_windows_test.go | 47 |
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) +} |
