summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Ross <tross@apache.org>2013-07-02 22:29:31 +0000
committerTed Ross <tross@apache.org>2013-07-02 22:29:31 +0000
commitadf570f71d94fa99f77e69d12283b78bdc7cd60e (patch)
treedccac383bd6d7758bfda44b57206bcc57ba2f0e0
parentd48d6d60421c14c28720f696ffeaeaa9aa096180 (diff)
downloadqpid-python-adf570f71d94fa99f77e69d12283b78bdc7cd60e.tar.gz
QPID-4974 - Added parsing tests (and fixes for bugs they found).
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1499133 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/extras/dispatch/include/qpid/dispatch.h4
-rw-r--r--qpid/extras/dispatch/include/qpid/dispatch/iterator.h5
-rw-r--r--qpid/extras/dispatch/src/iterator.c16
-rw-r--r--qpid/extras/dispatch/src/parse.c4
-rw-r--r--qpid/extras/dispatch/tests/CMakeLists.txt1
-rw-r--r--qpid/extras/dispatch/tests/parse_test.c76
-rw-r--r--qpid/extras/dispatch/tests/run_unit_tests.c2
7 files changed, 106 insertions, 2 deletions
diff --git a/qpid/extras/dispatch/include/qpid/dispatch.h b/qpid/extras/dispatch/include/qpid/dispatch.h
index ed8499ff37..72b3456099 100644
--- a/qpid/extras/dispatch/include/qpid/dispatch.h
+++ b/qpid/extras/dispatch/include/qpid/dispatch.h
@@ -27,6 +27,10 @@
#include <qpid/dispatch/iterator.h>
#include <qpid/dispatch/log.h>
#include <qpid/dispatch/router.h>
+#include <qpid/dispatch/amqp.h>
+#include <qpid/dispatch/parse.h>
+#include <qpid/dispatch/compose.h>
+#include <qpid/dispatch/config.h>
#include <qpid/dispatch/threading.h>
#include <qpid/dispatch/timer.h>
#include <qpid/dispatch/user_fd.h>
diff --git a/qpid/extras/dispatch/include/qpid/dispatch/iterator.h b/qpid/extras/dispatch/include/qpid/dispatch/iterator.h
index 5269abd4b2..3a4bf68b8a 100644
--- a/qpid/extras/dispatch/include/qpid/dispatch/iterator.h
+++ b/qpid/extras/dispatch/include/qpid/dispatch/iterator.h
@@ -101,6 +101,11 @@ void dx_field_iterator_set_address(const char *area, const char *router);
dx_field_iterator_t* dx_field_iterator_string(const char *text,
dx_iterator_view_t view);
+dx_field_iterator_t* dx_field_iterator_binary(const char *text,
+ int length,
+ dx_iterator_view_t view);
+
+
/**
* Create an iterator from a field in a buffer chain
*/
diff --git a/qpid/extras/dispatch/src/iterator.c b/qpid/extras/dispatch/src/iterator.c
index 43c3b755d0..9186465cde 100644
--- a/qpid/extras/dispatch/src/iterator.c
+++ b/qpid/extras/dispatch/src/iterator.c
@@ -250,6 +250,22 @@ dx_field_iterator_t* dx_field_iterator_string(const char *text, dx_iterator_view
}
+dx_field_iterator_t* dx_field_iterator_binary(const char *text, int length, dx_iterator_view_t view)
+{
+ dx_field_iterator_t *iter = new_dx_field_iterator_t();
+ if (!iter)
+ return 0;
+
+ iter->start_pointer.buffer = 0;
+ iter->start_pointer.cursor = (unsigned char*) text;
+ iter->start_pointer.length = length;
+
+ dx_field_iterator_reset_view(iter, view);
+
+ return iter;
+}
+
+
dx_field_iterator_t *dx_field_iterator_buffer(dx_buffer_t *buffer, int offset, int length, dx_iterator_view_t view)
{
dx_field_iterator_t *iter = new_dx_field_iterator_t();
diff --git a/qpid/extras/dispatch/src/parse.c b/qpid/extras/dispatch/src/parse.c
index 5a9c26b7ca..066d5c0243 100644
--- a/qpid/extras/dispatch/src/parse.c
+++ b/qpid/extras/dispatch/src/parse.c
@@ -190,9 +190,9 @@ uint32_t dx_parse_as_uint(dx_parsed_field_t *field)
switch (field->tag) {
case DX_AMQP_UINT:
result |= ((uint32_t) dx_field_iterator_octet(field->raw_iter)) << 24;
+ result |= ((uint32_t) dx_field_iterator_octet(field->raw_iter)) << 16;
case DX_AMQP_USHORT:
- result |= ((uint32_t) dx_field_iterator_octet(field->raw_iter)) << 16;
result |= ((uint32_t) dx_field_iterator_octet(field->raw_iter)) << 8;
// Fall Through...
@@ -249,9 +249,9 @@ int32_t dx_parse_as_int(dx_parsed_field_t *field)
switch (field->tag) {
case DX_AMQP_INT:
result |= ((int32_t) dx_field_iterator_octet(field->raw_iter)) << 24;
+ result |= ((int32_t) dx_field_iterator_octet(field->raw_iter)) << 16;
case DX_AMQP_SHORT:
- result |= ((int32_t) dx_field_iterator_octet(field->raw_iter)) << 16;
result |= ((int32_t) dx_field_iterator_octet(field->raw_iter)) << 8;
// Fall Through...
diff --git a/qpid/extras/dispatch/tests/CMakeLists.txt b/qpid/extras/dispatch/tests/CMakeLists.txt
index 351a0e4764..9523ab9ad4 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
+ parse_test.c
run_unit_tests.c
server_test.c
timer_test.c
diff --git a/qpid/extras/dispatch/tests/parse_test.c b/qpid/extras/dispatch/tests/parse_test.c
new file mode 100644
index 0000000000..792957c42a
--- /dev/null
+++ b/qpid/extras/dispatch/tests/parse_test.c
@@ -0,0 +1,76 @@
+/*
+ * 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 "test_case.h"
+#include <qpid/dispatch.h>
+
+struct vector_t {
+ const char *data;
+ int length;
+ uint8_t expected_tag;
+ int check_uint;
+ uint32_t expected_uint;
+} vectors[] = {
+{"\x40", 1, DX_AMQP_NULL, 0, 0},
+{"\x41", 1, DX_AMQP_TRUE, 1, 1},
+{"\x42", 1, DX_AMQP_FALSE, 1, 0},
+{"\x56\x00", 2, DX_AMQP_BOOLEAN, 1, 0},
+{"\x56\x01", 2, DX_AMQP_BOOLEAN, 1, 1},
+{"\x50\x45", 2, DX_AMQP_UBYTE, 1, 0x45},
+{"\x60\x02\x04", 3, DX_AMQP_USHORT, 1, 0x0204},
+{"\x70\x01\x02\x03\x04", 5, DX_AMQP_UINT, 1, 0x01020304},
+{"\x52\x06", 2, DX_AMQP_SMALLUINT, 1, 0x00000006},
+{"\x43", 1, DX_AMQP_UINT0, 1, 0x00000000},
+{0, 0, 0, 0, 0}
+};
+
+
+static char *test_parser_fixed_scalars(void *context)
+{
+ int idx = 0;
+
+ while (vectors[idx].data) {
+ dx_field_iterator_t *field = dx_field_iterator_binary(vectors[idx].data,
+ vectors[idx].length,
+ ITER_VIEW_ALL);
+ dx_parsed_field_t *parsed = dx_parse(field);
+ if (!dx_parse_ok(parsed)) return "Unexpected Parse Error";
+ if (dx_parse_tag(parsed) != vectors[idx].expected_tag) return "Mismatched Tag";
+ if (vectors[idx].check_uint &&
+ dx_parse_as_uint(parsed) != vectors[idx].expected_uint) return "Mismatched Uint";
+ idx++;
+ }
+
+ return 0;
+}
+
+
+int parse_tests()
+{
+ int result = 0;
+ dx_log_set_mask(LOG_NONE);
+
+ TEST_CASE(test_parser_fixed_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 4b83d84b40..99b58c5664 100644
--- a/qpid/extras/dispatch/tests/run_unit_tests.c
+++ b/qpid/extras/dispatch/tests/run_unit_tests.c
@@ -24,6 +24,7 @@ int tool_tests();
int timer_tests();
int alloc_tests();
int server_tests();
+int parse_tests();
int main(int argc, char** argv)
{
@@ -37,6 +38,7 @@ int main(int argc, char** argv)
result += timer_tests();
result += alloc_tests();
result += server_tests(argv[1]);
+ result += parse_tests(0);
return result;
}