| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- //go:build windows && (amd64 || arm64)
- package nativehost
- import (
- "github.com/wailsapp/go-webview2/pkg/combridge"
- "golang.org/x/sys/windows"
- "syscall"
- "testing"
- "unsafe"
- )
- func TestWindowsCallbackABI(t *testing.T) {
- if unsafe.Sizeof(winRect{}) != 16 || unsafe.Sizeof(winMessage{}) != 48 || unsafe.Sizeof(winClass{}) != 80 {
- t.Fatal("Win32 layout mismatch")
- }
- called := false
- callback := combridge.New[protocolCallback](&cdpDone{fn: func(hr uintptr, value *uint16) {
- called = true
- if hr != 0 {
- t.Fatal(hr)
- }
- s, e := boundedUTF16(value, 16)
- if e != nil || s != "WebView2 世界" {
- t.Fatal(s, e)
- }
- }})
- value, _ := windows.UTF16PtrFromString("WebView2 世界")
- object := (*winObject)(unsafe.Pointer(combridge.IUnknownFromUintptr(callback.Ref())))
- hr, _, _ := syscall.SyscallN(object.table[3], callback.Ref(), 0, uintptr(unsafe.Pointer(value)))
- if hr != 0 || !called {
- t.Fatal("COM callback not invoked", hr)
- }
- if e := callback.Close(); e != nil {
- t.Fatal(e)
- }
- if hrError(0) != nil || hrError(1) != nil || hrError(0x80004005) == nil {
- t.Fatal("HRESULT sign decoding failed")
- }
- if s, e := boundedUTF16(nil, 1); e != nil || s != "" {
- t.Fatal(s, e)
- }
- if _, e := boundedUTF16(value, 1); e == nil {
- t.Fatal("unbounded UTF-16 accepted")
- }
- }
|