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/05/22 12:39:56 UTC

[plc4x] 02/03: test(plc4go/spi): added tests for read buffer byte based

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

commit 5c19e725a4fefeaa7d604be10a6b0f983d057176
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Mon May 22 14:03:55 2023 +0200

    test(plc4go/spi): added tests for read buffer byte based
---
 plc4go/spi/utils/ReadBufferByteBased_test.go | 17 +++++++++++
 plc4go/spi/utils/ReadBuffer_test.go          | 43 ++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/plc4go/spi/utils/ReadBufferByteBased_test.go b/plc4go/spi/utils/ReadBufferByteBased_test.go
index 6e29f67940..d4e04a9f3c 100644
--- a/plc4go/spi/utils/ReadBufferByteBased_test.go
+++ b/plc4go/spi/utils/ReadBufferByteBased_test.go
@@ -1535,10 +1535,27 @@ func TestReadBuffer_ReadString(t *testing.T) {
 	}{
 		{
 			name: "read it",
+			args: args{bitLength: 8},
 			fields: fields{
 				reader: bitio.NewReader(bytes.NewBuffer([]byte{0x0})),
 			},
 		},
+		{
+			name: "read it (null terminated)",
+			args: args{bitLength: 8},
+			fields: fields{
+				reader: bitio.NewReader(bytes.NewBuffer([]byte{0x70, 0x0})),
+			},
+			want: "p",
+		},
+		{
+			name: "read it",
+			args: args{bitLength: 8},
+			fields: fields{
+				reader: bitio.NewReader(bytes.NewBuffer([]byte{0x70})),
+			},
+			want: "p",
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
diff --git a/plc4go/spi/utils/ReadBuffer_test.go b/plc4go/spi/utils/ReadBuffer_test.go
new file mode 100644
index 0000000000..c6101aa3d2
--- /dev/null
+++ b/plc4go/spi/utils/ReadBuffer_test.go
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package utils
+
+import (
+	"github.com/stretchr/testify/assert"
+	"testing"
+)
+
+func Test_readerArg_isReaderArgs(t *testing.T) {
+	tests := []struct {
+		name string
+		want bool
+	}{
+		{
+			name: "it is",
+			want: true,
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			re := readerArg{}
+			assert.Equalf(t, tt.want, re.isReaderArgs(), "isReaderArgs()")
+		})
+	}
+}