[dm-devel] [PATCH 01/12] Unit tests for basenamecpy
Martin Wilck
mwilck at suse.com
Mon Mar 19 09:49:21 UTC 2018
On Wed, 2018-03-14 at 12:46 -0500, Benjamin Marzinski wrote:
> The current implementation of basenamecpy is broken, so some of these
> tests currently fail. Fixes to follow.
>
> Signed-off-by: Benjamin Marzinski <bmarzins at redhat.com>
> ---
> tests/Makefile | 2 +-
> tests/util.c | 167
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 168 insertions(+), 1 deletion(-)
> create mode 100644 tests/util.c
>
> +static void test_basenamecpy_good6(void **state)
> +{
> + char dst[6];
> +
> + assert_int_equal(basenamecpy("/xyzzy/plugh ", dst,
> sizeof(dst)), 5);
> + assert_string_equal(dst, "plugh");
> +}
This deserves explanation. "basename" wouldn't normally strip trailing
whitespace.
> +/* ends in slash */
> +static void test_basenamecpy_bad1(void **state)
> +{
> + char dst[10];
> +
> + assert_int_equal(basenamecpy("foo/bar/", dst, sizeof(dst)),
> 0);
This, too, deviates from standard "basename" behavior and should be
explained ("basename /usr/" yields "usr", so does "basename /usr///").
> +}
> +
> +static void test_basenamecpy_bad2(void **state)
> +{
> + char dst[10];
> +
> + assert_int_equal(basenamecpy(NULL, dst, sizeof(dst)), 0);
> +}
> +
> +static void test_basenamecpy_bad3(void **state)
> +{
> + char dst[10];
> +
> + assert_int_equal(basenamecpy("", dst, sizeof(dst)), 0);
> +}
> +
> +static void test_basenamecpy_bad4(void **state)
> +{
> + char dst[10];
> +
> + assert_int_equal(basenamecpy("/", dst, sizeof(dst)), 0);
> +}
Another one: "basename /" yields "/" in the shell, so does
"basename ///").
I don't insist that basenamecpy behaves 100% identical as "basename",
but I reckon if expectations are different, we should explain why.
Regards,
Martin
--
Dr. Martin Wilck <mwilck at suse.com>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
More information about the dm-devel
mailing list