-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_fakes.cc
91 lines (73 loc) · 2.32 KB
/
test_fakes.cc
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2019 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mems_setup/test_fakes.h"
#include <base/logging.h>
namespace mems_setup {
namespace fakes {
namespace {
constexpr char kAcpiAlsTriggerName[] = "iioservice-acpi-als";
} // namespace
base::Optional<std::string> FakeDelegate::ReadVpdValue(
const std::string& name) {
auto k = vpd_.find(name);
if (k == vpd_.end())
return base::nullopt;
return k->second;
}
bool FakeDelegate::ProbeKernelModule(const std::string& module) {
probed_modules_.push_back(module);
return true;
}
bool FakeDelegate::CreateDirectory(const base::FilePath& fp) {
existing_files_.emplace(fp);
base::FilePath hrtimer_path("/sys/kernel/config/iio/triggers/hrtimer");
hrtimer_path = hrtimer_path.Append(kAcpiAlsTriggerName);
if (mock_context_ && fp == hrtimer_path) {
mock_context_->AddTrigger(std::make_unique<libmems::fakes::FakeIioDevice>(
mock_context_, kAcpiAlsTriggerName, 1));
}
return true;
}
bool FakeDelegate::Exists(const base::FilePath& fp) {
return existing_files_.count(fp) > 0;
}
void FakeDelegate::CreateFile(const base::FilePath& fp) {
existing_files_.emplace(fp);
}
base::Optional<gid_t> FakeDelegate::FindGroupId(const char* group) {
auto k = groups_.find(group);
if (k == groups_.end())
return base::nullopt;
return k->second;
}
int FakeDelegate::GetPermissions(const base::FilePath& path) {
auto k = permissions_.find(path.value());
if (k == permissions_.end())
return 0;
return k->second;
}
bool FakeDelegate::SetPermissions(const base::FilePath& path, int mode) {
permissions_[path.value()] = mode;
return true;
}
bool FakeDelegate::GetOwnership(const base::FilePath& path,
uid_t* user,
gid_t* group) {
auto k = ownerships_.find(path.value());
if (k == ownerships_.end())
return false;
if (user)
*user = k->second.first;
if (group)
*group = k->second.second;
return true;
}
bool FakeDelegate::SetOwnership(const base::FilePath& path,
uid_t user,
gid_t group) {
ownerships_[path.value()] = {user, group};
return true;
}
} // namespace fakes
} // namespace mems_setup