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/07/03 18:47:06 UTC

[plc4x] 01/02: - Made the ProtocolTestsuiteRunner also test the serialization

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/plc4x.git

commit eb7f046857633911a6abd29b953682a8dd173209
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Wed Jul 3 20:43:10 2019 +0200

    - Made the ProtocolTestsuiteRunner also test the serialization
---
 .../protocol/test/ProtocolTestsuiteRunner.java     | 24 +++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/plc4j/utils/protocol-test-utils/src/main/java/org/apache/plc4x/protocol/test/ProtocolTestsuiteRunner.java b/plc4j/utils/protocol-test-utils/src/main/java/org/apache/plc4x/protocol/test/ProtocolTestsuiteRunner.java
index ab00e7e..7853aba 100644
--- a/plc4j/utils/protocol-test-utils/src/main/java/org/apache/plc4x/protocol/test/ProtocolTestsuiteRunner.java
+++ b/plc4j/utils/protocol-test-utils/src/main/java/org/apache/plc4x/protocol/test/ProtocolTestsuiteRunner.java
@@ -24,9 +24,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.dataformat.xml.XmlMapper;
 import org.apache.commons.codec.DecoderException;
 import org.apache.commons.codec.binary.Hex;
-import org.apache.plc4x.java.utils.MessageIO;
-import org.apache.plc4x.java.utils.ParseException;
-import org.apache.plc4x.java.utils.ReadBuffer;
+import org.apache.plc4x.java.utils.*;
 import org.apache.plc4x.protocol.test.exceptions.ProtocolTestsuiteException;
 import org.apache.plc4x.protocol.test.model.ProtocolTestsuite;
 import org.apache.plc4x.protocol.test.model.Testcase;
@@ -39,9 +37,7 @@ import org.xmlunit.diff.Diff;
 
 import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.*;
 
 public class ProtocolTestsuiteRunner {
 
@@ -110,7 +106,21 @@ public class ProtocolTestsuiteRunner {
             Diff diff = DiffBuilder.compare(referenceXml).withTest(xmlString).ignoreWhitespace().build();
             if(diff.hasDifferences()) {
                 // TODO: Add some more information ...
-                throw new ProtocolTestsuiteException("Differences were found");
+                throw new ProtocolTestsuiteException("Differences were found after parsing.");
+            }
+            WriteBuffer writeBuffer = new WriteBuffer(((SizeAware) msg).getLengthInBytes());
+            messageIO.serialize(writeBuffer, msg);
+            byte[] data = writeBuffer.getData();
+            if(!Arrays.equals(testcase.getRaw(), data)) {
+                int i;
+                for(i = 0; i < data.length; i++) {
+                    if(data[i] != testcase.getRaw()[i]) {
+                        break;
+                    }
+                }
+                throw new ProtocolTestsuiteException("Differences were found after serializing.\nExpected: " +
+                    Hex.encodeHexString(testcase.getRaw()) + "\nBut Got:  " + Hex.encodeHexString(data) +
+                    "\n          " + String.join("", Collections.nCopies(i, "--")) + "^");
             }
         } catch (ParseException e) {
             throw new ProtocolTestsuiteException("Unable to parse message", e);