提交 8794d07c 编写于 作者: L limeng151

修改groups相关用例

Signed-off-by: Nlimeng151 <limeng151@huawei.com>
Change-Id: I69a10b1580c1a183ac05ce83037224da06f277e5
上级 cc7e85c6
......@@ -24,7 +24,8 @@
// max test number of uid/gid, not actual max number
const int MAX_UGID = 100000;
static int groupNum = -1;
static gid_t groupsArry[10] = {0};
const int ARRAY_SIZE = 10;
static gid_t groupsArray[ARRAY_SIZE] = {0};
// Assert all uid == expectUid
#define AssertAllUid(expectUid) do { \
......@@ -56,21 +57,29 @@ public:
return id;
}
protected:
static void SetUpTestCase() {
for (int i = 0; i < 10; i++) {
groupsArry[i] = -1;
static void SetUpTestCase()
{
for (int i = 0; i < ARRAY_SIZE; i++) {
groupsArray[i] = -1;
}
groupNum = getgroups(0, groupsArry);
groupNum = getgroups(0, groupsArray);
EXPECT_NE(groupNum, -1);
int rt = getgroups(groupNum, groupsArray);
EXPECT_EQ(rt, groupNum);
}
void TearDown()
{
LOG("TearDown: reset uid and gid");
gid_t groupIds[groupNum];
LOG("TearDown: reset uid and gid %d", sizeof(groupIds) / sizeof(gid_t));
for (int i = 0; i < groupNum; i++) {
groupIds[i] = groupsArray[i];
}
setuid(SHELL_UID);
setgid(SHELL_GID);
AssertAllUid(SHELL_UID);
AssertAllGid(SHELL_GID);
int rt = setgroups(groupNum, groupsArry);
int rt = setgroups(groupNum, groupIds);
EXPECT_EQ(rt, 0);
}
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册