aboutsummaryrefslogtreecommitdiff
path: root/ber/int_test.go
blob: 9a015c5b0b16b67a56308983b6b60eb8b2637712 (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
package ber

import (
	"bytes"
	"testing"
)

func testInt(t *testing.T, i int64, b []byte) {
	a := marshalInt(i)
	if !bytes.Equal(a, b) {
		t.Error("BER", i, "expected", b, "got", a)
	}

	n := unmarshalInt(b)
	if n != i {
		t.Error("UnBER", b, "expected", i, "got", n)
	}

}

func TestInt(t *testing.T) {
	testInt(t, 0, []byte{0x00})
	testInt(t, 127, []byte{0x7F})
	testInt(t, 128, []byte{0x00, 0x80})
	testInt(t, 256, []byte{0x01, 0x00})
	testInt(t, -128, []byte{0x80})
	testInt(t, -129, []byte{0xFF, 0x7F})

	testInt(t, 8388607, []byte{0x7f, 0xFF, 0xFF})
	testInt(t, -136, []byte{0xFF, 0x78})
	testInt(t, -8388607, []byte{0x80, 0x00, 0x01})
}