Skip to content

Commit

Permalink
Update tests to use SendableChooserSim
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold856 committed Jun 22, 2024
1 parent 362747b commit f28b76f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ TEST(SendableChooserTest,

TEST(SendableChooserTest, ChangeListener) {
frc::SendableChooser<int> chooser;
frc::sim::SendableChooserSim chooserSim = frc::sim::SendableChooserSim{

Check failure on line 62 in wpilibc/src/test/native/cpp/smartdashboard/SendableChooserTest.cpp

View workflow job for this annotation

GitHub Actions / Build - Windows

'frc::sim::SendableChooserSim': no appropriate default constructor available

Check failure on line 62 in wpilibc/src/test/native/cpp/smartdashboard/SendableChooserTest.cpp

View workflow job for this annotation

GitHub Actions / Build - Windows

'frc::sim::SendableChooserSim': no appropriate default constructor available
fmt::format("/SmartDashboard/ChangeListenerChooser/", GetParam())};

Check failure on line 63 in wpilibc/src/test/native/cpp/smartdashboard/SendableChooserTest.cpp

View workflow job for this annotation

GitHub Actions / Build - Windows

'GetParam': identifier not found

Check failure on line 63 in wpilibc/src/test/native/cpp/smartdashboard/SendableChooserTest.cpp

View workflow job for this annotation

GitHub Actions / Build - Windows

'fmt::v10::format': no matching overloaded function found

for (int i = 1; i <= 3; i++) {
chooser.AddOption(std::to_string(i), i);
Expand All @@ -68,7 +70,7 @@ TEST(SendableChooserTest, ChangeListener) {

frc::SmartDashboard::PutData("ChangeListenerChooser", &chooser);
frc::SmartDashboard::UpdateValues();
frc::SmartDashboard::PutString("ChangeListenerChooser/selected", "3");
chooserSim.SetSelected("3");
frc::SmartDashboard::UpdateValues();

EXPECT_EQ(3, currentVal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ void nullIsReturnedOnNoSelectAndNoDefault() {

@Test
void testChangeListener() {
try (var chooser = new SendableChooser<Integer>()) {
try (var chooser = new SendableChooser<Integer>();
var chooserSim = new SendableChooserSim(m_inst, "/SmartDashboard/changeListenerChooser/")) {
for (int i = 1; i <= 3; i++) {
chooser.addOption(String.valueOf(i), i);
}
Expand All @@ -79,31 +80,12 @@ void testChangeListener() {

SmartDashboard.putData("changeListenerChooser", chooser);
SmartDashboard.updateValues();
SmartDashboard.putString("changeListenerChooser/selected", "3");
chooserSim.setSelected("3");
SmartDashboard.updateValues();
assertEquals(3, currentVal.get());
}
}

@ValueSource(ints = {0, 1, 2, 3})
@ParameterizedTest
void testSendableChooserSim(int toSelect) {
try (var chooser = new SendableChooser<Integer>();
var chooserSim =
new SendableChooserSim(m_inst, "/SmartDashboard/SendableChooserSim" + toSelect + "/")) {
for (int i = 1; i <= 3; i++) {
chooser.addOption(String.valueOf(i), i);
}
chooser.setDefaultOption(String.valueOf(0), 0);

SmartDashboard.putData("SendableChooserSim" + toSelect, chooser);
SmartDashboard.updateValues();
chooserSim.setSelected(String.valueOf(toSelect));
SmartDashboard.updateValues();
assertEquals(toSelect, chooser.getSelected());
}
}

@AfterEach
void tearDown() {
m_inst.close();
Expand Down

0 comments on commit f28b76f

Please sign in to comment.