diff --git a/pw_analog/BUILD b/pw_analog/BUILD index d60252107..37fc74117 100644 --- a/pw_analog/BUILD +++ b/pw_analog/BUILD @@ -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 = [ diff --git a/pw_analog/BUILD.gn b/pw_analog/BUILD.gn index 360fc935a..dd2761acc 100644 --- a/pw_analog/BUILD.gn +++ b/pw_analog/BUILD.gn @@ -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", diff --git a/pw_analog/docs.rst b/pw_analog/docs.rst index 5176465b5..19285e09f 100644 --- a/pw_analog/docs.rst +++ b/pw_analog/docs.rst @@ -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. diff --git a/pw_analog/public/pw_analog/analog_input_gmock.h b/pw_analog/public/pw_analog/analog_input_gmock.h new file mode 100644 index 000000000..f328c93c1 --- /dev/null +++ b/pw_analog/public/pw_analog/analog_input_gmock.h @@ -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, + TryReadUntil, + (pw::chrono::SystemClock::time_point deadline), + (override)); + + MOCK_METHOD(Limits, GetLimits, (), (const, override)); +}; + +} // namespace pw::analog diff --git a/pw_analog/public/pw_analog/microvolt_input_gmock.h b/pw_analog/public/pw_analog/microvolt_input_gmock.h new file mode 100644 index 000000000..a6ce9227e --- /dev/null +++ b/pw_analog/public/pw_analog/microvolt_input_gmock.h @@ -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, + TryReadUntil, + (pw::chrono::SystemClock::time_point deadline), + (override)); + + MOCK_METHOD(Limits, GetLimits, (), (const, override)); + + MOCK_METHOD(References, GetReferences, (), (const, override)); +}; + +} // namespace pw::analog