You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kp...@apache.org on 2020/08/18 12:55:09 UTC

[qpid-proton] 01/01: PROTON-2244: Fix for Array of lists with first list empty encoding

This is an automated email from the ASF dual-hosted git repository.

kpvdr pushed a commit to branch array-of-lists-first-list-empty
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git

commit e4e0342b9f824ef481002f9ae0c98cece090fc5e
Author: Kim van der Riet <kp...@apache.org>
AuthorDate: Wed Jul 1 12:15:04 2020 -0400

    PROTON-2244: Fix for Array of lists with first list empty encoding
    
    PROTON-2244: Correction on previous fix, prevent zero-length array encoding for all array memebers of an array
    
    PROTON-2244: Minor correction to comment text
    
    PROTON-2244: Added a set of array encode-decode tests for Data.Array, including a array of lists test which catches this bug.
    
    PROTON-2244: Removed array codec tests from Python to C/C++ tests as requested
    
    PROTON-2244: Removed debug statements erroneously left in code from previous commit
    
    PROTON-2244: Fix for non-linux compilers and non-portable float types
    
    PROTON-2244: Further improvements to array check: fail if error during encoding or decoding
    
    PROTON-2244: Added tests for arrays of char and decimal32/64/128.
    
    PROTON-2244: Added some additional arrays of list test cases
    
    PROTON-2244: Removed array tests of all but array of lists, as this is the issue. The consensus is that we need to make the tests compare encoded bytes with expected encoded bytes, not perform an encode/decode comparison as these tests do at present. This should be done at a later time.
    
    NO_JIRA: Removed header files which are no longer used in c/tests/data_test.cpp
---
 c/src/core/encoder.c  |  5 +++--
 c/tests/data_test.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/c/src/core/encoder.c b/c/src/core/encoder.c
index 2be808c..472ea3b 100644
--- a/c/src/core/encoder.c
+++ b/c/src/core/encoder.c
@@ -336,8 +336,9 @@ static int pni_encoder_exit(void *ctx, pn_data_t *data, pni_node_t *node)
   pn_encoder_t *encoder = (pn_encoder_t *) ctx;
   char *pos;
 
-  // Special case 0 length list
-  if (node->atom.type==PN_LIST && node->children-encoder->null_count==0) {
+  // Special case 0 length list, but not as element in an array
+  pni_node_t *parent = pn_data_node(data, node->parent);
+  if (node->atom.type==PN_LIST && node->children-encoder->null_count==0 && !pn_is_in_array(data, parent, node)) {
     encoder->position = node->start-1; // position of list opcode
     pn_encoder_writef8(encoder, PNE_LIST0);
     encoder->null_count = 0;
diff --git a/c/tests/data_test.cpp b/c/tests/data_test.cpp
index a15c1b4..db6f554 100644
--- a/c/tests/data_test.cpp
+++ b/c/tests/data_test.cpp
@@ -26,6 +26,8 @@
 #include <proton/codec.h>
 #include <proton/error.h>
 
+#include <cstdarg>
+
 using namespace pn_test;
 
 // Make sure we can grow the capacity of a pn_data_t all the way to the max and
@@ -105,3 +107,52 @@ TEST_CASE("data_multiple") {
   pn_data_fill(data, "{S[iii]SI}", "foo", 1, 987, 3, "bar", 965);
   CHECK("{\"foo\"=[1, 987, 3], \"bar\"=965}" == inspect(data));
 }
+
+
+#define BUFSIZE 1024
+static void check_encode_decode(auto_free<pn_data_t, pn_data_free>& src) {
+	char buf[BUFSIZE];
+	auto_free<pn_data_t, pn_data_free> data(pn_data(1));
+	pn_data_clear(data);
+
+	// Encode src array to buf
+	int enc_size = pn_data_encode(src, buf, BUFSIZE - 1);
+	if (enc_size < 0) {
+		FAIL("pn_data_encode() error " << enc_size << ": " << pn_code(enc_size));
+	}
+
+	// Decode buf to data
+	int dec_size = pn_data_decode(data, buf, BUFSIZE - 1);
+	pn_error_t *dec_err = pn_data_error(data);
+	if (dec_size < 0) {
+		FAIL("pn_data_decode() error " << dec_size << ": " << pn_code(dec_size));
+	}
+
+	// Checks
+	CHECK(enc_size == dec_size);
+	CHECK(inspect(src) == inspect(data));
+}
+
+static void check_array(const char *fmt, ...) {
+	auto_free<pn_data_t, pn_data_free> src(pn_data(1));
+	pn_data_clear(src);
+
+	// Create src array
+	va_list ap;
+	va_start(ap, fmt);
+	pn_data_vfill(src, fmt, ap);
+	va_end(ap);
+
+	check_encode_decode(src);
+}
+
+TEST_CASE("array_list") {
+	check_array("@T[]", PN_LIST);
+	// TODO: PROTON-2248: using S and s reversed
+	// empty list as first array element
+	check_array("@T[[][oo][][iii][Sosid]]", PN_LIST, true, false, 1, 2, 3, "hello", false, "world", 43210, 2.565e-56);
+	// empty list not as first array element
+	check_array("@T[[Sid][oooo][]]", PN_LIST, "aaa", 123, double(3.2415), true, true, false, true);
+	// only empty lists
+	check_array("@T[[][][][][]]", PN_LIST);
+}


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