1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include <stdio.h>
17#include <string.h>
18#include <wchar.h>
19#include "test.h"
20
21/**
22 * @tc.name      : wcsncat_0100
23 * @tc.desc      : Test the wcsncat method to pass the source wide string into the target wide string according to the
24 *                 number passed in
25 * @tc.level     : Level 0
26 */
27void wcsncat_0100(void)
28{
29    wchar_t dst[32] = {0};
30    wchar_t *result = wcsncat(dst, L"hello, world!", 5);
31    if (wcscmp(dst, result) != 0) {
32        t_error("%s wcsncat get result is %s are not %s\n", __func__, dst, result);
33    }
34    if (wcscmp(dst, L"hello") != 0) {
35        t_error("%s wcsncat get result is %s are not 'hello'\n", __func__, dst);
36    }
37}
38
39/**
40 * @tc.name      : wcsncat_0200
41 * @tc.desc      : Test the result of the function wcsncat when the number of incoming copies is 0
42 * @tc.level     : Level 1
43 */
44void wcsncat_0200(void)
45{
46    wchar_t dst[32] = {0};
47    wchar_t *result = wcsncat(dst, L"hello, world!", 0);
48    if (wcscmp(dst, result) != 0) {
49        t_error("%s wcsncat get result is %s are not %s\n", __func__, dst, result);
50    }
51    if (wcscmp(dst, L"") != 0) {
52        t_error("%s wcsncat get result is %s are not 'hello'\n", __func__, dst);
53    }
54}
55
56/**
57 * @tc.name      : wcsncat_0300
58 * @tc.desc      : Test the result of the wcsncat function when the number of incoming copies is greater than the
59 *                 source string
60 * @tc.level     : Level 1
61 */
62void wcsncat_0300(void)
63{
64    wchar_t dst[32] = {0};
65    wchar_t *result = wcsncat(dst, L"hello, world!", 16);
66    if (wcscmp(dst, result) != 0) {
67        t_error("%s wcsncat get result is %s are not %s\n", __func__, dst, result);
68    }
69    if (wcscmp(dst, L"hello, world!") != 0) {
70        t_error("%s wcsncat get result is %s are not 'hello, world!'\n", __func__, dst);
71    }
72}
73
74int main(int argc, char *argv[])
75{
76    wcsncat_0100();
77    wcsncat_0200();
78    wcsncat_0300();
79    return t_status;
80}