Select Git revision
notifications_test.go
messagePart_test.go 2.72 KiB
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package parse
import (
"bytes"
"reflect"
"testing"
)
// Expected messagePart for checking against; generated by goTmp in
// Test_newMessagePart.
var expectedMP = messagePart{
Data: []uint8{0x0, 0x0, 0x0, 0x20, 0x6, 0x0, 0x7, 0x74, 0x65, 0x73, 0x74,
0x69, 0x6e, 0x67, messagePartCurrentVersion},
Id: []uint8{0x0, 0x0, 0x0, 0x20}, Part: []uint8{0x6},
Len: []uint8{0x0, 0x7},
Contents: []uint8{0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67},
Version: []uint8{messagePartCurrentVersion},
}
// Tests that a new function part is successfully created.
func Test_newMessagePart(t *testing.T) {
testStr := []byte{'t', 'e', 's', 't', 'i', 'n', 'g'}
goTmp := newMessagePart(32, 6, testStr, len(testStr)+8)
if !reflect.DeepEqual(goTmp, expectedMP) {
t.Errorf("MessagePart received and MessagePart expected do not match."+
"\nexpected: %#v\nreceived: %#v", expectedMP, goTmp)
}
}
// Test that messagePart.getID returns the correct ID.
func Test_messagePart_getID(t *testing.T) {
if expectedMP.getID() != 32 {
t.Errorf("received and expected do not match."+
"\n\tGot: %#v\nexpected: %#v", expectedMP.getID(), 32)
}
}
// Test that getPart returns the correct part number
func TestMessagePart_getPart(t *testing.T) {
if expectedMP.getPart() != 6 {
t.Errorf("received and expected do not match."+
"\n\tGot: %#v\nexpected: %#v", expectedMP.getPart(), 6)
}
}
// Test that getContents returns the message contests
func TestMessagePart_getContents(t *testing.T) {
if !bytes.Equal(expectedMP.getContents(),
[]byte{'t', 'e', 's', 't', 'i', 'n', 'g'}) {
t.Errorf("received and expected do not match."+
"\n\tGot: %#v\nexpected: %#v", expectedMP.getContents(), 6)
}
}
// Test that getSizedContents returns the message contests
func TestMessagePart_getSizedContents(t *testing.T) {
if !bytes.Equal(expectedMP.getSizedContents(),
[]byte{'t', 'e', 's', 't', 'i', 'n', 'g'}) {
t.Errorf("received and expected do not match."+
"\n\tGot: %#v\nexpected: %#v", expectedMP.getSizedContents(), 6)
}
}
// Test that getContentsLength returns the message length
func TestMessagePart_getContentsLength(t *testing.T) {
if expectedMP.getContentsLength() != 7 {
t.Errorf("received and expected do not match."+
"\n\tGot: %#v\nexpected: %#v", expectedMP.getContentsLength(), 7)
}
}