frame_parser_test.go 1.4 KB
Newer Older
D
Derek Parker 已提交
1 2 3 4 5 6 7
package frame

import (
	"bytes"
	"testing"
)

8
func TestDecodeULEB128(t *testing.T) {
D
Derek Parker 已提交
9 10
	var leb128 = bytes.NewBuffer([]byte{0xE5, 0x8E, 0x26})

D
Derek Parker 已提交
11
	n, c := decodeULEB128(leb128)
D
Derek Parker 已提交
12 13 14
	if n != 624485 {
		t.Fatal("Number was not decoded properly, got: ", n, c)
	}
15 16 17 18

	if c != 3 {
		t.Fatal("Count not returned correctly")
	}
D
Derek Parker 已提交
19 20
}

21 22 23 24 25 26 27 28 29
func TestDecodeSLEB128(t *testing.T) {
	sleb128 := bytes.NewBuffer([]byte{0x9b, 0xf1, 0x59})

	n, c := decodeSLEB128(sleb128)
	if n != -624485 {
		t.Fatal("Number was not decoded properly, got: ", n, c)
	}
}

D
Derek Parker 已提交
30 31 32 33 34 35 36 37 38 39
func TestParseString(t *testing.T) {
	bstr := bytes.NewBuffer([]byte{'h', 'i', 0x0, 0xFF, 0xCC})
	str, _ := parseString(bstr)

	if str != "hi" {
		t.Fatal("String was not parsed correctly")
	}
}

func TestParse(t *testing.T) {
40 41 42 43 44
	var (
		data = grabDebugFrameSection("../_fixtures/testprog", t)
		fe   = Parse(data)[0]
		ce   = fe.CIE
	)
D
Derek Parker 已提交
45 46

	if ce.Length != 16 {
47
		t.Error("Length was not parsed correctly, got ", ce.Length)
D
Derek Parker 已提交
48 49 50
	}

	if ce.Version != 0x3 {
51
		t.Fatalf("Version was not parsed correctly expected %#v got %#v", 0x3, ce.Version)
D
Derek Parker 已提交
52 53 54 55 56 57 58 59 60 61
	}

	if ce.Augmentation != "" {
		t.Fatal("Augmentation was not parsed correctly")
	}

	if ce.CodeAlignmentFactor != 0x1 {
		t.Fatal("Code Alignment Factor was not parsed correctly")
	}

62 63
	if ce.DataAlignmentFactor != -4 {
		t.Fatalf("Data Alignment Factor was not parsed correctly got %#v", ce.DataAlignmentFactor)
D
Derek Parker 已提交
64 65 66
	}

	if fe.Length != 32 {
67
		t.Fatal("Length was not parsed correctly, got ", fe.Length)
D
Derek Parker 已提交
68 69 70
	}

}