• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /**
21  * @tc.name      : strsep_0100
22  * @tc.desc      : Test calling strsep function to intercept string
23  * @tc.level     : Level 0
24  */
strsep_0100(void)25 void strsep_0100(void)
26 {
27     char str[12] = {0};
28     strcpy(str, "helloworld");
29     char *p = (char *)str;
30     char *sep = "w";
31     char *result = strsep(&p, sep);
32     if (strcmp(result, "hello") != 0) {
33         t_error("%s strsep get result is '%s' are not 'hello'\n", __func__, result);
34     }
35     if (strcmp(str, "hello") != 0) {
36         t_error("%s strsep get str is '%s' are not 'hello'\n", __func__, str);
37     }
38 }
39 
40 /**
41  * @tc.name      : strsep_0200
42  * @tc.desc      : Test strsep result when marker character appears multiple times in truncated string
43  * @tc.level     : Level 1
44  */
strsep_0200(void)45 void strsep_0200(void)
46 {
47     char str[12] = {0};
48     strcpy(str, "helloworld");
49     char *p = (char *)str;
50     char *sep = "l";
51     char *result = strsep(&p, sep);
52     if (strcmp(result, "he") != 0) {
53         t_error("%s strsep get result is '%s' are not 'he'\n", __func__, result);
54     }
55     if (strcmp(str, "he") != 0) {
56         t_error("%s strsep get result is '%s' are not 'he'\n", __func__, str);
57     }
58 }
59 
60 /**
61  * @tc.name      : strsep_0300
62  * @tc.desc      : test strsep result when marker character does not appear in truncated string
63  * @tc.level     : Level 1
64  */
strsep_0300(void)65 void strsep_0300(void)
66 {
67     char str[12] = {0};
68     strcpy(str, "helloworld");
69     char *p = (char *)str;
70     char *sep = "a";
71     char *result = strsep(&p, sep);
72     if (strcmp(result, "helloworld") != 0) {
73         t_error("%s strsep get result is '%s' are not 'helloworld'\n", __func__, result);
74     }
75     if (strcmp(str, "helloworld") != 0) {
76         t_error("%s strsep get result is '%s' are not 'helloworld'\n", __func__, str);
77     }
78 }
79 
main(int argc,char * argv[])80 int main(int argc, char *argv[])
81 {
82     strsep_0100();
83     strsep_0200();
84     strsep_0300();
85     return t_status;
86 }