You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/04/26 15:01:45 UTC
[plc4x] branch develop updated: test(plc4go/spi): add tests for read buffer
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new fde0f32766 test(plc4go/spi): add tests for read buffer
fde0f32766 is described below
commit fde0f327668a73793c2687fdd70ff63e612724e4
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Apr 26 17:01:38 2023 +0200
test(plc4go/spi): add tests for read buffer
---
plc4go/spi/utils/ReadBufferByteBased_test.go | 196 ++++++++++++++++++++++++---
1 file changed, 176 insertions(+), 20 deletions(-)
diff --git a/plc4go/spi/utils/ReadBufferByteBased_test.go b/plc4go/spi/utils/ReadBufferByteBased_test.go
index a84c652f51..9a7bddc555 100644
--- a/plc4go/spi/utils/ReadBufferByteBased_test.go
+++ b/plc4go/spi/utils/ReadBufferByteBased_test.go
@@ -20,6 +20,7 @@
package utils
import (
+ "bytes"
"encoding/binary"
"github.com/icza/bitio"
"github.com/stretchr/testify/assert"
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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())
+
+ })
+ }
+}