Author: tross
Date: Fri Sep 6 21:47:27 2013
New Revision: 1520706
URL: http://svn.apache.org/r1520706
Log:
NO-JIRA - Added tests for field composition, fixed exposed bug in nested
composites.
Added:
qpid/trunk/qpid/extras/dispatch/tests/compose_test.c (with props)
Modified:
qpid/trunk/qpid/extras/dispatch/src/compose.c
qpid/trunk/qpid/extras/dispatch/src/compose_private.h
qpid/trunk/qpid/extras/dispatch/tests/CMakeLists.txt
qpid/trunk/qpid/extras/dispatch/tests/run_unit_tests.c
Modified: qpid/trunk/qpid/extras/dispatch/src/compose.c
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/extras/dispatch/src/compose.c?rev=1520706&r1=1520705&r2=1520706&view=diff
==============================================================================
--- qpid/trunk/qpid/extras/dispatch/src/compose.c (original)
+++ qpid/trunk/qpid/extras/dispatch/src/compose.c Fri Sep 6 21:47:27 2013
@@ -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_
//
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++;
}
Modified: qpid/trunk/qpid/extras/dispatch/src/compose_private.h
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/extras/dispatch/src/compose_private.h?rev=1520706&r1=1520705&r2=1520706&view=diff
==============================================================================
--- qpid/trunk/qpid/extras/dispatch/src/compose_private.h (original)
+++ qpid/trunk/qpid/extras/dispatch/src/compose_private.h Fri Sep 6 21:47:27
2013
@@ -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
Modified: qpid/trunk/qpid/extras/dispatch/tests/CMakeLists.txt
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/extras/dispatch/tests/CMakeLists.txt?rev=1520706&r1=1520705&r2=1520706&view=diff
==============================================================================
--- qpid/trunk/qpid/extras/dispatch/tests/CMakeLists.txt (original)
+++ qpid/trunk/qpid/extras/dispatch/tests/CMakeLists.txt Fri Sep 6 21:47:27
2013
@@ -22,6 +22,7 @@
##
set(unit_test_SOURCES
alloc_test.c
+ compose_test.c
parse_test.c
run_unit_tests.c
server_test.c
Added: qpid/trunk/qpid/extras/dispatch/tests/compose_test.c
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/extras/dispatch/tests/compose_test.c?rev=1520706&view=auto
==============================================================================
--- qpid/trunk/qpid/extras/dispatch/tests/compose_test.c (added)
+++ qpid/trunk/qpid/extras/dispatch/tests/compose_test.c Fri Sep 6 21:47:27
2013
@@ -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;
+}
+
Propchange: qpid/trunk/qpid/extras/dispatch/tests/compose_test.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: qpid/trunk/qpid/extras/dispatch/tests/run_unit_tests.c
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/extras/dispatch/tests/run_unit_tests.c?rev=1520706&r1=1520705&r2=1520706&view=diff
==============================================================================
--- qpid/trunk/qpid/extras/dispatch/tests/run_unit_tests.c (original)
+++ qpid/trunk/qpid/extras/dispatch/tests/run_unit_tests.c Fri Sep 6 21:47:27
2013
@@ -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;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]