Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * KUnit test for struct string_stream.
0004  *
0005  * Copyright (C) 2019, Google LLC.
0006  * Author: Brendan Higgins <brendanhiggins@google.com>
0007  */
0008 
0009 #include <kunit/test.h>
0010 #include <linux/slab.h>
0011 
0012 #include "string-stream.h"
0013 
0014 static void string_stream_test_empty_on_creation(struct kunit *test)
0015 {
0016     struct string_stream *stream = alloc_string_stream(test, GFP_KERNEL);
0017 
0018     KUNIT_EXPECT_TRUE(test, string_stream_is_empty(stream));
0019 }
0020 
0021 static void string_stream_test_not_empty_after_add(struct kunit *test)
0022 {
0023     struct string_stream *stream = alloc_string_stream(test, GFP_KERNEL);
0024 
0025     string_stream_add(stream, "Foo");
0026 
0027     KUNIT_EXPECT_FALSE(test, string_stream_is_empty(stream));
0028 }
0029 
0030 static void string_stream_test_get_string(struct kunit *test)
0031 {
0032     struct string_stream *stream = alloc_string_stream(test, GFP_KERNEL);
0033     char *output;
0034 
0035     string_stream_add(stream, "Foo");
0036     string_stream_add(stream, " %s", "bar");
0037 
0038     output = string_stream_get_string(stream);
0039     KUNIT_ASSERT_STREQ(test, output, "Foo bar");
0040 }
0041 
0042 static struct kunit_case string_stream_test_cases[] = {
0043     KUNIT_CASE(string_stream_test_empty_on_creation),
0044     KUNIT_CASE(string_stream_test_not_empty_after_add),
0045     KUNIT_CASE(string_stream_test_get_string),
0046     {}
0047 };
0048 
0049 static struct kunit_suite string_stream_test_suite = {
0050     .name = "string-stream-test",
0051     .test_cases = string_stream_test_cases
0052 };
0053 kunit_test_suites(&string_stream_test_suite);