diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-12-08 23:38:02 +0100 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-12-09 21:07:01 +0100 |
commit | 86d7b7aed52c66d12f361a3ee8dc7a0eb419bdbc (patch) | |
tree | 444426ca7292326bf01fe619351533b908c485a8 /degesch.c | |
parent | 07201b7bdcff5612f573aee10f3caa007a9d98d5 (diff) | |
download | xK-86d7b7aed52c66d12f361a3ee8dc7a0eb419bdbc.tar.gz xK-86d7b7aed52c66d12f361a3ee8dc7a0eb419bdbc.tar.xz xK-86d7b7aed52c66d12f361a3ee8dc7a0eb419bdbc.zip |
degesch: add a unit test for message wrapping algo
Diffstat (limited to 'degesch.c')
-rw-r--r-- | degesch.c | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -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[] = |