Beispiel #1
0
func BenchmarkRemaining(b *testing.B) {
	d := dec.New(tBuf)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		d.Remaining()
	}
}
Beispiel #2
0
func BenchmarkInt16BE(b *testing.B) {
	d := dec.New(tBuf)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		d.BE.Int16()
		d.Reset()
	}
}
Beispiel #3
0
func BenchmarkString(b *testing.B) {
	d := dec.New(tBuf)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		d.String(len(tBuf))
		d.Reset()
	}
}
Beispiel #4
0
func TestString(t *testing.T) {
	d := dec.New(tBuf)

	act := d.String(len(tBuf))
	exp := "Hello, 世界\x23\x10\x00"
	if act != exp {
		t.Logf("act('%s') != exp('%s')", act, exp)
		t.Fail()
	}
}
Beispiel #5
0
func TestRemaining(t *testing.T) {
	d := dec.New(tBuf)
	for i := 0; i < len(tBuf); i++ {
		d.BE.Uint8()
	}

	if d.Remaining() != 0 {
		t.Logf("act(0x%02x) != exp(0x00)", d.Remaining())
		t.Fail()
	}
}
Beispiel #6
0
func TestInt64BE(t *testing.T) {
	d := dec.New(tBuf)
	i := 0
	for d.Remaining() > 0 {
		exp := tExpU64BE[i]
		act := uint64(d.BE.Int64())
		if act != exp {
			t.Logf("act(0x%16x) != exp(0x%16x)", act, exp)
			t.Fail()
		}
		i++
	}
}
Beispiel #7
0
func TestReset(t *testing.T) {
	d := dec.New(tBuf)
	for d.Remaining() > 0 {
		d.BE.Uint8()
	}

	d.Reset()

	if d.Remaining() != len(tBuf) {
		t.Logf("act(0x%02x) != exp(0x%02x)", d.Remaining(), len(tBuf))
		t.Fail()
	}
}
func TestInt32LE(t *testing.T) {
	d := dec.New(tBuf)
	i := 0
	for d.Remaining() > 0 {
		exp := tExpU32LE[i]
		act := uint32(d.LE.Int32())
		if act != exp {
			t.Logf("act(0x%08x) != exp(0x%08x)", act, exp)
			t.Fail()
		}
		i++
	}
}