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 2022/08/19 14:17:07 UTC
[plc4x] branch develop updated: test(plc4go): added a test for plc_value combinations
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 a2c15c2d4 test(plc4go): added a test for plc_value combinations
a2c15c2d4 is described below
commit a2c15c2d48d402411a07a0f50bb324b2b4336d91
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Aug 19 16:16:59 2022 +0200
test(plc4go): added a test for plc_value combinations
- This ensures that when a Is* method says yes then the getter should work
---
plc4go/pkg/api/values/plc_value.go | 72 +++++-
plc4go/spi/values/BINT.go | 15 +-
plc4go/spi/values/BOOL.go | 7 +-
plc4go/spi/values/BREAL.go | 12 +
plc4go/spi/values/BYTE.go | 7 +-
plc4go/spi/values/CHAR.go | 7 +-
plc4go/spi/values/DATE.go | 5 +
plc4go/spi/values/DATE_AND_TIME.go | 6 +-
plc4go/spi/values/DINT.go | 13 ++
plc4go/spi/values/DWORD.go | 7 +-
plc4go/spi/values/INT.go | 13 ++
plc4go/spi/values/LINT.go | 13 ++
plc4go/spi/values/LREAL.go | 4 +
plc4go/spi/values/LTIME.go | 6 +-
plc4go/spi/values/LWORD.go | 7 +-
plc4go/spi/values/NULL.go | 9 +-
plc4go/spi/values/PlcList.go | 7 +
plc4go/spi/values/PlcSimpleValueAdapter.go | 92 --------
plc4go/spi/values/PlcStruct.go | 7 +
plc4go/spi/values/PlcValueAdapter.go | 74 +++++-
plc4go/spi/values/REAL.go | 12 +
plc4go/spi/values/RawPlcValue.go | 7 +-
plc4go/spi/values/SINT.go | 13 ++
plc4go/spi/values/STRING.go | 7 +-
plc4go/spi/values/TIME.go | 6 +-
plc4go/spi/values/TIME_OF_DAY.go | 7 +-
plc4go/spi/values/UDINT.go | 13 ++
plc4go/spi/values/UINT.go | 13 ++
plc4go/spi/values/ULINT.go | 13 ++
plc4go/spi/values/USINT.go | 13 ++
plc4go/spi/values/WCHAR.go | 7 +-
plc4go/spi/values/WORD.go | 7 +-
plc4go/spi/values/WSTRING.go | 9 +-
plc4go/spi/values/value_combination_test.go | 338 ++++++++++++++++++++++++++++
34 files changed, 735 insertions(+), 113 deletions(-)
diff --git a/plc4go/pkg/api/values/plc_value.go b/plc4go/pkg/api/values/plc_value.go
index 368829f71..003e0b6ea 100644
--- a/plc4go/pkg/api/values/plc_value.go
+++ b/plc4go/pkg/api/values/plc_value.go
@@ -179,9 +179,79 @@ const (
TIME_OF_DAY
UDINT
UINT
- USINT
ULINT
+ USINT
WCHAR
WORD
WSTRING
)
+
+func (p PLCValueType) String() string {
+ switch {
+ case p == BINT:
+ return "BINT"
+ case p == BIT_STRING:
+ return "BIT_STRING"
+ case p == BOOL:
+ return "BOOL"
+ case p == BREAL:
+ return "BREAL"
+ case p == BYTE:
+ return "BYTE"
+ case p == BYTE_ARRAY:
+ return "BYTE_ARRAY"
+ case p == CHAR:
+ return "CHAR"
+ case p == DATE:
+ return "DATE"
+ case p == DATE_AND_TIME:
+ return "DATE_AND_TIME"
+ case p == DINT:
+ return "DINT"
+ case p == DWORD:
+ return "DWORD"
+ case p == INT:
+ return "INT"
+ case p == LINT:
+ return "LINT"
+ case p == LIST:
+ return "LIST"
+ case p == LREAL:
+ return "LREAL"
+ case p == LTIME:
+ return "LTIME"
+ case p == LWORD:
+ return "LWORD"
+ case p == NULL:
+ return "NULL"
+ case p == RAW_PLC_VALUE:
+ return "RAW_PLC_VALUE"
+ case p == REAL:
+ return "REAL"
+ case p == STRUCT:
+ return "STRUCT"
+ case p == SINT:
+ return "SINT"
+ case p == STRING:
+ return "STRING"
+ case p == TIME:
+ return "TIME"
+ case p == TIME_OF_DAY:
+ return "TIME_OF_DAY"
+ case p == UDINT:
+ return "UDINT"
+ case p == UINT:
+ return "UINT"
+ case p == ULINT:
+ return "ULINT"
+ case p == USINT:
+ return "USINT"
+ case p == WCHAR:
+ return "WCHAR"
+ case p == WORD:
+ return "WORD"
+ case p == WSTRING:
+ return "WSTRING"
+ }
+ return "Unknown"
+}
diff --git a/plc4go/spi/values/BINT.go b/plc4go/spi/values/BINT.go
index 8e064c455..d2694a771 100644
--- a/plc4go/spi/values/BINT.go
+++ b/plc4go/spi/values/BINT.go
@@ -20,6 +20,7 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
"math"
@@ -28,8 +29,8 @@ import (
)
type PlcBINT struct {
- value *big.Int
PlcSimpleNumericValueAdapter
+ value *big.Int
}
func NewPlcBINT(value *big.Int) PlcBINT {
@@ -49,6 +50,14 @@ func (m PlcBINT) GetBoolean() bool {
return true
}
+func (m PlcBINT) IsByte() bool {
+ return m.IsUint8()
+}
+
+func (m PlcBINT) GetByte() byte {
+ return m.GetUint8()
+}
+
func (m PlcBINT) IsUint8() bool {
return m.isEqualsOrGreaterZero() && m.value.Cmp(big.NewInt(math.MaxUint8)) <= 0
}
@@ -150,3 +159,7 @@ func (m PlcBINT) isLowerOrEqual(other int64) bool {
func (m PlcBINT) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteBigInt("PlcBINT", uint8(m.value.BitLen()), m.value)
}
+
+func (m PlcBINT) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), m.value.BitLen(), m.value)
+}
diff --git a/plc4go/spi/values/BOOL.go b/plc4go/spi/values/BOOL.go
index 8973086ae..b8545c14b 100644
--- a/plc4go/spi/values/BOOL.go
+++ b/plc4go/spi/values/BOOL.go
@@ -20,13 +20,14 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
)
type PlcBOOL struct {
- value bool
PlcSimpleValueAdapter
+ value bool
}
func NewPlcBOOL(value bool) PlcBOOL {
@@ -84,3 +85,7 @@ func (m PlcBOOL) GetPLCValueType() apiValues.PLCValueType {
func (m PlcBOOL) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteBit("PlcBOOL", m.value)
}
+
+func (m PlcBOOL) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), 1, m.value)
+}
diff --git a/plc4go/spi/values/BREAL.go b/plc4go/spi/values/BREAL.go
index ce6945c17..7ac32c036 100644
--- a/plc4go/spi/values/BREAL.go
+++ b/plc4go/spi/values/BREAL.go
@@ -95,6 +95,14 @@ func (m PlcBREAL) GetUint64() uint64 {
return 0
}
+func (m PlcBREAL) IsByte() bool {
+ return m.IsUint8()
+}
+
+func (m PlcBREAL) GetByte() byte {
+ return m.GetUint8()
+}
+
func (m PlcBREAL) IsInt8() bool {
return m.isGreaterOrEqual(math.MinInt8) && m.isLowerOrEqual(math.MaxInt8)
}
@@ -181,3 +189,7 @@ func (m PlcBREAL) Serialize(writeBuffer utils.WriteBuffer) error {
// TODO: fix this a insert a valid bit length calculation
return writeBuffer.WriteBigFloat("PlcBREAL", uint8(m.value.MinPrec()), m.value)
}
+
+func (m PlcBREAL) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), m.value.MinPrec(), m.value)
+}
diff --git a/plc4go/spi/values/BYTE.go b/plc4go/spi/values/BYTE.go
index a6ed568af..0dfffeee5 100644
--- a/plc4go/spi/values/BYTE.go
+++ b/plc4go/spi/values/BYTE.go
@@ -20,13 +20,14 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
)
type PlcBYTE struct {
- value byte
PlcSimpleValueAdapter
+ value byte
}
func NewPlcBYTE(value byte) PlcBYTE {
@@ -106,3 +107,7 @@ func (m PlcBYTE) GetPLCValueType() apiValues.PLCValueType {
func (m PlcBYTE) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteByte("PlcBYTE", m.value)
}
+
+func (m PlcBYTE) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), 8, m.value)
+}
diff --git a/plc4go/spi/values/CHAR.go b/plc4go/spi/values/CHAR.go
index f896ae22d..60c8d040e 100644
--- a/plc4go/spi/values/CHAR.go
+++ b/plc4go/spi/values/CHAR.go
@@ -20,14 +20,15 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
)
type PlcCHAR struct {
+ PlcSimpleValueAdapter
// TODO: Why is this a byte-array?
value []byte
- PlcSimpleValueAdapter
}
func NewPlcCHAR(value uint8) PlcCHAR {
@@ -55,3 +56,7 @@ func (m PlcCHAR) GetPLCValueType() apiValues.PLCValueType {
func (m PlcCHAR) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteString("PlcBYTE", 16, "UTF-8", string(m.value))
}
+
+func (m PlcCHAR) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), 16, m.value)
+}
diff --git a/plc4go/spi/values/DATE.go b/plc4go/spi/values/DATE.go
index 8b1898044..c0d3822dc 100644
--- a/plc4go/spi/values/DATE.go
+++ b/plc4go/spi/values/DATE.go
@@ -20,6 +20,7 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
"time"
@@ -74,3 +75,7 @@ func (m PlcDATE) GetPLCValueType() apiValues.PLCValueType {
func (m PlcDATE) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteString("PlcDATE", uint32(len([]rune(m.GetString()))*8), "UTF-8", m.GetString())
}
+
+func (m PlcDATE) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), uint32(len([]rune(m.GetString()))*8), m.value)
+}
diff --git a/plc4go/spi/values/DATE_AND_TIME.go b/plc4go/spi/values/DATE_AND_TIME.go
index 72fda2b11..589e1e7e1 100644
--- a/plc4go/spi/values/DATE_AND_TIME.go
+++ b/plc4go/spi/values/DATE_AND_TIME.go
@@ -47,7 +47,7 @@ func (m PlcDATE_AND_TIME) IsDateTime() bool {
return true
}
func (m PlcDATE_AND_TIME) GetDateTime() time.Time {
- return time.Time{}.Add(m.GetDuration())
+ return m.value
}
func (m PlcDATE_AND_TIME) GetString() string {
@@ -61,3 +61,7 @@ func (m PlcDATE_AND_TIME) GetPLCValueType() apiValues.PLCValueType {
func (m PlcDATE_AND_TIME) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteString("PlcDATE_AND_TIME", uint32(len([]rune(m.GetString()))*8), "UTF-8", m.GetString())
}
+
+func (m PlcDATE_AND_TIME) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), uint32(len([]rune(m.GetString()))*8), m.value)
+}
diff --git a/plc4go/spi/values/DINT.go b/plc4go/spi/values/DINT.go
index 663518847..997201bd6 100644
--- a/plc4go/spi/values/DINT.go
+++ b/plc4go/spi/values/DINT.go
@@ -20,6 +20,7 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
"math"
@@ -50,6 +51,14 @@ func (m PlcDINT) GetBoolean() bool {
return true
}
+func (m PlcDINT) IsByte() bool {
+ return m.IsUint8()
+}
+
+func (m PlcDINT) GetByte() byte {
+ return m.GetUint8()
+}
+
func (m PlcDINT) IsUint8() bool {
return m.value >= 0 && m.value <= math.MaxUint8
}
@@ -145,3 +154,7 @@ func (m PlcDINT) GetPLCValueType() apiValues.PLCValueType {
func (m PlcDINT) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteInt32("PlcDINT", 32, m.value)
}
+
+func (m PlcDINT) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), 32, m.value)
+}
diff --git a/plc4go/spi/values/DWORD.go b/plc4go/spi/values/DWORD.go
index ea438b21b..ed3e475fa 100644
--- a/plc4go/spi/values/DWORD.go
+++ b/plc4go/spi/values/DWORD.go
@@ -20,13 +20,14 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
)
type PlcDWORD struct {
- value uint32
PlcSimpleValueAdapter
+ value uint32
}
func NewPlcDWORD(value uint32) PlcDWORD {
@@ -105,3 +106,7 @@ func (m PlcDWORD) GetPLCValueType() apiValues.PLCValueType {
func (m PlcDWORD) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteUint32("PlcDINT", 32, m.value)
}
+
+func (m PlcDWORD) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), 32, m.value)
+}
diff --git a/plc4go/spi/values/INT.go b/plc4go/spi/values/INT.go
index 8e3e20b48..29a7f0832 100644
--- a/plc4go/spi/values/INT.go
+++ b/plc4go/spi/values/INT.go
@@ -20,6 +20,7 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
"math"
@@ -50,6 +51,14 @@ func (m PlcINT) GetBoolean() bool {
return true
}
+func (m PlcINT) IsByte() bool {
+ return m.IsUint8()
+}
+
+func (m PlcINT) GetByte() byte {
+ return m.GetUint8()
+}
+
func (m PlcINT) IsUint8() bool {
return m.value >= 0 && m.value <= math.MaxUint8
}
@@ -138,3 +147,7 @@ func (m PlcINT) GetPLCValueType() apiValues.PLCValueType {
func (m PlcINT) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteInt16("PlcINT", 16, m.value)
}
+
+func (m PlcINT) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), 16, m.value)
+}
diff --git a/plc4go/spi/values/LINT.go b/plc4go/spi/values/LINT.go
index 1b4a7b6fc..5bb1d749a 100644
--- a/plc4go/spi/values/LINT.go
+++ b/plc4go/spi/values/LINT.go
@@ -20,6 +20,7 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
"math"
@@ -50,6 +51,14 @@ func (m PlcLINT) GetBoolean() bool {
return true
}
+func (m PlcLINT) IsByte() bool {
+ return m.IsUint8()
+}
+
+func (m PlcLINT) GetByte() byte {
+ return m.GetUint8()
+}
+
func (m PlcLINT) IsUint8() bool {
return m.value >= 0 && m.value <= math.MaxUint8
}
@@ -152,3 +161,7 @@ func (m PlcLINT) GetPLCValueType() apiValues.PLCValueType {
func (m PlcLINT) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteInt64("PlcLINT", 64, m.value)
}
+
+func (m PlcLINT) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), 64, m.value)
+}
diff --git a/plc4go/spi/values/LREAL.go b/plc4go/spi/values/LREAL.go
index 16a9353ae..5827ce47d 100644
--- a/plc4go/spi/values/LREAL.go
+++ b/plc4go/spi/values/LREAL.go
@@ -168,3 +168,7 @@ func (m PlcLREAL) GetPLCValueType() apiValues.PLCValueType {
func (m PlcLREAL) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteFloat64("PlcLREAL", 64, m.value)
}
+
+func (m PlcLREAL) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), 64, m.value)
+}
diff --git a/plc4go/spi/values/LTIME.go b/plc4go/spi/values/LTIME.go
index 5060b259c..5b4dbada3 100644
--- a/plc4go/spi/values/LTIME.go
+++ b/plc4go/spi/values/LTIME.go
@@ -27,8 +27,8 @@ import (
)
type PlcLTIME struct {
- value uint64
PlcSimpleValueAdapter
+ value uint64
}
func NewPlcLTIME(value uint64) PlcLTIME {
@@ -66,3 +66,7 @@ func (m PlcLTIME) GetPLCValueType() apiValues.PLCValueType {
func (m PlcLTIME) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteString("PlcLTIME", uint32(len([]rune(m.GetString()))*8), "UTF-8", m.GetString())
}
+
+func (m PlcLTIME) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), uint32(len([]rune(m.GetString()))*8), m.value)
+}
diff --git a/plc4go/spi/values/LWORD.go b/plc4go/spi/values/LWORD.go
index e905b2e66..e0f508be3 100644
--- a/plc4go/spi/values/LWORD.go
+++ b/plc4go/spi/values/LWORD.go
@@ -20,13 +20,14 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
)
type PlcLWORD struct {
- value uint64
PlcSimpleValueAdapter
+ value uint64
}
func NewPlcLWORD(value uint64) PlcLWORD {
@@ -121,3 +122,7 @@ func (m PlcLWORD) GetPLCValueType() apiValues.PLCValueType {
func (m PlcLWORD) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteUint64("PlcLWORD", 64, m.value)
}
+
+func (m PlcLWORD) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), 64, m.value)
+}
diff --git a/plc4go/spi/values/NULL.go b/plc4go/spi/values/NULL.go
index 0d4e0e01e..d7b093918 100644
--- a/plc4go/spi/values/NULL.go
+++ b/plc4go/spi/values/NULL.go
@@ -19,7 +19,10 @@
package values
-import apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
+import (
+ "fmt"
+ apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
+)
type PlcNULL struct {
PlcValueAdapter
@@ -36,3 +39,7 @@ func (m PlcNULL) GetRaw() []byte {
func (m PlcNULL) GetPLCValueType() apiValues.PLCValueType {
return apiValues.NULL
}
+
+func (m PlcNULL) String() string {
+ return fmt.Sprintf("%s", m.GetPLCValueType())
+}
diff --git a/plc4go/spi/values/PlcList.go b/plc4go/spi/values/PlcList.go
index c83c58ea8..f90c8eed6 100644
--- a/plc4go/spi/values/PlcList.go
+++ b/plc4go/spi/values/PlcList.go
@@ -20,6 +20,7 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
"github.com/pkg/errors"
@@ -223,3 +224,9 @@ func (m PlcList) Serialize(writeBuffer utils.WriteBuffer) error {
}
return nil
}
+
+func (m PlcList) String() string {
+ allBits := 0
+ // TODO: do we want to aggregate the bit length?
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), allBits, m.Values)
+}
diff --git a/plc4go/spi/values/PlcSimpleValueAdapter.go b/plc4go/spi/values/PlcSimpleValueAdapter.go
deleted file mode 100644
index 2ec4bbe7f..000000000
--- a/plc4go/spi/values/PlcSimpleValueAdapter.go
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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 values
-
-type PlcSimpleValueAdapter struct {
- PlcValueAdapter
-}
-
-func (m PlcSimpleValueAdapter) IsSimple() bool {
- return true
-}
-
-func (m PlcSimpleValueAdapter) GetLength() uint32 {
- return 1
-}
-
-type PlcSimpleNumericValueAdapter struct {
- PlcSimpleValueAdapter
-}
-
-func (m PlcSimpleNumericValueAdapter) IsBool() bool {
- return true
-}
-
-func (m PlcSimpleNumericValueAdapter) IsByte() bool {
- return m.IsUint8()
-}
-
-func (m PlcSimpleNumericValueAdapter) GetByte() byte {
- return m.GetUint8()
-}
-
-func (m PlcSimpleNumericValueAdapter) IsUint8() bool {
- return true
-}
-
-func (m PlcSimpleNumericValueAdapter) IsUint16() bool {
- return true
-}
-
-func (m PlcSimpleNumericValueAdapter) IsUint32() bool {
- return true
-}
-
-func (m PlcSimpleNumericValueAdapter) IsUint64() bool {
- return true
-}
-
-func (m PlcSimpleNumericValueAdapter) IsInt8() bool {
- return true
-}
-
-func (m PlcSimpleNumericValueAdapter) IsInt16() bool {
- return true
-}
-
-func (m PlcSimpleNumericValueAdapter) IsInt32() bool {
- return true
-}
-
-func (m PlcSimpleNumericValueAdapter) IsInt64() bool {
- return true
-}
-
-func (m PlcSimpleNumericValueAdapter) IsFloat32() bool {
- return true
-}
-
-func (m PlcSimpleNumericValueAdapter) IsFloat64() bool {
- return true
-}
-
-func (m PlcSimpleNumericValueAdapter) IsString() bool {
- return true
-}
diff --git a/plc4go/spi/values/PlcStruct.go b/plc4go/spi/values/PlcStruct.go
index 121e93995..133125230 100644
--- a/plc4go/spi/values/PlcStruct.go
+++ b/plc4go/spi/values/PlcStruct.go
@@ -20,6 +20,7 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
"github.com/pkg/errors"
@@ -108,3 +109,9 @@ func (m PlcStruct) Serialize(writeBuffer utils.WriteBuffer) error {
}
return writeBuffer.PopContext("PlcStruct")
}
+
+func (m PlcStruct) String() string {
+ allBits := 0
+ // TODO: do we want to aggregate the bit length?
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), allBits, m.values)
+}
diff --git a/plc4go/spi/values/PlcValueAdapter.go b/plc4go/spi/values/PlcValueAdapter.go
index 1fbca95f9..09f1243e5 100644
--- a/plc4go/spi/values/PlcValueAdapter.go
+++ b/plc4go/spi/values/PlcValueAdapter.go
@@ -68,11 +68,11 @@ func (m PlcValueAdapter) GetBoolArray() []bool {
}
func (m PlcValueAdapter) IsByte() bool {
- return m.IsUint8()
+ return false
}
func (m PlcValueAdapter) GetByte() byte {
- return m.GetUint8()
+ panic("GetByte not implemented")
}
////////
@@ -225,7 +225,7 @@ func (m PlcValueAdapter) GetStruct() map[string]apiValues.PlcValue {
panic("GetStruct not implemented")
}
func (m PlcValueAdapter) IsDate() bool {
- panic("IsDate not implemented")
+ return false
}
func (m PlcValueAdapter) GetDate() time.Time {
panic("GetDate not implemented")
@@ -240,3 +240,71 @@ func (m PlcValueAdapter) GetDateTime() time.Time {
func (m PlcValueAdapter) GetPLCValueType() apiValues.PLCValueType {
panic("GetPLCValueType not implemented")
}
+
+type PlcSimpleValueAdapter struct {
+ PlcValueAdapter
+}
+
+func (m PlcSimpleValueAdapter) IsSimple() bool {
+ return true
+}
+
+func (m PlcSimpleValueAdapter) GetLength() uint32 {
+ return 1
+}
+
+type PlcSimpleNumericValueAdapter struct {
+ PlcSimpleValueAdapter
+}
+
+func (m PlcSimpleNumericValueAdapter) IsBool() bool {
+ return true
+}
+
+func (m PlcSimpleNumericValueAdapter) IsByte() bool {
+ return true
+}
+
+func (m PlcSimpleNumericValueAdapter) IsUint8() bool {
+ return true
+}
+
+func (m PlcSimpleNumericValueAdapter) IsUint16() bool {
+ return true
+}
+
+func (m PlcSimpleNumericValueAdapter) IsUint32() bool {
+ return true
+}
+
+func (m PlcSimpleNumericValueAdapter) IsUint64() bool {
+ return true
+}
+
+func (m PlcSimpleNumericValueAdapter) IsInt8() bool {
+ return true
+}
+
+func (m PlcSimpleNumericValueAdapter) IsInt16() bool {
+ return true
+}
+
+func (m PlcSimpleNumericValueAdapter) IsInt32() bool {
+ return true
+}
+
+func (m PlcSimpleNumericValueAdapter) IsInt64() bool {
+ return true
+}
+
+func (m PlcSimpleNumericValueAdapter) IsFloat32() bool {
+ return true
+}
+
+func (m PlcSimpleNumericValueAdapter) IsFloat64() bool {
+ return true
+}
+
+func (m PlcSimpleNumericValueAdapter) IsString() bool {
+ return true
+}
diff --git a/plc4go/spi/values/REAL.go b/plc4go/spi/values/REAL.go
index bd0bdeb84..8f8b92f2f 100644
--- a/plc4go/spi/values/REAL.go
+++ b/plc4go/spi/values/REAL.go
@@ -50,6 +50,14 @@ func (m PlcREAL) GetBoolean() bool {
return true
}
+func (m PlcREAL) IsByte() bool {
+ return m.IsUint8()
+}
+
+func (m PlcREAL) GetByte() byte {
+ return m.GetUint8()
+}
+
func (m PlcREAL) IsUint8() bool {
return m.value >= 0 && m.value <= math.MaxUint8
}
@@ -162,3 +170,7 @@ func (m PlcREAL) GetPLCValueType() apiValues.PLCValueType {
func (m PlcREAL) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteFloat32("PlcREAL", 32, m.value)
}
+
+func (m PlcREAL) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), 32, m.value)
+}
diff --git a/plc4go/spi/values/RawPlcValue.go b/plc4go/spi/values/RawPlcValue.go
index 0f580b796..d419453ef 100644
--- a/plc4go/spi/values/RawPlcValue.go
+++ b/plc4go/spi/values/RawPlcValue.go
@@ -21,6 +21,7 @@ package values
import (
"encoding/hex"
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
)
@@ -30,9 +31,9 @@ type PlcValueDecoder interface {
}
type RawPlcValue struct {
+ PlcValueAdapter
readBuffer utils.ReadBuffer
decoder PlcValueDecoder
- PlcValueAdapter
}
func NewRawPlcValue(readBuffer utils.ReadBuffer, decoder PlcValueDecoder) RawPlcValue {
@@ -85,3 +86,7 @@ func (m RawPlcValue) GetString() string {
func (m RawPlcValue) GetPLCValueType() apiValues.PLCValueType {
return apiValues.RAW_PLC_VALUE
}
+
+func (m RawPlcValue) String() string {
+ return fmt.Sprintf("%s", m.GetPLCValueType())
+}
diff --git a/plc4go/spi/values/SINT.go b/plc4go/spi/values/SINT.go
index c4261053a..39a401a2f 100644
--- a/plc4go/spi/values/SINT.go
+++ b/plc4go/spi/values/SINT.go
@@ -20,6 +20,7 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
"strconv"
@@ -49,6 +50,14 @@ func (m PlcSINT) GetBoolean() bool {
return true
}
+func (m PlcSINT) IsByte() bool {
+ return m.IsUint8()
+}
+
+func (m PlcSINT) GetByte() byte {
+ return m.GetUint8()
+}
+
func (m PlcSINT) IsUint8() bool {
return m.value >= 0
}
@@ -130,3 +139,7 @@ func (m PlcSINT) GetPLCValueType() apiValues.PLCValueType {
func (m PlcSINT) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteInt8("PlcINT", 8, m.value)
}
+
+func (m PlcSINT) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), 8, m.value)
+}
diff --git a/plc4go/spi/values/STRING.go b/plc4go/spi/values/STRING.go
index ac2e33d10..458038c3a 100644
--- a/plc4go/spi/values/STRING.go
+++ b/plc4go/spi/values/STRING.go
@@ -20,13 +20,14 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
)
type PlcSTRING struct {
- value string
PlcSimpleValueAdapter
+ value string
}
func NewPlcSTRING(value string) PlcSTRING {
@@ -56,3 +57,7 @@ func (m PlcSTRING) GetPLCValueType() apiValues.PLCValueType {
func (m PlcSTRING) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteString("PlcSTRING", uint32(len([]rune(m.value))*8), "UTF-8", m.value)
}
+
+func (m PlcSTRING) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), uint32(len([]rune(m.value))*8), m.value)
+}
diff --git a/plc4go/spi/values/TIME.go b/plc4go/spi/values/TIME.go
index 2bf89e1b4..96e4a2cf8 100644
--- a/plc4go/spi/values/TIME.go
+++ b/plc4go/spi/values/TIME.go
@@ -27,8 +27,8 @@ import (
)
type PlcTIME struct {
- value uint32
PlcSimpleValueAdapter
+ value uint32
}
func NewPlcTIME(value uint32) PlcTIME {
@@ -66,3 +66,7 @@ func (m PlcTIME) GetPLCValueType() apiValues.PLCValueType {
func (m PlcTIME) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteString("PlcTIME", uint32(len([]rune(m.GetString()))*8), "UTF-8", m.GetString())
}
+
+func (m PlcTIME) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), uint32(len([]rune(m.GetString()))*8), m.value)
+}
diff --git a/plc4go/spi/values/TIME_OF_DAY.go b/plc4go/spi/values/TIME_OF_DAY.go
index cb59c0b9d..43a879426 100644
--- a/plc4go/spi/values/TIME_OF_DAY.go
+++ b/plc4go/spi/values/TIME_OF_DAY.go
@@ -20,14 +20,15 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
"time"
)
type PlcTIME_OF_DAY struct {
- value time.Time
PlcSimpleValueAdapter
+ value time.Time
}
func NewPlcTIME_OF_DAY(value interface{}) PlcTIME_OF_DAY {
@@ -77,3 +78,7 @@ func (m PlcTIME_OF_DAY) GetPLCValueType() apiValues.PLCValueType {
func (m PlcTIME_OF_DAY) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteString("PlcTIME_OF_DAY", uint32(len([]rune(m.GetString()))*8), "UTF-8", m.GetString())
}
+
+func (m PlcTIME_OF_DAY) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), uint32(len([]rune(m.GetString()))*8), m.value)
+}
diff --git a/plc4go/spi/values/UDINT.go b/plc4go/spi/values/UDINT.go
index de9fc9886..3ba0f4d3a 100644
--- a/plc4go/spi/values/UDINT.go
+++ b/plc4go/spi/values/UDINT.go
@@ -20,6 +20,7 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
"math"
@@ -80,6 +81,14 @@ func (m PlcUDINT) GetUint64() uint64 {
return uint64(m.GetUint32())
}
+func (m PlcUDINT) IsByte() bool {
+ return m.IsUint8()
+}
+
+func (m PlcUDINT) GetByte() byte {
+ return m.GetUint8()
+}
+
func (m PlcUDINT) IsInt8() bool {
return m.value < math.MaxInt8
}
@@ -138,3 +147,7 @@ func (m PlcUDINT) GetPLCValueType() apiValues.PLCValueType {
func (m PlcUDINT) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteUint32("PlcUDINT", 32, m.value)
}
+
+func (m PlcUDINT) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), 32, m.value)
+}
diff --git a/plc4go/spi/values/UINT.go b/plc4go/spi/values/UINT.go
index 2eea82851..2186b761e 100644
--- a/plc4go/spi/values/UINT.go
+++ b/plc4go/spi/values/UINT.go
@@ -20,6 +20,7 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
"math"
@@ -50,6 +51,14 @@ func (m PlcUINT) GetBoolean() bool {
return true
}
+func (m PlcUINT) IsByte() bool {
+ return m.IsUint8()
+}
+
+func (m PlcUINT) GetByte() byte {
+ return m.GetUint8()
+}
+
func (m PlcUINT) IsUint8() bool {
return m.value <= math.MaxUint8
}
@@ -124,3 +133,7 @@ func (m PlcUINT) GetPLCValueType() apiValues.PLCValueType {
func (m PlcUINT) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteUint16("PlcUINT", 16, m.value)
}
+
+func (m PlcUINT) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), 16, m.value)
+}
diff --git a/plc4go/spi/values/ULINT.go b/plc4go/spi/values/ULINT.go
index 4e8f400b1..243f2a1e6 100644
--- a/plc4go/spi/values/ULINT.go
+++ b/plc4go/spi/values/ULINT.go
@@ -20,6 +20,7 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
"math"
@@ -50,6 +51,14 @@ func (m PlcULINT) GetBoolean() bool {
return true
}
+func (m PlcULINT) IsByte() bool {
+ return m.IsUint8()
+}
+
+func (m PlcULINT) GetByte() byte {
+ return m.GetUint8()
+}
+
func (m PlcULINT) IsUint8() bool {
return m.value <= math.MaxUint8
}
@@ -152,3 +161,7 @@ func (m PlcULINT) GetPLCValueType() apiValues.PLCValueType {
func (m PlcULINT) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteUint64("PlcUINT", 64, m.value)
}
+
+func (m PlcULINT) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), 64, m.value)
+}
diff --git a/plc4go/spi/values/USINT.go b/plc4go/spi/values/USINT.go
index 16891e9a1..12da8ac59 100644
--- a/plc4go/spi/values/USINT.go
+++ b/plc4go/spi/values/USINT.go
@@ -20,6 +20,7 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
"math"
@@ -50,6 +51,14 @@ func (m PlcUSINT) GetBoolean() bool {
return true
}
+func (m PlcUSINT) IsByte() bool {
+ return m.IsUint8()
+}
+
+func (m PlcUSINT) GetByte() byte {
+ return m.GetUint8()
+}
+
func (m PlcUSINT) GetUint8() uint8 {
return m.value
}
@@ -110,3 +119,7 @@ func (m PlcUSINT) GetPLCValueType() apiValues.PLCValueType {
func (m PlcUSINT) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteUint8("PlcUSINT", 8, m.value)
}
+
+func (m PlcUSINT) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), 8, m.value)
+}
diff --git a/plc4go/spi/values/WCHAR.go b/plc4go/spi/values/WCHAR.go
index f27b0f820..f2996e7b4 100644
--- a/plc4go/spi/values/WCHAR.go
+++ b/plc4go/spi/values/WCHAR.go
@@ -20,14 +20,15 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
"unicode/utf16"
)
type PlcWCHAR struct {
- value []rune
PlcSimpleValueAdapter
+ value []rune
}
func NewPlcWCHAR(value uint16) PlcWCHAR {
@@ -57,3 +58,7 @@ func (m PlcWCHAR) GetPLCValueType() apiValues.PLCValueType {
func (m PlcWCHAR) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteString("PlcSTRING", uint32(len(m.value)*8), "UTF-8", string(m.value))
}
+
+func (m PlcWCHAR) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), uint32(len(m.value)*8), m.value)
+}
diff --git a/plc4go/spi/values/WORD.go b/plc4go/spi/values/WORD.go
index c47167a0d..dd92a7ab6 100644
--- a/plc4go/spi/values/WORD.go
+++ b/plc4go/spi/values/WORD.go
@@ -20,13 +20,14 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
)
type PlcWORD struct {
- value uint16
PlcSimpleValueAdapter
+ value uint16
}
func NewPlcWORD(value uint16) PlcWORD {
@@ -97,3 +98,7 @@ func (m PlcWORD) GetPLCValueType() apiValues.PLCValueType {
func (m PlcWORD) Serialize(writeBuffer utils.WriteBuffer) error {
return writeBuffer.WriteUint16("PlcWORD", 16, m.value)
}
+
+func (m PlcWORD) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), 16, m.value)
+}
diff --git a/plc4go/spi/values/WSTRING.go b/plc4go/spi/values/WSTRING.go
index 7da2f87ab..89a9ed3c7 100644
--- a/plc4go/spi/values/WSTRING.go
+++ b/plc4go/spi/values/WSTRING.go
@@ -20,14 +20,15 @@
package values
import (
+ "fmt"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
"unicode/utf16"
)
type PlcWSTRING struct {
- value []rune
PlcSimpleValueAdapter
+ value []rune
}
func NewPlcWSTRING(value []uint16) PlcWSTRING {
@@ -55,5 +56,9 @@ func (m PlcWSTRING) GetPLCValueType() apiValues.PLCValueType {
}
func (m PlcWSTRING) Serialize(writeBuffer utils.WriteBuffer) error {
- return writeBuffer.WriteString("PlcSTRING", uint32(len([]rune(m.value))*8), "UTF-8", string(m.value))
+ return writeBuffer.WriteString("PlcSTRING", uint32(len(m.value)*8), "UTF-8", string(m.value))
+}
+
+func (m PlcWSTRING) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPLCValueType(), uint32(len(m.value)*8), m.value)
}
diff --git a/plc4go/spi/values/value_combination_test.go b/plc4go/spi/values/value_combination_test.go
new file mode 100644
index 000000000..a190e54c0
--- /dev/null
+++ b/plc4go/spi/values/value_combination_test.go
@@ -0,0 +1,338 @@
+/*
+ * 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 values
+
+import (
+ "fmt"
+ apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
+ "github.com/apache/plc4x/plc4go/spi/utils"
+ "github.com/stretchr/testify/assert"
+ "math"
+ "math/big"
+ "reflect"
+ "strings"
+ "testing"
+ "time"
+)
+
+func TestCombinations(t *testing.T) {
+ tests := []struct {
+ name apiValues.PLCValueType
+ arguments []apiValues.PlcValue
+ }{
+ {
+ name: apiValues.BINT,
+ arguments: []apiValues.PlcValue{
+ NewPlcBINT(big.NewInt(0)),
+ NewPlcBINT(big.NewInt(64)),
+ NewPlcBINT(big.NewInt(255)),
+ NewPlcBINT(big.NewInt(math.MinInt64)),
+ NewPlcBINT(big.NewInt(math.MaxInt64)),
+ },
+ },
+ {
+ name: apiValues.BOOL,
+ arguments: []apiValues.PlcValue{
+ NewPlcBOOL(true),
+ NewPlcBOOL(false),
+ },
+ },
+ {
+ name: apiValues.BREAL,
+ arguments: []apiValues.PlcValue{
+ NewPlcBREAL(big.NewFloat(0)),
+ NewPlcBREAL(big.NewFloat(64)),
+ NewPlcBREAL(big.NewFloat(255)),
+ NewPlcBREAL(big.NewFloat(math.MinInt64)),
+ NewPlcBREAL(big.NewFloat(math.MaxInt64)),
+ },
+ },
+ {
+ name: apiValues.BYTE,
+ arguments: []apiValues.PlcValue{
+ NewPlcBYTE(0),
+ NewPlcBYTE(64),
+ NewPlcBYTE(255),
+ },
+ },
+ {
+ name: apiValues.CHAR,
+ arguments: []apiValues.PlcValue{
+ NewPlcCHAR(0),
+ NewPlcCHAR(64),
+ NewPlcCHAR(255),
+ },
+ },
+ {
+ name: apiValues.DATE,
+ arguments: []apiValues.PlcValue{
+ NewPlcDATE(time.Now()),
+ },
+ },
+ {
+ name: apiValues.DATE_AND_TIME,
+ arguments: []apiValues.PlcValue{
+ NewPlcDATE_AND_TIME(time.Now()),
+ },
+ },
+ {
+ name: apiValues.DINT,
+ arguments: []apiValues.PlcValue{
+ NewPlcDINT(math.MinInt32),
+ NewPlcDINT(64),
+ NewPlcDINT(255),
+ NewPlcDINT(math.MaxInt32),
+ },
+ },
+ {
+ name: apiValues.DWORD,
+ arguments: []apiValues.PlcValue{
+ NewPlcDWORD(0),
+ NewPlcDWORD(64),
+ NewPlcDWORD(255),
+ NewPlcDWORD(math.MaxUint32),
+ },
+ },
+ {
+ name: apiValues.INT,
+ arguments: []apiValues.PlcValue{
+ NewPlcINT(0),
+ NewPlcINT(64),
+ NewPlcINT(255),
+ NewPlcINT(math.MaxInt16),
+ },
+ },
+ {
+ name: apiValues.LINT,
+ arguments: []apiValues.PlcValue{
+ NewPlcLINT(0),
+ NewPlcLINT(64),
+ NewPlcLINT(255),
+ NewPlcLINT(math.MaxInt64),
+ },
+ },
+ {
+ name: apiValues.LIST,
+ arguments: []apiValues.PlcValue{
+ NewPlcList(nil),
+ NewPlcList([]apiValues.PlcValue{
+ NewPlcBOOL(true),
+ NewPlcBOOL(false),
+ }),
+ },
+ },
+ {
+ name: apiValues.LREAL,
+ arguments: []apiValues.PlcValue{
+ NewPlcREAL(0),
+ NewPlcREAL(64),
+ NewPlcREAL(255),
+ NewPlcREAL(math.MinInt64),
+ NewPlcREAL(math.MaxInt64),
+ },
+ },
+ {
+ name: apiValues.LTIME,
+ arguments: []apiValues.PlcValue{
+ NewPlcLTIME(0),
+ NewPlcLTIME(64),
+ NewPlcLTIME(255),
+ NewPlcLTIME(math.MaxUint64),
+ },
+ },
+ {
+ name: apiValues.LWORD,
+ arguments: []apiValues.PlcValue{
+ NewPlcLWORD(0),
+ NewPlcLWORD(64),
+ NewPlcLWORD(255),
+ NewPlcLWORD(0),
+ NewPlcLWORD(math.MaxUint64),
+ },
+ },
+ {
+ name: apiValues.NULL,
+ arguments: []apiValues.PlcValue{
+ NewPlcNULL(),
+ },
+ },
+ {
+ name: apiValues.RAW_PLC_VALUE,
+ arguments: []apiValues.PlcValue{
+ NewRawPlcValue(utils.NewReadBufferByteBased([]byte{0x47, 0x11}), nil),
+ },
+ },
+ {
+ name: apiValues.REAL,
+ arguments: []apiValues.PlcValue{
+ NewPlcREAL(0),
+ NewPlcREAL(64),
+ NewPlcREAL(255),
+ NewPlcREAL(math.MaxInt64),
+ },
+ },
+ {
+ name: apiValues.STRUCT,
+ arguments: []apiValues.PlcValue{
+ NewPlcStruct(map[string]apiValues.PlcValue{
+ "something": NewPlcStruct(map[string]apiValues.PlcValue{
+ "more": NewPlcList([]apiValues.PlcValue{
+ NewPlcBOOL(true),
+ NewPlcBOOL(false),
+ }),
+ "evenMore": NewPlcBOOL(false),
+ }),
+ "somethingOther": NewPlcBOOL(true),
+ }),
+ },
+ },
+ {
+ name: apiValues.SINT,
+ arguments: []apiValues.PlcValue{
+ NewPlcSINT(-128),
+ NewPlcSINT(-64),
+ NewPlcSINT(0),
+ NewPlcSINT(64),
+ NewPlcSINT(127),
+ },
+ },
+ {
+ name: apiValues.STRING,
+ arguments: []apiValues.PlcValue{
+ NewPlcSTRING("Hello Tody"),
+ NewPlcSTRING("1"),
+ NewPlcSTRING("true"),
+ NewPlcSTRING("255"),
+ NewPlcSTRING("5.4"),
+ },
+ },
+ {
+ name: apiValues.TIME,
+ arguments: []apiValues.PlcValue{
+ NewPlcTIME(0),
+ NewPlcTIME(64),
+ NewPlcTIME(255),
+ NewPlcTIME(math.MaxUint32),
+ },
+ },
+ {
+ name: apiValues.TIME_OF_DAY,
+ arguments: []apiValues.PlcValue{
+ NewPlcTIME_OF_DAY(time.Now()),
+ NewPlcTIME_OF_DAY(0),
+ NewPlcTIME_OF_DAY(64),
+ NewPlcTIME_OF_DAY(255),
+ NewPlcTIME_OF_DAY(math.MaxUint32),
+ },
+ },
+ {
+ name: apiValues.UDINT,
+ arguments: []apiValues.PlcValue{
+ NewPlcUDINT(0),
+ NewPlcUDINT(64),
+ NewPlcUDINT(255),
+ NewPlcUDINT(math.MaxUint32),
+ },
+ },
+ {
+ name: apiValues.UINT,
+ arguments: []apiValues.PlcValue{
+ NewPlcUINT(0),
+ NewPlcUINT(64),
+ NewPlcUINT(255),
+ NewPlcUINT(math.MaxUint16),
+ },
+ },
+ {
+ name: apiValues.USINT,
+ arguments: []apiValues.PlcValue{
+ NewPlcUSINT(0),
+ NewPlcUSINT(64),
+ NewPlcUSINT(255),
+ NewPlcUSINT(math.MaxUint8),
+ },
+ },
+ {
+ name: apiValues.ULINT,
+ arguments: []apiValues.PlcValue{
+ NewPlcULINT(0),
+ NewPlcULINT(64),
+ NewPlcULINT(math.MaxUint8),
+ },
+ },
+ {
+ name: apiValues.WCHAR,
+ arguments: []apiValues.PlcValue{
+ NewPlcWCHAR(0),
+ NewPlcWCHAR(64),
+ NewPlcWCHAR(255),
+ NewPlcWCHAR(math.MaxUint16),
+ },
+ },
+ {
+ name: apiValues.WORD,
+ arguments: []apiValues.PlcValue{
+ NewPlcWORD(0),
+ NewPlcWORD(64),
+ NewPlcWORD(255),
+ NewPlcWORD(math.MaxUint16),
+ },
+ },
+ {
+ name: apiValues.WSTRING,
+ arguments: []apiValues.PlcValue{
+ NewPlcWSTRING([]uint16{0, 64, 255}),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name.String(), func(t *testing.T) {
+ for _, argument := range tt.arguments {
+ argumentCopy := argument
+ t.Run(fmt.Sprintf("%s", argument), func(t *testing.T) {
+ plcValueType := reflect.TypeOf((*apiValues.PlcValue)(nil)).Elem()
+ methods := make(map[string]reflect.Method)
+ for i := 0; i < plcValueType.NumMethod(); i++ {
+ method := plcValueType.Method(i)
+ methods[method.Name] = method
+ }
+
+ for methodName, _ := range methods {
+ if strings.HasPrefix(methodName, "Is") {
+ queryType := strings.TrimPrefix(methodName, "Is")
+ t.Run(queryType, func(t *testing.T) {
+ getMethod := methods[fmt.Sprintf("Get%s", queryType)]
+ isA := reflect.ValueOf(argumentCopy).MethodByName(methodName).Call([]reflect.Value{})[0].Bool()
+ t.Logf("%s() == %t", methodName, isA)
+ var emptyMethod reflect.Method
+ if isA && getMethod != emptyMethod {
+ t.Logf("Calling %s()", getMethod.Name)
+ value := reflect.ValueOf(argumentCopy).MethodByName(getMethod.Name).Call([]reflect.Value{})[0]
+ assert.True(t, value.IsValid())
+ t.Logf("Value: %v", value)
+ }
+ })
+ }
+ }
+ })
+ }
+ })
+ }
+}