#include "sensors/pluggable.hpp" #include "test/readinterface_mock.hpp" #include "test/writeinterface_mock.hpp" #include #include #include namespace pid_control { namespace { using ::testing::Invoke; TEST(PluggableSensorTest, BoringConstructorTest) { // Build a boring Pluggable Sensor. int64_t min = 0; int64_t max = 255; std::unique_ptr ri = std::make_unique(); std::unique_ptr wi = std::make_unique(min, max); std::string name = "name"; int64_t timeout = 1; PluggableSensor p(name, timeout, std::move(ri), std::move(wi)); // Successfully created it. } TEST(PluggableSensorTest, TryReadingTest) { // Verify calling read, calls the ReadInterface. int64_t min = 0; int64_t max = 255; std::unique_ptr ri = std::make_unique(); std::unique_ptr wi = std::make_unique(min, max); std::string name = "name"; int64_t timeout = 1; ReadInterfaceMock* rip = reinterpret_cast(ri.get()); PluggableSensor p(name, timeout, std::move(ri), std::move(wi)); ReadReturn r; r.value = 0.1; r.updated = std::chrono::high_resolution_clock::now(); EXPECT_CALL(*rip, read()).WillOnce(Invoke([&](void) { return r; })); // TODO(venture): Implement comparison operator for ReadReturn. ReadReturn v = p.read(); EXPECT_EQ(r.value, v.value); EXPECT_EQ(r.updated, v.updated); } TEST(PluggableSensorTest, TryWritingTest) { // Verify calling write, calls the WriteInterface. int64_t min = 0; int64_t max = 255; std::unique_ptr ri = std::make_unique(); std::unique_ptr wi = std::make_unique(min, max); std::string name = "name"; int64_t timeout = 1; WriteInterfaceMock* wip = reinterpret_cast(wi.get()); PluggableSensor p(name, timeout, std::move(ri), std::move(wi)); double value = 0.303; EXPECT_CALL(*wip, write(value)); p.write(value); } } // namespace } // namespace pid_control