Skip to content
Snippets Groups Projects
Select Git revision
  • 55cda9bf47174820a491b90d421a1e2fc73c6716
  • release default protected
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
41 results

messagePart_test.go

Blame
  • 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)
    	}
    }