• 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      : strtok_r_0100
22  * @tc.desc      : Test strtok_r function to intercept string according to input characters
23  * @tc.level     : Level 0
24  */
strtok_r_0100(void)25 void strtok_r_0100(void)
26 {
27     char *compare[3] = {"ABC", "DEF", "GHI"};
28     char buf[] = "ABC,DEF,GHI";
29     char *result[3];
30     char *p = buf;
31     char *outer_ptr = NULL;
32     for (int i = 0; i < 3; i++) {
33         result[i] = strtok_r(outer_ptr, ",", &p);
34     }
35     for (int a = 0; a < 3; a++) {
36         if (strcmp(result[a], compare[a]) != 0) {
37             t_error("%s strtok_r in %d get value is %s are not %s\n", __func__, a, result[a], compare[a]);
38         }
39     }
40 }
41 
42 /**
43  * @tc.name      : strtok_r_0200
44  * @tc.desc      : Test the return value of the strtok_r function when the intercepted string is an empty string
45  * @tc.level     : Level 1
46  */
strtok_r_0200(void)47 void strtok_r_0200(void)
48 {
49     char *p;
50     char *outer_ptr = NULL;
51     char *result = strtok_r(outer_ptr, ",", &p);
52     if (result) {
53         t_error("%s strtok_r error get result is %s not null\n", __func__, result);
54     }
55 }
56 
main(int argc,char * argv[])57 int main(int argc, char *argv[])
58 {
59     strtok_r_0100();
60     strtok_r_0200();
61     return t_status;
62 }