diff --git a/include/cryb/test.h b/include/cryb/test.h index 1138941..77f02e7 100644 --- a/include/cryb/test.h +++ b/include/cryb/test.h @@ -86,6 +86,7 @@ int t_is_null(const void *); int t_is_not_null(const void *); int t_compare_mem(const void *, const void *, size_t); int t_compare_str(const char *, const char *); +int t_compare_strn(const char *, const char *, size_t); #define t_compare_num(n, t) int t_compare_##n(t, t); t_compare_num(i, int); t_compare_num(u, unsigned int); diff --git a/lib/test/t_util.c b/lib/test/t_util.c index 025cdeb..8da5102 100644 --- a/lib/test/t_util.c +++ b/lib/test/t_util.c @@ -102,6 +102,22 @@ t_compare_str(const char *expected, const char *received) return (1); } +/* + * Compare two strings up to a specific length, and print a verbose + * message if they differ. + */ +int +t_compare_strn(const char *expected, const char *received, size_t len) +{ + + if (strncmp(expected, received, len) != 0) { + t_verbose("expected %.*s\n", (int)len, expected); + t_verbose("received %.*s\n", (int)len, received); + return (0); + } + return (1); +} + /* * Compare two numbers, and print a verbose message if they differ. */