diff options
Diffstat (limited to 'test/testutil.c')
-rw-r--r-- | test/testutil.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/testutil.c b/test/testutil.c index 3d2824c1f9..ae98e1096d 100644 --- a/test/testutil.c +++ b/test/testutil.c @@ -363,6 +363,38 @@ int test_str_ne(const char *file, int line, const char *st1, const char *st2, return 1; } +int test_strn_eq(const char *file, int line, const char *st1, const char *st2, + const char *s1, const char *s2, size_t len) +{ + int prec = (int)len; + + if (s1 == NULL && s2 == NULL) + return 1; + if (s1 == NULL || s2 == NULL || strncmp(s1, s2, len) != 0) { + test_fail_message(NULL, file, line, "string", "%.s [%.*s] == %s [%.*s]", + st1, prec, print_string_maybe_null(s1), + st2, prec, print_string_maybe_null(s2)); + return 0; + } + return 1; +} + +int test_strn_ne(const char *file, int line, const char *st1, const char *st2, + const char *s1, const char *s2, size_t len) +{ + int prec = (int)len; + + if ((s1 == NULL) ^ (s2 == NULL)) + return 1; + if (s1 == NULL || strncmp(s1, s2, len) == 0) { + test_fail_message(NULL, file, line, "string", "%s [%.*s] != %s [%.*s]", + st1, prec, print_string_maybe_null(s1), + st2, prec, print_string_maybe_null(s2)); + return 0; + } + return 1; +} + /* * We could use OPENSSL_buf2hexstr() to do this but trying to allocate memory * in a failure state isn't generally a great idea. |