aboutsummaryrefslogtreecommitdiff
path: root/ber/obj_test.go
blob: d8299bb8497c58521f7ce1408d545a17f827656a (plain)
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
package ber

import (
	"bytes"
	"testing"
)

func testBase128(t *testing.T, n int, e []byte) {
	a := base128(n)
	if !bytes.Equal(a, e) {
		t.Error("Base128", n, "expexted", e, "got", a)
	}
}

func TestBase128(t *testing.T) {
	testBase128(t, 643, []byte{0x85, 0x03})
	testBase128(t, 113549, []byte{0x86, 0xF7, 0x0D})
	testBase128(t, 49152, []byte{0x83, 0x80, 0x00})
}

func testObj(t *testing.T, o []int, e []byte) {
	a := marshalObj(o)
	if !bytes.Equal(a, e) {
		t.Error("Obj", o, "expexted", e, "got", a)
	}
}

func TestObj(t *testing.T) {
	testObj(t, []int{1, 3, 12, 0, 218},
		[]byte{0x2B, 0x0C, 0x00, 0x81, 0x5A})
	testObj(t, []int{1, 3, 12, 0, 285, 200},
		[]byte{0x2B, 0x0C, 0x00, 0x82, 0x1D, 0x81, 0x48})
}