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

Function TestDecodeValueErrors

encdec_test.go:537–754  ·  view source on GitHub ↗

Test errors in decoding values

(t *testing.T)

Source from the content-addressed store, hash-verified

535
536// Test errors in decoding values
537func TestDecodeValueErrors(t *testing.T) {
538 var d []byte
539 var err error
540 var m = &Message{}
541
542 hdr := []byte{
543 0x01, 0x01, // IPP version
544 0x00, 0x02, // Print-Job operation
545 0x01, 0x02, 0x03, 0x04, // Request ID
546 }
547
548 body := []byte{}
549
550 // integer: value must be 4 bytes
551 body = []byte{
552 uint8(TagJobGroup),
553 uint8(TagInteger),
554 0x00, 0x04, // Name length + name
555 'a', 't', 't', 'r',
556 0x00, 0x03, // Value length + value
557 0x00, 0x54, 0x56,
558 uint8(TagEnd),
559 }
560
561 d = append(hdr, body...)
562 err = m.DecodeBytes(d)
563 assertErrorIs(t, err, "integer: value must be 4 bytes")
564
565 // boolean: value must be 1 byte
566 body = []byte{
567 uint8(TagJobGroup),
568 uint8(TagBoolean),
569 0x00, 0x04, // Name length + name
570 'a', 't', 't', 'r',
571 0x00, 0x03, // Value length + value
572 0x00, 0x54, 0x56,
573 uint8(TagEnd),
574 }
575
576 d = append(hdr, body...)
577 err = m.DecodeBytes(d)
578 assertErrorIs(t, err, "boolean: value must be 1 byte")
579
580 // dateTime: value must be 11 bytes
581 body = []byte{
582 uint8(TagJobGroup),
583 uint8(TagDateTime),
584 0x00, 0x04, // Name length + name
585 'a', 't', 't', 'r',
586 0x00, 0x03, // Value length + value
587 0x00, 0x54, 0x56,
588 uint8(TagEnd),
589 }
590
591 d = append(hdr, body...)
592 err = m.DecodeBytes(d)
593 assertErrorIs(t, err, "dateTime: value must be 11 bytes")
594

Callers

nothing calls this directly

Calls 2

assertErrorIsFunction · 0.85
DecodeBytesMethod · 0.80

Tested by

no test coverage detected