1 //===-- UserIDResolverTest.cpp --------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Utility/UserIDResolver.h"
10 #include "gmock/gmock.h"
13 using namespace lldb_private
;
14 using namespace testing
;
17 class TestUserIDResolver
: public UserIDResolver
{
19 MOCK_METHOD1(DoGetUserName
, std::optional
<std::string
>(id_t uid
));
20 MOCK_METHOD1(DoGetGroupName
, std::optional
<std::string
>(id_t gid
));
24 TEST(UserIDResolver
, GetUserName
) {
25 StrictMock
<TestUserIDResolver
> r
;
26 llvm::StringRef
user47("foo");
27 EXPECT_CALL(r
, DoGetUserName(47)).Times(1).WillOnce(Return(user47
.str()));
28 EXPECT_CALL(r
, DoGetUserName(42)).Times(1).WillOnce(Return(std::nullopt
));
30 // Call functions twice to make sure the caching works.
31 EXPECT_EQ(user47
, r
.GetUserName(47));
32 EXPECT_EQ(user47
, r
.GetUserName(47));
33 EXPECT_EQ(std::nullopt
, r
.GetUserName(42));
34 EXPECT_EQ(std::nullopt
, r
.GetUserName(42));
37 TEST(UserIDResolver
, GetGroupName
) {
38 StrictMock
<TestUserIDResolver
> r
;
39 llvm::StringRef
group47("foo");
40 EXPECT_CALL(r
, DoGetGroupName(47)).Times(1).WillOnce(Return(group47
.str()));
41 EXPECT_CALL(r
, DoGetGroupName(42)).Times(1).WillOnce(Return(std::nullopt
));
43 // Call functions twice to make sure the caching works.
44 EXPECT_EQ(group47
, r
.GetGroupName(47));
45 EXPECT_EQ(group47
, r
.GetGroupName(47));
46 EXPECT_EQ(std::nullopt
, r
.GetGroupName(42));
47 EXPECT_EQ(std::nullopt
, r
.GetGroupName(42));