Skip to content

Commit

Permalink
fix field termination for terminators longer than one byte
Browse files Browse the repository at this point in the history
  • Loading branch information
jussimalinen committed Apr 27, 2015
1 parent d077810 commit 9d0c210
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions atest/terminated_fields.txt
Expand Up @@ -5,26 +5,28 @@ Suite teardown Reset Rammbock
Resource Protocols.txt
Default tags Regression

*** Variables ***
${default terminator}= 0x00


*** Test Cases ***
Get message with chars and end byte
Message with chars and end byte
Message with chars and end byte 0x00
${msg} get message arbitrary_length:foo.bar.zig
Should be equal foo.bar.zig ${msg.arbitrary_length.ascii}
should be equal as integers 12 ${msg.arbitrary_length.len}

Get message with chars and end byte long termination
Message with chars and end byte 0x0d0a
${msg} get message arbitrary_length:foo.bar.zig
Should be equal foo.bar.zig ${msg.arbitrary_length.ascii}
Should be equal foo.bar.zig\r\n ${msg.arbitrary_length._raw}
should be equal as integers 13 ${msg.arbitrary_length.len}

Send and receive message with chars with end byte
[tags]
Setup TCP server and client Test
Message with chars and end byte
Message with chars and end byte 0x0d0a
Client sends message arbitrary_length:foo.bar.zig
${msg}= Server receives message
Should be equal foo.bar.zig ${msg.arbitrary_length.ascii}
should be equal as integers 12 ${msg.arbitrary_length.len}

should be equal as integers 13 ${msg.arbitrary_length.len}

*** Keywords ***
Define protocol
Expand All @@ -34,6 +36,7 @@ Define protocol
end protocol

Message with chars and end byte
[Arguments] ${terminator}
new message ExampleMessage Test
chars * arbitrary_length ${none} terminator=${default terminator}
chars * arbitrary_length ${none} terminator=${terminator}
uint 8 some_integer 0x00
2 changes: 1 addition & 1 deletion src/Rammbock/templates/primitives.py
Expand Up @@ -207,7 +207,7 @@ def _encode_value(self, value, message, little_endian=False):

def _prepare_data(self, data):
if self._terminator:
return data[0:data.index(self._terminator) + 1]
return data[0:data.index(self._terminator) + len(self._terminator)]
return data


Expand Down

0 comments on commit 9d0c210

Please sign in to comment.