Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ jobs:
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --build-config ${{ matrix.build_type }}
run: ctest --progress --output-on-failure --build-config ${{ matrix.build_type }}
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ SET_TARGET_PROPERTIES(ucl PROPERTIES
INSTALL(TARGETS ucl EXPORT uclConfig DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

ENABLE_TESTING()
ADD_SUBDIRECTORY(tests)

IF(ENABLE_UTILS MATCHES "ON")
ADD_SUBDIRECTORY(utils)
ENDIF()
Expand Down
32 changes: 32 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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})
add_test(NAME ${testname} COMMAND ${CMAKE_SOURCE_DIR}/tests/${wrapper})
set_tests_properties(${testname} PROPERTIES ENVIRONMENT "${TEST_ENV_VARS}")
endmacro()

# None of the tests are currently written with Windows-portability in mind...
IF(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
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)
ENDIF(CMAKE_SYSTEM_NAME STRNEQUAL "Windows")

8 changes: 4 additions & 4 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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
check_PROGRAMS = test_basic test_speed test_generate test_schema \
test_streamline test_msgpack
16 changes: 8 additions & 8 deletions tests/test_generate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 */

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion tests/test_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 12 additions & 3 deletions tests/test_speed.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -37,8 +48,6 @@
#endif
#endif

#include "ucl.h"

static double
get_ticks (void)
{
Expand Down
Loading