1
2
3
4
5 package windows_test
6
7 import (
8 "internal/syscall/windows"
9 "strings"
10 "testing"
11 "unicode/utf16"
12 )
13
14 func TestUTF16PtrToStringAllocs(t *testing.T) {
15 msg := "Hello, world 🐻"
16 testUTF16PtrToStringAllocs(t, msg)
17 testUTF16PtrToStringAllocs(t, strings.Repeat(msg, 10))
18 }
19
20 func testUTF16PtrToStringAllocs(t *testing.T, msg string) {
21 in := utf16.Encode([]rune(msg + "\x00"))
22 var out string
23 alloccnt := testing.AllocsPerRun(1000, func() {
24 out = windows.UTF16PtrToString(&in[0])
25 })
26 if out != msg {
27 t.Errorf("windows.UTF16PtrToString(%v) returned %q; want %q", in, out, msg)
28 }
29 if alloccnt > 1.01 {
30 t.Errorf("windows.UTF16PtrToString(%v) made %v allocs per call; want 1", in, alloccnt)
31 }
32 }
33
View as plain text