aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2013-08-09 16:53:32 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2013-08-09 16:53:32 +0100
commit07011527b93630d0326e26d5b04eea07a7cc5a97 (patch)
tree1d36471bc4fc097d5916971e002b3ddfdbb63b66 /test
parent61200d8eafa814312ceb123ee8b22668a5f06a65 (diff)
downloadrspamd-07011527b93630d0326e26d5b04eea07a7cc5a97.tar.gz
rspamd-07011527b93630d0326e26d5b04eea07a7cc5a97.zip
Add a test suite for rcl.
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt4
-rw-r--r--test/rspamd_rcl_test.c72
-rw-r--r--test/rspamd_test_suite.c1
-rw-r--r--test/rspamd_url_test.c13
-rw-r--r--test/tests.h3
5 files changed, 79 insertions, 14 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index acf80497a..2877ac8fc 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -8,7 +8,8 @@ SET(TESTSRC rspamd_expression_test.c
rspamd_dns_test.c
rspamd_async_test.c
rspamd_dkim_test.c
- rspamd_rrd_test.c)
+ rspamd_rrd_test.c
+ rspamd_rcl_test.c)
ADD_EXECUTABLE(rspamd-test EXCLUDE_FROM_ALL ${TESTSRC})
SET_TARGET_PROPERTIES(rspamd-test PROPERTIES LINKER_LANGUAGE C)
@@ -21,6 +22,7 @@ TARGET_LINK_LIBRARIES(rspamd-test ${CMAKE_REQUIRED_LIBRARIES})
TARGET_LINK_LIBRARIES(rspamd-test rspamd-mime)
TARGET_LINK_LIBRARIES(rspamd-test rspamd-server)
TARGET_LINK_LIBRARIES(rspamd-test rspamd-util)
+TARGET_LINK_LIBRARIES(rspamd-test rspamd-rcl)
TARGET_LINK_LIBRARIES(rspamd-test hiredis)
IF(HAVE_LIBEVENT2)
TARGET_LINK_LIBRARIES(rspamd-test event_pthreads)
diff --git a/test/rspamd_rcl_test.c b/test/rspamd_rcl_test.c
new file mode 100644
index 000000000..20dcc8c24
--- /dev/null
+++ b/test/rspamd_rcl_test.c
@@ -0,0 +1,72 @@
+/* Copyright (c) 2013, Vsevolod Stakhov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "../src/config.h"
+#include "../src/rcl/rcl.h"
+#include "tests.h"
+
+const gchar *rcl_test_valid[] = {
+ /* Json like */
+ "{"
+ "\"key1\": value;"
+ "\"key1\": value2;"
+ "\"key1\": \"value;\""
+ "}\n",
+ /* Nginx like */
+ "section1 { param1 = value; param2 = value, param3 = [\"value1\", 100500]}\n"
+ "section2 { param1 = {key = value}, param1 = [\"key\"]}",
+ /* Numbers */
+ "key = 1s\n"
+ "key2 = 1min\n"
+ "key3 = 1kb\n"
+ "key4 = 5M\n"
+ "key5 = 10mS\n"
+ "key6 = 10y\n",
+ /* Strings */
+ "key = \"some string\";"
+ "key1 = /some/path;"
+ "key3 = 111some,"
+ "key4: s1,"
+ "\"key5\": \"\\n\\r123\"",
+ NULL
+};
+
+void
+rspamd_rcl_test_func (void)
+{
+ struct rspamd_cl_parser *parser;
+ rspamd_cl_object_t *obj;
+ const gchar **cur;
+ GError *err = NULL;
+
+ parser = rspamd_cl_parser_new ();
+ g_assert (parser != NULL);
+
+ cur = rcl_test_valid;
+ while (*cur != NULL) {
+ rspamd_cl_parser_add_chunk (parser, *cur, strlen (*cur), &err);
+ g_assert_no_error (err);
+ cur ++;
+ }
+
+}
diff --git a/test/rspamd_test_suite.c b/test/rspamd_test_suite.c
index b1f273cba..d249ee1fe 100644
--- a/test/rspamd_test_suite.c
+++ b/test/rspamd_test_suite.c
@@ -62,6 +62,7 @@ main (int argc, char **argv)
#if 0
g_test_add_func ("/rspamd/memcached", rspamd_memcached_test_func);
#endif
+ g_test_add_func ("/rspamd/rcl", rspamd_rcl_test_func);
g_test_add_func ("/rspamd/mem_pool", rspamd_mem_pool_test_func);
g_test_add_func ("/rspamd/fuzzy", rspamd_fuzzy_test_func);
g_test_add_func ("/rspamd/url", rspamd_url_test_func);
diff --git a/test/rspamd_url_test.c b/test/rspamd_url_test.c
index f716c1ab0..92dc5a0d4 100644
--- a/test/rspamd_url_test.c
+++ b/test/rspamd_url_test.c
@@ -1,16 +1,3 @@
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-#include <sys/param.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <syslog.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-
#include "../src/config.h"
#include "../src/main.h"
#include "../src/cfg_file.h"
diff --git a/test/tests.h b/test/tests.h
index 8fb22b656..dc484dbff 100644
--- a/test/tests.h
+++ b/test/tests.h
@@ -35,4 +35,7 @@ void rspamd_dkim_test_func (void);
/* RRD test */
void rspamd_rrd_test_func (void);
+/* RCL test */
+void rspamd_rcl_test_func (void);
+
#endif