|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | +/* |
| 3 | + * |
| 4 | + * KUnit tests of SMB1 maperror |
| 5 | + * |
| 6 | + * Copyright (C) 2026 KylinSoft Co., Ltd. All rights reserved. |
| 7 | + * Author(s): Youling Tang <tangyouling@kylinos.cn> |
| 8 | + * ChenXiaoSong <chenxiaosong@kylinos.cn> |
| 9 | + * |
| 10 | + */ |
| 11 | + |
| 12 | +#include <kunit/test.h> |
| 13 | +#include "smb1proto.h" |
| 14 | +#include "nterr.h" |
| 15 | + |
| 16 | +#define DEFINE_CHECK_SEARCH_FUNC(__struct_name, __field, \ |
| 17 | + __array, __num) \ |
| 18 | +static void check_search_ ## __array(struct kunit *test) \ |
| 19 | +{ \ |
| 20 | + unsigned int i; \ |
| 21 | + const struct __struct_name *expect, *result; \ |
| 22 | + \ |
| 23 | + for (i = 0; i < __num; i++) { \ |
| 24 | + expect = &__array ## _test[i]; \ |
| 25 | + result = search_ ## __array ## _test(expect->__field); \ |
| 26 | + KUNIT_ASSERT_NOT_NULL(test, result); \ |
| 27 | + test_cmp_ ## __struct_name(test, expect, result); \ |
| 28 | + } \ |
| 29 | +} |
| 30 | + |
| 31 | +static void |
| 32 | +test_cmp_ntstatus_to_dos_err(struct kunit *test, |
| 33 | + const struct ntstatus_to_dos_err *expect, |
| 34 | + const struct ntstatus_to_dos_err *result) |
| 35 | +{ |
| 36 | + KUNIT_EXPECT_EQ(test, expect->dos_class, result->dos_class); |
| 37 | + KUNIT_EXPECT_EQ(test, expect->dos_code, result->dos_code); |
| 38 | + KUNIT_EXPECT_EQ(test, expect->ntstatus, result->ntstatus); |
| 39 | + KUNIT_EXPECT_STREQ(test, expect->nt_errstr, result->nt_errstr); |
| 40 | +} |
| 41 | + |
| 42 | +/* check_search_ntstatus_to_dos_map */ |
| 43 | +DEFINE_CHECK_SEARCH_FUNC(ntstatus_to_dos_err, ntstatus, ntstatus_to_dos_map, |
| 44 | + ntstatus_to_dos_num); |
| 45 | + |
| 46 | +static struct kunit_case maperror_test_cases[] = { |
| 47 | + KUNIT_CASE(check_search_ntstatus_to_dos_map), |
| 48 | + {} |
| 49 | +}; |
| 50 | + |
| 51 | +static struct kunit_suite maperror_suite = { |
| 52 | + .name = "smb1_maperror", |
| 53 | + .test_cases = maperror_test_cases, |
| 54 | +}; |
| 55 | + |
| 56 | +kunit_test_suite(maperror_suite); |
| 57 | + |
| 58 | +MODULE_LICENSE("GPL"); |
0 commit comments