...

Source file src/github.com/Microsoft/go-winio/internal/stringbuffer/wstring_test.go

Documentation: github.com/Microsoft/go-winio/internal/stringbuffer

     1  //go:build windows
     2  
     3  package stringbuffer
     4  
     5  import "testing"
     6  
     7  func Test_BufferCapacity(t *testing.T) {
     8  	b := NewWString()
     9  
    10  	c := b.Cap()
    11  	if c < MinWStringCap {
    12  		t.Fatalf("expected capacity >= %d, got %d", MinWStringCap, c)
    13  	}
    14  
    15  	if l := len(b.b); l != int(c) {
    16  		t.Fatalf("buffer length (%d) and capacity (%d) mismatch", l, c)
    17  	}
    18  
    19  	n := uint32(1.5 * MinWStringCap)
    20  	nn := b.ResizeTo(n)
    21  	if len(b.b) != int(nn) {
    22  		t.Fatalf("resized buffer should be %d, was %d", nn, len(b.b))
    23  	}
    24  	if n > nn {
    25  		t.Fatalf("resized to a value smaller than requested")
    26  	}
    27  }
    28  
    29  func Test_BufferFree(t *testing.T) {
    30  	// make sure free-ing doesn't set pooled buffer to nil as well
    31  	for i := 0; i < 256; i++ {
    32  		// try allocating and freeing repeatedly since pool does not guarantee item reuse
    33  		b := NewWString()
    34  		b.Free()
    35  		if b.b != nil {
    36  			t.Fatalf("freed buffer is not nil")
    37  		}
    38  
    39  		b = NewWString()
    40  		c := b.Cap()
    41  		if c < MinWStringCap {
    42  			t.Fatalf("expected capacity >= %d, got %d", MinWStringCap, c)
    43  		}
    44  	}
    45  }
    46  

View as plain text