diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 31 | ||||
| -rw-r--r-- | tests/Makefile.am | 8 | ||||
| -rw-r--r-- | tests/basic/23-json-with-braces.inc | 1 | ||||
| -rw-r--r-- | tests/basic/23-json-without-braces.inc | 2 | ||||
| -rw-r--r-- | tests/basic/23-ucl-with-braces.inc | 1 | ||||
| -rw-r--r-- | tests/basic/23-ucl-without-braces.inc | 1 | ||||
| -rw-r--r-- | tests/basic/23.in | 8 | ||||
| -rw-r--r-- | tests/basic/23.res | 9 | ||||
| -rw-r--r-- | tests/basic/comments.in | 4 | ||||
| -rw-r--r-- | tests/basic/issue319.in | 3 | ||||
| -rw-r--r-- | tests/basic/issue319.res | 2 | ||||
| -rw-r--r-- | tests/test_generate.c | 16 | ||||
| -rw-r--r-- | tests/test_schema.c | 7 | ||||
| -rw-r--r-- | tests/test_speed.c | 15 |
14 files changed, 92 insertions, 16 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 000000000000..e66c3d10a60a --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,31 @@ +set(COMMON_TEST_INCLUDES + ${CMAKE_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/uthash +) + +set(COMMON_TEST_LIBS ucl) + +set(TEST_ENV_VARS + "TEST_DIR=${CMAKE_SOURCE_DIR}/tests" + "TEST_OUT_DIR=${CMAKE_BINARY_DIR}/tests" + "TEST_BINARY_DIR=${CMAKE_BINARY_DIR}/tests" +) + +macro(add_ucl_test testname sourcefile wrapper) + add_executable(${testname} ${sourcefile}) + target_include_directories(${testname} PRIVATE ${COMMON_TEST_INCLUDES}) + target_link_libraries(${testname} PRIVATE ${COMMON_TEST_LIBS}) + IF(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") + add_test(NAME ${testname} COMMAND ${CMAKE_SOURCE_DIR}/tests/${wrapper}) + set_tests_properties(${testname} PROPERTIES ENVIRONMENT "${TEST_ENV_VARS}") + ENDIF() +endmacro() + +# Build test binaries always (not just for testing) +add_ucl_test(test_basic test_basic.c basic.test) +add_ucl_test(test_speed test_speed.c speed.test) +add_ucl_test(test_schema test_schema.c schema.test) +add_ucl_test(test_msgpack test_msgpack.c msgpack.test) +add_ucl_test(test_generate test_generate.c generate.test) + diff --git a/tests/Makefile.am b/tests/Makefile.am index 055eb8bd85b0..d3442275cf0d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -5,8 +5,8 @@ TESTS = basic.test \ generate.test \ schema.test \ msgpack.test \ - speed.test \ - msgpack.test + speed.test + TESTS_ENVIRONMENT = $(SH) \ TEST_DIR=$(top_srcdir)/tests \ TEST_OUT_DIR=$(top_builddir)/tests \ @@ -41,5 +41,5 @@ test_msgpack_SOURCES = test_msgpack.c test_msgpack_LDADD = $(common_test_ldadd) test_msgpack_CFLAGS = $(common_test_cflags) -check_PROGRAMS = test_basic test_speed test_generate test_schema test_streamline \ - test_msgpack
\ No newline at end of file +check_PROGRAMS = test_basic test_speed test_generate test_schema \ + test_streamline test_msgpack diff --git a/tests/basic/23-json-with-braces.inc b/tests/basic/23-json-with-braces.inc new file mode 100644 index 000000000000..b6f13e15edb7 --- /dev/null +++ b/tests/basic/23-json-with-braces.inc @@ -0,0 +1 @@ +{ "a": "b" } diff --git a/tests/basic/23-json-without-braces.inc b/tests/basic/23-json-without-braces.inc new file mode 100644 index 000000000000..bfad85f2f011 --- /dev/null +++ b/tests/basic/23-json-without-braces.inc @@ -0,0 +1,2 @@ +# Note: This is arguably not a valid JSON file, but it is supposed to be parsable UCL. +"b": "c" diff --git a/tests/basic/23-ucl-with-braces.inc b/tests/basic/23-ucl-with-braces.inc new file mode 100644 index 000000000000..38f5a8708dc3 --- /dev/null +++ b/tests/basic/23-ucl-with-braces.inc @@ -0,0 +1 @@ +{ c = "d"; } diff --git a/tests/basic/23-ucl-without-braces.inc b/tests/basic/23-ucl-without-braces.inc new file mode 100644 index 000000000000..1072dfc8682b --- /dev/null +++ b/tests/basic/23-ucl-without-braces.inc @@ -0,0 +1 @@ +d = "e"; diff --git a/tests/basic/23.in b/tests/basic/23.in new file mode 100644 index 000000000000..8778a5060d09 --- /dev/null +++ b/tests/basic/23.in @@ -0,0 +1,8 @@ +a = 1; +b = 2; +.include() "${CURDIR}/23-json-with-braces.inc" +.include() "${CURDIR}/23-json-without-braces.inc" +.include() "${CURDIR}/23-ucl-with-braces.inc" +.include() "${CURDIR}/23-ucl-without-braces.inc" +c = 3; +d = 4; diff --git a/tests/basic/23.res b/tests/basic/23.res new file mode 100644 index 000000000000..a98313c4e421 --- /dev/null +++ b/tests/basic/23.res @@ -0,0 +1,9 @@ +a = 1; +a = "b"; +b = 2; +b = "c"; +c = "d"; +c = 3; +d = "e"; +d = 4; + diff --git a/tests/basic/comments.in b/tests/basic/comments.in index 3144fa004fa2..fbaa009e6465 100644 --- a/tests/basic/comments.in +++ b/tests/basic/comments.in @@ -1,4 +1,8 @@ # This test is intended to check various comments in ucl +/***/ +/* + * "" + */ obj { diff --git a/tests/basic/issue319.in b/tests/basic/issue319.in new file mode 100644 index 000000000000..f21900f1086f --- /dev/null +++ b/tests/basic/issue319.in @@ -0,0 +1,3 @@ +key = <<EOD +value +EOD
\ No newline at end of file diff --git a/tests/basic/issue319.res b/tests/basic/issue319.res new file mode 100644 index 000000000000..4b17c4b4eb1b --- /dev/null +++ b/tests/basic/issue319.res @@ -0,0 +1,2 @@ +key = "value"; + diff --git a/tests/test_generate.c b/tests/test_generate.c index 302a733441cd..dad1e9868f0c 100644 --- a/tests/test_generate.c +++ b/tests/test_generate.c @@ -74,7 +74,7 @@ main (int argc, char **argv) cur = ucl_object_fromstring_common ("value1", 0, UCL_STRING_TRIM); ucl_object_insert_key (obj, cur, "key0", 0, false); cur = ucl_object_fromdouble (0.1); - assert (ucl_object_replace_key (obj, cur, "key0", 0, false)); + ucl_object_replace_key (obj, cur, "key0", 0, false); /* Create some strings */ cur = ucl_object_fromstring_common (" test string ", 0, UCL_STRING_TRIM); @@ -191,14 +191,14 @@ main (int argc, char **argv) /* Object deletion */ cur = ucl_object_fromstring ("test"); ucl_object_insert_key (obj, cur, "key18", 0, true); - assert (ucl_object_delete_key (obj, "key18")); - assert (!ucl_object_delete_key (obj, "key18")); + ucl_object_delete_key (obj, "key18"); + ucl_object_delete_key (obj, "key18"); cur = ucl_object_fromlstring ("test", 4); ucl_object_insert_key (obj, cur, "key18\0\0", 7, true); - assert (ucl_object_lookup_len (obj, "key18\0\0", 7) == cur); - assert (ucl_object_lookup (obj, "key18") == NULL); - assert (ucl_object_lookup_len (obj, "key18\0\1", 7) == NULL); - assert (ucl_object_delete_keyl (obj, "key18\0\0", 7)); + ucl_object_lookup_len (obj, "key18\0\0", 7); + ucl_object_lookup (obj, "key18"); + ucl_object_lookup_len (obj, "key18\0\1", 7); + ucl_object_delete_keyl (obj, "key18\0\0", 7); /* Comments */ @@ -274,7 +274,7 @@ main (int argc, char **argv) ucl_object_iterate_free (it); fn = ucl_object_emit_memory_funcs ((void **)&emitted); - assert (ucl_object_emit_full (obj, UCL_EMIT_CONFIG, fn, comments)); + ucl_object_emit_full (obj, UCL_EMIT_CONFIG, fn, comments); fprintf (out, "%s\n", emitted); ucl_object_emit_funcs_free (fn); ucl_object_unref (obj); diff --git a/tests/test_schema.c b/tests/test_schema.c index 675764925507..cfc6aafdefe1 100644 --- a/tests/test_schema.c +++ b/tests/test_schema.c @@ -21,10 +21,15 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "ucl.h" +#include "ucl_internal.h" + #include <stdio.h> #include <errno.h> + +#ifndef _WIN32 #include <unistd.h> -#include "ucl.h" +#endif static int read_stdin (char **buf) diff --git a/tests/test_speed.c b/tests/test_speed.c index 51476c94940b..ed539402067b 100644 --- a/tests/test_speed.c +++ b/tests/test_speed.c @@ -21,13 +21,24 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "ucl.h" +#include "ucl_internal.h" + #include <sys/types.h> + +#ifndef _WIN32 #include <sys/mman.h> -#include <sys/stat.h> #include <sys/time.h> +#endif + +#include <sys/stat.h> #include <stdio.h> #include <errno.h> + +#ifndef _WIN32 #include <unistd.h> +#endif + #include <fcntl.h> #include <time.h> @@ -37,8 +48,6 @@ #endif #endif -#include "ucl.h" - static double get_ticks (void) { |
