• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 <strings.h>
17 
18 #include "IoTest.h"
19 
20 using namespace testing::ext;
21 
22 /**
23  * @tc.number SUB_KERNEL_IO_STRINGS_0100
24  * @tc.name   ffsl basic function test
25  * @tc.desc   [C- SOFTWARE -0200]
26  */
27 HWTEST_F(IoTest, testFfsl, Function | MediumTest | Level1)
28 {
29     int ret;
30     for (int i = 0; i < 32; i++) {
31         ret = ffsl(1 << i);
32         EXPECT_EQ(ret, i + 1);
33     }
34 
35     ret = ffsl(26);
36     EXPECT_EQ(ret, 2);
37 
38     ret = ffsl(0);
39     EXPECT_EQ(ret, 0);
40 }
41 
42 /**
43  * @tc.number SUB_KERNEL_IO_STRINGS_0200
44  * @tc.name   strncasecmp basic function test
45  * @tc.desc   [C- SOFTWARE -0200]
46  */
47 HWTEST_F(IoTest, testStrncasecmp, Function | MediumTest | Level1)
48 {
49     int ret = strncasecmp("abcdefg", "abcdEFg", 7);
50     EXPECT_EQ(ret, 0);
51 
52     ret = strncasecmp("abcdefg", "abcdEF", 7);
53     EXPECT_GT(ret, 0);
54 
55     ret = strncasecmp("abcdef", "abcdEFg", 7);
56     EXPECT_LT(ret, 0);
57 }
58 
59 /**
60  * @tc.number SUB_KERNEL_IO_STRINGS_0300
61  * @tc.name   strcasecmp basic function test
62  * @tc.desc   [C- SOFTWARE -0200]
63  */
64 HWTEST_F(IoTest, testStrcasecmp, Function | MediumTest | Level1)
65 {
66     int ret = strcasecmp("abcdefg", "abcdEFg");
67     EXPECT_EQ(ret, 0);
68 
69     ret = strcasecmp("abcdefg", "abcdEF");
70     EXPECT_GT(ret, 0);
71 
72     ret = strcasecmp("abcdef", "abcdEFg");
73     EXPECT_LT(ret, 0);
74 }
75 
76 /**
77  * @tc.number SUB_KERNEL_IO_STRINGS_0400
78  * @tc.name   index basic function test
79  * @tc.desc   [C- SOFTWARE -0200]
80  */
81 HWTEST_F(IoTest, testIndex, Function | MediumTest | Level1)
82 {
83     char src[] = "abcdef123456abcdef";
84     char *ret = index(src, '1');
85     EXPECT_STREQ(ret, "123456abcdef");
86 
87     ret = index(src, 'f');
88     EXPECT_STREQ(ret, "f123456abcdef");
89 
90     ret = index(src, ' ');
91     EXPECT_STREQ(ret, nullptr);
92 
93     char srcFir[50] = {0};
94     ret = index(srcFir, '?');
95     EXPECT_STREQ(ret, nullptr);
96 }
97 
98 /**
99  * @tc.number SUB_KERNEL_IO_STRINGS_0500
100  * @tc.name   rindex basic function test
101  * @tc.desc   [C- SOFTWARE -0200]
102  */
103 HWTEST_F(IoTest, testRindex, Function | MediumTest | Level1)
104 {
105     char src[] = "abcdef123456abcdef";
106     char *ret = rindex(src, '1');
107     EXPECT_STREQ(ret, "123456abcdef");
108 
109     ret = rindex(src, 'f');
110     EXPECT_STREQ(ret, "f");
111 
112     ret = rindex(src, ' ');
113     EXPECT_STREQ(ret, nullptr);
114 
115     char srcFir[50] = {0};
116     ret = rindex(srcFir, '?');
117     EXPECT_STREQ(ret, nullptr);
118 }