File: wstring_test.go

package info (click to toggle)
golang-github-microsoft-go-winio 0.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 764 kB
  • sloc: makefile: 3
file content (45 lines) | stat: -rw-r--r-- 992 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//go:build windows

package stringbuffer

import "testing"

func Test_BufferCapacity(t *testing.T) {
	b := NewWString()

	c := b.Cap()
	if c < MinWStringCap {
		t.Fatalf("expected capacity >= %d, got %d", MinWStringCap, c)
	}

	if l := len(b.b); l != int(c) {
		t.Fatalf("buffer length (%d) and capacity (%d) mismatch", l, c)
	}

	n := uint32(1.5 * MinWStringCap)
	nn := b.ResizeTo(n)
	if len(b.b) != int(nn) {
		t.Fatalf("resized buffer should be %d, was %d", nn, len(b.b))
	}
	if n > nn {
		t.Fatalf("resized to a value smaller than requested")
	}
}

func Test_BufferFree(t *testing.T) {
	// make sure free-ing doesn't set pooled buffer to nil as well
	for i := 0; i < 256; i++ {
		// try allocating and freeing repeatedly since pool does not guarantee item reuse
		b := NewWString()
		b.Free()
		if b.b != nil {
			t.Fatalf("freed buffer is not nil")
		}

		b = NewWString()
		c := b.Cap()
		if c < MinWStringCap {
			t.Fatalf("expected capacity >= %d, got %d", MinWStringCap, c)
		}
	}
}