|
9 | 9 | _parse_read_response, |
10 | 10 | _build_write_payload, |
11 | 11 | _parse_write_response, |
| 12 | +<<<<<<< HEAD |
12 | 13 | _build_explore_request, |
13 | 14 | _parse_explore_datablocks, |
| 15 | +||||||| parent of 22a5c08 (fix: add SequenceNumber to Get/SetMultiVariables payloads (#738)) |
| 16 | +======= |
| 17 | + _build_area_read_payload, |
| 18 | + _build_area_write_payload, |
| 19 | + _build_symbolic_read_payload, |
| 20 | + _build_symbolic_write_payload, |
| 21 | +>>>>>>> 22a5c08 (fix: add SequenceNumber to Get/SetMultiVariables payloads (#738)) |
14 | 22 | ) |
| 23 | +<<<<<<< HEAD |
15 | 24 | from s7.connection import S7CommPlusConnection |
16 | 25 | from s7.codec import encode_pvalue_blob |
17 | 26 | from s7.codec import _pvalue_element_size as _element_size |
18 | 27 | from s7.codec import skip_typed_value, parse_server_session_version |
| 28 | +||||||| parent of 22a5c08 (fix: add SequenceNumber to Get/SetMultiVariables payloads (#738)) |
| 29 | +from s7.codec import encode_pvalue_blob |
| 30 | +from s7.connection import S7CommPlusConnection, _element_size |
| 31 | +======= |
| 32 | +from s7.codec import encode_object_qualifier, encode_pvalue_blob |
| 33 | +from s7.connection import S7CommPlusConnection, _element_size |
| 34 | +>>>>>>> 22a5c08 (fix: add SequenceNumber to Get/SetMultiVariables payloads (#738)) |
19 | 35 | from s7.protocol import DataType, ElementID, ObjectId |
20 | 36 | from s7.vlq import ( |
21 | 37 | encode_uint32_vlq, |
@@ -194,6 +210,42 @@ def test_write_read_consistency(self) -> None: |
194 | 210 | assert isinstance(write_payload, bytes) |
195 | 211 |
|
196 | 212 |
|
| 213 | +class TestSequenceNumber: |
| 214 | + """Verify all payload builders include a SequenceNumber after ObjectQualifier.""" |
| 215 | + |
| 216 | + @staticmethod |
| 217 | + def _has_sequence_number(payload: bytes) -> bool: |
| 218 | + oq = encode_object_qualifier() |
| 219 | + idx = bytes(payload).find(oq) |
| 220 | + assert idx >= 0, "ObjectQualifier not found in payload" |
| 221 | + seq_offset = idx + len(oq) |
| 222 | + return payload[seq_offset : seq_offset + 1] == encode_uint32_vlq(1) |
| 223 | + |
| 224 | + def test_read_payload_has_sequence_number(self) -> None: |
| 225 | + payload = _build_read_payload([(1, 0, 4)]) |
| 226 | + assert self._has_sequence_number(payload) |
| 227 | + |
| 228 | + def test_write_payload_has_sequence_number(self) -> None: |
| 229 | + payload = _build_write_payload([(1, 0, bytes([1, 2, 3, 4]))]) |
| 230 | + assert self._has_sequence_number(payload) |
| 231 | + |
| 232 | + def test_area_read_payload_has_sequence_number(self) -> None: |
| 233 | + payload = _build_area_read_payload(82, 0, 4) |
| 234 | + assert self._has_sequence_number(payload) |
| 235 | + |
| 236 | + def test_area_write_payload_has_sequence_number(self) -> None: |
| 237 | + payload = _build_area_write_payload(82, 0, b"\x00\x00\x00\x00") |
| 238 | + assert self._has_sequence_number(payload) |
| 239 | + |
| 240 | + def test_symbolic_read_payload_has_sequence_number(self) -> None: |
| 241 | + payload = _build_symbolic_read_payload(0x8A0E0001, [1, 4]) |
| 242 | + assert self._has_sequence_number(payload) |
| 243 | + |
| 244 | + def test_symbolic_write_payload_has_sequence_number(self) -> None: |
| 245 | + payload = _build_symbolic_write_payload(0x8A0E0001, [1, 4], b"\x01") |
| 246 | + assert self._has_sequence_number(payload) |
| 247 | + |
| 248 | + |
197 | 249 | # -- Connection unit tests -- |
198 | 250 |
|
199 | 251 |
|
|
0 commit comments