message_set_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. package proto_test
  5. import (
  6. "bytes"
  7. "fmt"
  8. "testing"
  9. "github.com/golang/protobuf/proto"
  10. . "github.com/golang/protobuf/proto/test_proto"
  11. )
  12. func TestUnmarshalMessageSetWithDuplicate(t *testing.T) {
  13. /*
  14. Message{
  15. Tag{1, StartGroup},
  16. Message{
  17. Tag{2, Varint}, Uvarint(12345),
  18. Tag{3, Bytes}, Bytes("hoo"),
  19. },
  20. Tag{1, EndGroup},
  21. Tag{1, StartGroup},
  22. Message{
  23. Tag{2, Varint}, Uvarint(12345),
  24. Tag{3, Bytes}, Bytes("hah"),
  25. },
  26. Tag{1, EndGroup},
  27. }
  28. */
  29. var in []byte
  30. fmt.Sscanf("0b10b9601a03686f6f0c0b10b9601a036861680c", "%x", &in)
  31. /*
  32. Message{
  33. Tag{1, StartGroup},
  34. Message{
  35. Tag{2, Varint}, Uvarint(12345),
  36. Tag{3, Bytes}, Bytes("hoo"),
  37. },
  38. Tag{1, EndGroup},
  39. Tag{1, StartGroup},
  40. Message{
  41. Tag{2, Varint}, Uvarint(12345),
  42. Tag{3, Bytes}, Bytes("hah"),
  43. },
  44. Tag{1, EndGroup},
  45. }
  46. */
  47. var want []byte
  48. fmt.Sscanf("0b10b9601a03686f6f0c0b10b9601a036861680c", "%x", &want)
  49. var m MyMessageSet
  50. if err := proto.Unmarshal(in, &m); err != nil {
  51. t.Fatalf("unexpected Unmarshal error: %v", err)
  52. }
  53. got, err := proto.Marshal(&m)
  54. if err != nil {
  55. t.Fatalf("unexpected Marshal error: %v", err)
  56. }
  57. if !bytes.Equal(got, want) {
  58. t.Errorf("output mismatch:\ngot %x\nwant %x", got, want)
  59. }
  60. }