From: Vsevolod Stakhov Date: Fri, 9 Aug 2013 15:53:32 +0000 (+0100) Subject: Add a test suite for rcl. X-Git-Tag: 0.6.0~234 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07011527b93630d0326e26d5b04eea07a7cc5a97;p=thirdparty%2Frspamd.git Add a test suite for rcl. --- diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 846b68fc2b..af14035230 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -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) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index acf80497a0..2877ac8fc7 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 0000000000..20dcc8c240 --- /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 b1f273cba1..d249ee1fed 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 f716c1ab06..92dc5a0d49 100644 --- a/test/rspamd_url_test.c +++ b/test/rspamd_url_test.c @@ -1,16 +1,3 @@ -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - #include "../src/config.h" #include "../src/main.h" #include "../src/cfg_file.h" diff --git a/test/tests.h b/test/tests.h index 8fb22b6561..dc484dbfff 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