1 //===-- UserIDResolverTest.cpp --------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "lldb/Utility/UserIDResolver.h"
10 #include "gmock/gmock.h"
11
12 using namespace lldb_private;
13 using namespace testing;
14
15 namespace {
16 class TestUserIDResolver : public UserIDResolver {
17 public:
18 MOCK_METHOD1(DoGetUserName, llvm::Optional<std::string>(id_t uid));
19 MOCK_METHOD1(DoGetGroupName, llvm::Optional<std::string>(id_t gid));
20 };
21 } // namespace
22
TEST(UserIDResolver,GetUserName)23 TEST(UserIDResolver, GetUserName) {
24 StrictMock<TestUserIDResolver> r;
25 llvm::StringRef user47("foo");
26 EXPECT_CALL(r, DoGetUserName(47)).Times(1).WillOnce(Return(user47.str()));
27 EXPECT_CALL(r, DoGetUserName(42)).Times(1).WillOnce(Return(llvm::None));
28
29 // Call functions twice to make sure the caching works.
30 EXPECT_EQ(user47, r.GetUserName(47));
31 EXPECT_EQ(user47, r.GetUserName(47));
32 EXPECT_EQ(llvm::None, r.GetUserName(42));
33 EXPECT_EQ(llvm::None, r.GetUserName(42));
34 }
35
TEST(UserIDResolver,GetGroupName)36 TEST(UserIDResolver, GetGroupName) {
37 StrictMock<TestUserIDResolver> r;
38 llvm::StringRef group47("foo");
39 EXPECT_CALL(r, DoGetGroupName(47)).Times(1).WillOnce(Return(group47.str()));
40 EXPECT_CALL(r, DoGetGroupName(42)).Times(1).WillOnce(Return(llvm::None));
41
42 // Call functions twice to make sure the caching works.
43 EXPECT_EQ(group47, r.GetGroupName(47));
44 EXPECT_EQ(group47, r.GetGroupName(47));
45 EXPECT_EQ(llvm::None, r.GetGroupName(42));
46 EXPECT_EQ(llvm::None, r.GetGroupName(42));
47 }
48