MCPcopy Create free account
hub / github.com/OpenPrinting/goipp / testDecode

Function testDecode

encdec_test.go:866–900  ·  view source on GitHub ↗

Test message decoding

(t *testing.T, data []byte, opt DecoderOptions,
	mustFail, mustEncode bool)

Source from the content-addressed store, hash-verified

864
865// Test message decoding
866func 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
902func TestDecodeGoodMessage1(t *testing.T) {
903 testDecode(t, goodMessage1, DecoderOptions{}, false, true)

Callers 5

TestDecodeGoodMessage1Function · 0.85
TestDecodeGoodMessage2Function · 0.85
TestDecodeBadMessage1Function · 0.85
TestDecodePantumM7300FDWFunction · 0.85

Calls 7

DecodeBytesExMethod · 0.95
EqualMethod · 0.95
EncodeBytesMethod · 0.95
PrintMethod · 0.95
assertWithErrorFunction · 0.85
assertNoErrorFunction · 0.85
EqualMethod · 0.45

Tested by

no test coverage detected