summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAsk Solem <ask@celeryproject.org>2014-04-14 17:29:03 +0100
committerAsk Solem <ask@celeryproject.org>2014-04-14 17:29:03 +0100
commitbe3000b4c84d7503f5ef4067de44ff16d060d158 (patch)
treefecacb0f149b067202c443b59aad3cc027a0ff1c /tests
parentdcb8edaccd6e164d624edfab0f3120d96f707f0a (diff)
parentfe844e41ffad5691607982cbfe4054aacdcb81e0 (diff)
downloadrabbitmq-c-github-ask-be3000b4c84d7503f5ef4067de44ff16d060d158.tar.gz
Merge branch 'alanxz/master'
Conflicts: Makefile.am codegen
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt7
-rw-r--r--tests/test_hostcheck.c78
2 files changed, 85 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 7ebf545..3a90464 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -8,6 +8,8 @@ if (MSVC)
include_directories(win32/msinttypes)
endif (MSVC)
+add_definitions(-DHAVE_CONFIG_H)
+
add_executable(test_parse_url test_parse_url.c)
target_link_libraries(test_parse_url ${RMQ_LIBRARY_TARGET})
add_test(parse_url test_parse_url)
@@ -16,3 +18,8 @@ add_executable(test_tables test_tables.c)
target_link_libraries(test_tables ${RMQ_LIBRARY_TARGET})
add_test(tables test_tables)
configure_file(test_tables.expected ${CMAKE_CURRENT_BINARY_DIR}/tests/test_tables.expected COPY_ONLY)
+
+add_executable(test_hostcheck
+ test_hostcheck.c
+ ../librabbitmq/amqp_hostcheck.c)
+add_test(hostcheck test_hostcheck)
diff --git a/tests/test_hostcheck.c b/tests/test_hostcheck.c
new file mode 100644
index 0000000..8d562e6
--- /dev/null
+++ b/tests/test_hostcheck.c
@@ -0,0 +1,78 @@
+/* vim:set ft=c ts=2 sw=2 sts=2 et cindent: */
+/*
+ * Copyright 2014 Michael Steinert
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "amqp_hostcheck.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+static void
+hostcheck_success(const char *match_pattern, const char *url)
+{
+ int ok;
+
+ ok = amqp_hostcheck(match_pattern, url);
+ if (! ok) {
+ fprintf(stderr, "Expected hostname check to pass, but didn't: %s (%s)\n",
+ url, match_pattern);
+ abort();
+ }
+
+ fprintf(stdout, "ok: [success] %s, %s\n", url, match_pattern);
+}
+
+static void
+hostcheck_fail(const char *match_pattern, const char *url)
+{
+ int ok;
+
+ ok = amqp_hostcheck(match_pattern, url);
+ if (ok) {
+ fprintf(stderr, "Expected hostname check to fail, but didn't: %s (%s)\n",
+ url, match_pattern);
+ abort();
+ }
+
+ fprintf(stdout, "ok: [fail] %s, %s\n", url, match_pattern);
+}
+
+int
+main(void)
+{
+ hostcheck_success("www.rabbitmq.com", "www.rabbitmq.com");
+ hostcheck_success("www.rabbitmq.com", "wWw.RaBbItMq.CoM");
+ hostcheck_success("*.rabbitmq.com", "wWw.RaBbItMq.CoM");
+ hostcheck_fail("rabbitmq.com", "www.rabbitmq.com");
+ hostcheck_success("*.rabbitmq.com", "www.rabbitmq.com");
+ hostcheck_fail("*.com", "www.rabbitmq.com");
+ hostcheck_fail("*.rabbitmq.com", "long.url.rabbitmq.com");
+ hostcheck_success("*.url.rabbitmq.com", "long.url.rabbitmq.com");
+
+ return 0;
+}