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