summaryrefslogtreecommitdiff
path: root/src/pkg/encoding/binary/binary_test.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-10-20 13:00:16 -0700
committerRuss Cox <rsc@golang.org>2009-10-20 13:00:16 -0700
commit3b898983005c16f5b182d1b433e622f8a6de99eb (patch)
tree4c7e239969079349aa840a7444732ca7cad27deb /src/pkg/encoding/binary/binary_test.go
parent0f60a452df747c97b012636454382f70cddcac31 (diff)
downloadgolang-3b898983005c16f5b182d1b433e622f8a6de99eb.tar.gz
base64 -> encoding/base64
base85 -> encoding/ascii85, encoding/git85 debug/binary -> encoding/binary R=r DELTA=3190 (1884 added, 1297 deleted, 9 changed) OCL=35923 CL=35929
Diffstat (limited to 'src/pkg/encoding/binary/binary_test.go')
-rw-r--r--src/pkg/encoding/binary/binary_test.go86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/pkg/encoding/binary/binary_test.go b/src/pkg/encoding/binary/binary_test.go
new file mode 100644
index 000000000..a04684b72
--- /dev/null
+++ b/src/pkg/encoding/binary/binary_test.go
@@ -0,0 +1,86 @@
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package binary
+
+import (
+ "bytes";
+ "math";
+ "reflect";
+ "testing";
+)
+
+type Struct struct {
+ Int8 int8;
+ Int16 int16;
+ Int32 int32;
+ Int64 int64;
+ Uint8 uint8;
+ Uint16 uint16;
+ Uint32 uint32;
+ Uint64 uint64;
+ Float64 float64;
+ Array [4]uint8;
+}
+
+var s = Struct{
+ 0x01,
+ 0x0203,
+ 0x04050607,
+ 0x08090a0b0c0d0e0f,
+ 0x10,
+ 0x1112,
+ 0x13141516,
+ 0x1718191a1b1c1d1e,
+ math.Float64frombits(0x1f20212223242526),
+ [4]uint8{0x27, 0x28, 0x29, 0x2a},
+}
+
+var big = []byte{
+ 1,
+ 2, 3,
+ 4, 5, 6, 7,
+ 8, 9, 10, 11, 12, 13, 14, 15,
+ 16,
+ 17, 18,
+ 19, 20, 21, 22,
+ 23, 24, 25, 26, 27, 28, 29, 30,
+ 31, 32, 33, 34, 35, 36, 37, 38,
+ 39, 40, 41, 42,
+}
+
+var little = []byte{
+ 1,
+ 3, 2,
+ 7, 6, 5, 4,
+ 15, 14, 13, 12, 11, 10, 9, 8,
+ 16,
+ 18, 17,
+ 22, 21, 20, 19,
+ 30, 29, 28, 27, 26, 25, 24, 23,
+ 38, 37, 36, 35, 34, 33, 32, 31,
+ 39, 40, 41, 42,
+}
+
+func TestRead(t *testing.T) {
+ var sl, sb Struct;
+
+ err := Read(bytes.NewBuffer(big), BigEndian, &sb);
+ if err != nil {
+ t.Errorf("Read big-endian: %v", err);
+ goto little;
+ }
+ if !reflect.DeepEqual(sb, s) {
+ t.Errorf("Read big-endian:\n\thave %+v\n\twant %+v", sb, s);
+ }
+
+little:
+ err = Read(bytes.NewBuffer(little), LittleEndian, &sl);
+ if err != nil {
+ t.Errorf("Read little-endian: %v", err);
+ }
+ if !reflect.DeepEqual(sl, s) {
+ t.Errorf("Read big-endian:\n\thave %+v\n\twant %+v", sl, s);
+ }
+}