1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * KUnit test for struct string_stream. 4 * 5 * Copyright (C) 2019, Google LLC. 6 * Author: Brendan Higgins <brendanhiggins@google.com> 7 */ 8 9 #include <kunit/string-stream.h> 10 #include <kunit/test.h> 11 #include <linux/slab.h> 12 13 static void string_stream_test_empty_on_creation(struct kunit *test) 14 { 15 struct string_stream *stream = alloc_string_stream(test, GFP_KERNEL); 16 17 KUNIT_EXPECT_TRUE(test, string_stream_is_empty(stream)); 18 } 19 20 static void string_stream_test_not_empty_after_add(struct kunit *test) 21 { 22 struct string_stream *stream = alloc_string_stream(test, GFP_KERNEL); 23 24 string_stream_add(stream, "Foo"); 25 26 KUNIT_EXPECT_FALSE(test, string_stream_is_empty(stream)); 27 } 28 29 static void string_stream_test_get_string(struct kunit *test) 30 { 31 struct string_stream *stream = alloc_string_stream(test, GFP_KERNEL); 32 char *output; 33 34 string_stream_add(stream, "Foo"); 35 string_stream_add(stream, " %s", "bar"); 36 37 output = string_stream_get_string(stream); 38 KUNIT_ASSERT_STREQ(test, output, "Foo bar"); 39 } 40 41 static struct kunit_case string_stream_test_cases[] = { 42 KUNIT_CASE(string_stream_test_empty_on_creation), 43 KUNIT_CASE(string_stream_test_not_empty_after_add), 44 KUNIT_CASE(string_stream_test_get_string), 45 {} 46 }; 47 48 static struct kunit_suite string_stream_test_suite = { 49 .name = "string-stream-test", 50 .test_cases = string_stream_test_cases 51 }; 52 kunit_test_suite(string_stream_test_suite); 53