• 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 #include "test.h"
16 #include "strops.h"
17 #include "functionalext.h"
18 
19 typedef void (*TEST_FUN)(void);
20 
21 /**
22  * @tc.name      : strops_test_0010
23  * @tc.desc      : strlwc test args null
24  * @tc.level     : Level 2
25  */
strops_test_0010(void)26 void strops_test_0010(void)
27 {
28     char *str = NULL;
29     strlwc(str);
30     EXPECT_EQ(__FUNCTION__, str, NULL);
31 }
32 
33 /**
34  * @tc.name      : strops_test_0020
35  * @tc.desc      : Test strlwc with normal input
36  * @tc.level     : Level 0
37  */
strops_test_0020(void)38 void strops_test_0020(void)
39 {
40     char tmp[4] = "Abc";
41     tmp[3] = '\0';
42     strlwc(tmp);
43 
44     EXPECT_EQ(__FUNCTION__, strcmp(tmp, "abc"), 0);
45 }
46 
47 /**
48  * @tc.name      : strops_test_0030
49  * @tc.desc      : strlist_set test arg is NULL
50  * @tc.level     : Level 2
51  */
strops_test_0030(void)52 void strops_test_0030(void)
53 {
54     char *str = NULL;
55     strlist_set(NULL, NULL);
56 
57     EXPECT_EQ(__FUNCTION__, str, NULL);
58 }
59 
60 /**
61  * @tc.name      : strops_test_0040
62  * @tc.desc      : Test strlist_set with normal input
63  * @tc.level     : Level 0
64  */
strops_test_0040(void)65 void strops_test_0040(void)
66 {
67     strlist list;
68     list.size = 1;
69     list.num = 1;
70     strlist_set(&list, "abc");
71 
72     EXPECT_EQ(__FUNCTION__, list.size, 2);
73 }
74 
75 /**
76  * @tc.name      : strops_test_0050
77  * @tc.desc      : strtrim test arg is NULL
78  * @tc.level     : Level 2
79  */
strops_test_0050(void)80 void strops_test_0050(void)
81 {
82     size_t ret = strtrim(NULL);
83     EXPECT_EQ(__FUNCTION__, ret, 0);
84 }
85 
86 TEST_FUN G_Fun_Array[] = {
87     strops_test_0010,
88     strops_test_0020,
89     strops_test_0030,
90     strops_test_0040,
91     strops_test_0050
92 };
93 
main(void)94 int main(void)
95 {
96     int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
97     for (int pos = 0; pos < num; ++pos) {
98         G_Fun_Array[pos]();
99     }
100 
101     return t_status;
102 }