示例#1
0
func BenchmarkInt16LE(b *testing.B) {
	d := enc.New(make([]uint8, 16))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		d.LE.PutInt16(-1)
		d.Reset()
	}
}
示例#2
0
func BenchmarkReset(b *testing.B) {
	buf := makeRndBuf()
	d := enc.New(buf)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		d.Reset()
	}
}
示例#3
0
func BenchmarkPutStringDelim(b *testing.B) {
	buf := makeRndBuf()
	d := enc.New(buf)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		d.PutStringDelim("Hello, 世界\x23\x10", '\x00')
		d.Reset()
	}
}
示例#4
0
func BenchmarkFill(b *testing.B) {
	buf := makeRndBuf()
	d := enc.New(buf)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		d.Fill(0xff, len(buf))
		d.Reset()
	}
}
示例#5
0
func TestPutString(t *testing.T) {
	buf := makeRndBuf()
	d := enc.New(buf)

	d.PutString("Hello, 世界\x23\x10\x00")
	if !bytes.Equal(buf, tExp) {
		t.Logf("act(%#v) != exp(%#v)", buf, tExp)
		t.Fail()
	}
}
示例#6
0
func TestInt64LE(t *testing.T) {
	buf := make([]uint8, 16)
	d := enc.New(buf)
	for _, u64 := range tU64LE {
		d.LE.PutInt64(int64(u64))
	}

	if !bytes.Equal(buf, tExp) {
		t.Logf("act(%#v) != exp(%#v)", buf, tExp)
		t.Fail()
	}
}
示例#7
0
func TestFill(t *testing.T) {
	exp := []uint8{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}

	buf := makeRndBuf()
	d := enc.New(buf)
	d.Fill(0xff, len(buf))

	if !bytes.Equal(buf, exp) {
		t.Logf("act(%#v) != exp(%#v)", buf, exp)
		t.Fail()
	}
}
示例#8
0
func TestRemaining(t *testing.T) {
	buf := makeRndBuf()
	d := enc.New(buf)
	for _, u8 := range tU8 {
		d.BE.PutUint8(u8)
	}

	if d.Remaining() != 0 {
		t.Logf("act(0x%02x) != exp(0x00)", d.Remaining())
		t.Fail()
	}
}
示例#9
0
func TestInt32BE(t *testing.T) {
	buf := make([]uint8, 16)
	d := enc.New(buf)
	for _, u32 := range tU32BE {
		d.BE.PutInt32(int32(u32))
	}

	if !bytes.Equal(buf, tExp) {
		t.Logf("act(%#v) != exp(%#v)", buf, tExp)
		t.Fail()
	}
}
示例#10
0
func TestWrite(t *testing.T) {
	buf := makeRndBuf()
	d := enc.New(buf)

	n, err := d.Write(tU8)
	if n != len(buf) {
		t.Logf("n_act(%#v) != n_exp(%#v)", n, len(buf))
		t.Fail()
	}
	if err != nil {
		t.Logf("err_act(%#v) != err_exp(%#v)", err, nil)
		t.Fail()
	}
	if !bytes.Equal(buf, tU8) {
		t.Logf("act(%#v) != exp(%#v)", buf, tU8)
		t.Fail()
	}
}