mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpilib] SendableChooser: Add onChange listener (#5458)
This commit is contained in:
@@ -56,5 +56,22 @@ TEST(SendableChooserTest,
|
||||
EXPECT_EQ(0, chooser.GetSelected());
|
||||
}
|
||||
|
||||
TEST(SendableChooserTest, ChangeListener) {
|
||||
frc::SendableChooser<int> chooser;
|
||||
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
chooser.AddOption(std::to_string(i), i);
|
||||
}
|
||||
int currentVal = 0;
|
||||
chooser.OnChange([&](int val) { currentVal = val; });
|
||||
|
||||
frc::SmartDashboard::PutData("chooser", &chooser);
|
||||
frc::SmartDashboard::UpdateValues();
|
||||
frc::SmartDashboard::PutString("chooser/selected", "3");
|
||||
frc::SmartDashboard::UpdateValues();
|
||||
|
||||
EXPECT_EQ(3, currentVal);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(SendableChooserTests, SendableChooserTest,
|
||||
::testing::Values(0, 1, 2, 3));
|
||||
|
||||
Reference in New Issue
Block a user