Maxwell Henderson | f63a0d9 | 2023-06-24 14:49:51 -0700 | [diff] [blame^] | 1 | #include "y2023_bot4/swerve_publisher_lib.h" |
| 2 | |
| 3 | #include "gtest/gtest.h" |
| 4 | |
| 5 | #include "aos/events/simulated_event_loop.h" |
| 6 | |
| 7 | namespace y2023_bot4 { |
| 8 | namespace testing { |
| 9 | class SwervePublisherTest : public ::testing::Test { |
| 10 | public: |
| 11 | SwervePublisherTest() |
| 12 | : config_(aos::configuration::ReadConfig("y2023_bot4/aos_config.json")), |
| 13 | event_loop_factory_(&config_.message()), |
| 14 | roborio_(aos::configuration::GetNode( |
| 15 | event_loop_factory_.configuration(), "roborio")), |
| 16 | event_loop_( |
| 17 | event_loop_factory_.MakeEventLoop("swerve_publisher", roborio_)), |
| 18 | exit_handle_(event_loop_factory_.MakeExitHandle()), |
| 19 | drivetrain_swerve_output_fetcher_( |
| 20 | event_loop_->MakeFetcher< |
| 21 | frc971::control_loops::drivetrain::swerve::Output>( |
| 22 | "/drivetrain")), |
| 23 | swerve_publisher_(event_loop_.get(), exit_handle_.get(), |
| 24 | "y2023_bot4/swerve_drivetrain_output.json", 100) {} |
| 25 | |
| 26 | void SendOutput() { event_loop_factory_.Run(); } |
| 27 | |
| 28 | void CheckOutput() { |
| 29 | drivetrain_swerve_output_fetcher_.Fetch(); |
| 30 | |
| 31 | ASSERT_TRUE(drivetrain_swerve_output_fetcher_.get() != nullptr) |
| 32 | << ": No drivetrain output"; |
| 33 | } |
| 34 | |
| 35 | private: |
| 36 | aos::FlatbufferDetachedBuffer<aos::Configuration> config_; |
| 37 | aos::SimulatedEventLoopFactory event_loop_factory_; |
| 38 | const aos::Node *const roborio_; |
| 39 | |
| 40 | std::unique_ptr<aos::EventLoop> event_loop_; |
| 41 | std::unique_ptr<aos::ExitHandle> exit_handle_; |
| 42 | |
| 43 | aos::Fetcher<frc971::control_loops::drivetrain::swerve::Output> |
| 44 | drivetrain_swerve_output_fetcher_; |
| 45 | |
| 46 | y2023_bot4::SwervePublisher swerve_publisher_; |
| 47 | }; |
| 48 | |
| 49 | TEST_F(SwervePublisherTest, CheckSentFb) { |
| 50 | SendOutput(); |
| 51 | CheckOutput(); |
| 52 | } |
| 53 | } // namespace testing |
| 54 | } // namespace y2023_bot4 |