github.com/c-darwin/mobile@v0.0.0-20160313183840-ff625c46f7c9/bind/seq/seq_test.go (about) 1 // Copyright 2014 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package seq 6 7 import "testing" 8 9 func TestBuffer(t *testing.T) { 10 buf := new(Buffer) 11 buf.WriteInt64(1 << 42) 12 buf.WriteInt32(1 << 13) 13 buf.WriteUTF16("Hello, world") 14 buf.WriteFloat64(4.02) 15 buf.WriteFloat32(1.2) 16 buf.WriteGoRef(new(int)) 17 buf.WriteGoRef(new(int)) 18 19 buf.Offset = 0 20 21 if got, want := buf.ReadInt64(), int64(1<<42); got != want { 22 t.Errorf("buf.ReadInt64()=%d, want %d", got, want) 23 } 24 if got, want := buf.ReadInt32(), int32(1<<13); got != want { 25 t.Errorf("buf.ReadInt32()=%d, want %d", got, want) 26 } 27 if got, want := buf.ReadUTF16(), "Hello, world"; got != want { 28 t.Errorf("buf.ReadUTF16()=%q, want %q", got, want) 29 } 30 if got, want := buf.ReadFloat64(), 4.02; got != want { 31 t.Errorf("buf.ReadFloat64()=%f, want %f", got, want) 32 } 33 if got, want := buf.ReadFloat32(), float32(1.2); got != want { 34 t.Errorf("buf.ReadFloat32()=%f, want %f", got, want) 35 } 36 }