mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Move CameraServer and WPILib headers into their own folder
The old headers were moved into folders because doing so avoids polluting the system include directories. Folder names were also normalized to lowercase.
This commit is contained in:
committed by
Peter Johnson
parent
31ced30c1e
commit
d89b7dd412
80
hal/src/test/native/cpp/mockdata/AnalogInDataTests.cpp
Normal file
80
hal/src/test/native/cpp/mockdata/AnalogInDataTests.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "hal/AnalogInput.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "mockdata/AnalogInData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
std::string gTestAnalogInCallbackName;
|
||||
HAL_Value gTestAnalogInCallbackValue;
|
||||
|
||||
void TestAnalogInInitializationCallback(const char* name, void* param,
|
||||
const struct HAL_Value* value) {
|
||||
gTestAnalogInCallbackName = name;
|
||||
gTestAnalogInCallbackValue = *value;
|
||||
}
|
||||
|
||||
TEST(AnalogInSimTests, TestAnalogInInitialization) {
|
||||
const int INDEX_TO_TEST = 1;
|
||||
|
||||
int callbackParam = 0;
|
||||
int callbackId = HALSIM_RegisterAnalogInInitializedCallback(
|
||||
INDEX_TO_TEST, &TestAnalogInInitializationCallback, &callbackParam,
|
||||
false);
|
||||
ASSERT_TRUE(0 != callbackId);
|
||||
|
||||
int32_t status;
|
||||
HAL_PortHandle portHandle;
|
||||
HAL_DigitalHandle analogInHandle;
|
||||
|
||||
// Use out of range index
|
||||
status = 0;
|
||||
portHandle = 8000;
|
||||
gTestAnalogInCallbackName = "Unset";
|
||||
analogInHandle = HAL_InitializeAnalogInputPort(portHandle, &status);
|
||||
EXPECT_EQ(HAL_kInvalidHandle, analogInHandle);
|
||||
EXPECT_EQ(PARAMETER_OUT_OF_RANGE, status);
|
||||
EXPECT_STREQ("Unset", gTestAnalogInCallbackName.c_str());
|
||||
|
||||
// Successful setup
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
gTestAnalogInCallbackName = "Unset";
|
||||
analogInHandle = HAL_InitializeAnalogInputPort(portHandle, &status);
|
||||
EXPECT_TRUE(HAL_kInvalidHandle != analogInHandle);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("Initialized", gTestAnalogInCallbackName.c_str());
|
||||
|
||||
// Double initialize... should fail
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
gTestAnalogInCallbackName = "Unset";
|
||||
analogInHandle = HAL_InitializeAnalogInputPort(portHandle, &status);
|
||||
EXPECT_EQ(HAL_kInvalidHandle, analogInHandle);
|
||||
EXPECT_EQ(RESOURCE_IS_ALLOCATED, status);
|
||||
EXPECT_STREQ("Unset", gTestAnalogInCallbackName.c_str());
|
||||
|
||||
// Reset, should allow you to re-register
|
||||
hal::HandleBase::ResetGlobalHandles();
|
||||
HALSIM_ResetAnalogInData(INDEX_TO_TEST);
|
||||
callbackId = HALSIM_RegisterAnalogInInitializedCallback(
|
||||
INDEX_TO_TEST, &TestAnalogInInitializationCallback, &callbackParam,
|
||||
false);
|
||||
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
gTestAnalogInCallbackName = "Unset";
|
||||
analogInHandle = HAL_InitializeAnalogInputPort(portHandle, &status);
|
||||
EXPECT_TRUE(HAL_kInvalidHandle != analogInHandle);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("Initialized", gTestAnalogInCallbackName.c_str());
|
||||
}
|
||||
} // namespace hal
|
||||
80
hal/src/test/native/cpp/mockdata/AnalogOutDataTests.cpp
Normal file
80
hal/src/test/native/cpp/mockdata/AnalogOutDataTests.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "hal/AnalogOutput.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "mockdata/AnalogOutData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
std::string gTestAnalogOutCallbackName;
|
||||
HAL_Value gTestAnalogOutCallbackValue;
|
||||
|
||||
void TestAnalogOutInitializationCallback(const char* name, void* param,
|
||||
const struct HAL_Value* value) {
|
||||
gTestAnalogOutCallbackName = name;
|
||||
gTestAnalogOutCallbackValue = *value;
|
||||
}
|
||||
|
||||
TEST(AnalogOutSimTests, TestAnalogOutInitialization) {
|
||||
const int INDEX_TO_TEST = 1;
|
||||
|
||||
int callbackParam = 0;
|
||||
int callbackId = HALSIM_RegisterAnalogOutInitializedCallback(
|
||||
INDEX_TO_TEST, &TestAnalogOutInitializationCallback, &callbackParam,
|
||||
false);
|
||||
ASSERT_TRUE(0 != callbackId);
|
||||
|
||||
int32_t status;
|
||||
HAL_PortHandle portHandle;
|
||||
HAL_DigitalHandle analogOutHandle;
|
||||
|
||||
// Use out of range index
|
||||
status = 0;
|
||||
portHandle = 8000;
|
||||
gTestAnalogOutCallbackName = "Unset";
|
||||
analogOutHandle = HAL_InitializeAnalogOutputPort(portHandle, &status);
|
||||
EXPECT_EQ(HAL_kInvalidHandle, analogOutHandle);
|
||||
EXPECT_EQ(PARAMETER_OUT_OF_RANGE, status);
|
||||
EXPECT_STREQ("Unset", gTestAnalogOutCallbackName.c_str());
|
||||
|
||||
// Successful setup
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
gTestAnalogOutCallbackName = "Unset";
|
||||
analogOutHandle = HAL_InitializeAnalogOutputPort(portHandle, &status);
|
||||
EXPECT_TRUE(HAL_kInvalidHandle != analogOutHandle);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("Initialized", gTestAnalogOutCallbackName.c_str());
|
||||
|
||||
// Double initialize... should fail
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
gTestAnalogOutCallbackName = "Unset";
|
||||
analogOutHandle = HAL_InitializeAnalogOutputPort(portHandle, &status);
|
||||
EXPECT_EQ(HAL_kInvalidHandle, analogOutHandle);
|
||||
EXPECT_EQ(RESOURCE_IS_ALLOCATED, status);
|
||||
EXPECT_STREQ("Unset", gTestAnalogOutCallbackName.c_str());
|
||||
|
||||
// Reset, should allow you to re-register
|
||||
hal::HandleBase::ResetGlobalHandles();
|
||||
HALSIM_ResetAnalogOutData(INDEX_TO_TEST);
|
||||
callbackId = HALSIM_RegisterAnalogOutInitializedCallback(
|
||||
INDEX_TO_TEST, &TestAnalogOutInitializationCallback, &callbackParam,
|
||||
false);
|
||||
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
gTestAnalogOutCallbackName = "Unset";
|
||||
analogOutHandle = HAL_InitializeAnalogOutputPort(portHandle, &status);
|
||||
EXPECT_TRUE(HAL_kInvalidHandle != analogOutHandle);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("Initialized", gTestAnalogOutCallbackName.c_str());
|
||||
}
|
||||
} // namespace hal
|
||||
81
hal/src/test/native/cpp/mockdata/DIODataTests.cpp
Normal file
81
hal/src/test/native/cpp/mockdata/DIODataTests.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "hal/DIO.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "mockdata/DIOData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
std::string gTestDigitalIoCallbackName;
|
||||
HAL_Value gTestDigitalIoCallbackValue;
|
||||
|
||||
void TestDigitalIoInitializationCallback(const char* name, void* param,
|
||||
const struct HAL_Value* value) {
|
||||
gTestDigitalIoCallbackName = name;
|
||||
gTestDigitalIoCallbackValue = *value;
|
||||
}
|
||||
|
||||
TEST(DigitalIoSimTests, TestDigitalIoInitialization) {
|
||||
const int INDEX_TO_TEST = 3;
|
||||
|
||||
int callbackParam = 0;
|
||||
int callbackId = HALSIM_RegisterDIOInitializedCallback(
|
||||
INDEX_TO_TEST, &TestDigitalIoInitializationCallback, &callbackParam,
|
||||
false);
|
||||
ASSERT_TRUE(0 != callbackId);
|
||||
|
||||
int32_t status;
|
||||
HAL_PortHandle portHandle;
|
||||
HAL_DigitalHandle digitalIoHandle;
|
||||
|
||||
// Use out of range index
|
||||
status = 0;
|
||||
portHandle = 8000;
|
||||
gTestDigitalIoCallbackName = "Unset";
|
||||
digitalIoHandle = HAL_InitializeDIOPort(portHandle, true, &status);
|
||||
EXPECT_EQ(HAL_kInvalidHandle, digitalIoHandle);
|
||||
EXPECT_EQ(PARAMETER_OUT_OF_RANGE, status);
|
||||
EXPECT_STREQ("Unset", gTestDigitalIoCallbackName.c_str());
|
||||
|
||||
// Successful setup
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
gTestDigitalIoCallbackName = "Unset";
|
||||
digitalIoHandle = HAL_InitializeDIOPort(portHandle, true, &status);
|
||||
EXPECT_TRUE(HAL_kInvalidHandle != digitalIoHandle);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("Initialized", gTestDigitalIoCallbackName.c_str());
|
||||
|
||||
// Double initialize... should fail
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
gTestDigitalIoCallbackName = "Unset";
|
||||
digitalIoHandle = HAL_InitializeDIOPort(portHandle, true, &status);
|
||||
EXPECT_EQ(HAL_kInvalidHandle, digitalIoHandle);
|
||||
EXPECT_EQ(RESOURCE_IS_ALLOCATED, status);
|
||||
EXPECT_STREQ("Unset", gTestDigitalIoCallbackName.c_str());
|
||||
|
||||
// Reset, should allow you to re-register
|
||||
hal::HandleBase::ResetGlobalHandles();
|
||||
HALSIM_ResetDIOData(INDEX_TO_TEST);
|
||||
callbackId = HALSIM_RegisterDIOInitializedCallback(
|
||||
INDEX_TO_TEST, &TestDigitalIoInitializationCallback, &callbackParam,
|
||||
false);
|
||||
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
gTestDigitalIoCallbackName = "Unset";
|
||||
digitalIoHandle = HAL_InitializeDIOPort(portHandle, true, &status);
|
||||
EXPECT_TRUE(HAL_kInvalidHandle != digitalIoHandle);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("Initialized", gTestDigitalIoCallbackName.c_str());
|
||||
}
|
||||
|
||||
} // namespace hal
|
||||
143
hal/src/test/native/cpp/mockdata/DriverStationDataTests.cpp
Normal file
143
hal/src/test/native/cpp/mockdata/DriverStationDataTests.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/Solenoid.h"
|
||||
#include "mockdata/DriverStationData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
TEST(DriverStationTests, JoystickTests) {
|
||||
HAL_JoystickAxes axes;
|
||||
HAL_JoystickPOVs povs;
|
||||
HAL_JoystickButtons buttons;
|
||||
|
||||
// Check default values before anything has been set
|
||||
for (int joystickNum = 0; joystickNum < 6; ++joystickNum) {
|
||||
HAL_GetJoystickAxes(joystickNum, &axes);
|
||||
HAL_GetJoystickPOVs(joystickNum, &povs);
|
||||
HAL_GetJoystickButtons(joystickNum, &buttons);
|
||||
|
||||
EXPECT_EQ(0, axes.count);
|
||||
for (int i = 0; i < HAL_kMaxJoystickAxes; ++i) {
|
||||
EXPECT_EQ(0, axes.axes[i]);
|
||||
}
|
||||
|
||||
EXPECT_EQ(0, povs.count);
|
||||
for (int i = 0; i < HAL_kMaxJoystickPOVs; ++i) {
|
||||
EXPECT_EQ(0, povs.povs[i]);
|
||||
}
|
||||
|
||||
EXPECT_EQ(0, buttons.count);
|
||||
EXPECT_EQ(0u, buttons.buttons);
|
||||
}
|
||||
|
||||
HAL_JoystickAxes set_axes;
|
||||
std::memset(&set_axes, 0, sizeof(HAL_JoystickAxes));
|
||||
HAL_JoystickPOVs set_povs;
|
||||
std::memset(&set_povs, 0, sizeof(HAL_JoystickPOVs));
|
||||
HAL_JoystickButtons set_buttons;
|
||||
std::memset(&set_buttons, 0, sizeof(HAL_JoystickButtons));
|
||||
|
||||
// Set values
|
||||
int joystickUnderTest = 4;
|
||||
set_axes.count = 5;
|
||||
for (int i = 0; i < set_axes.count; ++i) {
|
||||
set_axes.axes[i] = i * .125;
|
||||
}
|
||||
|
||||
set_povs.count = 3;
|
||||
for (int i = 0; i < set_povs.count; ++i) {
|
||||
set_povs.povs[i] = i * 15 + 12;
|
||||
}
|
||||
|
||||
set_buttons.count = 8;
|
||||
set_buttons.buttons = 0xDEADBEEF;
|
||||
|
||||
HALSIM_SetJoystickAxes(joystickUnderTest, &set_axes);
|
||||
HALSIM_SetJoystickPOVs(joystickUnderTest, &set_povs);
|
||||
HALSIM_SetJoystickButtons(joystickUnderTest, &set_buttons);
|
||||
|
||||
// Check the set values
|
||||
HAL_GetJoystickAxes(joystickUnderTest, &axes);
|
||||
HAL_GetJoystickPOVs(joystickUnderTest, &povs);
|
||||
HAL_GetJoystickButtons(joystickUnderTest, &buttons);
|
||||
|
||||
EXPECT_EQ(5, axes.count);
|
||||
EXPECT_NEAR(0.000, axes.axes[0], 0.000001);
|
||||
EXPECT_NEAR(0.125, axes.axes[1], 0.000001);
|
||||
EXPECT_NEAR(0.250, axes.axes[2], 0.000001);
|
||||
EXPECT_NEAR(0.375, axes.axes[3], 0.000001);
|
||||
EXPECT_NEAR(0.500, axes.axes[4], 0.000001);
|
||||
EXPECT_NEAR(0, axes.axes[5], 0.000001); // Should not have been set, still 0
|
||||
EXPECT_NEAR(0, axes.axes[6], 0.000001); // Should not have been set, still 0
|
||||
|
||||
EXPECT_EQ(3, povs.count);
|
||||
EXPECT_EQ(12, povs.povs[0]);
|
||||
EXPECT_EQ(27, povs.povs[1]);
|
||||
EXPECT_EQ(42, povs.povs[2]);
|
||||
EXPECT_EQ(0, povs.povs[3]); // Should not have been set, still 0
|
||||
EXPECT_EQ(0, povs.povs[4]); // Should not have been set, still 0
|
||||
EXPECT_EQ(0, povs.povs[5]); // Should not have been set, still 0
|
||||
EXPECT_EQ(0, povs.povs[6]); // Should not have been set, still 0
|
||||
|
||||
EXPECT_EQ(8, buttons.count);
|
||||
EXPECT_EQ(0xDEADBEEFu, buttons.buttons);
|
||||
|
||||
// Reset
|
||||
HALSIM_ResetDriverStationData();
|
||||
for (int joystickNum = 0; joystickNum < 6; ++joystickNum) {
|
||||
HAL_GetJoystickAxes(joystickNum, &axes);
|
||||
HAL_GetJoystickPOVs(joystickNum, &povs);
|
||||
HAL_GetJoystickButtons(joystickNum, &buttons);
|
||||
|
||||
EXPECT_EQ(0, axes.count);
|
||||
for (int i = 0; i < HAL_kMaxJoystickAxes; ++i) {
|
||||
EXPECT_EQ(0, axes.axes[i]);
|
||||
}
|
||||
|
||||
EXPECT_EQ(0, povs.count);
|
||||
for (int i = 0; i < HAL_kMaxJoystickPOVs; ++i) {
|
||||
EXPECT_EQ(0, povs.povs[i]);
|
||||
}
|
||||
|
||||
EXPECT_EQ(0, buttons.count);
|
||||
EXPECT_EQ(0u, buttons.buttons);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DriverStationTests, EventInfoTest) {
|
||||
std::string eventName = "UnitTest";
|
||||
std::string gameData = "Insert game specific info here :D";
|
||||
HAL_MatchInfo info;
|
||||
std::snprintf(info.eventName, sizeof(info.eventName), "%s",
|
||||
eventName.c_str());
|
||||
std::snprintf(reinterpret_cast<char*>(info.gameSpecificMessage),
|
||||
sizeof(info.gameSpecificMessage), "%s", gameData.c_str());
|
||||
info.gameSpecificMessageSize = gameData.size();
|
||||
info.matchNumber = 5;
|
||||
info.matchType = HAL_MatchType::HAL_kMatchType_qualification;
|
||||
info.replayNumber = 42;
|
||||
HALSIM_SetMatchInfo(&info);
|
||||
|
||||
HAL_MatchInfo dataBack;
|
||||
HAL_GetMatchInfo(&dataBack);
|
||||
|
||||
std::string gsm{reinterpret_cast<char*>(dataBack.gameSpecificMessage),
|
||||
dataBack.gameSpecificMessageSize};
|
||||
|
||||
EXPECT_STREQ(eventName.c_str(), dataBack.eventName);
|
||||
EXPECT_EQ(gameData, gsm);
|
||||
EXPECT_EQ(5, dataBack.matchNumber);
|
||||
EXPECT_EQ(HAL_MatchType::HAL_kMatchType_qualification, dataBack.matchType);
|
||||
EXPECT_EQ(42, dataBack.replayNumber);
|
||||
}
|
||||
|
||||
} // namespace hal
|
||||
43
hal/src/test/native/cpp/mockdata/I2CDataTests.cpp
Normal file
43
hal/src/test/native/cpp/mockdata/I2CDataTests.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/I2C.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "mockdata/I2CData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
std::string gTestI2CCallbackName;
|
||||
HAL_Value gTestI2CCallbackValue;
|
||||
|
||||
void TestI2CInitializationCallback(const char* name, void* param,
|
||||
const struct HAL_Value* value) {
|
||||
gTestI2CCallbackName = name;
|
||||
gTestI2CCallbackValue = *value;
|
||||
}
|
||||
|
||||
TEST(I2CSimTests, TestI2CInitialization) {
|
||||
const int INDEX_TO_TEST = 1;
|
||||
|
||||
int32_t status;
|
||||
HAL_I2CPort port;
|
||||
|
||||
int callbackParam = 0;
|
||||
int callbackId = HALSIM_RegisterI2CInitializedCallback(
|
||||
INDEX_TO_TEST, &TestI2CInitializationCallback, &callbackParam, false);
|
||||
ASSERT_TRUE(0 != callbackId);
|
||||
|
||||
status = 0;
|
||||
port = HAL_I2C_kMXP;
|
||||
gTestI2CCallbackName = "Unset";
|
||||
HAL_InitializeI2C(port, &status);
|
||||
EXPECT_STREQ("Initialized", gTestI2CCallbackName.c_str());
|
||||
}
|
||||
|
||||
} // namespace hal
|
||||
83
hal/src/test/native/cpp/mockdata/PCMDataTests.cpp
Normal file
83
hal/src/test/native/cpp/mockdata/PCMDataTests.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/Solenoid.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "mockdata/PCMData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
std::string gTestSolenoidCallbackName;
|
||||
HAL_Value gTestSolenoidCallbackValue;
|
||||
|
||||
void TestSolenoidInitializationCallback(const char* name, void* param,
|
||||
const struct HAL_Value* value) {
|
||||
gTestSolenoidCallbackName = name;
|
||||
gTestSolenoidCallbackValue = *value;
|
||||
}
|
||||
|
||||
TEST(SolenoidSimTests, TestSolenoidInitialization) {
|
||||
const int MODULE_TO_TEST = 2;
|
||||
const int CHANNEL_TO_TEST = 3;
|
||||
|
||||
int callbackParam = 0;
|
||||
int callbackId = HALSIM_RegisterPCMSolenoidInitializedCallback(
|
||||
MODULE_TO_TEST, CHANNEL_TO_TEST, &TestSolenoidInitializationCallback,
|
||||
&callbackParam, false);
|
||||
ASSERT_TRUE(0 != callbackId);
|
||||
|
||||
int32_t status;
|
||||
HAL_PortHandle portHandle;
|
||||
HAL_DigitalHandle solenoidHandle;
|
||||
|
||||
// Use out of range index
|
||||
status = 0;
|
||||
portHandle = 8000;
|
||||
gTestSolenoidCallbackName = "Unset";
|
||||
solenoidHandle = HAL_InitializeSolenoidPort(portHandle, &status);
|
||||
EXPECT_EQ(HAL_kInvalidHandle, solenoidHandle);
|
||||
EXPECT_EQ(HAL_HANDLE_ERROR, status);
|
||||
EXPECT_STREQ("Unset", gTestSolenoidCallbackName.c_str());
|
||||
|
||||
// Successful setup
|
||||
status = 0;
|
||||
portHandle = HAL_GetPortWithModule(MODULE_TO_TEST, CHANNEL_TO_TEST);
|
||||
gTestSolenoidCallbackName = "Unset";
|
||||
solenoidHandle = HAL_InitializeSolenoidPort(portHandle, &status);
|
||||
EXPECT_TRUE(HAL_kInvalidHandle != solenoidHandle);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("SolenoidInitialized", gTestSolenoidCallbackName.c_str());
|
||||
|
||||
// Double initialize... should fail
|
||||
status = 0;
|
||||
portHandle = HAL_GetPortWithModule(MODULE_TO_TEST, CHANNEL_TO_TEST);
|
||||
gTestSolenoidCallbackName = "Unset";
|
||||
solenoidHandle = HAL_InitializeSolenoidPort(portHandle, &status);
|
||||
EXPECT_EQ(HAL_kInvalidHandle, solenoidHandle);
|
||||
EXPECT_EQ(NO_AVAILABLE_RESOURCES, status);
|
||||
EXPECT_STREQ("Unset", gTestSolenoidCallbackName.c_str());
|
||||
|
||||
// Reset, should allow you to re-register
|
||||
hal::HandleBase::ResetGlobalHandles();
|
||||
HALSIM_ResetPCMData(MODULE_TO_TEST);
|
||||
callbackId = HALSIM_RegisterPCMSolenoidInitializedCallback(
|
||||
MODULE_TO_TEST, CHANNEL_TO_TEST, &TestSolenoidInitializationCallback,
|
||||
&callbackParam, false);
|
||||
ASSERT_TRUE(0 != callbackId);
|
||||
|
||||
status = 0;
|
||||
portHandle = HAL_GetPortWithModule(MODULE_TO_TEST, CHANNEL_TO_TEST);
|
||||
gTestSolenoidCallbackName = "Unset";
|
||||
solenoidHandle = HAL_InitializeSolenoidPort(portHandle, &status);
|
||||
EXPECT_TRUE(HAL_kInvalidHandle != solenoidHandle);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("SolenoidInitialized", gTestSolenoidCallbackName.c_str());
|
||||
}
|
||||
|
||||
} // namespace hal
|
||||
43
hal/src/test/native/cpp/mockdata/PDPDataTests.cpp
Normal file
43
hal/src/test/native/cpp/mockdata/PDPDataTests.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/PDP.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "mockdata/PDPData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
std::string gTestPdpCallbackName;
|
||||
HAL_Value gTestPdpCallbackValue;
|
||||
|
||||
void TestPdpInitializationCallback(const char* name, void* param,
|
||||
const struct HAL_Value* value) {
|
||||
gTestPdpCallbackName = name;
|
||||
gTestPdpCallbackValue = *value;
|
||||
}
|
||||
|
||||
TEST(PdpSimTests, TestPdpInitialization) {
|
||||
const int INDEX_TO_TEST = 1;
|
||||
|
||||
int callbackParam = 0;
|
||||
int callbackId = HALSIM_RegisterPDPInitializedCallback(
|
||||
INDEX_TO_TEST, &TestPdpInitializationCallback, &callbackParam, false);
|
||||
ASSERT_TRUE(0 != callbackId);
|
||||
|
||||
int32_t status;
|
||||
|
||||
// Use out of range index
|
||||
status = 0;
|
||||
gTestPdpCallbackName = "Unset";
|
||||
HAL_InitializePDP(INDEX_TO_TEST, &status);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("Initialized", gTestPdpCallbackName.c_str());
|
||||
}
|
||||
|
||||
} // namespace hal
|
||||
78
hal/src/test/native/cpp/mockdata/PWMDataTests.cpp
Normal file
78
hal/src/test/native/cpp/mockdata/PWMDataTests.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/PWM.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "mockdata/PWMData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
std::string gTestPwmCallbackName;
|
||||
HAL_Value gTestPwmCallbackValue;
|
||||
|
||||
void TestPwmInitializationCallback(const char* name, void* param,
|
||||
const struct HAL_Value* value) {
|
||||
gTestPwmCallbackName = name;
|
||||
gTestPwmCallbackValue = *value;
|
||||
}
|
||||
|
||||
TEST(PWMSimTests, TestPwmInitialization) {
|
||||
const int INDEX_TO_TEST = 7;
|
||||
|
||||
int callbackParam = 0;
|
||||
int callbackId = HALSIM_RegisterPWMInitializedCallback(
|
||||
INDEX_TO_TEST, &TestPwmInitializationCallback, &callbackParam, false);
|
||||
ASSERT_TRUE(0 != callbackId);
|
||||
|
||||
int32_t status;
|
||||
HAL_PortHandle portHandle;
|
||||
HAL_DigitalHandle pwmHandle;
|
||||
|
||||
// Use out of range index
|
||||
status = 0;
|
||||
portHandle = 8000;
|
||||
gTestPwmCallbackName = "Unset";
|
||||
pwmHandle = HAL_InitializePWMPort(portHandle, &status);
|
||||
EXPECT_EQ(HAL_kInvalidHandle, pwmHandle);
|
||||
EXPECT_EQ(PARAMETER_OUT_OF_RANGE, status);
|
||||
EXPECT_STREQ("Unset", gTestPwmCallbackName.c_str());
|
||||
|
||||
// Successful setup
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
gTestPwmCallbackName = "Unset";
|
||||
pwmHandle = HAL_InitializePWMPort(portHandle, &status);
|
||||
EXPECT_TRUE(HAL_kInvalidHandle != pwmHandle);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("Initialized", gTestPwmCallbackName.c_str());
|
||||
|
||||
// Double initialize... should fail
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
gTestPwmCallbackName = "Unset";
|
||||
pwmHandle = HAL_InitializePWMPort(portHandle, &status);
|
||||
EXPECT_EQ(HAL_kInvalidHandle, pwmHandle);
|
||||
EXPECT_EQ(RESOURCE_IS_ALLOCATED, status);
|
||||
EXPECT_STREQ("Unset", gTestPwmCallbackName.c_str());
|
||||
|
||||
// Reset, should allow you to re-register
|
||||
hal::HandleBase::ResetGlobalHandles();
|
||||
HALSIM_ResetPWMData(INDEX_TO_TEST);
|
||||
callbackId = HALSIM_RegisterPWMInitializedCallback(
|
||||
INDEX_TO_TEST, &TestPwmInitializationCallback, &callbackParam, false);
|
||||
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
gTestPwmCallbackName = "Unset";
|
||||
pwmHandle = HAL_InitializePWMPort(portHandle, &status);
|
||||
EXPECT_TRUE(HAL_kInvalidHandle != pwmHandle);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("Initialized", gTestPwmCallbackName.c_str());
|
||||
}
|
||||
} // namespace hal
|
||||
79
hal/src/test/native/cpp/mockdata/RelayDataTests.cpp
Normal file
79
hal/src/test/native/cpp/mockdata/RelayDataTests.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/Relay.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "mockdata/RelayData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
std::string gTestRelayCallbackName;
|
||||
HAL_Value gTestRelayCallbackValue;
|
||||
|
||||
void TestRelayInitializationCallback(const char* name, void* param,
|
||||
const struct HAL_Value* value) {
|
||||
gTestRelayCallbackName = name;
|
||||
gTestRelayCallbackValue = *value;
|
||||
}
|
||||
|
||||
TEST(RelaySimTests, TestRelayInitialization) {
|
||||
const int INDEX_TO_TEST = 3;
|
||||
|
||||
int callbackParam = 0;
|
||||
int callbackId = HALSIM_RegisterRelayInitializedForwardCallback(
|
||||
INDEX_TO_TEST, &TestRelayInitializationCallback, &callbackParam, false);
|
||||
ASSERT_TRUE(0 != callbackId);
|
||||
|
||||
int32_t status;
|
||||
HAL_PortHandle portHandle;
|
||||
HAL_DigitalHandle pdpHandle;
|
||||
|
||||
// Use out of range index
|
||||
status = 0;
|
||||
portHandle = 8000;
|
||||
gTestRelayCallbackName = "Unset";
|
||||
pdpHandle = HAL_InitializeRelayPort(portHandle, true, &status);
|
||||
EXPECT_EQ(HAL_kInvalidHandle, pdpHandle);
|
||||
EXPECT_EQ(PARAMETER_OUT_OF_RANGE, status);
|
||||
EXPECT_STREQ("Unset", gTestRelayCallbackName.c_str());
|
||||
|
||||
// Successful setup
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
gTestRelayCallbackName = "Unset";
|
||||
pdpHandle = HAL_InitializeRelayPort(portHandle, true, &status);
|
||||
EXPECT_TRUE(HAL_kInvalidHandle != pdpHandle);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("InitializedForward", gTestRelayCallbackName.c_str());
|
||||
|
||||
// Double initialize... should fail
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
gTestRelayCallbackName = "Unset";
|
||||
pdpHandle = HAL_InitializeRelayPort(portHandle, true, &status);
|
||||
EXPECT_EQ(HAL_kInvalidHandle, pdpHandle);
|
||||
EXPECT_EQ(RESOURCE_IS_ALLOCATED, status);
|
||||
EXPECT_STREQ("Unset", gTestRelayCallbackName.c_str());
|
||||
|
||||
// Reset, should allow you to re-register
|
||||
hal::HandleBase::ResetGlobalHandles();
|
||||
HALSIM_ResetRelayData(INDEX_TO_TEST);
|
||||
callbackId = HALSIM_RegisterRelayInitializedForwardCallback(
|
||||
INDEX_TO_TEST, &TestRelayInitializationCallback, &callbackParam, false);
|
||||
|
||||
status = 0;
|
||||
portHandle = HAL_GetPort(INDEX_TO_TEST);
|
||||
gTestRelayCallbackName = "Unset";
|
||||
pdpHandle = HAL_InitializeRelayPort(portHandle, true, &status);
|
||||
EXPECT_TRUE(HAL_kInvalidHandle != pdpHandle);
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_STREQ("InitializedForward", gTestRelayCallbackName.c_str());
|
||||
}
|
||||
|
||||
} // namespace hal
|
||||
43
hal/src/test/native/cpp/mockdata/SPIDataTests.cpp
Normal file
43
hal/src/test/native/cpp/mockdata/SPIDataTests.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "hal/HAL.h"
|
||||
#include "hal/SPI.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "mockdata/SPIData.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
std::string gTestSpiCallbackName;
|
||||
HAL_Value gTestSpiCallbackValue;
|
||||
|
||||
void TestSpiInitializationCallback(const char* name, void* param,
|
||||
const struct HAL_Value* value) {
|
||||
gTestSpiCallbackName = name;
|
||||
gTestSpiCallbackValue = *value;
|
||||
}
|
||||
|
||||
TEST(SpiSimTests, TestSpiInitialization) {
|
||||
const int INDEX_TO_TEST = 2;
|
||||
|
||||
int32_t status;
|
||||
HAL_SPIPort port;
|
||||
|
||||
int callbackParam = 0;
|
||||
int callbackId = HALSIM_RegisterSPIInitializedCallback(
|
||||
INDEX_TO_TEST, &TestSpiInitializationCallback, &callbackParam, false);
|
||||
ASSERT_TRUE(0 != callbackId);
|
||||
|
||||
status = 0;
|
||||
port = HAL_SPI_kOnboardCS2;
|
||||
gTestSpiCallbackName = "Unset";
|
||||
HAL_InitializeSPI(port, &status);
|
||||
EXPECT_STREQ("Initialized", gTestSpiCallbackName.c_str());
|
||||
}
|
||||
|
||||
} // namespace hal
|
||||
Reference in New Issue
Block a user