blob: 79090de86b26abc5408ce1dd7ce6144b82879d81 [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
7using mems_setup::mocks::MockDelegate;
8using mems_setup::mocks::MockIioChannel;
9using mems_setup::mocks::MockIioContext;
10using mems_setup::mocks::MockIioDevice;
11
12namespace mems_setup {
13namespace testing {
14
15bool MockSysfsTrigger::WriteNumberAttribute(const std::string& name,
16 int64_t value) {
17 bool ok = this->MockIioDevice::WriteNumberAttribute(name, value);
18 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)
27 : mock_context_(new MockIioContext),
28 mock_delegate_(new MockDelegate),
29 mock_device_(
30 std::make_unique<MockIioDevice>(mock_context_.get(), name, id)),
31 mock_trigger0_(std::make_unique<MockIioDevice>(
32 mock_context_.get(), "trigger0", "trigger0")),
33 mock_sysfs_trigger_(std::make_unique<MockSysfsTrigger>(
34 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