Add test with byteoperations and buffers larger than uint32
@@ -20,6 +20,8 @@ import (
"github.com/stretchr/testify/require"
)
+const MaxUint = ^uint32(0)
+
// Create a buffer with space for several values and first write into it and then test that the values can be read again
func TestReadAnWrite(t *testing.T) {
valuesNumbers := []uint64{234, 78, 23, 66, 8, 9, 2, 346745, 1}
@@ -49,3 +51,15 @@ func TestReadAnWrite(t *testing.T) {
require.Equal(t, byteOpsRead.ReadUint64(), valuesNumbers[4])
require.Equal(t, byteOpsRead.ReadUint16(), uint16(valuesNumbers[5]))
}
+
+// create buffer that is larger than uint32 and write to the end and then try to reread it
+func TestReadAnWriteLargeBuffer(t *testing.T) {
+ writeBuffer := make([]byte, uint64(MaxUint)+4)
+ byteOpsWrite := ByteOperations{Buffer: writeBuffer}
+ byteOpsWrite.MoveBufferPositionForward(MaxUint)
+ byteOpsWrite.WriteUint16(uint16(10))
+
+ byteOpsRead := ByteOperations{Buffer: writeBuffer}
+ byteOpsRead.MoveBufferPositionForward(MaxUint)
+ require.Equal(t, byteOpsRead.ReadUint16(), uint16(10))
+}
