diff options
| author | Dmitry Torokhov <[email protected]> | 2020-01-31 17:42:33 -0800 |
|---|---|---|
| committer | Dmitry Torokhov <[email protected]> | 2020-01-31 17:42:33 -0800 |
| commit | b19efcabb587e5470a423ef778905f47e5a47f1a (patch) | |
| tree | 8863c2233ed8a30d55c4e4029a98c3d7faf359a8 /lib/kunit/string-stream-test.c | |
| parent | 996d5d5f89a558a3608a46e73ccd1b99f1b1d058 (diff) | |
| parent | c5ccf2ad3d33413fee06ae87d0b970d8cc540db6 (diff) | |
Merge branch 'next' into for-linus
Prepare input updates for 5.6 merge window.
Diffstat (limited to 'lib/kunit/string-stream-test.c')
| -rw-r--r-- | lib/kunit/string-stream-test.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/kunit/string-stream-test.c b/lib/kunit/string-stream-test.c new file mode 100644 index 000000000000..76cc05eb00ed --- /dev/null +++ b/lib/kunit/string-stream-test.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit test for struct string_stream. + * + * Copyright (C) 2019, Google LLC. + * Author: Brendan Higgins <[email protected]> + */ + +#include <kunit/string-stream.h> +#include <kunit/test.h> +#include <linux/slab.h> + +static void string_stream_test_empty_on_creation(struct kunit *test) +{ + struct string_stream *stream = alloc_string_stream(test, GFP_KERNEL); + + KUNIT_EXPECT_TRUE(test, string_stream_is_empty(stream)); +} + +static void string_stream_test_not_empty_after_add(struct kunit *test) +{ + struct string_stream *stream = alloc_string_stream(test, GFP_KERNEL); + + string_stream_add(stream, "Foo"); + + KUNIT_EXPECT_FALSE(test, string_stream_is_empty(stream)); +} + +static void string_stream_test_get_string(struct kunit *test) +{ + struct string_stream *stream = alloc_string_stream(test, GFP_KERNEL); + char *output; + + string_stream_add(stream, "Foo"); + string_stream_add(stream, " %s", "bar"); + + output = string_stream_get_string(stream); + KUNIT_ASSERT_STREQ(test, output, "Foo bar"); +} + +static struct kunit_case string_stream_test_cases[] = { + KUNIT_CASE(string_stream_test_empty_on_creation), + KUNIT_CASE(string_stream_test_not_empty_after_add), + KUNIT_CASE(string_stream_test_get_string), + {} +}; + +static struct kunit_suite string_stream_test_suite = { + .name = "string-stream-test", + .test_cases = string_stream_test_cases +}; +kunit_test_suite(string_stream_test_suite); |