Summary: This creates an abstract base class called "UserIDResolver", which can be implemented to provide user/group ID resolution capabilities for various objects. Posix host implement a PosixUserIDResolver, which does that using posix apis (getpwuid and friends). PlatformGDBRemote forwards queries over the gdb-remote link, etc. ProcessInstanceInfo class is refactored to make use of this interface instead of taking a platform pointer as an argument. The base resolver class already implements caching and thread-safety, so implementations don't have to worry about that. The main motivating factor for this was to remove external dependencies from the ProcessInstanceInfo class (so it can be put next to ProcessLaunchInfo and friends), but it has other benefits too: - ability to test the user name caching code - ability to test ProcessInstanceInfo dumping code - consistent interface for user/group resolution between Platform and Host classes. Reviewers: zturner, clayborg, jingham Subscribers: mgorny, lldb-commits Differential Revision: https://reviews.llvm.org/D58167 llvm-svn: 355323
48 lines
1.7 KiB
C++
48 lines
1.7 KiB
C++
//===-- UserIDResolverTest.cpp ----------------------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "lldb/Utility/UserIDResolver.h"
|
|
#include "gmock/gmock.h"
|
|
|
|
using namespace lldb_private;
|
|
using namespace testing;
|
|
|
|
namespace {
|
|
class TestUserIDResolver : public UserIDResolver {
|
|
public:
|
|
MOCK_METHOD1(DoGetUserName, llvm::Optional<std::string>(id_t uid));
|
|
MOCK_METHOD1(DoGetGroupName, llvm::Optional<std::string>(id_t gid));
|
|
};
|
|
} // namespace
|
|
|
|
TEST(UserIDResolver, GetUserName) {
|
|
StrictMock<TestUserIDResolver> r;
|
|
llvm::StringRef user47("foo");
|
|
EXPECT_CALL(r, DoGetUserName(47)).Times(1).WillOnce(Return(user47.str()));
|
|
EXPECT_CALL(r, DoGetUserName(42)).Times(1).WillOnce(Return(llvm::None));
|
|
|
|
// Call functions twice to make sure the caching works.
|
|
EXPECT_EQ(user47, r.GetUserName(47));
|
|
EXPECT_EQ(user47, r.GetUserName(47));
|
|
EXPECT_EQ(llvm::None, r.GetUserName(42));
|
|
EXPECT_EQ(llvm::None, r.GetUserName(42));
|
|
}
|
|
|
|
TEST(UserIDResolver, GetGroupName) {
|
|
StrictMock<TestUserIDResolver> r;
|
|
llvm::StringRef group47("foo");
|
|
EXPECT_CALL(r, DoGetGroupName(47)).Times(1).WillOnce(Return(group47.str()));
|
|
EXPECT_CALL(r, DoGetGroupName(42)).Times(1).WillOnce(Return(llvm::None));
|
|
|
|
// Call functions twice to make sure the caching works.
|
|
EXPECT_EQ(group47, r.GetGroupName(47));
|
|
EXPECT_EQ(group47, r.GetGroupName(47));
|
|
EXPECT_EQ(llvm::None, r.GetGroupName(42));
|
|
EXPECT_EQ(llvm::None, r.GetGroupName(42));
|
|
}
|