Forráskód Böngészése

First tests for a message with a repeated field.

Bart Hertog 6 éve
szülő
commit
16e2107fa3

+ 1 - 1
generator/Header_Template.h

@@ -93,7 +93,7 @@ class {{ msg.name }} final: public ::EmbeddedProto::MessageInterface
       result = (size_{{field.name}} <= buffer.get_available_size());
       if(result && (0 < size_{{field.name}}))
       {
-        uint32_t tag = ::EmbeddedProto::WireFormatter::MakeTag({{field.variable_id_name}}, ::EmbeddedProto::WireFormatter::WireType::{{field.wire_type}});
+        uint32_t tag = ::EmbeddedProto::WireFormatter::MakeTag({{field.variable_id_name}}, ::EmbeddedProto::WireFormatter::WireType::LENGTH_DELIMITED);
         result = ::EmbeddedProto::WireFormatter::SerializeVarint(tag, buffer);
         result = result && ::EmbeddedProto::WireFormatter::SerializeVarint(size_{{field.name}}, buffer);
         result = result && {{field.variable_name}}.serialize(buffer);

+ 73 - 0
test/test_RepeatedFieldMessage.cpp

@@ -0,0 +1,73 @@
+
+#include "gtest/gtest.h"
+
+#include <WireFormatter.h>
+#include <ReadBufferMock.h>
+#include <WriteBufferMock.h>
+
+#include <cstdint>    
+#include <limits> 
+
+// EAMS message definitions
+#include <repeated_fields.h>
+
+using ::testing::_;
+using ::testing::InSequence;
+using ::testing::Return;
+using ::testing::SetArgReferee;
+
+namespace test_EmbeddedAMS_RepeatedFieldMessage
+{
+
+static constexpr uint32_t Y_SIZE = 3;
+
+TEST(RepeatedFieldMessage, construction) 
+{
+  repeated_fields<Y_SIZE> msg;
+}
+
+TEST(RepeatedFieldMessage, serialize_array_one)
+{
+  InSequence s;
+  Mocks::WriteBufferMock buffer;
+
+  repeated_fields<Y_SIZE> msg;
+  msg.add_y(1);
+  msg.add_y(1);
+  msg.add_y(1);
+
+  uint8_t expected_uv[] = {0x12, 0x03, 0x01, 0x01, 0x01}; // y
+
+  EXPECT_CALL(buffer, get_available_size()).Times(1).WillOnce(Return(5));
+
+  for(auto e : expected_uv) {
+    EXPECT_CALL(buffer, push(e)).Times(1).WillOnce(Return(true));
+  }
+
+  EXPECT_TRUE(msg.serialize(buffer));
+}
+
+
+
+TEST(RepeatedFieldMessage, serialize_array_max)
+{
+  InSequence s;
+  Mocks::WriteBufferMock buffer;
+
+  repeated_fields<Y_SIZE> msg;
+  msg.add_y(std::numeric_limits<uint32_t>::max());
+  msg.add_y(std::numeric_limits<uint32_t>::max());
+  msg.add_y(std::numeric_limits<uint32_t>::max());
+
+  uint8_t expected_uv[] = {0x12, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x0f}; // y
+
+  EXPECT_CALL(buffer, get_available_size()).Times(1).WillOnce(Return(17));
+
+  for(auto e : expected_uv) {
+    EXPECT_CALL(buffer, push(e)).Times(1).WillOnce(Return(true));
+  }
+
+  EXPECT_TRUE(msg.serialize(buffer));
+}
+
+} // End of namespace test_EmbeddedAMS_RepeatedFieldMessage

+ 0 - 24
test/test_RepeatedFields.cpp

@@ -1,24 +0,0 @@
-
-#include "gtest/gtest.h"
-
-#include <WireFormatter.h>
-#include <ReadBufferMock.h>
-#include <WriteBufferMock.h>
-
-#include <cstdint>    
-#include <limits> 
-
-// EAMS message definitions
-#include <repeated_fields.h>
-
-namespace test_EmbeddedAMS_RepeatedFields
-{
-
-TEST(NestedMessage, construction) 
-{
-  static constexpr uint32_t Y_SIZE = 3;
-  repeated_fields<Y_SIZE> a;
-
-}
-
-} // End of namespace test_EmbeddedAMS_RepeatedFields

+ 3 - 3
test_data.py

@@ -97,9 +97,9 @@ def test_nested_message():
 def test_repeated_fields():
     msg = rf.repeated_fields()
 
-    y = msg.y.append(1)
-    y = msg.y.append(1)
-    y = msg.y.append(255)
+    y = msg.y.append(pow(2, 32) - 1)
+    y = msg.y.append(pow(2, 32) - 1)
+    y = msg.y.append(pow(2, 32) - 1)
 
     str = ""
     msg_str = msg.SerializeToString()