diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-01-17 12:40:45 +0100 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-01-17 12:40:45 +0100 |
commit | 3e45412327a2654a77944249962b3652e6142299 (patch) | |
tree | bc3bf69452afa055423cbe0c5cfa8ca357df6ccf /src/pkg/asn1/marshal_test.go | |
parent | c533680039762cacbc37db8dc7eed074c3e497be (diff) | |
download | golang-upstream/2011.01.12.tar.gz |
Imported Upstream version 2011.01.12upstream/2011.01.12
Diffstat (limited to 'src/pkg/asn1/marshal_test.go')
-rw-r--r-- | src/pkg/asn1/marshal_test.go | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/src/pkg/asn1/marshal_test.go b/src/pkg/asn1/marshal_test.go index 67878f9bb..85eafc9e4 100644 --- a/src/pkg/asn1/marshal_test.go +++ b/src/pkg/asn1/marshal_test.go @@ -58,40 +58,43 @@ type marshalTest struct { } var marshalTests = []marshalTest{ - marshalTest{10, "02010a"}, - marshalTest{intStruct{64}, "3003020140"}, - marshalTest{twoIntStruct{64, 65}, "3006020140020141"}, - marshalTest{nestedStruct{intStruct{127}}, "3005300302017f"}, - marshalTest{[]byte{1, 2, 3}, "0403010203"}, - marshalTest{implicitTagTest{64}, "3003850140"}, - marshalTest{explicitTagTest{64}, "3005a503020140"}, - marshalTest{time.SecondsToUTC(0), "170d3730303130313030303030305a"}, - marshalTest{time.SecondsToUTC(1258325776), "170d3039313131353232353631365a"}, - marshalTest{setPST(time.SecondsToUTC(1258325776)), "17113039313131353232353631362d30383030"}, - marshalTest{BitString{[]byte{0x80}, 1}, "03020780"}, - marshalTest{BitString{[]byte{0x81, 0xf0}, 12}, "03030481f0"}, - marshalTest{ObjectIdentifier([]int{1, 2, 3, 4}), "06032a0304"}, - marshalTest{ObjectIdentifier([]int{1, 2, 840, 133549, 1, 1, 5}), "06092a864888932d010105"}, - marshalTest{"test", "130474657374"}, - marshalTest{ia5StringTest{"test"}, "3006160474657374"}, - marshalTest{printableStringTest{"test"}, "3006130474657374"}, - marshalTest{printableStringTest{"test*"}, "30071305746573742a"}, - marshalTest{rawContentsStruct{nil, 64}, "3003020140"}, - marshalTest{rawContentsStruct{[]byte{0x30, 3, 1, 2, 3}, 64}, "3003010203"}, - marshalTest{RawValue{Tag: 1, Class: 2, IsCompound: false, Bytes: []byte{1, 2, 3}}, "8103010203"}, - marshalTest{testSET([]int{10}), "310302010a"}, + {10, "02010a"}, + {127, "02017f"}, + {128, "02020080"}, + {-128, "020180"}, + {-129, "0202ff7f"}, + {intStruct{64}, "3003020140"}, + {twoIntStruct{64, 65}, "3006020140020141"}, + {nestedStruct{intStruct{127}}, "3005300302017f"}, + {[]byte{1, 2, 3}, "0403010203"}, + {implicitTagTest{64}, "3003850140"}, + {explicitTagTest{64}, "3005a503020140"}, + {time.SecondsToUTC(0), "170d3730303130313030303030305a"}, + {time.SecondsToUTC(1258325776), "170d3039313131353232353631365a"}, + {setPST(time.SecondsToUTC(1258325776)), "17113039313131353232353631362d30383030"}, + {BitString{[]byte{0x80}, 1}, "03020780"}, + {BitString{[]byte{0x81, 0xf0}, 12}, "03030481f0"}, + {ObjectIdentifier([]int{1, 2, 3, 4}), "06032a0304"}, + {ObjectIdentifier([]int{1, 2, 840, 133549, 1, 1, 5}), "06092a864888932d010105"}, + {"test", "130474657374"}, + {ia5StringTest{"test"}, "3006160474657374"}, + {printableStringTest{"test"}, "3006130474657374"}, + {printableStringTest{"test*"}, "30071305746573742a"}, + {rawContentsStruct{nil, 64}, "3003020140"}, + {rawContentsStruct{[]byte{0x30, 3, 1, 2, 3}, 64}, "3003010203"}, + {RawValue{Tag: 1, Class: 2, IsCompound: false, Bytes: []byte{1, 2, 3}}, "8103010203"}, + {testSET([]int{10}), "310302010a"}, } func TestMarshal(t *testing.T) { for i, test := range marshalTests { - buf := bytes.NewBuffer(nil) - err := Marshal(buf, test.in) + data, err := Marshal(test.in) if err != nil { t.Errorf("#%d failed: %s", i, err) } out, _ := hex.DecodeString(test.out) - if bytes.Compare(out, buf.Bytes()) != 0 { - t.Errorf("#%d got: %x want %x", i, buf.Bytes(), out) + if bytes.Compare(out, data) != 0 { + t.Errorf("#%d got: %x want %x", i, data, out) } } } |