blob: dbb2e2eedc583439ec825680b481e94d68b8fda0 [file] [log] [blame]
Enrico Granata60b1cbc2019-05-20 11:06:46 -07001// Copyright 2019 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "mems_setup/test_helper.h"
6
Enrico Granata9bb17522019-06-28 17:22:42 -07007using libmems::fakes::FakeIioChannel;
8using libmems::fakes::FakeIioContext;
9using libmems::fakes::FakeIioDevice;
10using mems_setup::fakes::FakeDelegate;
Enrico Granata60b1cbc2019-05-20 11:06:46 -070011
12namespace mems_setup {
13namespace testing {
14
Enrico Granata9bb17522019-06-28 17:22:42 -070015bool FakeSysfsTrigger::WriteNumberAttribute(const std::string& name,
Enrico Granata60b1cbc2019-05-20 11:06:46 -070016 int64_t value) {
Enrico Granata9bb17522019-06-28 17:22:42 -070017 bool ok = this->FakeIioDevice::WriteNumberAttribute(name, value);
Enrico Granata60b1cbc2019-05-20 11:06:46 -070018 if (ok && name == "add_trigger" && value == 0) {
19 mock_context_->AddDevice(mock_trigger0_);
20 }
21 return ok;
22}
23
24SensorTestBase::SensorTestBase(const char* name,
25 const char* id,
26 SensorKind kind)
Enrico Granata9bb17522019-06-28 17:22:42 -070027 : mock_context_(new FakeIioContext),
28 mock_delegate_(new FakeDelegate),
Enrico Granata60b1cbc2019-05-20 11:06:46 -070029 mock_device_(
Enrico Granata9bb17522019-06-28 17:22:42 -070030 std::make_unique<FakeIioDevice>(mock_context_.get(), name, id)),
31 mock_trigger0_(std::make_unique<FakeIioDevice>(
Enrico Granata60b1cbc2019-05-20 11:06:46 -070032 mock_context_.get(), "trigger0", "trigger0")),
Enrico Granata9bb17522019-06-28 17:22:42 -070033 mock_sysfs_trigger_(std::make_unique<FakeSysfsTrigger>(
Enrico Granata60b1cbc2019-05-20 11:06:46 -070034 mock_context_.get(), mock_trigger0_.get())),
35 sensor_kind_(kind) {
36 mock_context_->AddDevice(mock_device_.get());
37 mock_context_->AddDevice(mock_sysfs_trigger_.get());
38}
39
40void SensorTestBase::SetSingleSensor(const char* location) {
41 mock_device_->WriteStringAttribute("location", location);
42}
43
44void SensorTestBase::ConfigureVpd(
45 std::initializer_list<std::pair<const char*, const char*>> values) {
46 for (const auto& value : values) {
47 mock_delegate_->SetVpdValue(value.first, value.second);
48 }
49}
50
51Configuration* SensorTestBase::GetConfiguration() {
52 if (config_ == nullptr) {
53 config_.reset(new Configuration(mock_device_.get(), sensor_kind_,
54 mock_delegate_.get()));
55 }
56
57 return config_.get();
58}
59
60} // namespace testing
61} // namespace mems_setup