degesch: add a unit test for message wrapping algo
This commit is contained in:
parent
07201b7bdc
commit
86d7b7aed5
|
@ -34,6 +34,6 @@ before_script:
|
|||
script:
|
||||
- cmake .. -DCMAKE_INSTALL_PREFIX=/usr
|
||||
-DWANT_READLINE=$readline -DWANT_LIBEDIT=$libedit
|
||||
- make
|
||||
- make all test
|
||||
- cpack -G DEB
|
||||
- ../test
|
||||
|
|
|
@ -122,6 +122,23 @@ target_link_libraries (degesch ${project_libraries})
|
|||
add_executable (kike kike.c kike-replies.c ${common_sources} ${common_headers})
|
||||
target_link_libraries (kike ${project_libraries})
|
||||
|
||||
# Tests
|
||||
function (make_tests_for target_name)
|
||||
get_target_property (sources ${target_name} SOURCES)
|
||||
get_target_property (libraries ${target_name} LINK_LIBRARIES)
|
||||
|
||||
set (test test-${target_name})
|
||||
add_executable (${test} ${sources})
|
||||
target_link_libraries (${test} ${libraries})
|
||||
add_test (NAME ${test} COMMAND ${test})
|
||||
set_target_properties (${test} PROPERTIES COMPILE_DEFINITIONS TESTING)
|
||||
endfunction (make_tests_for)
|
||||
|
||||
include (CTest)
|
||||
if (BUILD_TESTING)
|
||||
make_tests_for (degesch)
|
||||
endif (BUILD_TESTING)
|
||||
|
||||
# Various clang-based diagnostics, loads of fake positives and spam
|
||||
file (GLOB clang_tidy_sources *.c)
|
||||
set (clang_tidy_checks misc-* readability-*
|
||||
|
|
36
degesch.c
36
degesch.c
|
@ -11197,6 +11197,42 @@ init_poller_events (struct app_context *ctx)
|
|||
ctx->autoaway_tmr.user_data = ctx;
|
||||
}
|
||||
|
||||
// --- Tests -------------------------------------------------------------------
|
||||
|
||||
// The application is quite monolithic and can only be partially unit-tested
|
||||
|
||||
#ifdef TESTING
|
||||
|
||||
static void
|
||||
test_wrapping (void)
|
||||
{
|
||||
struct str_vector v;
|
||||
str_vector_init (&v);
|
||||
|
||||
static const char *message = " foo bar foobar fóóbárbáz";
|
||||
static const char *split[] =
|
||||
{ " foo", "bar", "foob", "ar", "fó", "ób", "árb", "áz" };
|
||||
|
||||
hard_assert (wrap_message (message, 4, &v, NULL));
|
||||
hard_assert (v.len == N_ELEMENTS (split));
|
||||
for (size_t i = 0; i < N_ELEMENTS (split); i++)
|
||||
hard_assert (!strcmp (v.vector[i], split[i]));
|
||||
|
||||
str_vector_free (&v);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
struct test test;
|
||||
test_init (&test, argc, argv);
|
||||
test_add_simple (&test, "/wrapping", NULL, test_wrapping);
|
||||
return test_run (&test);
|
||||
}
|
||||
|
||||
#define main main_shadowed
|
||||
#endif // TESTING
|
||||
|
||||
// --- Main program ------------------------------------------------------------
|
||||
|
||||
static const char *g_logo[] =
|
||||
|
|
Loading…
Reference in New Issue