forked from DeziderMesko/gssapi
-
Notifications
You must be signed in to change notification settings - Fork 2
/
buffer_test.go
67 lines (59 loc) · 1.37 KB
/
buffer_test.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2013-2015 Apcera Inc. All rights reserved.
package gssapi
import (
"bytes"
"testing"
)
func TestNewBuffer(t *testing.T) {
l, err := testLoad()
if err != nil {
t.Fatal(err)
}
defer l.Unload()
for a := range []int{allocNone, allocMalloc, allocGSSAPI} {
b, err := l.MakeBuffer(a)
if err != nil {
t.Fatalf("alloc: %v: %s", a, err)
}
defer b.Release()
if b == nil {
t.Fatalf("alloc: %v: Got nil, expected non-nil", a)
}
if b.Lib != l {
t.Fatalf("alloc: %v: b.Lib didn't get set correctly, got %p, expected %p",
a, b.Lib, l)
}
if b.C_gss_buffer_t == nil {
t.Fatalf("alloc: %v: Got nil buffer, expected non-nil", a)
}
if b.String() != "" {
t.Fatalf(`alloc: %v: String(): got %q, expected ""`,
a, b.String())
}
}
}
// Also tests MakeBufferBytes, implicitly
func TestMakeBufferString(t *testing.T) {
l, err := testLoad()
if err != nil {
t.Fatal(err)
}
defer l.Unload()
test := "testing"
b, err := l.MakeBufferString(test)
if err != nil {
t.Fatal(err)
}
defer b.Release()
if b == nil {
t.Fatal("Got nil, expected non-nil")
}
if b.Lib != l {
t.Fatalf("b.Lib didn't get set correctly, got %p, expected %p", b.Lib, l)
}
if b.String() != test {
t.Fatalf("Got %q, expected %q", b.String(), test)
} else if !bytes.Equal(b.Bytes(), []byte(test)) {
t.Fatalf("Got '%v'; expected '%v'", b.Bytes(), []byte(test))
}
}