mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpiutil] Change Struct to allow non-constexpr implementation (#5992)
This required changing the constant values (e.g. kSize) into functions (e.g. GetSize()). Fixed implementations of ForEachNested to be inline (as these are actually templates). Also added a ntcore Struct test.
This commit is contained in:
@@ -16,8 +16,8 @@ const Pose2d kExpectedData{
|
||||
} // namespace
|
||||
|
||||
TEST(Pose2dStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
Pose2d unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
@@ -17,8 +17,8 @@ const Pose3d kExpectedData{
|
||||
} // namespace
|
||||
|
||||
TEST(Pose3dStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
Pose3d unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
@@ -15,8 +15,8 @@ const Quaternion kExpectedData{Quaternion{1.1, 0.191, 35.04, 19.1}};
|
||||
} // namespace
|
||||
|
||||
TEST(QuaternionStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
Quaternion unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
@@ -15,8 +15,8 @@ const Rotation2d kExpectedData{Rotation2d{1.91_rad}};
|
||||
} // namespace
|
||||
|
||||
TEST(Rotation2dStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
Rotation2d unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
@@ -16,8 +16,8 @@ const Rotation3d kExpectedData{
|
||||
} // namespace
|
||||
|
||||
TEST(Rotation3dStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
Rotation3d unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
@@ -16,8 +16,8 @@ const Transform2d kExpectedData{
|
||||
} // namespace
|
||||
|
||||
TEST(Transform2dStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
Transform2d unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
@@ -17,8 +17,8 @@ const Transform3d kExpectedData{
|
||||
} // namespace
|
||||
|
||||
TEST(Transform3dStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
Transform3d unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
@@ -15,8 +15,8 @@ const Translation2d kExpectedData{Translation2d{3.504_m, 22.9_m}};
|
||||
} // namespace
|
||||
|
||||
TEST(Translation2dStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
Translation2d unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
@@ -15,8 +15,8 @@ const Translation3d kExpectedData{Translation3d{35.04_m, 22.9_m, 3.504_m}};
|
||||
} // namespace
|
||||
|
||||
TEST(Translation3dStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
Translation3d unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
@@ -15,8 +15,8 @@ const Twist2d kExpectedData{Twist2d{2.29_m, 35.04_m, 35.04_rad}};
|
||||
} // namespace
|
||||
|
||||
TEST(Twist2dStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
Twist2d unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
@@ -16,8 +16,8 @@ const Twist3d kExpectedData{
|
||||
} // namespace
|
||||
|
||||
TEST(Twist3dStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
Twist3d unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
@@ -16,8 +16,8 @@ const ChassisSpeeds kExpectedData{
|
||||
} // namespace
|
||||
|
||||
TEST(ChassisSpeedsStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
ChassisSpeeds unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
@@ -16,8 +16,8 @@ const DifferentialDriveKinematics kExpectedData{
|
||||
} // namespace
|
||||
|
||||
TEST(DifferentialDriveKinematicsStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
DifferentialDriveKinematics unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
@@ -16,8 +16,8 @@ const DifferentialDriveWheelSpeeds kExpectedData{
|
||||
} // namespace
|
||||
|
||||
TEST(DifferentialDriveWheelSpeedsStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
DifferentialDriveWheelSpeeds unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
@@ -17,8 +17,8 @@ const MecanumDriveKinematics kExpectedData{MecanumDriveKinematics{
|
||||
} // namespace
|
||||
|
||||
TEST(MecanumDriveKinematicsStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
MecanumDriveKinematics unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
@@ -16,8 +16,8 @@ const MecanumDriveWheelPositions kExpectedData{
|
||||
} // namespace
|
||||
|
||||
TEST(MecanumDriveWheelPositionsStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
MecanumDriveWheelPositions unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
@@ -16,8 +16,8 @@ const MecanumDriveWheelSpeeds kExpectedData{
|
||||
} // namespace
|
||||
|
||||
TEST(MecanumDriveWheelSpeedsStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
MecanumDriveWheelSpeeds unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
@@ -16,8 +16,8 @@ const SwerveModulePosition kExpectedData{
|
||||
} // namespace
|
||||
|
||||
TEST(SwerveModulePositionStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
SwerveModulePosition unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
@@ -16,8 +16,8 @@ const SwerveModuleState kExpectedData{
|
||||
} // namespace
|
||||
|
||||
TEST(SwerveModuleStateStructTest, Roundtrip) {
|
||||
uint8_t buffer[StructType::kSize];
|
||||
std::memset(buffer, 0, StructType::kSize);
|
||||
uint8_t buffer[StructType::GetSize()];
|
||||
std::memset(buffer, 0, StructType::GetSize());
|
||||
StructType::Pack(buffer, kExpectedData);
|
||||
|
||||
SwerveModuleState unpacked_data = StructType::Unpack(buffer);
|
||||
|
||||
Reference in New Issue
Block a user