test_RepeatedField.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 adress:
  26. * Johan Huizingalaan 763a
  27. * 1066 VH, Amsterdam
  28. * the Netherlands
  29. */
  30. #include <gtest/gtest.h>
  31. #include <Fields.h>
  32. #include <RepeatedField.h>
  33. namespace test_EmbeddedAMS_RepeatedField
  34. {
  35. TEST(RepeatedField, construction)
  36. {
  37. static constexpr uint32_t SIZE = 3;
  38. EmbeddedProto::RepeatedFieldSize<::EmbeddedProto::uint32, SIZE> x;
  39. }
  40. TEST(RepeatedField, size_uint32_t)
  41. {
  42. static constexpr uint32_t SIZE = 3;
  43. EmbeddedProto::RepeatedFieldSize<::EmbeddedProto::uint32, SIZE> x;
  44. static constexpr int32_t UINT32_SIZE = sizeof(::EmbeddedProto::uint32);
  45. EXPECT_EQ(0, x.get_size());
  46. EXPECT_EQ(SIZE*UINT32_SIZE, x.get_max_size());
  47. EXPECT_EQ(0, x.get_length());
  48. EXPECT_EQ(SIZE, x.get_max_length());
  49. x.add(1);
  50. x.add(2);
  51. EXPECT_EQ(2*UINT32_SIZE, x.get_size());
  52. EXPECT_EQ(2, x.get_length());
  53. x.add(3);
  54. EXPECT_EQ(SIZE*UINT32_SIZE, x.get_size());
  55. EXPECT_EQ(SIZE*UINT32_SIZE, x.get_max_size());
  56. EXPECT_EQ(SIZE, x.get_length());
  57. EXPECT_EQ(SIZE, x.get_max_length());
  58. }
  59. TEST(RepeatedField, set)
  60. {
  61. static constexpr uint32_t SIZE = 3;
  62. EmbeddedProto::RepeatedFieldSize<::EmbeddedProto::uint32, SIZE> x;
  63. // First add a value in the middle and see if we have a size of two.
  64. x.set(1, 2);
  65. EXPECT_EQ(2, x.get(1));
  66. EXPECT_EQ(2, x.get_length());
  67. x.set(0, 1);
  68. EXPECT_EQ(1, x.get(0));
  69. x.set(2, 3);
  70. EXPECT_EQ(3, x.get(2));
  71. }
  72. } // End namespace test_EmbeddedAMS_RepeatedField