• 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 <fcntl.h>
17 #include <sys/xattr.h>
18 #include "functionalext.h"
19 
20 const char *path = "file.txt";
21 const char *name = "user.txt";
22 const char *value = "dat";
23 const int size = 3;
24 
25 /**
26  * @tc.name      : lremovexattr_0100
27  * @tc.desc      : Verify lremovexattr process success.
28  * @tc.level     : Level 0
29  */
lremovexattr_0100(void)30 void lremovexattr_0100(void)
31 {
32     int fd = open(path, O_RDWR | O_CREAT, TEST_MODE);
33     if (fd < 0) {
34         t_error("%s failed: fd = %d\n", __func__, fd);
35         return;
36     }
37 
38     char str[] = "dat";
39     write(fd, str, sizeof(str));
40     close(fd);
41 
42     int ret = lsetxattr(path, name, value, strlen(value), XATTR_CREATE);
43     if (ret != 0) {
44         t_error("%s failed: ret = %d\n", __func__, ret);
45         return;
46     }
47 
48     char buf[BUFSIZ] = {0};
49 
50     ret = lgetxattr(path, name, buf, sizeof(buf));
51     EXPECT_EQ("lgetxattr_0100", ret, size);
52     EXPECT_STREQ("lgetxattr_0100", buf, str);
53 
54     ret = lremovexattr(path, name);
55     EXPECT_EQ("lremovexattr_0100", ret, 0);
56 
57     ret = lgetxattr(path, name, buf, sizeof(buf));
58     EXPECT_EQ("lgetxattr_0100", ret, -1);
59 
60     ret = remove(path);
61     EXPECT_EQ("lgetxattr_0100", ret, 0);
62 }
63 
64 /**
65  * @tc.name      : lremovexattr_0200
66  * @tc.desc      : Verify lremovexattr process fail bacause param is null.
67  * @tc.level     : Level 0
68  */
lremovexattr_0200(void)69 void lremovexattr_0200(void)
70 {
71     int ret = lremovexattr(NULL, NULL);
72     EXPECT_EQ("lremovexattr_0200", ret, -1);
73 }
74 
main(void)75 int main(void)
76 {
77     lremovexattr_0100();
78     lremovexattr_0200();
79     return t_status;
80 }
81