encoder_decoder_test.go 582 B

12345678910111213141516171819202122232425
  1. package protocol
  2. import (
  3. "bytes"
  4. "testing"
  5. )
  6. // no actual tests, just helper functions for testing structures that
  7. // implement the encoder or decoder interfaces
  8. func testEncodable(t *testing.T, name string, in encoder, expect []byte) {
  9. packet, err := encode(in)
  10. if err != nil {
  11. t.Error(err)
  12. } else if !bytes.Equal(packet, expect) {
  13. t.Error("Encoding", name, "failed\ngot ", packet, "\nwant", expect)
  14. }
  15. }
  16. func testDecodable(t *testing.T, name string, out decoder, in []byte) {
  17. err := decode(in, out)
  18. if err != nil {
  19. t.Error("Decoding", name, "failed:", err)
  20. }
  21. }