• 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      : strcasestr_0100
22  * @tc.desc      : Test strcasestr method to intercept string
23  * @tc.level     : Level 0
24  */
strcasestr_0100(void)25 void strcasestr_0100(void)
26 {
27     char *haystate = "bIg dAdDy/gIaNt hAyStAcKs";
28     char *result = strcasestr(haystate, "");
29     if (strcmp(result, "bIg dAdDy/gIaNt hAyStAcKs") != 0) {
30         t_error("%s strcasestr error get result is %s\n", __func__, result);
31     }
32 }
33 
34 /**
35  * @tc.name      : strcasestr_0200
36  * @tc.desc      : Test strcasestr method incoming uppercase letter interception
37  * @tc.level     : Level 1
38  */
strcasestr_0200(void)39 void strcasestr_0200(void)
40 {
41     char *haystate = "bIg dAdDy/gIaNt hAyStAcKs";
42     char *result = strcasestr(haystate, "B");
43     if (strcmp(result, "bIg dAdDy/gIaNt hAyStAcKs") != 0) {
44         t_error("%s strcasestr error get result is %s\n", __func__, result);
45     }
46 }
47 
48 /**
49  * @tc.name      : strcasestr_0300
50  * @tc.desc      : Test strcasestr method incoming lowercase letter interception
51  * @tc.level     : Level 1
52  */
strcasestr_0300(void)53 void strcasestr_0300(void)
54 {
55     char *haystate = "bIg dAdDy/gIaNt hAyStAcKs";
56     char *result = strcasestr(haystate, "i");
57     if (strcmp(result, "Ig dAdDy/gIaNt hAyStAcKs") != 0) {
58         t_error("%s strcasestr error get result is %s\n", __func__, result);
59     }
60 }
61 
62 /**
63  * @tc.name      : strcasestr_0400
64  * @tc.desc      : Test strcasestr method incoming string interception
65  * @tc.level     : Level 1
66  */
strcasestr_0400(void)67 void strcasestr_0400(void)
68 {
69     char *haystate = "bIg dAdDy/gIaNt hAyStAcKs";
70     char *result = strcasestr(haystate, "Da");
71     if (strcmp(result, "dAdDy/gIaNt hAyStAcKs") != 0) {
72         t_error("%s strcasestr error get result is %s\n", __func__, result);
73     }
74 }
75 
main(int argc,char * argv[])76 int main(int argc, char *argv[])
77 {
78     strcasestr_0100();
79     strcasestr_0200();
80     strcasestr_0300();
81     strcasestr_0400();
82     return t_status;
83 }