-
Notifications
You must be signed in to change notification settings - Fork 0
/
ostr_test.go
69 lines (59 loc) · 1.8 KB
/
ostr_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
68
69
package dirsyn
import (
"fmt"
"testing"
)
func ExampleOctetString_IsZero() {
var oct OctetString
fmt.Println(oct.IsZero())
// Output: true
}
func TestOctetString(t *testing.T) {
var r RFC4517
for _, raw := range []string{
``,
`This is an OctetString.`,
} {
if oct, err := r.OctetString(raw); err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
} else if got := oct.String(); raw != got {
t.Errorf("%s failed:\nwant: %s\ngot: %s",
t.Name(), raw, got)
}
}
octet1 := OctetString{0x01, 0x02, 0x02}
octet2 := OctetString{0x01, 0x02, 0x02}
result, err := octetStringMatch(octet1, octet2)
if err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
} else if !result.True() {
t.Errorf("%s failed:\nwant: TRUE\ngot: %s", t.Name(), result)
}
octet1 = OctetString{0x01, 0x02, 0x03}
result, err = octetStringMatch(octet1, octet2)
if err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
return
} else if !result.False() {
t.Errorf("%s failed:\nwant: TRUE\ngot: %s", t.Name(), result)
return
}
result, err = octetStringOrderingMatch(octet1, octet2)
if err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
} else if !result.True() {
t.Errorf("%s failed:\nwant: TRUE\ngot: %s", t.Name(), result)
}
_, _ = octetStringMatch([]byte{}, []byte{})
_, _ = octetStringMatch([]byte{}, struct{}{})
_, _ = octetStringMatch(struct{}{}, []byte{})
_, _ = octetStringMatch([]byte{}, []byte{0x0})
_, _ = octetStringMatch([]byte{0x0}, []byte{})
_, _ = octetStringOrderingMatch([]byte{}, []byte{})
_, _ = octetStringOrderingMatch([]byte{}, struct{}{})
_, _ = octetStringOrderingMatch(struct{}{}, []byte{})
_, _ = octetStringOrderingMatch([]byte{0x0}, []byte{0x1, 0x2})
_, _ = octetStringOrderingMatch([]byte{0x1}, []byte{})
_ = octetString([]byte{})
_ = octetString([]byte{0x0, 0x1, 0x2})
}