Author: tross
Date: Tue Jul  2 22:29:31 2013
New Revision: 1499133

URL: http://svn.apache.org/r1499133
Log:
QPID-4974 - Added parsing tests (and fixes for bugs they found).

Added:
    qpid/trunk/qpid/extras/dispatch/tests/parse_test.c   (with props)
Modified:
    qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch.h
    qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch/iterator.h
    qpid/trunk/qpid/extras/dispatch/src/iterator.c
    qpid/trunk/qpid/extras/dispatch/src/parse.c
    qpid/trunk/qpid/extras/dispatch/tests/CMakeLists.txt
    qpid/trunk/qpid/extras/dispatch/tests/run_unit_tests.c

Modified: qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch.h
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch.h?rev=1499133&r1=1499132&r2=1499133&view=diff
==============================================================================
--- qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch.h (original)
+++ qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch.h Tue Jul  2 22:29:31 
2013
@@ -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>

Modified: qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch/iterator.h
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch/iterator.h?rev=1499133&r1=1499132&r2=1499133&view=diff
==============================================================================
--- qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch/iterator.h (original)
+++ qpid/trunk/qpid/extras/dispatch/include/qpid/dispatch/iterator.h Tue Jul  2 
22:29:31 2013
@@ -101,6 +101,11 @@ void dx_field_iterator_set_address(const
 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
  */

Modified: qpid/trunk/qpid/extras/dispatch/src/iterator.c
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/extras/dispatch/src/iterator.c?rev=1499133&r1=1499132&r2=1499133&view=diff
==============================================================================
--- qpid/trunk/qpid/extras/dispatch/src/iterator.c (original)
+++ qpid/trunk/qpid/extras/dispatch/src/iterator.c Tue Jul  2 22:29:31 2013
@@ -250,6 +250,22 @@ dx_field_iterator_t* dx_field_iterator_s
 }
 
 
+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();

Modified: qpid/trunk/qpid/extras/dispatch/src/parse.c
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/extras/dispatch/src/parse.c?rev=1499133&r1=1499132&r2=1499133&view=diff
==============================================================================
--- qpid/trunk/qpid/extras/dispatch/src/parse.c (original)
+++ qpid/trunk/qpid/extras/dispatch/src/parse.c Tue Jul  2 22:29:31 2013
@@ -190,9 +190,9 @@ uint32_t dx_parse_as_uint(dx_parsed_fiel
     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_
     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...
 

Modified: qpid/trunk/qpid/extras/dispatch/tests/CMakeLists.txt
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/extras/dispatch/tests/CMakeLists.txt?rev=1499133&r1=1499132&r2=1499133&view=diff
==============================================================================
--- qpid/trunk/qpid/extras/dispatch/tests/CMakeLists.txt (original)
+++ qpid/trunk/qpid/extras/dispatch/tests/CMakeLists.txt Tue Jul  2 22:29:31 
2013
@@ -22,6 +22,7 @@
 ##
 set(unit_test_SOURCES
     alloc_test.c
+    parse_test.c
     run_unit_tests.c
     server_test.c
     timer_test.c

Added: qpid/trunk/qpid/extras/dispatch/tests/parse_test.c
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/extras/dispatch/tests/parse_test.c?rev=1499133&view=auto
==============================================================================
--- qpid/trunk/qpid/extras/dispatch/tests/parse_test.c (added)
+++ qpid/trunk/qpid/extras/dispatch/tests/parse_test.c Tue Jul  2 22:29:31 2013
@@ -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;
+}
+

Propchange: qpid/trunk/qpid/extras/dispatch/tests/parse_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=1499133&r1=1499132&r2=1499133&view=diff
==============================================================================
--- qpid/trunk/qpid/extras/dispatch/tests/run_unit_tests.c (original)
+++ qpid/trunk/qpid/extras/dispatch/tests/run_unit_tests.c Tue Jul  2 22:29:31 
2013
@@ -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;
 }
 



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

Reply via email to