Răsfoiți Sursa

Testing setting an imported message.

Bart Hertog 6 ani în urmă
părinte
comite
8fb09f326c
3 a modificat fișierele cu 96 adăugiri și 16 ștergeri
  1. 2 1
      build_test.sh
  2. 49 1
      test/test_IncludeOtherFiles.cpp
  3. 45 14
      test_data.py

+ 2 - 1
build_test.sh

@@ -14,7 +14,8 @@ protoc -I./test/proto --python_out=./build/python ./test/proto/simple_types.prot
 protoc -I./test/proto --python_out=./build/python ./test/proto/nested_message.proto
 protoc -I./test/proto --python_out=./build/python ./test/proto/repeated_fields.proto
 protoc -I./test/proto --python_out=./build/python ./test/proto/oneof_fields.proto
-
+protoc -I./test/proto --python_out=./build/python ./test/proto/include_other_files.proto
+protoc -I./test/proto --python_out=./build/python ./test/proto/file_to_include.proto
 
 # Build the tests
 mkdir -p build/test

+ 49 - 1
test/test_IncludeOtherFiles.cpp

@@ -9,6 +9,7 @@
 
 // EAMS message definitions
 #include <include_other_files.h>
+#include <repeated_fields.h>
 
 using ::testing::_;
 using ::testing::InSequence;
@@ -18,12 +19,15 @@ using ::testing::SetArgReferee;
 namespace test_EmbeddedAMS_IncludeOtherFiles
 {
 
+
+static constexpr uint32_t RF_SIZE = 3;
+
 TEST(IncludeOtherFiles, zero) 
 {
   InSequence s;
 
   // See if an empty message results in no data been pushed.
-  ::IncludedMessages<3> msg;
+  ::IncludedMessages<RF_SIZE> msg;
   Mocks::WriteBufferMock buffer;
 
   EXPECT_CALL(buffer, push(_)).Times(0);
@@ -35,5 +39,49 @@ TEST(IncludeOtherFiles, zero)
   EXPECT_EQ(0, msg.serialized_size());
 }
 
+TEST(IncludeOtherFiles, set) 
+{
+  InSequence s;
+
+  // See if an empty message results in no data been pushed.
+  ::IncludedMessages<RF_SIZE> msg;
+  Mocks::WriteBufferMock buffer;
+
+  msg.set_state(::CommonStates::StateA);
+
+  ::CommonMessage cmsg;
+  cmsg.set_a(1);
+  cmsg.set_b(1.0F);
+  msg.set_msg(cmsg);
+
+  msg.mutable_rf().set_x(1);
+  msg.mutable_rf().add_y(1);
+  msg.mutable_rf().add_y(1);
+  msg.mutable_rf().add_y(1);
+  msg.mutable_rf().set_z(1);
+
+
+  ON_CALL(buffer, get_available_size()).WillByDefault(Return(99));
+
+  uint8_t expected[] = { 0x08, 0x01, // state
+                         // cmsg
+                         0x12, 0x07, 
+                         0x08, 0x01, // msg.a
+                         0x15, 0x00, 0x00, 0x80, 0x3f, // msg.b
+                         // rf
+                         0x1a, 0x09, 
+                         0x08, 0x01, // rf.x
+                         0x12, 0x03, 0x01, 0x01, 0x01, // rf.y
+                         0x18, 0x01}; // rf.z
+
+  for(auto e : expected) 
+  {
+    EXPECT_CALL(buffer, push(e)).Times(1).WillOnce(Return(true));
+  }   
+
+  EXPECT_TRUE(msg.serialize(buffer));
+
+}
+
 
 } // End of namespace

+ 45 - 14
test_data.py

@@ -1,7 +1,13 @@
-import build.python.simple_types_pb2 as st
-import build.python.nested_message_pb2 as nm
-import build.python.repeated_fields_pb2 as rf
-import build.python.oneof_fields_pb2 as of
+
+from sys import path
+path.append('./build/python/')
+
+import simple_types_pb2 as st
+import nested_message_pb2 as nm
+import repeated_fields_pb2 as rf
+import oneof_fields_pb2 as of
+import file_to_include_pb2 as fti
+import include_other_files_pb2 as iof
 
 
 def test_simple_types():
@@ -52,7 +58,6 @@ def test_simple_types():
     print(str)
     print()
 
-
     x = bytearray([0x08, 0x80, 0x80, 0x80, 0x80, 0x08,
                  0x10, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01,
                  0x28, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F,])
@@ -127,7 +132,7 @@ def test_repeated_fields():
     print(len(msg_str))
     print(msg_str)
     for x in msg_str:
-      str += "0x{:02x}, ".format(x)
+        str += "0x{:02x}, ".format(x)
 
     print(str)
     print()
@@ -136,22 +141,22 @@ def test_repeated_fields():
 def test_repeated_message():
     msg = rf.repeated_message()
 
-    msg.x = 0
+    msg.a = 0
     for i in range(3):
-        nmsg = msg.y.add()
+        nmsg = msg.b.add()
         nmsg.u = 0
         nmsg.v = 0
-    msg.z = 0
+    msg.c = 0
 
-    msg.y[1].u = 1
-    msg.y[1].v = 1
+    msg.b[1].u = 1
+    msg.b[1].v = 1
 
     str = ""
     msg_str = msg.SerializeToString()
     print(len(msg_str))
     print(msg_str)
     for x in msg_str:
-      str += "0x{:02x}, ".format(x)
+        str += "0x{:02x}, ".format(x)
 
     print(str)
     print()
@@ -170,7 +175,32 @@ def test_oneof_fields():
     print(len(msg_str))
     print(msg_str)
     for x in msg_str:
-      str += "0x{:02x}, ".format(x)
+        str += "0x{:02x}, ".format(x)
+
+    print(str)
+    print()
+
+
+def test_included_proto():
+    msg = iof.IncludedMessages()
+
+    msg.state = fti.StateA
+
+    msg.msg.a = 1
+    msg.msg.b = 1.0
+
+    msg.rf.x = 1
+    msg.rf.y.append(1)
+    msg.rf.y.append(1)
+    msg.rf.y.append(1)
+    msg.rf.z = 1
+
+    str = ""
+    msg_str = msg.SerializeToString()
+    print(len(msg_str))
+    print(msg_str)
+    for x in msg_str:
+        str += "0x{:02x}, ".format(x)
 
     print(str)
     print()
@@ -179,4 +209,5 @@ def test_oneof_fields():
 #test_repeated_fields()
 #test_repeated_message()
 #test_nested_message()
-test_oneof_fields()
+#test_oneof_fields()
+test_included_proto()