summaryrefslogtreecommitdiff
path: root/qpid/extras
diff options
context:
space:
mode:
authorTed Ross <tross@apache.org>2013-09-06 21:47:27 +0000
committerTed Ross <tross@apache.org>2013-09-06 21:47:27 +0000
commit593e701a88a3c6f1d74940a0716b72b019cfa425 (patch)
tree0286df768440c354f46038b6cdba14ba0d2a62e4 /qpid/extras
parent9f89516b7a87b0a60abc665c4d83ae7daecbc8ad (diff)
downloadqpid-python-593e701a88a3c6f1d74940a0716b72b019cfa425.tar.gz
NO-JIRA - Added tests for field composition, fixed exposed bug in nested composites.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1520706 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/extras')
-rw-r--r--qpid/extras/dispatch/src/compose.c22
-rw-r--r--qpid/extras/dispatch/src/compose_private.h21
-rw-r--r--qpid/extras/dispatch/tests/CMakeLists.txt1
-rw-r--r--qpid/extras/dispatch/tests/compose_test.c192
-rw-r--r--qpid/extras/dispatch/tests/run_unit_tests.c2
5 files changed, 217 insertions, 21 deletions
diff --git a/qpid/extras/dispatch/src/compose.c b/qpid/extras/dispatch/src/compose.c
index 352c282258..6eb2ab1c73 100644
--- a/qpid/extras/dispatch/src/compose.c
+++ b/qpid/extras/dispatch/src/compose.c
@@ -21,30 +21,10 @@
#include <qpid/dispatch/alloc.h>
#include <qpid/dispatch/buffer.h>
#include <qpid/dispatch/amqp.h>
-#include "message_private.h"
#include "compose_private.h"
#include <memory.h>
-typedef struct dx_composite_t {
- DEQ_LINKS(struct dx_composite_t);
- int isMap;
- uint32_t count;
- uint32_t length;
- dx_field_location_t length_location;
- dx_field_location_t count_location;
-} dx_composite_t;
-
-ALLOC_DECLARE(dx_composite_t);
ALLOC_DEFINE(dx_composite_t);
-DEQ_DECLARE(dx_composite_t, dx_field_stack_t);
-
-
-struct dx_composed_field_t {
- dx_buffer_list_t buffers;
- dx_field_stack_t fieldStack;
-};
-
-ALLOC_DECLARE(dx_composed_field_t);
ALLOC_DEFINE(dx_composed_field_t);
@@ -197,7 +177,7 @@ static void dx_compose_end_composite(dx_composed_field_t *field)
//
dx_composite_t *enclosing = DEQ_HEAD(field->fieldStack);
if (enclosing) {
- enclosing->length += 4 + comp->length;
+ enclosing->length += (comp->length - 4); // the length and count were already accounted for
enclosing->count++;
}
diff --git a/qpid/extras/dispatch/src/compose_private.h b/qpid/extras/dispatch/src/compose_private.h
index 65d137a8c7..6e72185f3c 100644
--- a/qpid/extras/dispatch/src/compose_private.h
+++ b/qpid/extras/dispatch/src/compose_private.h
@@ -20,7 +20,28 @@
*/
#include <qpid/dispatch/compose.h>
+#include "message_private.h"
dx_buffer_list_t *dx_compose_buffers(dx_composed_field_t *field);
+typedef struct dx_composite_t {
+ DEQ_LINKS(struct dx_composite_t);
+ int isMap;
+ uint32_t count;
+ uint32_t length;
+ dx_field_location_t length_location;
+ dx_field_location_t count_location;
+} dx_composite_t;
+
+ALLOC_DECLARE(dx_composite_t);
+DEQ_DECLARE(dx_composite_t, dx_field_stack_t);
+
+
+struct dx_composed_field_t {
+ dx_buffer_list_t buffers;
+ dx_field_stack_t fieldStack;
+};
+
+ALLOC_DECLARE(dx_composed_field_t);
+
#endif
diff --git a/qpid/extras/dispatch/tests/CMakeLists.txt b/qpid/extras/dispatch/tests/CMakeLists.txt
index b70972b37b..fc85018991 100644
--- a/qpid/extras/dispatch/tests/CMakeLists.txt
+++ b/qpid/extras/dispatch/tests/CMakeLists.txt
@@ -22,6 +22,7 @@
##
set(unit_test_SOURCES
alloc_test.c
+ compose_test.c
parse_test.c
run_unit_tests.c
server_test.c
diff --git a/qpid/extras/dispatch/tests/compose_test.c b/qpid/extras/dispatch/tests/compose_test.c
new file mode 100644
index 0000000000..9eaeeaa038
--- /dev/null
+++ b/qpid/extras/dispatch/tests/compose_test.c
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <assert.h>
+#include <string.h>
+#include <inttypes.h>
+#include "test_case.h"
+#include <qpid/dispatch.h>
+#include "compose_private.h"
+
+
+static char *vector1 =
+ "\x00\x53\x71" // delivery annotations
+ "\xd1\x00\x00\x00\x3d\x00\x00\x00\x04" // map32 with two item pairs
+ "\xa1\x06key001" // str8-utf8
+ "\x52\x0a" // smalluint
+ "\xa1\x06key002" // str8-utf8
+ "\xd0\x00\x00\x00\x22\x00\x00\x00\x04" // list32 with four items
+ "\xa1\x05item1" // str8-utf8
+ "\xa1\x05item2" // str8-utf8
+ "\xa1\x05item3" // str8-utf8
+ "\xd0\x00\x00\x00\x04\x00\x00\x00\x00" // list32 empty
+ ;
+
+static int vector1_length = 69;
+
+static char *test_compose_nested_composites(void *context)
+{
+ dx_composed_field_t *field = dx_compose(DX_PERFORMATIVE_DELIVERY_ANNOTATIONS, 0);
+
+ dx_compose_start_map(field);
+
+ dx_compose_insert_string(field, "key001");
+ dx_compose_insert_uint(field, 10);
+
+ dx_compose_insert_string(field, "key002");
+ dx_compose_start_list(field);
+
+ dx_compose_insert_string(field, "item1");
+ dx_compose_insert_string(field, "item2");
+ dx_compose_insert_string(field, "item3");
+
+ dx_compose_start_list(field);
+ dx_compose_end_list(field);
+
+ dx_compose_end_list(field);
+ dx_compose_end_map(field);
+
+ dx_buffer_t *buf = DEQ_HEAD(field->buffers);
+
+ if (dx_buffer_size(buf) != vector1_length) return "Incorrect Length of Buffer";
+
+ char *left = vector1;
+ char *right = (char*) dx_buffer_base(buf);
+ int idx;
+
+ for (idx = 0; idx < vector1_length; idx++) {
+ if (*left != *right) return "Pattern Mismatch";
+ left++;
+ right++;
+ }
+
+ dx_compose_free(field);
+ return 0;
+}
+
+static char *vector2 =
+ "\x00\x53\x73" // properties
+ "\xd0\x00\x00\x00\x83\x00\x00\x00\x1c" // list32 with 28 items
+ "\x40" // null
+ "\x42" // false
+ "\x41" // true
+ "\x43" // uint0
+ "\x52\x01" // smalluint
+ "\x52\xff" // smalluint
+ "\x70\x00\x00\x01\x00" // uint
+ "\x70\x10\x00\x00\x00" // uint
+ "\x44" // ulong0
+ "\x53\x01" // smallulong
+ "\x53\xff" // smallulong
+ "\x80\x00\x00\x00\x00\x00\x00\x01\x00" // ulong
+ "\x80\x00\x00\x00\x00\x20\x00\x00\x00" // ulong
+ "\x54\x00" // smallint
+ "\x54\x01" // smallint
+ "\x54\xff" // smallint
+ "\x71\x00\x00\x00\xff" // int
+ "\x71\x00\x00\x01\x00" // int
+ "\x55\x00" // smalllong
+ "\x55\x01" // smalllong
+ "\x55\xff" // smalllong
+ "\x81\x00\x00\x00\x00\x00\x00\x00\xff" // long
+ "\x81\x00\x00\x00\x00\x00\x00\x01\x00" // long
+ "\x83\x00\x11\x22\x33\x44\x55\x66\x77" // timestamp
+ "\x98\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x00" // uuid
+ "\xa0\x02\x00\x11" // vbin8
+ "\xa1\x06string" // str8-utf8
+ "\xa3\x06symbol" // sym8
+ ;
+
+static int vector2_length = 139;
+
+static char *test_compose_scalars(void *context)
+{
+ dx_composed_field_t *field = dx_compose(DX_PERFORMATIVE_PROPERTIES, 0);
+
+ dx_compose_start_list(field);
+
+ dx_compose_insert_null(field);
+
+ dx_compose_insert_bool(field, 0);
+ dx_compose_insert_bool(field, 1);
+
+ dx_compose_insert_uint(field, 0);
+ dx_compose_insert_uint(field, 1);
+ dx_compose_insert_uint(field, 255);
+ dx_compose_insert_uint(field, 256);
+ dx_compose_insert_uint(field, 0x10000000);
+
+ dx_compose_insert_ulong(field, 0);
+ dx_compose_insert_ulong(field, 1);
+ dx_compose_insert_ulong(field, 255);
+ dx_compose_insert_ulong(field, 256);
+ dx_compose_insert_ulong(field, 0x20000000);
+
+ dx_compose_insert_int(field, 0);
+ dx_compose_insert_int(field, 1);
+ dx_compose_insert_int(field, -1);
+ dx_compose_insert_int(field, 255);
+ dx_compose_insert_int(field, 256);
+
+ dx_compose_insert_long(field, 0);
+ dx_compose_insert_long(field, 1);
+ dx_compose_insert_long(field, -1);
+ dx_compose_insert_long(field, 255);
+ dx_compose_insert_long(field, 256);
+
+ dx_compose_insert_timestamp(field, 0x0011223344556677);
+ dx_compose_insert_uuid(field, (uint8_t*) "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x00");
+ dx_compose_insert_binary(field, (uint8_t*) "\x00\x11", 2);
+ dx_compose_insert_string(field, "string");
+ dx_compose_insert_symbol(field, "symbol");
+
+ dx_compose_end_list(field);
+
+ dx_buffer_t *buf = DEQ_HEAD(field->buffers);
+
+ if (dx_buffer_size(buf) != vector2_length) return "Incorrect Length of Buffer";
+
+ char *left = vector2;
+ char *right = (char*) dx_buffer_base(buf);
+ int idx;
+
+ for (idx = 0; idx < vector2_length; idx++) {
+ if (*left != *right) return "Pattern Mismatch";
+ left++;
+ right++;
+ }
+
+ dx_compose_free(field);
+ return 0;
+}
+
+
+int compose_tests()
+{
+ int result = 0;
+ dx_log_set_mask(LOG_NONE);
+
+ TEST_CASE(test_compose_nested_composites, 0);
+ TEST_CASE(test_compose_scalars, 0);
+
+ return result;
+}
+
diff --git a/qpid/extras/dispatch/tests/run_unit_tests.c b/qpid/extras/dispatch/tests/run_unit_tests.c
index 99b58c5664..2cb75169c1 100644
--- a/qpid/extras/dispatch/tests/run_unit_tests.c
+++ b/qpid/extras/dispatch/tests/run_unit_tests.c
@@ -25,6 +25,7 @@ int timer_tests();
int alloc_tests();
int server_tests();
int parse_tests();
+int compose_tests();
int main(int argc, char** argv)
{
@@ -39,6 +40,7 @@ int main(int argc, char** argv)
result += alloc_tests();
result += server_tests(argv[1]);
result += parse_tests(0);
+ result += compose_tests(0);
return result;
}