You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2019/01/21 15:10:47 UTC
[incubator-plc4x] branch develop updated: - Added tests to fully
test the tpkt protocol.
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new 54f4269 - Added tests to fully test the tpkt protocol.
54f4269 is described below
commit 54f426914e9de393828216f913b6bf15838f1e37
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Jan 21 16:10:43 2019 +0100
- Added tests to fully test the tpkt protocol.
---
.../apache/plc4x/protocols/TpktProtocolTest.java | 18 +++++++--
.../org/apache/plc4x/protocols/tpkt-protocol.tdml | 45 ++++++++++++++++++++++
2 files changed, 60 insertions(+), 3 deletions(-)
diff --git a/protocols/src/test/java/org/apache/plc4x/protocols/TpktProtocolTest.java b/protocols/src/test/java/org/apache/plc4x/protocols/TpktProtocolTest.java
index 4fcd540..c34132d 100644
--- a/protocols/src/test/java/org/apache/plc4x/protocols/TpktProtocolTest.java
+++ b/protocols/src/test/java/org/apache/plc4x/protocols/TpktProtocolTest.java
@@ -31,7 +31,6 @@ public class TpktProtocolTest {
@BeforeEach
public void setup() {
- System.out.println("Starting");
String tpktProtocolTestCases = "org/apache/plc4x/protocols/tpkt-protocol.tdml";
testSuite = new DFDLTestSuite(Misc.getRequiredResource(tpktProtocolTestCases), true, true, false,
Runner.defaultRoundTripDefaultDefault(), Runner.defaultValidationDefaultDefault());
@@ -39,9 +38,22 @@ public class TpktProtocolTest {
@Test
public void tpktPacketContainingCotpConnectResponse() {
- System.out.println("Running");
testSuite.runOneTest("tpktPacketContainingCotpConnectResponse", scala.Option.apply(null), false);
- System.out.println("Done");
+ }
+
+ @Test
+ public void invalidMagicByte() {
+ testSuite.runOneTest("invalidMagicByte", scala.Option.apply(null), false);
+ }
+
+ @Test
+ public void tooShortPayload() {
+ testSuite.runOneTest("tooShortPayload", scala.Option.apply(null), false);
+ }
+
+ @Test
+ public void tooLongPayload() {
+ testSuite.runOneTest("tooLongPayload", scala.Option.apply(null), false);
}
}
diff --git a/protocols/src/test/resources/org/apache/plc4x/protocols/tpkt-protocol.tdml b/protocols/src/test/resources/org/apache/plc4x/protocols/tpkt-protocol.tdml
index 652600b..1881ecb 100644
--- a/protocols/src/test/resources/org/apache/plc4x/protocols/tpkt-protocol.tdml
+++ b/protocols/src/test/resources/org/apache/plc4x/protocols/tpkt-protocol.tdml
@@ -39,6 +39,10 @@
<xs:element name="tpktMessage" type="tpkt:TpktMessageType"/>
</tdml:defineSchema>
+ <!--
+ In this test-case the data should be parsable to a valid result.
+ It's a TPKT package containing a COTP connection-response payload.
+ -->
<tdml:parserTestCase name="tpktPacketContainingCotpConnectResponse"
root="tpktMessage"
model="tkptSchema"
@@ -62,6 +66,47 @@
</tdml:infoset>
</tdml:parserTestCase>
+ <!--
+ In this test-case the packet doesn't start with the required magic byte 0x03.
+ -->
+ <tdml:parserTestCase name="invalidMagicByte">
+ <tdml:document>
+ <tdml:documentPart type="byte">0400001611D00001000200C00109C1020100C2020102</tdml:documentPart>
+ </tdml:document>
+
+ <tdml:errors>
+ <tdml:error>Schema Definition Error</tdml:error>
+ </tdml:errors>
+ </tdml:parserTestCase>
+
+ <!--
+ In this test-case the payload of the packet doesn't match the
+ length provided in the packet header (Too short)
+ -->
+ <tdml:parserTestCase name="tooShortPayload">
+ <tdml:document>
+ <tdml:documentPart type="byte">0300001611D00001000200C00109C102010</tdml:documentPart>
+ </tdml:document>
+
+ <tdml:errors>
+ <tdml:error>Schema Definition Error</tdml:error>
+ </tdml:errors>
+ </tdml:parserTestCase>
+
+ <!--
+ In this test-case the payload of the packet doesn't match the
+ length provided in the packet header (Too long)
+ -->
+ <tdml:parserTestCase name="tooLongPayload">
+ยด <tdml:document>
+ <tdml:documentPart type="byte">0300001611D00001000200C00109C1020100C20201021234567890</tdml:documentPart>
+ </tdml:document>
+
+ <tdml:errors>
+ <tdml:error>Schema Definition Error</tdml:error>
+ </tdml:errors>
+ </tdml:parserTestCase>
+
</testSuite>