You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ch...@apache.org on 2017/01/06 18:13:57 UTC

qpid-interop-test git commit: QPIDIT-70: Properly encode json results

Repository: qpid-interop-test
Updated Branches:
  refs/heads/master 26faaadf2 -> f5c4263a4


QPIDIT-70: Properly encode json results

This test 'gets tests to pass' by escaping double quotes and
backslashes.

The patch does not use .NET library json serializer yet. The
library is unicode centric and its encoding of a single quote
as '<backslash>u0027' fails in the test framework.


Project: http://git-wip-us.apache.org/repos/asf/qpid-interop-test/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-interop-test/commit/f5c4263a
Tree: http://git-wip-us.apache.org/repos/asf/qpid-interop-test/tree/f5c4263a
Diff: http://git-wip-us.apache.org/repos/asf/qpid-interop-test/diff/f5c4263a

Branch: refs/heads/master
Commit: f5c4263a48353b1431d0a4d36d777a86ebf51aa3
Parents: 26faaad
Author: Chuck Rolke <cr...@redhat.com>
Authored: Fri Jan 6 12:34:58 2017 -0500
Committer: Chuck Rolke <cr...@redhat.com>
Committed: Fri Jan 6 13:13:17 2017 -0500

----------------------------------------------------------------------
 .../src/amqp_types_test/Receiver/Receiver.cs    | 61 ++++++++++++++++----
 1 file changed, 50 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-interop-test/blob/f5c4263a/shims/amqpnetlite/src/amqp_types_test/Receiver/Receiver.cs
----------------------------------------------------------------------
diff --git a/shims/amqpnetlite/src/amqp_types_test/Receiver/Receiver.cs b/shims/amqpnetlite/src/amqp_types_test/Receiver/Receiver.cs
index d008ce0..e7f563e 100644
--- a/shims/amqpnetlite/src/amqp_types_test/Receiver/Receiver.cs
+++ b/shims/amqpnetlite/src/amqp_types_test/Receiver/Receiver.cs
@@ -154,6 +154,51 @@ namespace Qpidit
 
 
         /// <summary>
+        /// Json-encode an array of bytes assumed to be plain ascii text.
+        /// </summary>
+        /// <param name="theBytes">The byte array.</param>
+        /// <returns>Serialized string</returns>
+        public string SerializeBytes(byte[] theBytes)
+        {
+            StringBuilder builder = new StringBuilder();
+            byte asciiSlash = Encoding.Default.GetBytes("\\")[0];
+            byte asciiDoubleQuote = Encoding.Default.GetBytes("\"")[0];
+            foreach (byte b in theBytes)
+            {
+                if (b == asciiSlash) {
+                    // backslash needs backslash escape
+                    builder.Append((char)asciiSlash);
+                    builder.Append((char)asciiSlash);
+                }
+                else if (b == asciiDoubleQuote) {
+                    // doublequote needs backslash escape
+                    builder.Append((char)asciiSlash);
+                    builder.Append((char)asciiDoubleQuote);
+                }
+                else if (b >= 32 && b <= 127)
+                    // printable ascii passed through
+                    builder.Append((char)b);
+                else
+                    // non-printable ascii as escaped hex bytes
+                    builder.Append(String.Format("\\x{0:x2}", b));
+            }
+            return builder.ToString();
+        }
+
+
+        /// <summary>
+        /// Json-encode an object whose string value is assumed to be plain ascii text.
+        /// </summary>
+        /// <param name="theObject">The object.</param>
+        /// <returns>Serialized string</returns>
+        public string SerializeString(object theObject)
+        {
+            byte[] bytes = Encoding.ASCII.GetBytes(theObject.ToString());
+            return SerializeBytes(bytes);
+        }
+
+
+        /// <summary>
         /// Decode message body's object type names and QpidIt display details.
         /// Recursively process maps and lists.
         /// </summary>
@@ -276,12 +321,12 @@ namespace Qpidit
                     case "Single":
                         byte[] sbytes = BitConverter.GetBytes((Single)messageValue);
                         qpiditType = "float";
-                        valueString = BytesReversedToString(sbytes);
+                        valueString = "0x" + BytesReversedToString(sbytes);
                         break;
                     case "Double":
                         byte[] dbytes = BitConverter.GetBytes((Double)messageValue);
                         qpiditType = "double";
-                        valueString = BytesReversedToString(dbytes);
+                        valueString = "0x" + BytesReversedToString(dbytes);
                         break;
                     case "DateTime":
                         // epochTicks is the number of 100uSec ticks between 01/01/0001
@@ -299,21 +344,15 @@ namespace Qpidit
                     case "Byte[]":
                         qpiditType = "binary";
                         byte[] binstr = (byte[])messageValue;
-                        StringBuilder builder = new StringBuilder();
-                        foreach (byte b in binstr)
-                            if (b >= 32 && b <= 127)
-                                builder.Append((char)b);
-                            else
-                                builder.Append(String.Format("\\{0:x2}", b));
-                        valueString = builder.ToString();
+                        valueString = SerializeBytes(binstr);
                         break;
                     case "String":
                         qpiditType = "string";
-                        valueString = messageValue.ToString();
+                        valueString = SerializeString(messageValue);
                         break;
                     case "Symbol":
                         qpiditType = "symbol";
-                        valueString = messageValue.ToString();
+                        valueString = SerializeString(messageValue);
                         break;
                     default:
                         qpiditType = "unknown";


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org