UserIDResolverTest.cpp
1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//===-- 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));
}