2014-06-02 21:33:02 +00:00
|
|
|
package frame
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-06-09 22:19:44 +00:00
|
|
|
func TestDecodeULEB128(t *testing.T) {
|
2014-06-02 21:33:02 +00:00
|
|
|
var leb128 = bytes.NewBuffer([]byte{0xE5, 0x8E, 0x26})
|
|
|
|
|
2014-06-07 00:23:09 +00:00
|
|
|
n, c := decodeULEB128(leb128)
|
2014-06-02 21:33:02 +00:00
|
|
|
if n != 624485 {
|
|
|
|
t.Fatal("Number was not decoded properly, got: ", n, c)
|
|
|
|
}
|
2014-06-25 19:14:29 +00:00
|
|
|
|
|
|
|
if c != 3 {
|
|
|
|
t.Fatal("Count not returned correctly")
|
|
|
|
}
|
2014-06-02 21:33:02 +00:00
|
|
|
}
|
|
|
|
|
2014-06-09 22:19:44 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-02 21:33:02 +00:00
|
|
|
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) {
|
2014-06-25 19:14:29 +00:00
|
|
|
var (
|
|
|
|
data = grabDebugFrameSection("../_fixtures/testprog", t)
|
|
|
|
fe = Parse(data)[0]
|
|
|
|
ce = fe.CIE
|
|
|
|
)
|
2014-06-02 21:33:02 +00:00
|
|
|
|
|
|
|
if ce.Length != 16 {
|
2014-06-25 19:14:29 +00:00
|
|
|
t.Error("Length was not parsed correctly, got ", ce.Length)
|
2014-06-02 21:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ce.Version != 0x3 {
|
2014-06-25 19:14:29 +00:00
|
|
|
t.Fatalf("Version was not parsed correctly expected %#v got %#v", 0x3, ce.Version)
|
2014-06-02 21:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ce.Augmentation != "" {
|
|
|
|
t.Fatal("Augmentation was not parsed correctly")
|
|
|
|
}
|
|
|
|
|
|
|
|
if ce.CodeAlignmentFactor != 0x1 {
|
|
|
|
t.Fatal("Code Alignment Factor was not parsed correctly")
|
|
|
|
}
|
|
|
|
|
2014-06-09 22:24:48 +00:00
|
|
|
if ce.DataAlignmentFactor != -4 {
|
|
|
|
t.Fatalf("Data Alignment Factor was not parsed correctly got %#v", ce.DataAlignmentFactor)
|
2014-06-02 21:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if fe.Length != 32 {
|
2014-06-25 19:14:29 +00:00
|
|
|
t.Fatal("Length was not parsed correctly, got ", fe.Length)
|
2014-06-02 21:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|