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 <wordexp.h>
17 #include "functionalext.h"
18
19 /**
20 * @tc.name : wordfree_0100
21 * @tc.desc : Verify that after wordexp operation, wordfree releases the resources properly.
22 * @tc.level : level 0
23 */
wordfree_0100null24 void wordfree_0100()
25 {
26 wordexp_t we;
27 int ret = wordexp("ls -l", &we, 0);
28 EXPECT_EQ("wordfree_0100", ret, 0);
29 EXPECT_EQ("wordfree_0100", we.we_wordc > 0, 1);
30 EXPECT_EQ("wordfree_0100", we.we_wordv != NULL, 1);
31 wordfree(&we);
32 EXPECT_EQ("wordfree_0100", we.we_wordv, (char **)0);
33 EXPECT_EQ("wordfree_0100", we.we_wordc, 0);
34 }
35
36 /**
37 * @tc.name : wordfree_0200
38 * @tc.desc : Verify that wordfree can handle and release an uninitialized wordexp_t structure.
39 * @tc.level : level 0
40 */
wordfree_0200null41 void wordfree_0200()
42 {
43 wordexp_t we = {0};
44 wordfree(&we);
45 EXPECT_EQ("wordfree_0200", we.we_wordv, (char **)0);
46 EXPECT_EQ("wordfree_0200", we.we_wordc, 0);
47 }
48
mainnull49 int main()
50 {
51 wordfree_0100();
52 wordfree_0200();
53 return t_status;
54 }
55