test_MessageSizeCalculator.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
  3. *
  4. * This file is part of Embedded Proto.
  5. *
  6. * Embedded Proto is open source software: you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as published
  8. * by the Free Software Foundation, version 3 of the license.
  9. *
  10. * Embedded Proto is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
  17. *
  18. * For commercial and closed source application please visit:
  19. * <https://EmbeddedProto.com/license/>.
  20. *
  21. * Embedded AMS B.V.
  22. * Info:
  23. * info at EmbeddedProto dot com
  24. *
  25. * Postal address:
  26. * Johan Huizingalaan 763a
  27. * 1066 VH, Amsterdam
  28. * the Netherlands
  29. */
  30. #include "gtest/gtest.h"
  31. #include <MessageSizeCalculator.h>
  32. #include <cstdint>
  33. #include <limits>
  34. namespace test_EmbeddedAMS_MessageSizeCalculator
  35. {
  36. TEST(MessageSizeCalculator, push)
  37. {
  38. ::EmbeddedProto::MessageSizeCalculator msc;
  39. uint8_t byte = 0;
  40. EXPECT_EQ(0, msc.get_size());
  41. EXPECT_TRUE(msc.push(byte));
  42. EXPECT_EQ(1, msc.get_size());
  43. EXPECT_TRUE(msc.push(byte));
  44. EXPECT_EQ(2, msc.get_size());
  45. // Clear the content
  46. msc.clear();
  47. EXPECT_EQ(0, msc.get_size());
  48. }
  49. TEST(MessageSizeCalculator, push_n)
  50. {
  51. ::EmbeddedProto::MessageSizeCalculator msc;
  52. static constexpr uint8_t SIZE = 3;
  53. uint8_t bytes[SIZE] = {1, 2, 3};
  54. EXPECT_TRUE(msc.push(bytes, SIZE));
  55. EXPECT_EQ(3, msc.get_size());
  56. }
  57. TEST(MessageSizeCalculator, unlimited_size)
  58. {
  59. ::EmbeddedProto::MessageSizeCalculator msc;
  60. EXPECT_EQ(std::numeric_limits<uint32_t>::max(), msc.get_max_size());
  61. EXPECT_EQ(std::numeric_limits<uint32_t>::max(), msc.get_available_size());
  62. }
  63. } // End of namespace test_EmbeddedAMS_MessageSizeCalculator