Skip to content

Commit

Permalink
Use smaller test
Browse files Browse the repository at this point in the history
  • Loading branch information
KangarooKoala committed Dec 28, 2023
1 parent 609894f commit ba6fe12
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
22 changes: 18 additions & 4 deletions wpimath/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,22 @@ configure_file(wpimath-config.cmake.in ${WPILIB_BINARY_DIR}/wpimath-config.cmake
install(FILES ${WPILIB_BINARY_DIR}/wpimath-config.cmake DESTINATION share/wpimath)
install(EXPORT wpimath DESTINATION share/wpimath)

if(WITH_TESTS)
wpilib_add_test(wpimath src/test/native/cpp)
target_include_directories(wpimath_test PRIVATE src/test/native/include)
target_link_libraries(wpimath_test wpimath gmock_main)
# if(WITH_TESTS)
# wpilib_add_test(wpimath src/test/native/cpp)
# target_include_directories(wpimath_test PRIVATE src/test/native/include)
# target_link_libraries(wpimath_test wpimath gmock_main)
# endif()

add_executable(wpimath_test2 src/test/quick_test.cpp)
if(MSVC)
target_compile_options(wpimath_test2 PRIVATE /wd4101 /wd4251)
endif()
add_test(NAME wpimath COMMAND wpimath_test2)
add_custom_command(
TARGET wpimath_test2
POST_BUILD
COMMAND echo built wpimath_test2
VERBATIM
)
target_link_libraries(wpimath_test2 wpimath)

26 changes: 26 additions & 0 deletions wpimath/src/test/quick_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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.

#include <wpi/protobuf/Protobuf.h>

#include "frc/system/plant/DCMotor.h"
#include "plant.pb.h"

int main(int arc, char** argv) {
const frc::DCMotor kExpectedData = frc::DCMotor{units::volt_t{1.91},
units::newton_meter_t{19.1},
units::ampere_t{1.74},
units::ampere_t{2.29},
units::radians_per_second_t{2.2},
2};
google::protobuf::Arena arena;
google::protobuf::Message* proto = wpi::Protobuf<frc::DCMotor>::New(&arena);
wpi::PackProtobuf(proto, kExpectedData);
frc::DCMotor unpacked_data = wpi::UnpackProtobuf<frc::DCMotor>(*proto);

if (unpacked_data.nominalVoltage.value() != kExpectedData.nominalVoltage.value()) {
return 1;
}
return 0;
}

0 comments on commit ba6fe12

Please sign in to comment.