Source file src/internal/syscall/windows/syscall_windows_test.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     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