mirror of
https://fuchsia.googlesource.com/third_party/pigweed.googlesource.com/pigweed/pigweed
synced 2024-09-20 22:00:58 +00:00
pw_analog: Add gmocks for interfaces
Change-Id: I43c5a555ff6ee8983ab4f78bf9b3dfb00f06df37 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/48321 Commit-Queue: Kevin Zeng <zengk@google.com> Reviewed-by: Wyatt Hepler <hepler@google.com>
This commit is contained in:
parent
0f1f464bf9
commit
fb88887d6a
|
@ -48,6 +48,30 @@ pw_cc_library(
|
|||
],
|
||||
)
|
||||
|
||||
pw_cc_library(
|
||||
name = "microvolt_input_gmock",
|
||||
hdrs = [
|
||||
"public/pw_analog/microvolt_input_gmock.h",
|
||||
],
|
||||
includes = ["public"],
|
||||
deps = [
|
||||
":microvolt_input",
|
||||
"$dir_pw_third_party/googletest",
|
||||
],
|
||||
)
|
||||
|
||||
pw_cc_library(
|
||||
name = "analog_input_gmock",
|
||||
hdrs = [
|
||||
"public/pw_analog/analog_input_gmock.h",
|
||||
],
|
||||
includes = ["public"],
|
||||
deps = [
|
||||
":analog_input",
|
||||
"$dir_pw_third_party/googletest",
|
||||
],
|
||||
)
|
||||
|
||||
pw_cc_test(
|
||||
name = "analog_input_test",
|
||||
srcs = [
|
||||
|
|
|
@ -23,7 +23,14 @@ config("public_include_path") {
|
|||
include_dirs = [ "public" ]
|
||||
}
|
||||
|
||||
pw_source_set("pw_analog") {
|
||||
group("pw_analog") {
|
||||
public_deps = [
|
||||
":analog_input",
|
||||
":microvolt_input",
|
||||
]
|
||||
}
|
||||
|
||||
pw_source_set("analog_input") {
|
||||
public_configs = [ ":public_include_path" ]
|
||||
public_deps = [
|
||||
"$dir_pw_chrono:system_clock",
|
||||
|
@ -35,7 +42,7 @@ pw_source_set("pw_analog") {
|
|||
pw_source_set("microvolt_input") {
|
||||
public_configs = [ ":public_include_path" ]
|
||||
public_deps = [
|
||||
":pw_analog",
|
||||
":analog_input",
|
||||
"$dir_pw_chrono:system_clock",
|
||||
"$dir_pw_result",
|
||||
"$dir_pw_status",
|
||||
|
@ -43,6 +50,24 @@ pw_source_set("microvolt_input") {
|
|||
public = [ "public/pw_analog/microvolt_input.h" ]
|
||||
}
|
||||
|
||||
pw_source_set("analog_input_gmock") {
|
||||
public_configs = [ ":public_include_path" ]
|
||||
public_deps = [
|
||||
":analog_input",
|
||||
"$dir_pw_third_party/googletest",
|
||||
]
|
||||
public = [ "public/pw_analog/analog_input_gmock.h" ]
|
||||
}
|
||||
|
||||
pw_source_set("microvolt_input_gmock") {
|
||||
public_configs = [ ":public_include_path" ]
|
||||
public_deps = [
|
||||
":microvolt_input",
|
||||
"$dir_pw_third_party/googletest",
|
||||
]
|
||||
public = [ "public/pw_analog/microvolt_input_gmock.h" ]
|
||||
}
|
||||
|
||||
pw_test_group("tests") {
|
||||
tests = [
|
||||
":analog_input_test",
|
||||
|
|
|
@ -28,3 +28,11 @@ own ADC driver implementation in order to configure and enable the ADC
|
|||
peripheral in order to provide the reference voltages and to configure and
|
||||
enable the ADC peripheral where needed. Users are responsible for managing
|
||||
multithreaded access to the ADC driver if the ADC services multiple channels.
|
||||
|
||||
pw::analog::GmockAnalogInput
|
||||
-------------------------------
|
||||
gMock of AnalogInput used for testing and mocking out the AnalogInput.
|
||||
|
||||
pw::analog::GmockMicrovoltInput
|
||||
-------------------------------
|
||||
gMock of MicrovoltInput used for testing and mocking out the MicrovoltInput.
|
||||
|
|
31
pw_analog/public/pw_analog/analog_input_gmock.h
Normal file
31
pw_analog/public/pw_analog/analog_input_gmock.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Copyright 2021 The Pigweed Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
// use this file except in compliance with the License. You may obtain a copy of
|
||||
// the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
// License for the specific language governing permissions and limitations under
|
||||
// the License.
|
||||
#pragma once
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "pw_analog/analog_input.h"
|
||||
|
||||
namespace pw::analog {
|
||||
|
||||
class GmockAnalogInput : public AnalogInput {
|
||||
public:
|
||||
MOCK_METHOD(pw::Result<int32_t>,
|
||||
TryReadUntil,
|
||||
(pw::chrono::SystemClock::time_point deadline),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(Limits, GetLimits, (), (const, override));
|
||||
};
|
||||
|
||||
} // namespace pw::analog
|
33
pw_analog/public/pw_analog/microvolt_input_gmock.h
Normal file
33
pw_analog/public/pw_analog/microvolt_input_gmock.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Copyright 2021 The Pigweed Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
// use this file except in compliance with the License. You may obtain a copy of
|
||||
// the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
// License for the specific language governing permissions and limitations under
|
||||
// the License.
|
||||
#pragma once
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "pw_analog/microvolt_input.h"
|
||||
|
||||
namespace pw::analog {
|
||||
|
||||
class GmockMicrovoltInput : public MicrovoltInput {
|
||||
public:
|
||||
MOCK_METHOD(pw::Result<int32_t>,
|
||||
TryReadUntil,
|
||||
(pw::chrono::SystemClock::time_point deadline),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(Limits, GetLimits, (), (const, override));
|
||||
|
||||
MOCK_METHOD(References, GetReferences, (), (const, override));
|
||||
};
|
||||
|
||||
} // namespace pw::analog
|
Loading…
Reference in New Issue
Block a user