1 // Copyright 2021 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #include "pw_analog/analog_input.h"
15
16 #include "pw_unit_test/framework.h"
17
18 namespace pw {
19 namespace analog {
20 namespace {
21
22 constexpr int32_t kLimitsMax = 4096;
23 constexpr int32_t kLimitsMin = 0;
24
25 // Fake test analog input that's used for testing.
26 class TestAnalogInput : public AnalogInput {
27 public:
TestAnalogInput()28 TestAnalogInput()
29 : limits_({
30 .min = kLimitsMin,
31 .max = kLimitsMax,
32 }) {}
33
TryReadUntil(chrono::SystemClock::time_point)34 Result<int32_t> TryReadUntil(chrono::SystemClock::time_point) override {
35 return Status::Unimplemented();
36 }
37
GetLimits() const38 Limits GetLimits() const override { return limits_; }
39
40 private:
41 const Limits limits_;
42 };
43
TEST(AnalogInputTest,Construction)44 TEST(AnalogInputTest, Construction) {
45 TestAnalogInput analog_input = TestAnalogInput();
46 }
47
TEST(AnalogInputTest,GetLimits)48 TEST(AnalogInputTest, GetLimits) {
49 TestAnalogInput analog_input = TestAnalogInput();
50 AnalogInput::Limits limits = analog_input.GetLimits();
51 EXPECT_EQ(limits.min, kLimitsMin);
52 EXPECT_EQ(limits.max, kLimitsMax);
53 }
54
55 } // namespace
56 } // namespace analog
57 } // namespace pw
58