Skip to content

Commit

Permalink
test(plc4go/spi): add tests for read buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Apr 26, 2023
1 parent 0ddb758 commit fde0f32
Showing 1 changed file with 176 additions and 20 deletions.
196 changes: 176 additions & 20 deletions plc4go/spi/utils/ReadBufferByteBased_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package utils

import (
"bytes"
"encoding/binary"
"github.com/icza/bitio"
"github.com/stretchr/testify/assert"
Expand All @@ -35,9 +36,15 @@ func TestNewReadBuffer(t *testing.T) {
tests := []struct {
name string
args args
want *ReadBuffer
want ReadBufferByteBased
}{
// TODO: Add test cases.
{
name: "create it",
want: &byteReadBuffer{
reader: bitio.NewReader(bytes.NewBuffer(nil)),
byteOrder: binary.BigEndian,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -60,7 +67,9 @@ func TestReadBuffer_GetBytes(t *testing.T) {
fields fields
want []uint8
}{
// TODO: Add test cases.
{
name: "get em",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -89,7 +98,9 @@ func TestReadBuffer_GetPos(t *testing.T) {
fields fields
want uint16
}{
// TODO: Add test cases.
{
name: "get it",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -118,7 +129,9 @@ func TestReadBuffer_GetTotalBytes(t *testing.T) {
fields fields
want uint64
}{
// TODO: Add test cases.
{
name: "get it",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -151,7 +164,10 @@ func TestReadBuffer_HasMore(t *testing.T) {
args args
want bool
}{
// TODO: Add test cases.
{
name: "has it",
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -184,7 +200,12 @@ func TestReadBuffer_PeekByte(t *testing.T) {
args args
want uint8
}{
// TODO: Add test cases.
{
name: "peek it",
fields: fields{
data: []byte{0x0},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -218,7 +239,13 @@ func TestReadBuffer_ReadBigFloat(t *testing.T) {
want *big.Float
wantErr bool
}{
// TODO: Add test cases.
{
name: "read it",
fields: fields{
reader: bitio.NewReader(bytes.NewBuffer(nil)),
},
want: big.NewFloat(0),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -257,7 +284,13 @@ func TestReadBuffer_ReadBigInt(t *testing.T) {
want *big.Int
wantErr bool
}{
// TODO: Add test cases.
{
name: "read it",
fields: fields{
reader: bitio.NewReader(bytes.NewBuffer(nil)),
},
want: big.NewInt(0),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -292,7 +325,12 @@ func TestReadBuffer_ReadBit(t *testing.T) {
want bool
wantErr bool
}{
// TODO: Add test cases.
{
name: "read it",
fields: fields{
reader: bitio.NewReader(bytes.NewBuffer([]byte{0x0})),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -331,7 +369,12 @@ func TestReadBuffer_ReadFloat32(t *testing.T) {
want float32
wantErr bool
}{
// TODO: Add test cases.
{
name: "read it",
fields: fields{
reader: bitio.NewReader(bytes.NewBuffer([]byte{0x0})),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -1275,7 +1318,12 @@ func TestReadBuffer_ReadInt16(t *testing.T) {
want int16
wantErr bool
}{
// TODO: Add test cases.
{
name: "read it",
fields: fields{
reader: bitio.NewReader(bytes.NewBuffer([]byte{0x0})),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -1314,7 +1362,12 @@ func TestReadBuffer_ReadInt32(t *testing.T) {
want int32
wantErr bool
}{
// TODO: Add test cases.
{
name: "read it",
fields: fields{
reader: bitio.NewReader(bytes.NewBuffer([]byte{0x0})),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -1353,7 +1406,12 @@ func TestReadBuffer_ReadInt64(t *testing.T) {
want int64
wantErr bool
}{
// TODO: Add test cases.
{
name: "read it",
fields: fields{
reader: bitio.NewReader(bytes.NewBuffer([]byte{0x0})),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -1392,7 +1450,12 @@ func TestReadBuffer_ReadInt8(t *testing.T) {
want int8
wantErr bool
}{
// TODO: Add test cases.
{
name: "read it",
fields: fields{
reader: bitio.NewReader(bytes.NewBuffer([]byte{0x0})),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -1431,7 +1494,12 @@ func TestReadBuffer_ReadString(t *testing.T) {
want string
wantErr bool
}{
// TODO: Add test cases.
{
name: "read it",
fields: fields{
reader: bitio.NewReader(bytes.NewBuffer([]byte{0x0})),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -1470,7 +1538,12 @@ func TestReadBuffer_ReadUint16(t *testing.T) {
want uint16
wantErr bool
}{
// TODO: Add test cases.
{
name: "read it",
fields: fields{
reader: bitio.NewReader(bytes.NewBuffer([]byte{0x0})),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -1697,7 +1770,12 @@ func TestReadBuffer_ReadUint64(t *testing.T) {
want uint64
wantErr bool
}{
// TODO: Add test cases.
{
name: "read it",
fields: fields{
reader: bitio.NewReader(bytes.NewBuffer([]byte{0x0})),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -1736,7 +1814,12 @@ func TestReadBuffer_ReadUint8(t *testing.T) {
want uint8
wantErr bool
}{
// TODO: Add test cases.
{
name: "read it",
fields: fields{
reader: bitio.NewReader(bytes.NewBuffer([]byte{0x0})),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -1773,7 +1856,12 @@ func TestReadBuffer_Reset(t *testing.T) {
fields fields
args args
}{
// TODO: Add test cases.
{
name: "reset it",
fields: fields{
reader: bitio.NewReader(bytes.NewBuffer([]byte{0x0})),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -1787,3 +1875,71 @@ func TestReadBuffer_Reset(t *testing.T) {
})
}
}

func TestReadBuffer_SetByteOrder(t *testing.T) {
type fields struct {
data []uint8
reader *bitio.Reader
pos uint64
byteOrder binary.ByteOrder
}
type args struct {
byteOrder binary.ByteOrder
}
tests := []struct {
name string
fields fields
args args
}{
{
name: "set it",
fields: fields{
reader: bitio.NewReader(bytes.NewBuffer([]byte{0x0})),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rb := &byteReadBuffer{
data: tt.fields.data,
reader: tt.fields.reader,
pos: tt.fields.pos,
byteOrder: tt.fields.byteOrder,
}
rb.SetByteOrder(tt.args.byteOrder)
})
}
}

func TestReadBuffer_GetByteOrder(t *testing.T) {
type fields struct {
data []uint8
reader *bitio.Reader
pos uint64
byteOrder binary.ByteOrder
}
tests := []struct {
name string
fields fields
want binary.ByteOrder
}{
{
name: "get it",
fields: fields{
reader: bitio.NewReader(bytes.NewBuffer([]byte{0x0})),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rb := &byteReadBuffer{
data: tt.fields.data,
reader: tt.fields.reader,
pos: tt.fields.pos,
byteOrder: tt.fields.byteOrder,
}
assert.Equal(t, tt.want, rb.GetByteOrder())

})
}
}

0 comments on commit fde0f32

Please sign in to comment.