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
|
|
|
|
2020-06-27 22:11:24 -07:00
|
|
|
#include <hal/SimDevice.h>
|
2019-12-02 23:27:33 -08:00
|
|
|
#include <wpi/StringRef.h>
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
TEST(SimDeviceSimTests, TestBasic) {
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(SimDeviceSimTests, TestEnumerateDevices) {
|
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) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (wpi::StringRef(name) == "test") {
|
|
|
|
|
foundit = true;
|
|
|
|
|
}
|
2019-12-02 23:27:33 -08:00
|
|
|
});
|
|
|
|
|
EXPECT_TRUE(foundit);
|
|
|
|
|
}
|