2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2019-12-02 23:27:33 -08:00
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <string_view>
|
|
|
|
|
|
2020-06-27 22:11:24 -07:00
|
|
|
#include <hal/SimDevice.h>
|
2019-12-02 23:27:33 -08:00
|
|
|
|
2020-06-27 22:11:24 -07:00
|
|
|
#include "frc/simulation/SimDeviceSim.h"
|
2019-12-02 23:27:33 -08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
using namespace frc::sim;
|
|
|
|
|
|
2021-09-17 22:51:51 -07:00
|
|
|
TEST(SimDeviceSimTest, Basic) {
|
2020-06-27 22:11:24 -07:00
|
|
|
hal::SimDevice dev{"test"};
|
|
|
|
|
hal::SimBoolean devBool = dev.CreateBoolean("bool", false, false);
|
2019-12-02 23:27:33 -08:00
|
|
|
|
|
|
|
|
SimDeviceSim sim{"test"};
|
2020-06-27 22:11:24 -07:00
|
|
|
hal::SimBoolean simBool = sim.GetBoolean("bool");
|
2019-12-02 23:27:33 -08:00
|
|
|
EXPECT_FALSE(simBool.Get());
|
|
|
|
|
simBool.Set(true);
|
|
|
|
|
EXPECT_TRUE(devBool.Get());
|
2023-01-11 14:45:15 -05:00
|
|
|
|
|
|
|
|
EXPECT_EQ(sim.GetName(), "test");
|
2019-12-02 23:27:33 -08:00
|
|
|
}
|
|
|
|
|
|
2021-09-17 22:51:51 -07:00
|
|
|
TEST(SimDeviceSimTest, EnumerateDevices) {
|
2020-06-27 22:11:24 -07:00
|
|
|
hal::SimDevice dev{"test"};
|
2019-12-02 23:27:33 -08:00
|
|
|
|
|
|
|
|
bool foundit = false;
|
|
|
|
|
SimDeviceSim::EnumerateDevices(
|
|
|
|
|
"te", [&](const char* name, HAL_SimDeviceHandle handle) {
|
2021-06-06 16:13:58 -07:00
|
|
|
if (std::string_view(name) == "test") {
|
2020-12-28 12:58:06 -08:00
|
|
|
foundit = true;
|
|
|
|
|
}
|
2019-12-02 23:27:33 -08:00
|
|
|
});
|
|
|
|
|
EXPECT_TRUE(foundit);
|
|
|
|
|
}
|