Преглед изворни кода

Add field enum generation

- Add optional generation of enum containing field names and their
  number in proto file
- Update tests

Fixes: #108
Alexey Edelev пре 4 година
родитељ
комит
f16b170c35

+ 8 - 1
CMakeLists.txt

@@ -28,7 +28,8 @@ set(GRPC_QUICK_PLUGIN_NAME grpcquickplugin)
 set(QT_PROTOBUF_MAKE_TESTS ON CACHE BOOL "Enable QtProtobuf tests build")
 set(QT_PROTOBUF_MAKE_EXAMPLES ON CACHE BOOL "Enable QtProtobuf examples build")
 set(QT_PROTOBUF_MAKE_COVERAGE OFF CACHE BOOL "Enable QtProtobuf build for profiler (gcov)")
-set(BUILD_SHARED_LIBS ON CACHE BOOL "Enable QtProtobuf static library build (disables shared library build)")
+set(QT_PROTOBUF_FIELD_ENUM OFF CACHE BOOL "Enable generation of enumeration with fields numbers for well-known and Qt types libraries")
+set(BUILD_SHARED_LIBS ON CACHE BOOL "Enable QtProtobuf shared library build (disables static library build)")
 
 if(CMAKE_CROSSCOMPILING)
     set(QT_PROTOBUF_MAKE_TESTS OFF)
@@ -66,6 +67,12 @@ add_subdirectory("src/generator")
 
 add_subdirectory("src/protobuf")
 add_subdirectory("src/grpc")
+
+set(EXTRA_TYPE_LIBRARIES_OPTIONS "") #Prevent to set from outside
+if(QT_PROTOBUF_FIELD_ENUM)
+    set(EXTRA_TYPE_LIBRARIES_OPTIONS "FIELDENUM ${EXTRA_TYPE_LIBRARIES_OPTIONS}")
+endif()
+
 if(NOT WIN32)#TODO: There are linking issues with windows build of well-known types...
     add_subdirectory("src/wellknowntypes")
 endif()

+ 17 - 11
README.md

@@ -45,17 +45,19 @@ QtProtobuf provides Qt-native support of Google protocol buffers. Generated code
 
 ## Build options
 
-*QT_PROTOBUF_MAKE_COVERAGE* - if **TRUE/ON**, enables gcov intergration, to collect code coverage reports(usefull for developers). **FALSE** by default
+*QT_PROTOBUF_MAKE_COVERAGE* - if **TRUE/ON**, enables gcov intergration, to collect code coverage reports(usefull for developers). **FALSE** by default.
 
-*QT_PROTOBUF_MAKE_TESTS* - if **TRUE/ON**, enables tests for QtProtobuf. **TRUE** by default
+*QT_PROTOBUF_MAKE_TESTS* - if **TRUE/ON**, enables tests for QtProtobuf. **TRUE** by default.
 
-*QT_PROTOBUF_MAKE_EXAMPLES* - if **TRUE/ON**, enables built-in examples. **TRUE** by default
+*QT_PROTOBUF_MAKE_EXAMPLES* - if **TRUE/ON**, enables built-in examples. **TRUE** by default.
 
-*QT_PROTOBUF_NATIVE_GRPC_CHANNEL* - if **TRUE/ON**, enables build of an additional channel wrapping native gGRPC C++ library (**Note:** grpc++ library is required)
+*QT_PROTOBUF_NATIVE_GRPC_CHANNEL* - if **TRUE/ON**, enables build of an additional channel wrapping native gGRPC C++ library (**Note:** grpc++ library is required).
 
 *BUILD_SHARED_LIBS* - if **TRUE/ON**, enables shared libraries build, **FALSE** by default, static libraries build is performed.
 
-> **Note:** In case if you use static QtProtobuf in your non-cmake/-qmake build system, you additionaly **need manually** add QT_PROTOBUF_STATIC compiler definition
+> **Note:** In case if you use static QtProtobuf in your non-cmake/-qmake build system, you additionaly **need manually** add QT_PROTOBUF_STATIC compiler definition.
+
+*QT_PROTOBUF_FIELD_ENUM* - if **TRUE/ON**, adds enumeration with message fields for generated messages in QtProtobufTypes and QtProtobufWellKnownTypes libraries. **FALSE** by default.
 
 ## Linux Build
 ### Prerequesties
@@ -137,7 +139,7 @@ sudo zypper --non-interactive in --type pattern devel_C_C++
 
 If required versions of libraries are not found in your system, you may use all-in-one build procedure for prerequesties.
 
-Manually install Qt version you need [](https://www.qt.io/download)
+Manually install Qt version you need [](https://www.qt.io/download).
 
 Update submodules to fetch 3rdparty dependencies:
 
@@ -145,7 +147,7 @@ Update submodules to fetch 3rdparty dependencies:
 git submodule update --init --recursive
 ```
 
->**Note:** All installation rules are disabled for all-in-one build
+>**Note:** All installation rules are disabled for all-in-one build.
 
 #### Option 3: Use as sub-module
 
@@ -298,7 +300,7 @@ To intergrate QtProtobuf add it as a dependency to your conanfile.py:
 ## Direct usage of generator
 
 ```bash
-[QT_PROTOBUF_OPTIONS="[SINGLE|MULTI]:QML:COMMENTS:FOLDER"] protoc --plugin=protoc-gen-qtprotobuf=<path/to/bin/>qtprotobufgen --qtprotobuf_out=<output_dir> [-I/extra/proto/include/path] <protofile>.proto
+[QT_PROTOBUF_OPTIONS="[SINGLE|MULTI]:QML:COMMENTS:FOLDER:FIELDENUM"] protoc --plugin=protoc-gen-qtprotobuf=<path/to/bin/>qtprotobufgen --qtprotobuf_out=<output_dir> [-I/extra/proto/include/path] <protofile>.proto
 ```
 
 ### QT_PROTOBUF_OPTIONS
@@ -306,7 +308,7 @@ To intergrate QtProtobuf add it as a dependency to your conanfile.py:
 For protoc command you also may specify extra options using QT_PROTOBUF_OPTIONS environment variable and colon-separated format:
 
 ``` bash
-[QT_PROTOBUF_OPTIONS="[SINGLE|MULTI]:QML:COMMENTS:FOLDER"] protoc --plugin=protoc-gen-qtprotobuf=<path/to/bin/>qtprotobufgen --qtprotobuf_out=<output_dir> [-I/extra/proto/include/path] <protofile>.proto
+[QT_PROTOBUF_OPTIONS="[SINGLE|MULTI]:QML:COMMENTS:FOLDER:FIELDENUM"] protoc --plugin=protoc-gen-qtprotobuf=<path/to/bin/>qtprotobufgen --qtprotobuf_out=<output_dir> [-I/extra/proto/include/path] <protofile>.proto
 ```
 
 Following options are supported:
@@ -325,6 +327,8 @@ Following options are supported:
 
 *FOLDER* - enables folder-based generation
 
+*FIELDENUM* - adds enumeration with message fields for generated messages.
+
 ## Integration with CMake project
 
 You can integrate QtProtobuf as submodule in your project or as installed in system package. Add following line in your project CMakeLists.txt:
@@ -390,7 +394,7 @@ qtprotobuf_generate is cmake helper function that automatically generates STATIC
 
 ***Options:***
 
-*MULTI* - Enables multi-files generation mode. If provided in parameter list generator will create pair of header/source files for each message
+*MULTI* - Enables multi-files generation mode. If provided in parameter list generator will create pair of header/source files for each message.
 
 >**Note:** multi-files generation mode is defined as deprecated by QtProtobuf team, and might have poor support in future
 
@@ -398,10 +402,12 @@ qtprotobuf_generate is cmake helper function that automatically generates STATIC
 
 *COMMENTS* - Enables comments copying from .proto files. If provided in parameter list message and field related comments will be copied to generated header files.
 
-*FOLDER* - Enables folder based generation. If provided in parameter list generator will place generated artifacts to folder structure according to package of corresponding .proto file
+*FOLDER* - Enables folder based generation. If provided in parameter list generator will place generated artifacts to folder structure according to package of corresponding .proto file.
 
 >**Note:** enabled by default if MULTI option provided
 
+*FIELDENUM* - Adds enumeration with message fields for generated messages.
+
 #### qtprotobuf_link_target
 
 qtprotobuf_link_target is cmake helper function that links generated protobuf target to your binary. It's useful when you try to link generated target to shared library or/and to executable that doesn't utilize all protobuf generated classes directly from C++ code, but requires them from QML.

+ 5 - 1
cmake/QtProtobufGen.cmake

@@ -5,7 +5,7 @@ function(qtprotobuf_link_target TARGET GENERATED_TARGET)
 endfunction()
 
 function(qtprotobuf_generate)
-    set(options MULTI QML COMMENTS FOLDER)
+    set(options MULTI QML COMMENTS FOLDER FIELDENUM)
     set(oneValueArgs OUT_DIR TARGET GENERATED_TARGET)
     set(multiValueArgs GENERATED_HEADERS EXCLUDE_HEADERS PROTO_FILES PROTO_INCLUDES)
     cmake_parse_arguments(qtprotobuf_generate "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
@@ -47,6 +47,10 @@ function(qtprotobuf_generate)
         set(FOLDER_ENABLED "FOLDER")
     endif()
 
+    if(qtprotobuf_generate_FIELDENUM)
+        message(STATUS "Enabled FIELDENUM generation for ${GENERATED_TARGET_NAME}")
+        set(GENERATION_OPTIONS "${GENERATION_OPTIONS}:FIELDENUM")
+    endif()
 
     if(WIN32)
         set(PROTOC_COMMAND set QT_PROTOBUF_OPTIONS=${GENERATION_OPTIONS}&& $<TARGET_FILE:protobuf::protoc>)

+ 4 - 1
cmake/QtProtobufTest.cmake

@@ -3,7 +3,7 @@ find_package(${QT_PROTOBUF_PROJECT} COMPONENTS QtProtobuf QtGrpc REQUIRED)
 include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufCommon.cmake)
 
 function(add_test_target)
-    set(options MULTI QML)
+    set(options MULTI QML FIELDENUM)
     set(oneValueArgs QML_DIR TARGET)
     set(multiValueArgs SOURCES GENERATED_HEADERS EXCLUDE_HEADERS PROTO_FILES PROTO_INCLUDES)
     cmake_parse_arguments(add_test_target "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
@@ -33,6 +33,9 @@ function(add_test_target)
     if(add_test_target_QML)
         set(EXTRA_OPTIONS ${EXTRA_OPTIONS} QML)
     endif()
+    if(add_test_target_FIELDENUM)
+        set(EXTRA_OPTIONS ${EXTRA_OPTIONS} FIELDENUM)
+    endif()
 
     qtprotobuf_generate(TARGET ${add_test_target_TARGET}
         OUT_DIR ${GENERATED_SOURCES_DIR}

+ 1 - 0
src/generator/generatorcommon.cpp

@@ -321,6 +321,7 @@ PropertyMap common::producePropertyMap(const FieldDescriptor *field, const Descr
     propertyMap["key_type"] = "";
     propertyMap["value_type"] = "";
     propertyMap["classname"] = scope != nullptr ? utils::upperCaseName(scope->name()) : "";
+    propertyMap["number"] = std::to_string(field->number());
 
     if (field->is_map()) {
         const Descriptor *type = field->message_type();

+ 5 - 0
src/generator/generatoroptions.cpp

@@ -33,6 +33,7 @@ static const std::string MultifileBuildOption("MULTI");
 static const std::string QmlPluginOption("QML");
 static const std::string CommentsGenerationOption("COMMENTS");
 static const std::string FolderGenerationOption("FOLDER");
+static const std::string FieldEnumGenerationOption("FIELDENUM");
 
 
 using namespace ::QtProtobuf::generator;
@@ -41,6 +42,7 @@ GeneratorOptions::GeneratorOptions() : mIsMulti(false)
   , mHasQml(false)
   , mGenerateComments(false)
   , mIsFolder(false)
+  , mGenerateFieldEnum(false)
 {
 }
 
@@ -61,6 +63,9 @@ void GeneratorOptions::parseFromEnv(const std::string &options)
         } else if (option.compare(FolderGenerationOption) == 0) {
             QT_PROTOBUF_DEBUG("set mIsFolder: true");
             mIsFolder = true;
+        } else if (option.compare(FieldEnumGenerationOption) == 0) {
+            QT_PROTOBUF_DEBUG("set mGenerateFieldEnum: true");
+            mGenerateFieldEnum = true;
         }
     }
 }

+ 2 - 0
src/generator/generatoroptions.h

@@ -50,12 +50,14 @@ public:
     bool hasQml() const { return mHasQml; }
     bool generateComments() const { return mGenerateComments; }
     bool isFolder() const { return mIsFolder; }
+    bool generateFieldEnum() const { return mGenerateFieldEnum; }
 
 private:
     bool mIsMulti;
     bool mHasQml;
     bool mGenerateComments;
     bool mIsFolder;
+    bool mGenerateFieldEnum;
 };
 
 }}

+ 22 - 3
src/generator/messagedeclarationprinter.cpp

@@ -337,12 +337,18 @@ void MessageDeclarationPrinter::printPrivateMethods()
 }
 
 void MessageDeclarationPrinter::printQEnums() {
+    if (GeneratorOptions::instance().generateFieldEnum()) {
+        printFieldEnum();
+        Indent();
+            mPrinter->Print({{"type", Templates::QtProtobufFieldEnum}}, Templates::QEnumTemplate);
+        Outdent();
+        mPrinter->Print("\n");
+    }
+
     if (mDescriptor->enum_type_count() <= 0) {
         return;
     }
 
-    printPublicBlock();
-
     Indent();
     for (int i = 0; i < mDescriptor->enum_type_count(); i++) {
         const auto enumDescr = mDescriptor->enum_type(i);
@@ -371,9 +377,9 @@ void MessageDeclarationPrinter::printQEnums() {
 void MessageDeclarationPrinter::printClassBody()
 {
     printProperties();
-    printQEnums();
 
     printPublicBlock();
+    printQEnums();
     printNested();
     printMaps();
 
@@ -430,3 +436,16 @@ void MessageDeclarationPrinter::printDestructor()
 {
     mPrinter->Print({{"classname", mName}}, "virtual ~$classname$();\n");
 }
+
+void MessageDeclarationPrinter::printFieldEnum()
+{
+    Indent();
+    mPrinter->Print(Templates::FieldEnumTemplate);
+    Indent();
+    common::iterateMessageFields(mDescriptor, [&](const FieldDescriptor *, const PropertyMap &propertyMap) {
+        mPrinter->Print(propertyMap, Templates::FieldNumberTemplate);
+    });
+    Outdent();
+    mPrinter->Print(Templates::SemicolonBlockEnclosureTemplate);
+    Outdent();
+}

+ 1 - 0
src/generator/messagedeclarationprinter.h

@@ -66,6 +66,7 @@ private:
     void printNested();
     void printMetaTypesDeclaration();
     void printClassDeclarationBegin();
+    void printFieldEnum();
 
     void printQEnums();
 

+ 4 - 0
src/generator/templates.cpp

@@ -393,3 +393,7 @@ const char *Templates::EnumClassSuffix = "Gadget";
 
 const char *Templates::QtProtobufNamespace = "QtProtobuf";
 const char *Templates::QtProtobufNestedNamespace = "_QtProtobufNested";
+
+const char *Templates::QtProtobufFieldEnum = "QtProtobufFieldEnum";
+const char *Templates::FieldEnumTemplate = "enum QtProtobufFieldEnum {\n";
+const char *Templates::FieldNumberTemplate = "$property_name_cap$ProtoFieldNumber = $number$,\n";

+ 4 - 0
src/generator/templates.h

@@ -211,6 +211,10 @@ public:
 
     static const char *QtProtobufNamespace;
     static const char *QtProtobufNestedNamespace;
+
+    static const char *FieldEnumTemplate;
+    static const char *FieldNumberTemplate;
+    static const char *QtProtobufFieldEnum;
 };
 
 } //namespace generator

+ 1 - 1
src/qttypes/CMakeLists.txt

@@ -41,7 +41,7 @@ file(GLOB PROTO_FILE ${CMAKE_CURRENT_SOURCE_DIR}/QtProtobuf/Qt*.proto)
 qtprotobuf_generate(TARGET ${TARGET}
     OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated
     PROTO_FILES ${PROTO_FILE}
-    QML FOLDER)
+    QML FOLDER ${EXTRA_TYPE_LIBRARIES_OPTIONS})
 
 target_compile_definitions(${TARGET} PRIVATE QT_BUILD_PROTOBUF_QT_TYPES_LIB PUBLIC QT_PROTOBUF_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
     QT_PROTOBUF_VERSION_MINOR=${PROJECT_VERSION_MINOR})

+ 1 - 1
src/wellknowntypes/CMakeLists.txt

@@ -39,7 +39,7 @@ function(add_wellknowntype TYPENAME)
                 OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated
                 PROTO_FILES ${PROTO_FILE}
                 PROTO_INCLUDES "-I\"${INCLUDE_DIR}\""
-                QML FOLDER)
+                QML FOLDER ${EXTRA_TYPE_LIBRARIES_OPTIONS})
             target_include_directories(${TYPENAME} PRIVATE
                 $<TARGET_PROPERTY:${QT_PROTOBUF_PROJECT}::QtProtobufWellKnownTypes,INTERFACE_INCLUDE_DIRECTORIES>)
             get_target_property(GENERATED_PUBLIC_HEADER_PRIVATE ${TYPENAME} PUBLIC_HEADER)

+ 1 - 1
tests/test_protobuf/CMakeLists.txt

@@ -18,7 +18,7 @@ endif()
 
 add_test_target(TARGET ${TARGET}
     SOURCES ${SOURCES}
-    QML)
+    QML FIELDENUM)
 add_target_windeployqt(TARGET ${TARGET}
     QML_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 

+ 28 - 0
tests/test_protobuf/simpletest.cpp.inc

@@ -60,6 +60,8 @@ TEST_F(SimpleTest, SimpleBoolMessageTest)
     ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(true)));
     ASSERT_EQ(test.property(propertyName).value<bool>(), true);
     ASSERT_EQ(test.testFieldBool(), true);
+
+    EXPECT_EQ(SimpleBoolMessage::TestFieldBoolProtoFieldNumber, 1);
 }
 
 TEST_F(SimpleTest, SimpleIntMessageTest)
@@ -71,6 +73,8 @@ TEST_F(SimpleTest, SimpleIntMessageTest)
     ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int32>(1)));
     ASSERT_EQ(test.property(propertyName).value<int32>(), 1);
     ASSERT_EQ(test.testFieldInt(), 1);
+
+    EXPECT_EQ(SimpleIntMessage::TestFieldIntProtoFieldNumber, 1);
 }
 
 TEST_F(SimpleTest, SimpleSIntMessageTest)
@@ -82,6 +86,8 @@ TEST_F(SimpleTest, SimpleSIntMessageTest)
     ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint32>(1)));
     ASSERT_EQ(test.property(propertyName).value<sint32>(), 1);
     ASSERT_EQ(test.testFieldInt(), 1);
+
+    EXPECT_EQ(SimpleSIntMessage::TestFieldIntProtoFieldNumber, 1);
 }
 
 TEST_F(SimpleTest, SimpleUIntMessageTest)
@@ -93,6 +99,8 @@ TEST_F(SimpleTest, SimpleUIntMessageTest)
     ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<uint32>(1)));
     ASSERT_EQ(test.property(propertyName).value<uint32>(), 1);
     ASSERT_EQ(test.testFieldInt(), 1);
+
+    EXPECT_EQ(SimpleUIntMessage::TestFieldIntProtoFieldNumber, 1);
 }
 
 TEST_F(SimpleTest, SimpleInt64MessageTest)
@@ -104,6 +112,8 @@ TEST_F(SimpleTest, SimpleInt64MessageTest)
     ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int64>(1)));
     ASSERT_EQ(test.property(propertyName).value<int64>(), 1);
     ASSERT_EQ(test.testFieldInt(), 1);
+
+    EXPECT_EQ(SimpleInt64Message::TestFieldIntProtoFieldNumber, 1);
 }
 
 TEST_F(SimpleTest, SimpleSInt64MessageTest)
@@ -115,6 +125,8 @@ TEST_F(SimpleTest, SimpleSInt64MessageTest)
     ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint64>(1)));
     ASSERT_EQ(test.property(propertyName).value<sint64>(), 1);
     ASSERT_EQ(test.testFieldInt(), 1);
+
+    EXPECT_EQ(SimpleSInt64Message::TestFieldIntProtoFieldNumber, 1);
 }
 
 TEST_F(SimpleTest, SimpleUInt64MessageTest)
@@ -126,6 +138,8 @@ TEST_F(SimpleTest, SimpleUInt64MessageTest)
     ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<uint64>(1)));
     ASSERT_EQ(test.property(propertyName).value<uint64>(), 1);
     ASSERT_EQ(test.testFieldInt(), 1);
+
+    EXPECT_EQ(SimpleUInt64Message::TestFieldIntProtoFieldNumber, 1);
 }
 
 TEST_F(SimpleTest, SimpleFixedInt32MessageTest)
@@ -137,6 +151,8 @@ TEST_F(SimpleTest, SimpleFixedInt32MessageTest)
     ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<fixed32>(1)));
     ASSERT_EQ(test.property(propertyName).value<fixed32>(), 1);
     ASSERT_EQ(test.testFieldFixedInt32(), 1);
+
+    EXPECT_EQ(SimpleFixedInt32Message::TestFieldFixedInt32ProtoFieldNumber, 1);
 }
 
 TEST_F(SimpleTest, SimpleFixedInt64MessageTest)
@@ -148,6 +164,8 @@ TEST_F(SimpleTest, SimpleFixedInt64MessageTest)
     ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<fixed64>(1)));
     ASSERT_EQ(test.property(propertyName).value<fixed64>(), 1);
     ASSERT_EQ(test.testFieldFixedInt64(), 1);
+
+    EXPECT_EQ(SimpleFixedInt64Message::TestFieldFixedInt64ProtoFieldNumber, 1);
 }
 
 TEST_F(SimpleTest, SimpleSFixedInt32MessageTest)
@@ -159,6 +177,8 @@ TEST_F(SimpleTest, SimpleSFixedInt32MessageTest)
     ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sfixed32>(1)));
     ASSERT_EQ(test.property(propertyName).value<sfixed32>(), 1);
     ASSERT_EQ(test.testFieldFixedInt32(), 1);
+
+    EXPECT_EQ(SimpleSFixedInt32Message::TestFieldFixedInt32ProtoFieldNumber, 1);
 }
 
 TEST_F(SimpleTest, SimpleSFixedInt64MessageTest)
@@ -170,6 +190,8 @@ TEST_F(SimpleTest, SimpleSFixedInt64MessageTest)
     ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sfixed64>(1)));
     ASSERT_EQ(test.property(propertyName).value<sfixed64>(), 1);
     ASSERT_EQ(test.testFieldFixedInt64(), 1);
+
+    EXPECT_EQ(SimpleSFixedInt64Message::TestFieldFixedInt64ProtoFieldNumber, 1);
 }
 
 TEST_F(SimpleTest, SimpleStringMessageTest)
@@ -182,6 +204,8 @@ TEST_F(SimpleTest, SimpleStringMessageTest)
     ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(QString("test1"))));
     ASSERT_STREQ(test.property(propertyName).toString().toStdString().c_str(), "test1");
     ASSERT_STREQ(test.testFieldString().toStdString().c_str(), "test1");
+
+    EXPECT_EQ(SimpleStringMessage::TestFieldStringProtoFieldNumber, 6);
 }
 
 TEST_F(SimpleTest, SimpleFloatMessageTest)
@@ -196,6 +220,8 @@ TEST_F(SimpleTest, SimpleFloatMessageTest)
     ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<float>(assignedValue)));
     ASSERT_FLOAT_EQ(test.property(propertyName).toFloat(), assignedValue);
     ASSERT_FLOAT_EQ(test.testFieldFloat(), assignedValue);
+
+    EXPECT_EQ(SimpleFloatMessage::TestFieldFloatProtoFieldNumber, 7);
 }
 
 TEST_F(SimpleTest, SimpleDoubleMessageTest)
@@ -210,6 +236,8 @@ TEST_F(SimpleTest, SimpleDoubleMessageTest)
     ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<double>(assignedValue)));
     ASSERT_DOUBLE_EQ(test.property(propertyName).toDouble(), assignedValue);
     ASSERT_DOUBLE_EQ(test.testFieldDouble(), assignedValue);
+
+    EXPECT_EQ(SimpleDoubleMessage::TestFieldDoubleProtoFieldNumber, 8);
 }
 
 TEST_F(SimpleTest, SimpleLocalEnumTest)

+ 2 - 1
tests/test_protobuf_multifile/CMakeLists.txt

@@ -12,7 +12,8 @@ add_test_target(TARGET ${TARGET}
     PROTO_FILES ${PROTO_FILES}
     SOURCES ${SOURCES}
     QML
-    MULTI)
+    MULTI
+    FIELDENUM)
 add_target_windeployqt(TARGET ${TARGET}
     QML_DIR ${CMAKE_CURRENT_SOURCE_DIR})