mtest.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * MAVLink C++11 test runner.
  3. *
  4. * Run command (ubuntu):
  5. g++ -std=c++11 -I mavlink/common -I /usr/src/gtest -pthread mtest.cpp /usr/src/gtest/src/gtest-all.cc && ./a.out
  6. * NOTE:
  7. * - mavlink is a directory with geterated C and C++ library.
  8. * - by changing "common" to other dialect may select another messages
  9. */
  10. #include <iostream>
  11. #include <array>
  12. //#define PRINT_MSG(m) print_msg(m)
  13. namespace mavlink {
  14. struct __mavlink_message;
  15. void print_msg(struct __mavlink_message &m);
  16. }
  17. // Since C++11 do not have things like std::to_array() which needs C++14 features
  18. template<size_t _N>
  19. std::array<char, _N> to_char_array(const char (&a)[_N])
  20. {
  21. std::array<char, _N> out{};
  22. std::copy(a, a+_N, out.begin());
  23. return out;
  24. }
  25. #define TEST_INTEROP
  26. #include "gtestsuite.hpp"
  27. const mavlink::mavlink_msg_entry_t *mavlink::mavlink_get_msg_entry(uint32_t msgid)
  28. {
  29. return nullptr;
  30. }
  31. void mavlink::print_msg(mavlink_message_t &m)
  32. {
  33. std::cout << std::hex << std::setfill('0')
  34. << "msgid: " << std::setw(6) << m.msgid
  35. << " len: " << std::setw(2) << +m.len
  36. << " crc: " << std::setw(4) << m.checksum
  37. << " p:";
  38. for (size_t i = 0; i < MAVLINK_MAX_PAYLOAD_LEN; i++)
  39. std::cout << " " << std::hex << std::setw(2) << std::setfill('0') << +(_MAV_PAYLOAD(&m)[i]);
  40. std::cout << std::endl;
  41. }
  42. int main(int argc, char *argv[])
  43. {
  44. ::testing::InitGoogleTest(&argc, argv);
  45. return RUN_ALL_TESTS();
  46. }