Skip to content

Commit 72f1e1e

Browse files
committed
improve custom struct test and fix bug in ua_binary
1 parent 43c9146 commit 72f1e1e

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

opcua/ua/ua_binary.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def pack_array(self, array):
9191
length = len(array)
9292
b = [self.pack(val) for val in array]
9393
b.insert(0, Primitives.Int32.pack(length))
94+
return b"".join(b)
9495

9596
def unpack_array(self, data):
9697
length = Primitives.Int32.unpack(data)

tests/tests_unit.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_custom_structs(self):
5757
#self.GuidValue = uuid.uudib"14"
5858
v.ByteStringValue = b"fifteen"
5959
v.XmlElementValue = ua.XmlElement("<toto>titi</toto>")
60-
v.NodeIdValue = ua.NodeId("ns=4;i=9999")
60+
v.NodeIdValue = ua.NodeId.from_string("ns=4;i=9999")
6161
#self.ExpandedNodeIdValue =
6262
#self.QualifiedNameValue =
6363
#self.LocalizedTextValue =
@@ -74,6 +74,54 @@ def test_custom_structs(self):
7474
v2 = s.ScalarValueDataType.from_binary(ua.utils.Buffer(data))
7575
self.assertEqual(v.NodeIdValue, v2.NodeIdValue)
7676

77+
def test_custom_structs_array(self):
78+
xmlpath = "tests/example.bsd"
79+
c = StructGenerator(xmlpath, "structures.py")
80+
c.run()
81+
import structures as s
82+
83+
# test with default values
84+
v = s.ArrayValueDataType()
85+
data = v.to_binary()
86+
v2 = s.ArrayValueDataType.from_binary(ua.utils.Buffer(data))
87+
88+
89+
# set some values
90+
v = s.ArrayValueDataType()
91+
v.SbyteValue = [1]
92+
v.ByteValue = [2]
93+
v.Int16Value = [3]
94+
v.UInt16Value = [4]
95+
v.Int32Value = [5]
96+
v.UInt32Value = [6]
97+
v.Int64Value = [7]
98+
v.UInt64Value = [8]
99+
v.FloatValue = [9.0]
100+
v.DoubleValue = [10.0]
101+
v.StringValue = ["elleven"]
102+
v.DateTimeValue = [datetime.utcnow()]
103+
#self.GuidValue = uuid.uudib"14"
104+
v.ByteStringValue = [b"fifteen", b"sixteen"]
105+
v.XmlElementValue = [ua.XmlElement("<toto>titi</toto>")]
106+
v.NodeIdValue = [ua.NodeId.from_string("ns=4;i=9999"), ua.NodeId.from_string("i=6")]
107+
#self.ExpandedNodeIdValue =
108+
#self.QualifiedNameValue =
109+
#self.LocalizedTextValue =
110+
#self.StatusCodeValue =
111+
#self.VariantValue =
112+
#self.EnumerationValue =
113+
#self.StructureValue =
114+
#self.Number =
115+
#self.Integer =
116+
#self.UInteger =
117+
118+
119+
data = v.to_binary()
120+
v2 = s.ArrayValueDataType.from_binary(ua.utils.Buffer(data))
121+
self.assertEqual(v.NodeIdValue, v2.NodeIdValue)
122+
print(v2.NodeIdValue)
123+
124+
77125
def test_nodeid_ordering(self):
78126
a = ua.NodeId(2000, 1)
79127
b = ua.NodeId(3000, 1)

0 commit comments

Comments
 (0)