test_IncludeOtherFiles.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "gtest/gtest.h"
  2. #include <WireFormatter.h>
  3. #include <ReadBufferMock.h>
  4. #include <WriteBufferMock.h>
  5. #include <cstdint>
  6. #include <limits>
  7. // EAMS message definitions
  8. #include <include_other_files.h>
  9. #include <repeated_fields.h>
  10. using ::testing::_;
  11. using ::testing::InSequence;
  12. using ::testing::Return;
  13. using ::testing::SetArgReferee;
  14. namespace test_EmbeddedAMS_IncludeOtherFiles
  15. {
  16. static constexpr uint32_t RF_SIZE = 3;
  17. TEST(IncludeOtherFiles, zero)
  18. {
  19. InSequence s;
  20. // See if an empty message results in no data been pushed.
  21. ::IncludedMessages<RF_SIZE> msg;
  22. Mocks::WriteBufferMock buffer;
  23. EXPECT_CALL(buffer, push(_)).Times(0);
  24. EXPECT_CALL(buffer, push(_,_)).Times(0);
  25. EXPECT_CALL(buffer, get_available_size()).WillRepeatedly(Return(99));
  26. EXPECT_TRUE(msg.serialize(buffer));
  27. EXPECT_EQ(0, msg.serialized_size());
  28. }
  29. TEST(IncludeOtherFiles, set)
  30. {
  31. InSequence s;
  32. // See if an empty message results in no data been pushed.
  33. ::IncludedMessages<RF_SIZE> msg;
  34. Mocks::WriteBufferMock buffer;
  35. msg.set_state(::CommonStates::StateA);
  36. ::CommonMessage cmsg;
  37. cmsg.set_a(1);
  38. cmsg.set_b(1.0F);
  39. msg.set_msg(cmsg);
  40. msg.mutable_rf().set_x(1);
  41. msg.mutable_rf().add_y(1);
  42. msg.mutable_rf().add_y(1);
  43. msg.mutable_rf().add_y(1);
  44. msg.mutable_rf().set_z(1);
  45. ON_CALL(buffer, get_available_size()).WillByDefault(Return(99));
  46. uint8_t expected[] = { 0x08, 0x01, // state
  47. // cmsg
  48. 0x12, 0x07,
  49. 0x08, 0x01, // msg.a
  50. 0x15, 0x00, 0x00, 0x80, 0x3f, // msg.b
  51. // rf
  52. 0x1a, 0x09,
  53. 0x08, 0x01, // rf.x
  54. 0x12, 0x03, 0x01, 0x01, 0x01, // rf.y
  55. 0x18, 0x01}; // rf.z
  56. for(auto e : expected)
  57. {
  58. EXPECT_CALL(buffer, push(e)).Times(1).WillOnce(Return(true));
  59. }
  60. EXPECT_TRUE(msg.serialize(buffer));
  61. }
  62. } // End of namespace