You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2014/03/10 22:15:56 UTC

svn commit: r1576090 - in /qpid/proton/trunk/proton-c/src/tests: CMakeLists.txt parse-url.c

Author: astitcher
Date: Mon Mar 10 21:15:55 2014
New Revision: 1576090

URL: http://svn.apache.org/r1576090
Log:
PROTON-506: Added unit tests for C url parser

Added:
    qpid/proton/trunk/proton-c/src/tests/parse-url.c
Modified:
    qpid/proton/trunk/proton-c/src/tests/CMakeLists.txt

Modified: qpid/proton/trunk/proton-c/src/tests/CMakeLists.txt
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/tests/CMakeLists.txt?rev=1576090&r1=1576089&r2=1576090&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/tests/CMakeLists.txt (original)
+++ qpid/proton/trunk/proton-c/src/tests/CMakeLists.txt Mon Mar 10 21:15:55 2014
@@ -34,4 +34,5 @@ endmacro(pn_add_c_test)
 pn_add_c_test (c-object-tests object.c)
 pn_add_c_test (c-message-tests message.c)
 pn_add_c_test (c-engine-tests engine.c)
+pn_add_c_test (c-parse-url-tests parse-url.c)
 

Added: qpid/proton/trunk/proton-c/src/tests/parse-url.c
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/tests/parse-url.c?rev=1576090&view=auto
==============================================================================
--- qpid/proton/trunk/proton-c/src/tests/parse-url.c (added)
+++ qpid/proton/trunk/proton-c/src/tests/parse-url.c Mon Mar 10 21:15:55 2014
@@ -0,0 +1,82 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+// No point in running this code if assert doesn't work!
+#undef NDEBUG
+#include <assert.h>
+
+#include <proton/error.h>
+#include <proton/util.h>
+
+static inline bool equalStrP(const char* s1, const char* s2)
+{
+  return (s1==s2) || (s1 && s2 && strcmp(s1,s2)==0);
+}
+
+static bool test_url_parse(const char* url0, const char* scheme0, const char* user0, const char* pass0, const char* host0, const char* port0, const char*path0)
+{
+  char* url = (char*)malloc(strlen(url0)+1);
+  char* scheme = 0;
+  char* user = 0;
+  char* pass = 0;
+  char* host = 0;
+  char* port = 0;
+  char* path = 0;
+
+  strcpy(url, url0);
+
+  pni_parse_url(url, &scheme, &user, &pass, &host, &port, &path);
+  bool r =  equalStrP(scheme,scheme0) &&
+            equalStrP(user, user0) &&
+            equalStrP(pass, pass0) &&
+            equalStrP(host, host0) &&
+            equalStrP(port, port0) &&
+            equalStrP(path, path0);
+
+  free(url);
+
+  return r;
+}
+
+int main(int argc, char **argv)
+{
+  assert(test_url_parse("host", 0, 0, 0, "host", 0, 0));
+  assert(test_url_parse("host:423", 0, 0, 0, "host", "423", 0));
+  assert(test_url_parse("user@host", 0, "user", 0, "host", 0, 0));
+  assert(test_url_parse("user:1243^&^:pw@host:423", 0, "user", "1243^&^:pw", "host", "423", 0));
+  assert(test_url_parse("user:1243^&^:pw@host:423/Foo.bar:90087", 0, "user", "1243^&^:pw", "host", "423", "Foo.bar:90087"));
+  assert(test_url_parse("user:1243^&^:pw@host:423/Foo.bar:90087@somewhere", 0, "user", "1243^&^:pw", "host", "423", "Foo.bar:90087@somewhere"));
+  assert(test_url_parse("amqp://host", "amqp", 0, 0, "host", 0, 0));
+  assert(test_url_parse("amqp://user@host", "amqp", "user", 0, "host", 0, 0));
+  assert(test_url_parse("amqp://user@host/path:%", "amqp", "user", 0, "host", 0, "path:%"));
+  assert(test_url_parse("amqp://user@host:5674/path:%", "amqp", "user", 0, "host", "5674", "path:%"));
+  assert(test_url_parse("amqp://user@host/path:%", "amqp", "user", 0, "host", 0, "path:%"));
+  assert(test_url_parse("amqp://bigbird@host/queue@host", "amqp", "bigbird", 0, "host", 0, "queue@host"));
+  assert(test_url_parse("amqp://host/queue@host", "amqp", 0, 0, "host", 0, "queue@host"));
+  assert(test_url_parse("amqp://host:9765/queue@host", "amqp", 0, 0, "host", "9765", "queue@host"));
+  return 0;
+}



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