Просмотр исходного кода

Reworked the template to prevent empty messages from failing to build upon the constructor.

Bart Hertog 5 лет назад
Родитель
Сommit
7f7100f49f
4 измененных файлов с 84 добавлено и 1 удалено
  1. 1 0
      build_test.sh
  2. 2 1
      generator/Header_Template.h
  3. 37 0
      test/proto/empty_message.proto
  4. 44 0
      test/test_empty_messages.cpp

+ 1 - 0
build_test.sh

@@ -40,6 +40,7 @@ protoc --plugin=protoc-gen-eams=protoc-gen-eams -I./test/proto --eams_out=./buil
 # Delibertly do not manually generate file_to_include.proto and subfolder/file_to_include_from_subfolder.proto 
 # to test the automatic generation of files from including them in include_other_files.proto.
 protoc --plugin=protoc-gen-eams=protoc-gen-eams -I./test/proto --eams_out=./build/EAMS ./test/proto/string_bytes.proto
+protoc --plugin=protoc-gen-eams=protoc-gen-eams -I./test/proto --eams_out=./build/EAMS ./test/proto/empty_message.proto
 
 # For validation and testing generate the same message using python
 mkdir -p ./build/python

+ 2 - 1
generator/Header_Template.h

@@ -336,7 +336,8 @@ else
 class {{ msg.name }} final: public ::EmbeddedProto::MessageInterface
 {
   public:
-    {{ msg.name }}() :
+    {{ msg.name }}(){% if (msg.has_fields or msg.has_oneofs) %} :
+    {% endif %}
     {% for field in msg.fields() %}
         {% if field.of_type_enum %}
         {{field.variable_full_name}}({{field.default_value}}){{"," if not loop.last}}

+ 37 - 0
test/proto/empty_message.proto

@@ -0,0 +1,37 @@
+/*
+ *  Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
+ *
+ *  This file is part of Embedded Proto.
+ *
+ *  Embedded Proto is open source software: you can redistribute it and/or 
+ *  modify it under the terms of the GNU General Public License as published 
+ *  by the Free Software Foundation, version 3 of the license.
+ *
+ *  Embedded Proto  is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
+ *
+ *  For commercial and closed source application please visit:
+ *  <https://EmbeddedProto.com/license/>.
+ *
+ *  Embedded AMS B.V.
+ *  Info:
+ *    info at EmbeddedProto dot com
+ *
+ *  Postal address:
+ *    Johan Huizingalaan 763a
+ *    1066 VH, Amsterdam
+ *    the Netherlands
+ */
+
+// This file is used to test serializing repeated fields.
+
+syntax = "proto3";
+
+message empty_message {
+  
+}

+ 44 - 0
test/test_empty_messages.cpp

@@ -0,0 +1,44 @@
+/*
+ *  Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
+ *
+ *  This file is part of Embedded Proto.
+ *
+ *  Embedded Proto is open source software: you can redistribute it and/or 
+ *  modify it under the terms of the GNU General Public License as published 
+ *  by the Free Software Foundation, version 3 of the license.
+ *
+ *  Embedded Proto  is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
+ *
+ *  For commercial and closed source application please visit:
+ *  <https://EmbeddedProto.com/license/>.
+ *
+ *  Embedded AMS B.V.
+ *  Info:
+ *    info at EmbeddedProto dot com
+ *
+ *  Postal address:
+ *    Johan Huizingalaan 763a
+ *    1066 VH, Amsterdam
+ *    the Netherlands
+ */
+
+#include "gtest/gtest.h"
+#include "gmock/gmock.h"
+
+#include "empty_message.h"
+
+namespace test_EmbeddedAMS_empty_messages
+{
+
+TEST(EmptyMessages, construction)
+{
+  empty_message empty;
+}
+
+} // End of namespace test_EmbeddedAMS_empty_messages