third_party.pigweed.src/pw_analog/analog_input_test.cc
Carlos Chinchilla 7db269ec0a pw_{allocator,analog}: Use unit test framework
Include pw_unit_test/framework.h instead of gtest/gtest.h as the facade
for unit tests.

Change-Id: I5fae0b2c125f163480c589441dd1e1846cad7964
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/183270
Pigweed-Auto-Submit: Carlos Chinchilla <cachinchilla@google.com>
Reviewed-by: Taylor Cramer <cramertj@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
2023-12-06 19:48:35 +00:00

58 lines
1.6 KiB
C++

// 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.
#include "pw_analog/analog_input.h"
#include "pw_unit_test/framework.h"
namespace pw {
namespace analog {
namespace {
constexpr int32_t kLimitsMax = 4096;
constexpr int32_t kLimitsMin = 0;
// Fake test analog input that's used for testing.
class TestAnalogInput : public AnalogInput {
public:
TestAnalogInput()
: limits_({
.min = kLimitsMin,
.max = kLimitsMax,
}) {}
Result<int32_t> TryReadUntil(chrono::SystemClock::time_point) override {
return Status::Unimplemented();
}
Limits GetLimits() const override { return limits_; }
private:
const Limits limits_;
};
TEST(AnalogInputTest, Construction) {
TestAnalogInput analog_input = TestAnalogInput();
}
TEST(AnalogInputTest, GetLimits) {
TestAnalogInput analog_input = TestAnalogInput();
AnalogInput::Limits limits = analog_input.GetLimits();
EXPECT_EQ(limits.min, kLimitsMin);
EXPECT_EQ(limits.max, kLimitsMax);
}
} // namespace
} // namespace analog
} // namespace pw