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 "test.h"
19
20 #define T(no, str, c, substr) \
21 { \
22 char *result = strrchr(str, c); \
23 if (strcmp(result, substr) != 0) \
24 t_error("%s strrchr(%s,%s) returned %s, wanted %s\n", #no, #str, #c, result, substr); \
25 }
26
27 #define N(no, str, c) \
28 { \
29 char *result = strrchr(str, c); \
30 if (result != NULL) \
31 t_error("%s strrchr(%s,%s) returned %s is not NULL\n", #no, #str, #c, result); \
32 }
33
34 #define N1(no, str) \
35 { \
36 char *result = strrchr(str, 0); \
37 if (strcmp(result, "") != 0) \
38 t_error("%s strrchr(%s,NULL) returned %s is not ''\n", #no, #str, result); \
39 }
40
main(int argc,char * argv[])41 int main(int argc, char *argv[])
42 {
43 /**
44 * @tc.name : strrchr_0100
45 * @tc.desc : Get the position of the last occurrence of a character in a string
46 * @tc.level : Level 0
47 */
48 T("strrchr_0100", "happy", 'a', "appy");
49 /**
50 * @tc.name : strrchr_0200
51 * @tc.desc : Get is the last occurrence of a character in a string
52 * @tc.level : Level 1
53 */
54 T("strrchr_0200", "happy", 'p', "py");
55 /**
56 * @tc.name : strrchr_0300
57 * @tc.desc : Test string does not appear parameter
58 * @tc.level : Level 1
59 */
60 N("strrchr_0300", "happy", 'd');
61 /**
62 * @tc.name : strrchr_0400
63 * @tc.desc : Test empty string as parameter
64 * @tc.level : Level 2
65 */
66 N("strrchr_0400", "", 'd');
67 /**
68 * @tc.name : strrchr_0500
69 * @tc.desc : Test null character as parameter
70 * @tc.level : Level 2
71 */
72 N1("strrchr_0500", "happy");
73 return t_status;
74 }