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 <string.h>
17#include "test.h"
18
19/**
20 * @tc.name      : strchrnul_0100
21 * @tc.desc      : Find the specified character in a string
22 * @tc.level     : Level 0
23 */
24void strchrnul_0100(void)
25{
26    char *str = "Hello world";
27    char *tmp = NULL;
28
29    tmp = strchrnul(str, 'w');
30    if (tmp == NULL) {
31        t_error("%s tmp is NULL", __func__);
32    }
33
34    if (strcmp(tmp, "world")) {
35        t_error("%s tmp is %s, not world", __func__, tmp);
36    }
37}
38
39/**
40 * @tc.name      : strchrnul_0200
41 * @tc.desc      : Find \0 Character in String
42 * @tc.level     : Level 1
43 */
44void strchrnul_0200(void)
45{
46    char *str = "Hello world";
47    char *tmp = NULL;
48
49    tmp = strchrnul(str, '\0');
50    if (tmp == NULL) {
51        t_error("%s tmp is NULL", __func__);
52    }
53
54    if (strcmp(tmp, "")) {
55        t_error("%s tmp is %s, not 0", __func__, tmp);
56    }
57}
58
59/**
60 * @tc.name      : strchrnul_0300
61 * @tc.desc      : Find \0 Character in String
62 * @tc.level     : Level 2
63 */
64void strchrnul_0300(void)
65{
66    char *str = "Hello world";
67    char *tmp = NULL;
68
69    tmp = strchrnul(str, 'a');
70    if (tmp == NULL) {
71        t_error("%s tmp is NULL", __func__);
72    }
73
74    if (strcmp(tmp, "")) {
75        t_error("%s tmp is %s, not NULL", __func__, tmp);
76    }
77}
78
79int main(int argc, char *argv[])
80{
81    strchrnul_0100();
82    strchrnul_0200();
83    strchrnul_0300();
84    return t_status;
85}
86