Test message decoding
(t *testing.T, data []byte, opt DecoderOptions, mustFail, mustEncode bool)
| 864 | |
| 865 | // Test message decoding |
| 866 | func testDecode(t *testing.T, data []byte, opt DecoderOptions, |
| 867 | mustFail, mustEncode bool) { |
| 868 | |
| 869 | var m Message |
| 870 | err := m.DecodeBytesEx(data, opt) |
| 871 | |
| 872 | if mustFail { |
| 873 | assertWithError(t, err) |
| 874 | } else { |
| 875 | assertNoError(t, err) |
| 876 | } |
| 877 | |
| 878 | if err != nil { |
| 879 | return |
| 880 | } |
| 881 | |
| 882 | //m.Print(os.Stdout, true) |
| 883 | |
| 884 | if !m.Equal(m) { |
| 885 | t.Errorf("Message is not equal to itself") |
| 886 | } |
| 887 | |
| 888 | if mustEncode { |
| 889 | buf, err := m.EncodeBytes() |
| 890 | assertNoError(t, err) |
| 891 | |
| 892 | if !bytes.Equal(buf, data) { |
| 893 | t.Errorf("Message is not the same after decoding and encoding") |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | // We can't test a lot of (*Message) Print(), so lets test |
| 898 | // at least that it doesn't hand |
| 899 | m.Print(ioutil.Discard, true) |
| 900 | } |
| 901 | |
| 902 | func TestDecodeGoodMessage1(t *testing.T) { |
| 903 | testDecode(t, goodMessage1, DecoderOptions{}, false, true) |
no test coverage detected