]> source.dussan.org Git - rspamd.git/commitdiff
Add a test suite for rcl.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 9 Aug 2013 15:53:32 +0000 (16:53 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 9 Aug 2013 15:53:32 +0000 (16:53 +0100)
lib/CMakeLists.txt
test/CMakeLists.txt
test/rspamd_rcl_test.c [new file with mode: 0644]
test/rspamd_test_suite.c
test/rspamd_url_test.c
test/tests.h

index 846b68fc2b1d9c5569165913014c3dedf836a614..af140352306cec244defb2090ee6ffa8b7b0d62c 100644 (file)
@@ -150,7 +150,10 @@ SET_TARGET_PROPERTIES(rspamd-server PROPERTIES LINKER_LANGUAGE C COMPILE_FLAGS "
 TARGET_LINK_LIBRARIES(rspamd-server rspamd-lua)
 TARGET_LINK_LIBRARIES(rspamd-server rspamd-json)
 TARGET_LINK_LIBRARIES(rspamd-server rspamd-cdb)
-TARGET_LINK_LIBRARIES(rspamd-server rspamd-util)      
+TARGET_LINK_LIBRARIES(rspamd-server rspamd-util)   
+IF(LIBJUDY_LIBRARY)
+       TARGET_LINK_LIBRARIES(rspamd-server Judy)
+ENDIF(LIBJUDY_LIBRARY)   
 IF(CMAKE_COMPILER_IS_GNUCC)
 SET_TARGET_PROPERTIES(rspamd-server PROPERTIES COMPILE_FLAGS "-DRSPAMD_LIB -fno-strict-aliasing")
 ENDIF(CMAKE_COMPILER_IS_GNUCC)
index acf80497a010d5fc1a377d4ed3c8c4520a365d62..2877ac8fc7a901f5700a4f2aa62524a9fe217316 100644 (file)
@@ -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 (file)
index 0000000..20dcc8c
--- /dev/null
@@ -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 ++;
+       }
+
+}
index b1f273cba101946809d2bc950aa3d9dfebfd7123..d249ee1fed6ab73b93c2f499fbd4a7382fe222c4 100644 (file)
@@ -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);
index f716c1ab068f577fd8f0c6d71a5a9fe0975f8a79..92dc5a0d496f7d2ca34e6ac1b6887bd98c33da5d 100644 (file)
@@ -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"
index 8fb22b6561255df0b7ab76b9471ab1da009c117c..dc484dbfffde12962feb1c155c92e807bc345fc1 100644 (file)
@@ -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