blob: e834659c7c1af262a702122370a4a8bd33e6f58f [file] [log] [blame]
Maxwell Hendersonf63a0d92023-06-24 14:49:51 -07001#include "y2023_bot4/swerve_publisher_lib.h"
2
3#include "gtest/gtest.h"
4
5#include "aos/events/simulated_event_loop.h"
6
Stephan Pleinesf63bde82024-01-13 15:59:33 -08007namespace y2023_bot4::testing {
Maxwell Hendersonf63a0d92023-06-24 14:49:51 -07008class SwervePublisherTest : public ::testing::Test {
9 public:
10 SwervePublisherTest()
11 : config_(aos::configuration::ReadConfig("y2023_bot4/aos_config.json")),
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()),
18 drivetrain_swerve_output_fetcher_(
19 event_loop_->MakeFetcher<
20 frc971::control_loops::drivetrain::swerve::Output>(
21 "/drivetrain")),
22 swerve_publisher_(event_loop_.get(), exit_handle_.get(),
23 "y2023_bot4/swerve_drivetrain_output.json", 100) {}
24
25 void SendOutput() { event_loop_factory_.Run(); }
26
27 void CheckOutput() {
28 drivetrain_swerve_output_fetcher_.Fetch();
29
30 ASSERT_TRUE(drivetrain_swerve_output_fetcher_.get() != nullptr)
31 << ": No drivetrain output";
32 }
33
34 private:
35 aos::FlatbufferDetachedBuffer<aos::Configuration> config_;
36 aos::SimulatedEventLoopFactory event_loop_factory_;
37 const aos::Node *const roborio_;
38
39 std::unique_ptr<aos::EventLoop> event_loop_;
40 std::unique_ptr<aos::ExitHandle> exit_handle_;
41
42 aos::Fetcher<frc971::control_loops::drivetrain::swerve::Output>
43 drivetrain_swerve_output_fetcher_;
44
45 y2023_bot4::SwervePublisher swerve_publisher_;
46};
47
48TEST_F(SwervePublisherTest, CheckSentFb) {
49 SendOutput();
50 CheckOutput();
51}
Stephan Pleinesf63bde82024-01-13 15:59:33 -080052} // namespace y2023_bot4::testing