You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2018/11/02 20:46:54 UTC

[34/50] qpid-proton git commit: PROTON-1942: [c] decoding a message does not set the inferred flag.

PROTON-1942: [c] decoding a message does not set the inferred flag.


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

Branch: refs/heads/go1
Commit: b114344ffa2281b09af60b9635a79f7fb735a012
Parents: b429db0
Author: Alan Conway <ac...@redhat.com>
Authored: Thu Sep 27 14:04:48 2018 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Thu Sep 27 14:08:00 2018 -0400

----------------------------------------------------------------------
 c/src/core/message.c |  6 +++++
 c/tests/message.c    | 57 +++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 59 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b114344f/c/src/core/message.c
----------------------------------------------------------------------
diff --git a/c/src/core/message.c b/c/src/core/message.c
index 41ccd08..a52dce8 100644
--- a/c/src/core/message.c
+++ b/c/src/core/message.c
@@ -737,7 +737,13 @@ int pn_message_decode(pn_message_t *msg, const char *bytes, size_t size)
       break;
     case DATA:
     case AMQP_SEQUENCE:
+      msg->inferred = true;
+      pn_data_narrow(msg->data);
+      err = pn_data_copy(msg->body, msg->data);
+      if (err) return err;
+      break;
     case AMQP_VALUE:
+      msg->inferred = false;
       pn_data_narrow(msg->data);
       err = pn_data_copy(msg->body, msg->data);
       if (err) return err;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b114344f/c/tests/message.c
----------------------------------------------------------------------
diff --git a/c/tests/message.c b/c/tests/message.c
index 5362b7d..7a6dc4f 100644
--- a/c/tests/message.c
+++ b/c/tests/message.c
@@ -19,6 +19,8 @@
  *
  */
 
+#include "test_tools.h"
+
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -28,20 +30,67 @@
 
 #define assert(E) ((E) ? 0 : (abort(), 0))
 
-static void test_overflow_error(void)
+static void test_overflow_error(test_t *t)
 {
   pn_message_t *message = pn_message();
   char buf[6];
   size_t size = 6;
 
   int err = pn_message_encode(message, buf, &size);
-  assert(err == PN_OVERFLOW);
-  assert(pn_message_errno(message) == 0);
+  TEST_INT_EQUAL(t,PN_OVERFLOW, err);
+  TEST_INT_EQUAL(t, 0, pn_message_errno(message));
   pn_message_free(message);
 }
 
+static void recode(pn_message_t *dst, pn_message_t *src) {
+  pn_rwbytes_t buf = { 0 };
+  int size = pn_message_encode2(src, &buf);
+  assert(size > 0);
+  pn_message_decode(dst, buf.start, size);
+  free(buf.start);
+}
+
+static void test_inferred(test_t *t) {
+  pn_message_t *src = pn_message();
+  pn_message_t *dst = pn_message();
+
+  TEST_CHECK(t, !pn_message_is_inferred(src));
+  pn_data_put_binary(pn_message_body(src), PN_BYTES_LITERAL("hello"));
+  recode(dst, src);
+  TEST_CHECK(t, !pn_message_is_inferred(dst));
+  pn_message_set_inferred(src, true);
+  recode(dst, src);
+  TEST_CHECK(t, pn_message_is_inferred(dst));
+
+  pn_message_clear(src);
+  TEST_CHECK(t, !pn_message_is_inferred(src));
+  pn_data_put_list(pn_message_body(src));
+  pn_data_enter(pn_message_body(src));
+  pn_data_put_binary(pn_message_body(src), PN_BYTES_LITERAL("hello"));
+  recode(dst, src);
+  TEST_CHECK(t, !pn_message_is_inferred(dst));
+  pn_message_set_inferred(src, true);
+  recode(dst, src);
+  TEST_CHECK(t, pn_message_is_inferred(dst));
+
+  pn_message_clear(src);
+  TEST_CHECK(t, !pn_message_is_inferred(src));
+  pn_data_put_string(pn_message_body(src), PN_BYTES_LITERAL("hello"));
+  recode(dst, src);
+  TEST_CHECK(t, !pn_message_is_inferred(dst));
+  pn_message_set_inferred(src, true);
+  recode(dst, src);
+  /* A value section is never considered to be inferred */
+  TEST_CHECK(t, !pn_message_is_inferred(dst));
+
+  pn_message_free(src);
+  pn_message_free(dst);
+}
+
 int main(int argc, char **argv)
 {
-  test_overflow_error();
+  int failed = 0;
+  RUN_ARGV_TEST(failed, t, test_overflow_error(&t));
+  RUN_ARGV_TEST(failed, t, test_inferred(&t));
   return 0;
 }


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