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

Add common qtprotobuf_global.pb.h for types registration

- Add common qtprotobuf_global.pb.h for types registration
- Replace type-by-type registration by common package-wide
  registration
- Apply hack to simple chat, because of trash in std::string
- Rename registerProtobufTypes() to qRegisterProtobufTypes()
- Update README accorging to changed
- Code cleanup
Alexey Edelev пре 5 година
родитељ
комит
79db2ab057

+ 7 - 1
README.md

@@ -130,13 +130,15 @@ To enable QtProtobuf project you need to register protobuf types. It's good prac
 ...
 int main(int argc, char *argv[])
 {
-    QtProtobuf::registerProtoTypes();
+    QtProtobuf::qRegisterProtobufTypes();
     ... //Qt application initialization and run
 }
 ```
 
 **For each generated class you also need to call 'qRegisterProtobufType<GeneratedClassName>' to enable serialization and QML support**
 
+**Other option is to include common "qtprotobuf_global.pb.h" file and call apptopriate qRegisterProtobufTypes() method for you package**
+
 ## CMake functions reference
 
 ### generate_qtprotobuf
@@ -157,6 +159,10 @@ Due to cmake restrictions it's required to specify resulting artifacts manually
 
 *PROTO_FILES* - List of .proto files that will be used in generation procedure
 
+*MULTI* - Enabled/disabled multi-files generation mode. In case if this property is set to TRUE 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
+
 **Outcome:**
 
 *QtProtobuf_GENERATED* - variable that will contain generated STATIC library target name

+ 0 - 9
examples/addressbook/addressbookengine.cpp

@@ -28,7 +28,6 @@
 #include "addressbook.pb.h"
 #include "addressbook_grpc.pb.h"
 
-//#include "addressbookclient.h"
 #include <QGrpcHttp2Channel>
 #include <InsecureCredentials>
 #include <SslCredentials>
@@ -53,14 +52,6 @@ AddressBookEngine::AddressBookEngine() : QObject()
   , m_contacts(new ContactsListModel({}, this))
   , m_callStatus(CallStatus::Inactive)
 {
-    qRegisterProtobufType<Contact>();
-    qRegisterProtobufType<ListFrame>();
-    qRegisterProtobufType<CallStatus>();
-    qRegisterProtobufType<PhoneNumber>();
-    qRegisterProtobufType<None>();
-    qRegisterProtobufType<Address>();
-    qRegisterProtobufType<Job>();
-
     //Prepare ssl configuration
     QSslConfiguration conf = QSslConfiguration::defaultConfiguration();
     QFile certFile("cert.pem");

+ 0 - 3
examples/addressbook/addressbookengine.h

@@ -27,9 +27,6 @@
 
 #include <QObject>
 #include "addressbook.pb.h"
-//#include "contacts.h"
-//#include "callstatus.h"
-
 
 #include "universallistmodel.h"
 

+ 4 - 3
examples/addressbook/main.cpp

@@ -31,8 +31,7 @@
 
 #include "addressbookengine.h"
 #include "addressbook.pb.h"
-//#include <contacts.h>
-//#include <contact.h>
+#include "qtprotobuf_global.pb.h"
 
 #include <QMetaProperty>
 #include <QQmlPropertyMap>
@@ -41,7 +40,9 @@ using namespace qtprotobuf::examples;
 
 int main(int argc, char *argv[])
 {
-    QtProtobuf::registerProtoTypes();
+    QtProtobuf::qRegisterProtobufTypes();
+    qtprotobuf::examples::qRegisterProtobufTypes();
+
     QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
 
     qmlRegisterType<ContactsListModel>("examples.addressbook", 1, 0, "ContactsListModel");

+ 4 - 4
examples/simplechat/main.cpp

@@ -30,10 +30,8 @@
 #include <QQmlContext>
 
 #include "simplechat.pb.h"
+#include "qtprotobuf_global.pb.h"
 
-//#include <chatmessage.h>
-//#include <user.h>
-//#include <chatmessages.h>
 #include "simplechatengine.h"
 
 #include <QMetaProperty>
@@ -44,7 +42,9 @@ using namespace qtprotobuf::examples;
 
 int main(int argc, char *argv[])
 {
-    QtProtobuf::registerProtoTypes();
+    QtProtobuf::qRegisterProtobufTypes();
+    qtprotobuf::examples::qRegisterProtobufTypes();
+
     QGuiApplication app(argc, argv);
 
     QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

+ 0 - 3
examples/simplechat/simplechatengine.cpp

@@ -56,9 +56,6 @@ public:
 SimpleChatEngine::SimpleChatEngine(QObject *parent) : QObject(parent), m_client(new SimpleChatClient)
   , m_clipBoard(QGuiApplication::clipboard())
 {
-    qRegisterProtobufType<ChatMessage>();
-    qRegisterProtobufType<ChatMessages>();
-
     if (m_clipBoard) {
         connect(m_clipBoard, &QClipboard::dataChanged, this, &SimpleChatEngine::clipBoardContentTypeChanged);
     }

+ 0 - 3
examples/simplechat/simplechatengine.h

@@ -30,9 +30,6 @@
 #include "simplechat.pb.h"
 #include "simplechat_grpc.pb.h"
 
-//#include <chatmessages.h>
-//#include "simplechatclient.h"
-
 #include "universallistmodel.h"
 
 class QClipboard;

+ 7 - 6
examples/simplechatserver/main.cpp

@@ -62,11 +62,12 @@ public:
     }
 
     std::tuple<std::string, std::string> extractCredentials(grpc::ServerContext *context) {
-        std::string name{};
-        std::string password{};
+        std::string name{""};
+        std::string password{""};
         for (auto it = context->client_metadata().begin(); it != context->client_metadata().end(); ++it) {
             if ((*it).first == std::string("user-name")) {
                 name = std::string((*it).second.data());
+                name.resize(5);
             }
             if ((*it).first == std::string("user-password")) {
                 password = std::string((*it).second.data());
@@ -78,8 +79,8 @@ public:
 
     ::grpc::Status sendMessage(grpc::ServerContext *context, const ChatMessage *request, None *) override
     {
-        std::string name{};
-        std::string password{};
+        std::string name{""};
+        std::string password{""};
         std::tie(name, password) = extractCredentials(context);
         if (!checkUserCredentials(name, password)) {
             return ::grpc::Status(::grpc::StatusCode::UNAUTHENTICATED, "User or login are invalid");
@@ -149,8 +150,8 @@ int main(int argc, char *argv[])
             continue;
         }
         if ((*tag) == 0xdeadbeef) {
-            std::string name{};
-            std::string password{};
+            std::string name{""};
+            std::string password{""};
             std::tie(name, password) = service.extractCredentials(&(last->ctx_));
             if (!service.checkUserCredentials(name, password)) {
                 std::cout << "Authentication failed" << std::endl;

+ 4 - 2
src/generator/CMakeLists.txt

@@ -17,7 +17,8 @@ file(GLOB SOURCES main.cpp
     classsourcegeneratorbase.cpp
     protobufsourcegenerator.cpp
     clientsourcegenerator.cpp
-    singlefilegenerator.cpp)
+    singlefilegenerator.cpp
+    generatorbase.cpp)
 
 file(GLOB HEADERS classgeneratorbase.h
     classsourcegeneratorbase.h
@@ -32,7 +33,8 @@ file(GLOB HEADERS classgeneratorbase.h
     servicegeneratorbase.h
     templates.h
     utils.h
-    singlefilegenerator.h)
+    singlefilegenerator.h
+    generatorbase.h)
 
 add_executable(${TARGET} ${SOURCES})
 

+ 4 - 1
src/generator/generator.cpp

@@ -47,6 +47,9 @@ using namespace ::QtProtobuf::generator;
 using namespace ::google::protobuf;
 using namespace ::google::protobuf::compiler;
 
+QtGenerator::QtGenerator() : GeneratorBase(GeneratorBase::MultiMode)
+{}
+
 bool QtGenerator::Generate(const FileDescriptor *file,
                            const std::string &parameter,
                            GeneratorContext *generatorContext,
@@ -137,6 +140,6 @@ bool QtGenerator::GenerateAll(const std::vector<const FileDescriptor *> &files,
     enumSourceGen.printHeaders();
     enumSourceGen.run();
 
-    return CodeGenerator::GenerateAll(files, parameter, generatorContext, error);
+    return GeneratorBase::GenerateAll(files, parameter, generatorContext, error);
 }
 

+ 5 - 2
src/generator/generator.h

@@ -30,6 +30,8 @@
 #include <string>
 #include <memory>
 
+#include "generatorbase.h"
+
 namespace google { namespace protobuf {
 class FileDescriptor;
 namespace compiler {
@@ -39,8 +41,10 @@ class GeneratorContext;
 namespace QtProtobuf {
 namespace generator {
 
-class QtGenerator : public ::google::protobuf::compiler::CodeGenerator
+class QtGenerator : public GeneratorBase
 {
+public:
+    QtGenerator();
     bool Generate(const ::google::protobuf::FileDescriptor *file,
                           const std::string &parameter,
                           ::google::protobuf::compiler::GeneratorContext *generatorContext,
@@ -50,7 +54,6 @@ class QtGenerator : public ::google::protobuf::compiler::CodeGenerator
                              const std::string &parameter,
                              ::google::protobuf::compiler::GeneratorContext *generatorContext,
                              std::string *error) const override;
-    bool HasGenerateAll() const override { return true; }
 };
 
 } //namespace generator

+ 131 - 0
src/generator/generatorbase.cpp

@@ -0,0 +1,131 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>
+ *
+ * This file is part of QtProtobuf project https://git.semlanik.org/semlanik/qtprotobuf
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this
+ * software and associated documentation files (the "Software"), to deal in the Software
+ * without restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
+ * to permit persons to whom the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies
+ * or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+ * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "generatorbase.h"
+
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/io/printer.h>
+#include <google/protobuf/io/zero_copy_stream.h>
+
+#include "utils.h"
+#include "templates.h"
+
+using namespace ::QtProtobuf::generator;
+using namespace ::google::protobuf;
+using namespace ::google::protobuf::compiler;
+
+GeneratorBase::GeneratorBase(Mode mode) : m_mode(mode)
+{
+
+}
+void GeneratorBase::iterateNonNestedFileds(const ::google::protobuf::FileDescriptor *file, std::function<void(const ::google::protobuf::Descriptor *)> callback) const
+{
+    for (int i = 0; i < file->message_type_count(); i++) {
+        const Descriptor *message = file->message_type(i);
+
+        //Detect nested fields and filter maps fields
+        int mapsFieldsCount = 0;
+        for (int j = 0; j < message->nested_type_count(); j++) {
+            for (int k = 0; k < message->field_count(); k++) {
+                if (message->field(k)->is_map() && message->field(k)->message_type() == message->nested_type(j)) {
+                    ++mapsFieldsCount;
+                }
+            }
+        }
+
+        if (message->nested_type_count() > 0 && message->nested_type_count() > mapsFieldsCount) {
+            std::cerr << file->name() << ":" << (message->index() + 1) << ": " << " Error: Meta object features not supported for nested classes in " << message->full_name() << std::endl;
+            continue;
+        }
+        callback(message);
+    }
+}
+
+bool GeneratorBase::GenerateAll(const std::vector<const FileDescriptor *> &files, const string &parameter, GeneratorContext *generatorContext, string *error) const
+{
+    PackagesList packageList;
+    for (auto file : files) {
+        packageList[file->package()].push_back(file);
+    }
+
+    std::shared_ptr<io::ZeroCopyOutputStream> outfHeader(generatorContext->Open(Templates::GlobalDeclarationsFilename + Templates::ProtoFileSuffix + ".h"));
+    std::shared_ptr<::google::protobuf::io::Printer> outfHeaderPrinter(new ::google::protobuf::io::Printer(outfHeader.get(), '$'));
+
+    outfHeaderPrinter->Print(Templates::DisclaimerTemplate);
+    outfHeaderPrinter->Print(Templates::PreambleTemplate);
+    outfHeaderPrinter->Print(Templates::DefaultProtobufIncludesTemplate);
+
+    bool addGlobalEnumsHeader = false;
+    for (auto file : files) {
+        if (m_mode == SingleMode) {
+            if (file->message_type_count() > 0) {
+                outfHeaderPrinter->Print({{"include", utils::extractFileName(file->name()) + Templates::ProtoFileSuffix}}, Templates::InternalIncludeTemplate);
+            }
+        } else {
+            iterateNonNestedFileds(file, [&outfHeaderPrinter, file, &addGlobalEnumsHeader](const ::google::protobuf::Descriptor *message) {
+                std::string messageName = message->name();
+                utils::tolower(messageName);
+                outfHeaderPrinter->Print({{"include", messageName}}, Templates::InternalIncludeTemplate);
+                if (file->enum_type_count() > 0) {
+                    addGlobalEnumsHeader = true;
+                }
+            });
+        }
+    }
+
+    if (addGlobalEnumsHeader) {
+        outfHeaderPrinter->Print({{"include", "globalenums"}}, Templates::InternalIncludeTemplate);
+    }
+
+    for (auto package : packageList) {
+        std::vector<std::string> namespaces;
+        utils::split(package.first, namespaces, '.');
+        for (auto ns : namespaces) {
+            outfHeaderPrinter->Print({{"namespace", ns}}, Templates::NamespaceTemplate);
+        }
+        outfHeaderPrinter->Print("inline void qRegisterProtobufTypes() {\n");
+        outfHeaderPrinter->Indent();
+        outfHeaderPrinter->Indent();
+        for (auto file : package.second) {
+            iterateNonNestedFileds(file, [&outfHeaderPrinter](const ::google::protobuf::Descriptor *message) {
+                outfHeaderPrinter->Print({{"classname", message->name()}}, "qRegisterProtobufType<$classname$>();\n");
+            });
+
+            if (file->enum_type_count() > 0) {
+                outfHeaderPrinter->Print("GlobalEnums::registerTypes();\n");
+            }
+        }
+        outfHeaderPrinter->Outdent();
+        outfHeaderPrinter->Outdent();
+        outfHeaderPrinter->Print("}\n");
+        for (size_t i = 0; i < namespaces.size(); i++) {
+            outfHeaderPrinter->Print("}\n");
+        }
+    }
+
+    return CodeGenerator::GenerateAll(files, parameter, generatorContext, error);
+}

+ 68 - 0
src/generator/generatorbase.h

@@ -0,0 +1,68 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>
+ *
+ * This file is part of QtProtobuf project https://git.semlanik.org/semlanik/qtprotobuf
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this
+ * software and associated documentation files (the "Software"), to deal in the Software
+ * without restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
+ * to permit persons to whom the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies
+ * or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+ * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#pragma once
+
+#include <google/protobuf/compiler/code_generator.h>
+#include <google/protobuf/io/zero_copy_stream.h>
+#include <string>
+#include <memory>
+#include <functional>
+
+namespace google { namespace protobuf {
+class FileDescriptor;
+class Descriptor;
+namespace compiler {
+class GeneratorContext;
+}}}
+
+namespace QtProtobuf {
+namespace generator {
+
+class GeneratorBase: public ::google::protobuf::compiler::CodeGenerator
+{
+public:
+    enum Mode {
+        SingleMode = 0,
+        MultiMode,
+    };
+    GeneratorBase(Mode mode);
+    virtual ~GeneratorBase() = default;
+
+    virtual bool GenerateAll(const std::vector<const ::google::protobuf::FileDescriptor *> &files,
+                             const std::string &parameter,
+                             ::google::protobuf::compiler::GeneratorContext *generatorContext,
+                             std::string *error) const override;
+    bool HasGenerateAll() const override { return true; }
+
+protected:
+    void iterateNonNestedFileds(const ::google::protobuf::FileDescriptor *file, std::function<void(const ::google::protobuf::Descriptor *)> callback) const;
+
+private:
+    Mode m_mode;
+};
+
+}
+}

+ 13 - 83
src/generator/singlefilegenerator.cpp

@@ -43,14 +43,13 @@
 #include <google/protobuf/io/zero_copy_stream.h>
 #include <google/protobuf/descriptor.h>
 
-static const char *protoFileSuffix = ".pb";
-static const char *grpcFileSuffix = "_grpc";
-static const std::string globalDeclarationsFilename = std::string("globaldeclarations") + protoFileSuffix;
-
 using namespace ::QtProtobuf::generator;
 using namespace ::google::protobuf;
 using namespace ::google::protobuf::compiler;
 
+SingleFileGenerator::SingleFileGenerator() : GeneratorBase(GeneratorBase::SingleMode)
+{}
+
 bool SingleFileGenerator::Generate(const FileDescriptor *file,
                                    const std::string &parameter,
                                    GeneratorContext *generatorContext,
@@ -65,74 +64,6 @@ bool SingleFileGenerator::Generate(const FileDescriptor *file,
             && GenerateServices(file, parameter, generatorContext, error);
 }
 
-bool SingleFileGenerator::GenerateAll(const std::vector<const FileDescriptor *> &files, const string &parameter, GeneratorContext *generatorContext, string *error) const
-{
-    PackagesList packageList;
-    for (auto file : files) {
-        packageList[file->package()].push_back(file);
-    }
-
-    std::shared_ptr<io::ZeroCopyOutputStream> outfHeader(generatorContext->Open(globalDeclarationsFilename + ".h"));
-    std::shared_ptr<::google::protobuf::io::Printer> outfHeaderPrinter(new ::google::protobuf::io::Printer(outfHeader.get(), '$'));
-
-    outfHeaderPrinter->Print(Templates::DisclaimerTemplate);
-    outfHeaderPrinter->Print(Templates::PreambleTemplate);
-    outfHeaderPrinter->Print(Templates::DefaultProtobufIncludesTemplate);
-
-    for (auto file : files) {
-        if (file->message_type_count() > 0) {
-            outfHeaderPrinter->Print({{"include", utils::extractFileName(file->name()) + protoFileSuffix}}, Templates::InternalIncludeTemplate);
-        }
-    }
-
-    for (auto package : packageList) {
-        std::vector<std::string> namespaces;
-        utils::split(package.first, namespaces, '.');
-        for (auto ns : namespaces) {
-            outfHeaderPrinter->Print({{"namespace", ns}}, Templates::NamespaceTemplate);
-        }
-        outfHeaderPrinter->Print("inline void qRegisterProtobufTypes() {\n");
-        outfHeaderPrinter->Indent();
-        outfHeaderPrinter->Indent();
-        for (auto file : package.second) {
-            iterateNonNestedFileds(file, [&outfHeaderPrinter](const ::google::protobuf::Descriptor *message){
-                outfHeaderPrinter->Print({{"classname", message->name()}}, "qRegisterProtobufType<$classname$>();\n");
-            });
-        }
-        outfHeaderPrinter->Outdent();
-        outfHeaderPrinter->Outdent();
-        outfHeaderPrinter->Print("}\n");
-        for (size_t i = 0; i < namespaces.size(); i++) {
-            outfHeaderPrinter->Print("}\n");
-        }
-    }
-
-    return CodeGenerator::GenerateAll(files, parameter, generatorContext, error);
-}
-
-void SingleFileGenerator::iterateNonNestedFileds(const ::google::protobuf::FileDescriptor *file, std::function<void(const ::google::protobuf::Descriptor *)> callback) const
-{
-    for (int i = 0; i < file->message_type_count(); i++) {
-        const Descriptor *message = file->message_type(i);
-
-        //Detect nested fields and filter maps fields
-        int mapsFieldsCount = 0;
-        for (int j = 0; j < message->nested_type_count(); j++) {
-            for (int k = 0; k < message->field_count(); k++) {
-                if (message->field(k)->is_map() && message->field(k)->message_type() == message->nested_type(j)) {
-                    ++mapsFieldsCount;
-                }
-            }
-        }
-
-        if (message->nested_type_count() > 0 && message->nested_type_count() > mapsFieldsCount) {
-            std::cerr << file->name() << ":" << (message->index() + 1) << ": " << " Error: Meta object features not supported for nested classes in " << message->full_name() << std::endl;
-            continue;
-        }
-        callback(message);
-    }
-}
-
 bool SingleFileGenerator::GenerateMessages(const ::google::protobuf::FileDescriptor *file,
                                            const std::string &,
                                            ::google::protobuf::compiler::GeneratorContext *generatorContext,
@@ -144,8 +75,8 @@ bool SingleFileGenerator::GenerateMessages(const ::google::protobuf::FileDescrip
     std::string outFileBasename = utils::extractFileName(file->name());
     std::set<std::string> internalIncludes;
     std::set<std::string> externalIncludes;
-    std::shared_ptr<io::ZeroCopyOutputStream> outHeader(generatorContext->Open(outFileBasename + protoFileSuffix + ".h"));
-    std::shared_ptr<io::ZeroCopyOutputStream> outSource(generatorContext->Open(outFileBasename + protoFileSuffix + ".cpp"));
+    std::shared_ptr<io::ZeroCopyOutputStream> outHeader(generatorContext->Open(outFileBasename + Templates::ProtoFileSuffix + ".h"));
+    std::shared_ptr<io::ZeroCopyOutputStream> outSource(generatorContext->Open(outFileBasename + Templates::ProtoFileSuffix + ".cpp"));
     std::shared_ptr<::google::protobuf::io::Printer> outHeaderPrinter(new ::google::protobuf::io::Printer(outHeader.get(), '$'));
     std::shared_ptr<::google::protobuf::io::Printer> outSourcePrinter(new ::google::protobuf::io::Printer(outSource.get(), '$'));
 
@@ -155,13 +86,13 @@ bool SingleFileGenerator::GenerateMessages(const ::google::protobuf::FileDescrip
     outHeaderPrinter->Print(Templates::DefaultProtobufIncludesTemplate);
 
     outSourcePrinter->Print(Templates::DisclaimerTemplate);
-    outSourcePrinter->Print({{"include", outFileBasename + protoFileSuffix}}, Templates::InternalIncludeTemplate);
+    outSourcePrinter->Print({{"include", outFileBasename + Templates::ProtoFileSuffix}}, Templates::InternalIncludeTemplate);
 
     externalIncludes.insert("QByteArray");
     externalIncludes.insert("QString");
 
     for (int i = 0; i < file->dependency_count(); i++) {
-        internalIncludes.insert(utils::extractFileName(file->dependency(i)->name()) + protoFileSuffix);
+        internalIncludes.insert(utils::extractFileName(file->dependency(i)->name()) + Templates::ProtoFileSuffix);
     }
 
     for(auto include : externalIncludes) {
@@ -250,8 +181,8 @@ bool SingleFileGenerator::GenerateServices(const ::google::protobuf::FileDescrip
     std::string outFileBasename = utils::extractFileName(file->name());
     std::set<std::string> internalIncludes;
     std::set<std::string> externalIncludes;
-    std::shared_ptr<io::ZeroCopyOutputStream> outHeader(generatorContext->Open(outFileBasename + grpcFileSuffix + protoFileSuffix + ".h"));
-    std::shared_ptr<io::ZeroCopyOutputStream> outSource(generatorContext->Open(outFileBasename + grpcFileSuffix + protoFileSuffix + ".cpp"));
+    std::shared_ptr<io::ZeroCopyOutputStream> outHeader(generatorContext->Open(outFileBasename + Templates::GrpcFileSuffix + Templates::ProtoFileSuffix + ".h"));
+    std::shared_ptr<io::ZeroCopyOutputStream> outSource(generatorContext->Open(outFileBasename + Templates::GrpcFileSuffix + Templates::ProtoFileSuffix + ".cpp"));
     std::shared_ptr<::google::protobuf::io::Printer> outHeaderPrinter(new ::google::protobuf::io::Printer(outHeader.get(), '$'));
     std::shared_ptr<::google::protobuf::io::Printer> outSourcePrinter(new ::google::protobuf::io::Printer(outSource.get(), '$'));
 
@@ -260,18 +191,18 @@ bool SingleFileGenerator::GenerateServices(const ::google::protobuf::FileDescrip
     outHeaderPrinter->Print(Templates::DefaultProtobufIncludesTemplate);
 
     outSourcePrinter->Print(Templates::DisclaimerTemplate);
-    outSourcePrinter->Print({{"include", outFileBasename + grpcFileSuffix + protoFileSuffix}}, Templates::InternalIncludeTemplate);
+    outSourcePrinter->Print({{"include", outFileBasename + Templates::GrpcFileSuffix + Templates::ProtoFileSuffix}}, Templates::InternalIncludeTemplate);
 
     for (int i = 0; i < file->service_count(); i++) {
         const ServiceDescriptor *service = file->service(i);
         for (int i = 0; i < service->method_count(); i++) {
             const MethodDescriptor *method = service->method(i);
             if (method->input_type()->file() != service->file()) {
-                internalIncludes.insert(utils::extractFileName(method->input_type()->file()->name()) + protoFileSuffix);
+                internalIncludes.insert(utils::extractFileName(method->input_type()->file()->name()) + Templates::ProtoFileSuffix);
             }
 
             if (method->output_type()->file() != service->file()) {
-                internalIncludes.insert(utils::extractFileName(method->output_type()->file()->name()) + protoFileSuffix);
+                internalIncludes.insert(utils::extractFileName(method->output_type()->file()->name()) + Templates::ProtoFileSuffix);
             }
         }
     }
@@ -280,9 +211,8 @@ bool SingleFileGenerator::GenerateServices(const ::google::protobuf::FileDescrip
     externalIncludes.insert("QAbstractGrpcClient");
     externalIncludes.insert("QGrpcAsyncReply");
 
-    internalIncludes.insert(globalDeclarationsFilename);
     if (file->message_type_count() > 0) {
-        internalIncludes.insert(outFileBasename + protoFileSuffix);
+        internalIncludes.insert(outFileBasename + Templates::ProtoFileSuffix);
     }
     for(auto include : externalIncludes) {
         outHeaderPrinter->Print({{"include", include}}, Templates::ExternalIncludeTemplate);

+ 4 - 11
src/generator/singlefilegenerator.h

@@ -30,6 +30,7 @@
 #include <string>
 #include <memory>
 #include <functional>
+#include "generatorbase.h"
 
 namespace google { namespace protobuf {
 class FileDescriptor;
@@ -41,23 +42,15 @@ class GeneratorContext;
 namespace QtProtobuf {
 namespace generator {
 
-class SingleFileGenerator : public ::google::protobuf::compiler::CodeGenerator
+class SingleFileGenerator : public GeneratorBase
 {
+public:
+    SingleFileGenerator();
     bool Generate(const ::google::protobuf::FileDescriptor *file,
                           const std::string &parameter,
                           ::google::protobuf::compiler::GeneratorContext *generatorContext,
                           std::string *error) const override;
-
-    bool GenerateAll(const std::vector<const ::google::protobuf::FileDescriptor *> &files,
-                             const std::string &parameter,
-                             ::google::protobuf::compiler::GeneratorContext *generatorContext,
-                             std::string *error) const override;
-    bool HasGenerateAll() const override { return true; }
-
-
 private:
-    void iterateNonNestedFileds(const ::google::protobuf::FileDescriptor *file, std::function<void(const ::google::protobuf::Descriptor *)> callback) const;
-
     bool GenerateServices(const ::google::protobuf::FileDescriptor *file,
                           const std::string &parameter,
                           ::google::protobuf::compiler::GeneratorContext *generatorContext,

+ 6 - 0
src/generator/templates.cpp

@@ -252,3 +252,9 @@ const std::unordered_map<::google::protobuf::FieldDescriptor::Type, std::string>
     {::google::protobuf::FieldDescriptor::TYPE_SINT32, "sint32"},
     {::google::protobuf::FieldDescriptor::TYPE_SINT64, "sint64"}     //Limited usage see https://doc.qt.io/qt-5/qtqml-typesystem-basictypes.html
 };
+
+const char *Templates::ProtoFileSuffix = ".pb";
+const char *Templates::GrpcFileSuffix = "_grpc";
+
+const std::string Templates::GlobalDeclarationsFilename = std::string("qtprotobuf_global");
+

+ 3 - 0
src/generator/templates.h

@@ -137,8 +137,11 @@ public:
     static const char *ClientMethodServerStream2DefinitionTemplate;
 
     static const char *ListSuffix;
+    static const char *ProtoFileSuffix;
+    static const char *GrpcFileSuffix;
 
     static const std::unordered_map<::google::protobuf::FieldDescriptor::Type, std::string> TypeReflection;
+    static const std::string GlobalDeclarationsFilename;
 };
 
 } //namespace generator

+ 1 - 1
src/protobuf/qtprotobuf.cpp

@@ -82,7 +82,7 @@ void registerBasicConverters() {
 
 }
 
-void registerProtoTypes() {
+void qRegisterProtobufTypes() {
     static bool registred = false;
     if (registred) {
         return;

+ 1 - 1
src/protobuf/qtprotobuftypes.h

@@ -224,7 +224,7 @@ using DoubleList = QList<double>;
  * \brief registerTypes
  * This method should be called in all applications that supposed to use QtProtobuf
  */
-Q_PROTOBUF_EXPORT extern void registerProtoTypes();
+Q_PROTOBUF_EXPORT extern void qRegisterProtobufTypes();
 
 /*! \} */
 }

+ 3 - 3
tests/test_grpc/clienttest.cpp

@@ -24,11 +24,11 @@
  */
 
 #include "testservice_grpc.pb.h"
+#include "qtprotobuf_global.pb.h"
 
-//#include "testserviceclient.h"
 #include "qgrpchttp2channel.h"
 #include "insecurecredentials.h"
-//#include "blobmessage.h"
+
 #include <sslcredentials.h>
 
 #include <QTimer>
@@ -48,7 +48,7 @@ class ClientTest : public ::testing::Test
 {
 protected:
     static void SetUpTestCase() {
-        QtProtobuf::registerProtoTypes();
+        QtProtobuf::qRegisterProtobufTypes();
         qRegisterProtobufType<SimpleStringMessage>();
     }
     static QCoreApplication m_app;

+ 1 - 1
tests/test_grpc/sslclienttest.cpp

@@ -44,7 +44,7 @@ class ClientTest : public ::testing::Test
 {
 protected:
     static void SetUpTestCase() {
-        QtProtobuf::registerProtoTypes();
+        QtProtobuf::qRegisterProtobufTypes();
         qRegisterProtobufType<SimpleStringMessage>();
     }
     static QCoreApplication m_app;

+ 1 - 1
tests/test_protobuf/converterstest.cpp

@@ -36,7 +36,7 @@ class CoverterTest : public ::testing::Test
 public:
     CoverterTest() = default;
     static void SetUpTestCase() {
-        QtProtobuf::registerProtoTypes();
+        QtProtobuf::qRegisterProtobufTypes();
     }
 };
 

+ 5 - 122
tests/test_protobuf/deserializationtest.cpp

@@ -26,70 +26,7 @@
 #include "deserializationtest.h"
 
 #include "simpletest.pb.h"
-//#include "simpleboolmessage.h"
-//#include "simplefixedint32message.h"
-//#include "simplefixedint64message.h"
-//#include "simplesfixedint32message.h"
-//#include "simplesfixedint64message.h"
-//#include "simplefloatmessage.h"
-//#include "simpledoublemessage.h"
-//#include "simpleintmessage.h"
-//#include "simplesintmessage.h"
-//#include "simpleuintmessage.h"
-//#include "simplestringmessage.h"
-//#include "complexmessage.h"
-//#include "repeatedstringmessage.h"
-//#include "repeatedbytesmessage.h"
-//#include "repeateddoublemessage.h"
-//#include "repeatedfloatmessage.h"
-//#include "repeatedintmessage.h"
-//#include "repeatedsintmessage.h"
-//#include "repeateduintmessage.h"
-//#include "repeatedint64message.h"
-//#include "repeatedsint64message.h"
-//#include "repeateduint64message.h"
-//#include "repeatedfixedintmessage.h"
-//#include "repeatedsfixedintmessage.h"
-//#include "repeatedfixedint64message.h"
-//#include "repeatedsfixedint64message.h"
-//#include "simpleenummessage.h"
-//#include "simplebytesmessage.h"
-//#include "repeatedcomplexmessage.h"
-
-//#include "simplefixed32stringmapmessage.h"
-//#include "simplesfixed32stringmapmessage.h"
-//#include "simpleint32stringmapmessage.h"
-//#include "simplesint32stringmapmessage.h"
-//#include "simpleuint32stringmapmessage.h"
-
-//#include "simplefixed64stringmapmessage.h"
-//#include "simplesfixed64stringmapmessage.h"
-//#include "simpleint64stringmapmessage.h"
-//#include "simplesint64stringmapmessage.h"
-//#include "simpleuint64stringmapmessage.h"
-
-//#include "simplestringstringmapmessage.h"
-
-//#include "simplefixed32complexmessagemapmessage.h"
-//#include "simplesfixed32complexmessagemapmessage.h"
-//#include "simpleint32complexmessagemapmessage.h"
-//#include "simplesint32complexmessagemapmessage.h"
-//#include "simpleuint32complexmessagemapmessage.h"
-
-//#include "simplefixed64complexmessagemapmessage.h"
-//#include "simplesfixed64complexmessagemapmessage.h"
-//#include "simpleint64complexmessagemapmessage.h"
-//#include "simplesint64complexmessagemapmessage.h"
-//#include "simpleuint64complexmessagemapmessage.h"
-
-//#include "simplestringcomplexmessagemapmessage.h"
-
-//#include "fieldindextest1message.h"
-//#include "fieldindextest2message.h"
-//#include "fieldindextest3message.h"
-//#include "fieldindextest4message.h"
-
-//#include "simpleenumlistmessage.h"
+#include "qtprotobuf_global.pb.h"
 
 using namespace qtprotobufnamespace::tests;
 using namespace QtProtobuf::tests;
@@ -98,64 +35,10 @@ using namespace QtProtobuf;
 void DeserializationTest::SetUpTestCase()
 {
     //Register all types
-    QtProtobuf::registerProtoTypes();
-    qRegisterProtobufType<SimpleIntMessage>();
-    qRegisterProtobufType<SimpleUIntMessage>();
-    qRegisterProtobufType<SimpleSIntMessage>();
-//    qRegisterProtobufType<SimpleInt64Message>();
-//    qRegisterProtobufType<SimpleUInt64Message>();
-//    qRegisterProtobufType<SimpleSInt64Message>();
-    qRegisterProtobufType<SimpleFixedInt32Message>();
-    qRegisterProtobufType<SimpleFixedInt64Message>();
-    qRegisterProtobufType<SimpleSFixedInt32Message>();
-    qRegisterProtobufType<SimpleSFixedInt64Message>();
-    qRegisterProtobufType<SimpleFloatMessage>();
-    qRegisterProtobufType<SimpleDoubleMessage>();
-    qRegisterProtobufType<SimpleStringMessage>();
-    qRegisterProtobufType<ComplexMessage>();
-    qRegisterProtobufType<RepeatedIntMessage>();
-    qRegisterProtobufType<RepeatedSIntMessage>();
-    qRegisterProtobufType<RepeatedUIntMessage>();
-    qRegisterProtobufType<RepeatedInt64Message>();
-    qRegisterProtobufType<RepeatedSInt64Message>();
-    qRegisterProtobufType<RepeatedUInt64Message>();
-    qRegisterProtobufType<RepeatedFixedIntMessage>();
-    qRegisterProtobufType<RepeatedSFixedIntMessage>();
-    qRegisterProtobufType<RepeatedFixedInt64Message>();
-    qRegisterProtobufType<RepeatedStringMessage>();
-    qRegisterProtobufType<RepeatedDoubleMessage>();
-    qRegisterProtobufType<RepeatedBytesMessage>();
-    qRegisterProtobufType<RepeatedFloatMessage>();
-    qRegisterProtobufType<RepeatedComplexMessage>();
-    qRegisterProtobufType<SimpleFixed32StringMapMessage>();
-    qRegisterProtobufType<SimpleSFixed32StringMapMessage>();
-    qRegisterProtobufType<SimpleInt32StringMapMessage>();
-    qRegisterProtobufType<SimpleSInt32StringMapMessage>();
-    qRegisterProtobufType<SimpleUInt32StringMapMessage>();
-    qRegisterProtobufType<SimpleFixed64StringMapMessage>();
-    qRegisterProtobufType<SimpleSFixed64StringMapMessage>();
-    qRegisterProtobufType<SimpleInt64StringMapMessage>();
-    qRegisterProtobufType<SimpleSInt64StringMapMessage>();
-    qRegisterProtobufType<SimpleUInt64StringMapMessage>();
-    qRegisterProtobufType<SimpleStringStringMapMessage>();
-    qRegisterProtobufType<FieldIndexTest1Message>();
-    qRegisterProtobufType<FieldIndexTest2Message>();
-    qRegisterProtobufType<FieldIndexTest3Message>();
-    qRegisterProtobufType<FieldIndexTest4Message>();
-    qRegisterProtobufType<SimpleEnumListMessage>();
-    qRegisterProtobufType<SimpleBytesMessage>();
-    qRegisterProtobufType<SimpleFixed32ComplexMessageMapMessage>();
-    qRegisterProtobufType<SimpleSFixed32ComplexMessageMapMessage>();
-    qRegisterProtobufType<SimpleInt32ComplexMessageMapMessage>();
-    qRegisterProtobufType<SimpleSInt32ComplexMessageMapMessage>();
-    qRegisterProtobufType<SimpleUInt32ComplexMessageMapMessage>();
-    qRegisterProtobufType<SimpleFixed64ComplexMessageMapMessage>();
-    qRegisterProtobufType<SimpleSFixed64ComplexMessageMapMessage>();
-    qRegisterProtobufType<SimpleInt64ComplexMessageMapMessage>();
-    qRegisterProtobufType<SimpleSInt64ComplexMessageMapMessage>();
-    qRegisterProtobufType<SimpleUInt64ComplexMessageMapMessage>();
-    qRegisterProtobufType<SimpleStringComplexMessageMapMessage>();
-    qRegisterProtobufType<SimpleEnumMessage>();
+    QtProtobuf::qRegisterProtobufTypes();
+    qtprotobufnamespace::tests::qRegisterProtobufTypes();
+    qtprotobufnamespace1::externaltests::qRegisterProtobufTypes();
+    qtprotobufnamespace::tests::globalenums::qRegisterProtobufTypes();
 }
 
 void DeserializationTest::SetUp()

+ 8 - 3
tests/test_protobuf/jsonserializationtest.cpp

@@ -26,10 +26,12 @@
 #include <gtest/gtest.h>
 #include <QByteArray>
 #include <QString>
-#include "simpletest.pb.h"
-//#include <simplefixedint32message.h>
+
 #include <qprotobufjsonserializer.h>
 
+#include "simpletest.pb.h"
+#include "qtprotobuf_global.pb.h"
+
 using namespace qtprotobufnamespace::tests;
 
 namespace QtProtobuf {
@@ -41,7 +43,10 @@ public:
     JsonSerializationTest() = default;
     void SetUp() override;
     static void SetUpTestCase() {
-        QtProtobuf::registerProtoTypes();
+        QtProtobuf::qRegisterProtobufTypes();
+        qtprotobufnamespace::tests::qRegisterProtobufTypes();
+        qtprotobufnamespace1::externaltests::qRegisterProtobufTypes();
+        qtprotobufnamespace::tests::globalenums::qRegisterProtobufTypes();
     }
 
 protected:

+ 0 - 14
tests/test_protobuf/serializationcomplexmessagemap.cpp

@@ -27,20 +27,6 @@
 
 #include "simpletest.pb.h"
 
-//#include "simplefixed32complexmessagemapmessage.h"
-//#include "simplesfixed32complexmessagemapmessage.h"
-//#include "simpleint32complexmessagemapmessage.h"
-//#include "simplesint32complexmessagemapmessage.h"
-//#include "simpleuint32complexmessagemapmessage.h"
-
-//#include "simplefixed64complexmessagemapmessage.h"
-//#include "simplesfixed64complexmessagemapmessage.h"
-//#include "simpleint64complexmessagemapmessage.h"
-//#include "simplesint64complexmessagemapmessage.h"
-//#include "simpleuint64complexmessagemapmessage.h"
-
-//#include "simplestringcomplexmessagemapmessage.h"
-
 using namespace qtprotobufnamespace::tests;
 using namespace QtProtobuf::tests;
 using namespace QtProtobuf;

+ 5 - 99
tests/test_protobuf/serializationtest.cpp

@@ -26,58 +26,7 @@
 #include "serializationtest.h"
 
 #include "simpletest.pb.h"
-//#include "simpleintmessage.h"
-//#include "simpleuintmessage.h"
-//#include "simplesintmessage.h"
-//#include "simpleint64message.h"
-//#include "simpleuint64message.h"
-//#include "simplesint64message.h"
-//#include "simplefixedint32message.h"
-//#include "simplefixedint64message.h"
-//#include "simplesfixedint32message.h"
-//#include "simplesfixedint64message.h"
-//#include "simplefloatmessage.h"
-//#include "simpledoublemessage.h"
-//#include "simplestringmessage.h"
-//#include "complexmessage.h"
-//#include "repeatedintmessage.h"
-//#include "repeatedsintmessage.h"
-//#include "repeateduintmessage.h"
-//#include "repeatedint64message.h"
-//#include "repeatedsint64message.h"
-//#include "repeateduint64message.h"
-//#include "repeatedfixedintmessage.h"
-//#include "repeatedsfixedintmessage.h"
-//#include "repeatedfixedint64message.h"
-//#include "repeatedsfixedint64message.h"
-//#include "repeatedstringmessage.h"
-//#include "repeateddoublemessage.h"
-//#include "repeatedbytesmessage.h"
-//#include "repeatedfloatmessage.h"
-//#include "repeatedcomplexmessage.h"
-//#include "simpleboolmessage.h"
-//#include "simpleenummessage.h"
-
-//#include "simplefixed32stringmapmessage.h"
-//#include "simplesfixed32stringmapmessage.h"
-//#include "simpleint32stringmapmessage.h"
-//#include "simplesint32stringmapmessage.h"
-//#include "simpleuint32stringmapmessage.h"
-
-//#include "simplefixed64stringmapmessage.h"
-//#include "simplesfixed64stringmapmessage.h"
-//#include "simpleint64stringmapmessage.h"
-//#include "simplesint64stringmapmessage.h"
-//#include "simpleuint64stringmapmessage.h"
-
-//#include "simplestringstringmapmessage.h"
-
-//#include "fieldindextest1message.h"
-//#include "fieldindextest2message.h"
-//#include "fieldindextest3message.h"
-//#include "fieldindextest4message.h"
-//#include "simpleenumlistmessage.h"
-//#include "simplebytesmessage.h"
+#include "qtprotobuf_global.pb.h"
 
 using namespace qtprotobufnamespace::tests;
 using namespace QtProtobuf::tests;
@@ -87,53 +36,10 @@ using namespace QtProtobuf;
 void SerializationTest::SetUpTestCase()
 {
     //Register all types
-    QtProtobuf::registerProtoTypes();
-    qRegisterProtobufType<SimpleIntMessage>();
-    qRegisterProtobufType<SimpleUIntMessage>();
-    qRegisterProtobufType<SimpleSIntMessage>();
-    qRegisterProtobufType<SimpleInt64Message>();
-    qRegisterProtobufType<SimpleUInt64Message>();
-    qRegisterProtobufType<SimpleSInt64Message>();
-    qRegisterProtobufType<SimpleFixedInt32Message>();
-    qRegisterProtobufType<SimpleFixedInt64Message>();
-    qRegisterProtobufType<SimpleSFixedInt32Message>();
-    qRegisterProtobufType<SimpleSFixedInt64Message>();
-    qRegisterProtobufType<SimpleFloatMessage>();
-    qRegisterProtobufType<SimpleDoubleMessage>();
-    qRegisterProtobufType<SimpleStringMessage>();
-    qRegisterProtobufType<ComplexMessage>();
-    qRegisterProtobufType<RepeatedIntMessage>();
-    qRegisterProtobufType<RepeatedSIntMessage>();
-    qRegisterProtobufType<RepeatedUIntMessage>();
-    qRegisterProtobufType<RepeatedInt64Message>();
-    qRegisterProtobufType<RepeatedSInt64Message>();
-    qRegisterProtobufType<RepeatedUInt64Message>();
-    qRegisterProtobufType<RepeatedFixedIntMessage>();
-    qRegisterProtobufType<RepeatedSFixedIntMessage>();
-    qRegisterProtobufType<RepeatedFixedInt64Message>();
-    qRegisterProtobufType<RepeatedStringMessage>();
-    qRegisterProtobufType<RepeatedDoubleMessage>();
-    qRegisterProtobufType<RepeatedBytesMessage>();
-    qRegisterProtobufType<RepeatedFloatMessage>();
-    qRegisterProtobufType<RepeatedComplexMessage>();
-    qRegisterProtobufType<SimpleFixed32StringMapMessage>();
-    qRegisterProtobufType<SimpleSFixed32StringMapMessage>();
-    qRegisterProtobufType<SimpleInt32StringMapMessage>();
-    qRegisterProtobufType<SimpleSInt32StringMapMessage>();
-    qRegisterProtobufType<SimpleUInt32StringMapMessage>();
-    qRegisterProtobufType<SimpleFixed64StringMapMessage>();
-    qRegisterProtobufType<SimpleSFixed64StringMapMessage>();
-    qRegisterProtobufType<SimpleInt64StringMapMessage>();
-    qRegisterProtobufType<SimpleSInt64StringMapMessage>();
-    qRegisterProtobufType<SimpleUInt64StringMapMessage>();
-    qRegisterProtobufType<SimpleStringStringMapMessage>();
-    qRegisterProtobufType<FieldIndexTest1Message>();
-    qRegisterProtobufType<FieldIndexTest2Message>();
-    qRegisterProtobufType<FieldIndexTest3Message>();
-    qRegisterProtobufType<FieldIndexTest4Message>();
-    qRegisterProtobufType<SimpleEnumListMessage>();
-    qRegisterProtobufType<SimpleBytesMessage>();
-    qRegisterProtobufType<SimpleEnumMessage>();
+    QtProtobuf::qRegisterProtobufTypes();
+    qtprotobufnamespace::tests::qRegisterProtobufTypes();
+    qtprotobufnamespace1::externaltests::qRegisterProtobufTypes();
+    qtprotobufnamespace::tests::globalenums::qRegisterProtobufTypes();
 }
 
 void SerializationTest::SetUp()

+ 6 - 54
tests/test_protobuf/simpletest.cpp.inc

@@ -29,6 +29,8 @@
 
 #include <gtest/gtest.h>
 
+#include "qtprotobuf_global.pb.h"
+
 using namespace qtprotobufnamespace::tests;
 
 namespace QtProtobuf {
@@ -58,60 +60,10 @@ public:
 
 void SimpleTest::SetUpTestCase()
 {
-    QtProtobuf::registerProtoTypes();
-    qRegisterProtobufType<SimpleIntMessage>();
-    qRegisterProtobufType<SimpleUIntMessage>();
-    qRegisterProtobufType<SimpleSIntMessage>();
-    qRegisterProtobufType<SimpleInt64Message>();
-    qRegisterProtobufType<SimpleUInt64Message>();
-    qRegisterProtobufType<SimpleSInt64Message>();
-    qRegisterProtobufType<SimpleFixedInt32Message>();
-    qRegisterProtobufType<SimpleFixedInt64Message>();
-    qRegisterProtobufType<SimpleSFixedInt32Message>();
-    qRegisterProtobufType<SimpleSFixedInt64Message>();
-    qRegisterProtobufType<SimpleFloatMessage>();
-    qRegisterProtobufType<SimpleDoubleMessage>();
-    qRegisterProtobufType<SimpleStringMessage>();
-    qRegisterProtobufType<ComplexMessage>();
-    qRegisterProtobufType<RepeatedIntMessage>();
-    qRegisterProtobufType<RepeatedSIntMessage>();
-    qRegisterProtobufType<RepeatedUIntMessage>();
-    qRegisterProtobufType<RepeatedInt64Message>();
-    qRegisterProtobufType<RepeatedSInt64Message>();
-    qRegisterProtobufType<RepeatedUInt64Message>();
-    qRegisterProtobufType<RepeatedFixedIntMessage>();
-    qRegisterProtobufType<RepeatedSFixedIntMessage>();
-    qRegisterProtobufType<RepeatedFixedInt64Message>();
-    qRegisterProtobufType<RepeatedStringMessage>();
-    qRegisterProtobufType<RepeatedDoubleMessage>();
-    qRegisterProtobufType<RepeatedBytesMessage>();
-    qRegisterProtobufType<RepeatedFloatMessage>();
-    qRegisterProtobufType<RepeatedComplexMessage>();
-//    qRegisterProtobufType<SimpleFixed32StringMapMessage>();
-//    qRegisterProtobufType<SimpleSFixed32StringMapMessage>();
-//    qRegisterProtobufType<SimpleInt32StringMapMessage>();
-    qRegisterProtobufType<SimpleSInt32StringMapMessage>();
-//    qRegisterProtobufType<SimpleUInt32StringMapMessage>();
-//    qRegisterProtobufType<SimpleFixed64StringMapMessage>();
-//    qRegisterProtobufType<SimpleSFixed64StringMapMessage>();
-//    qRegisterProtobufType<SimpleInt64StringMapMessage>();
-//    qRegisterProtobufType<SimpleSInt64StringMapMessage>();
-//    qRegisterProtobufType<SimpleUInt64StringMapMessage>();
-    qRegisterProtobufType<SimpleStringStringMapMessage>();
-//    qRegisterProtobufType<FieldIndexTest1Message>();
-//    qRegisterProtobufType<FieldIndexTest2Message>();
-//    qRegisterProtobufType<FieldIndexTest3Message>();
-//    qRegisterProtobufType<FieldIndexTest4Message>();
-    qRegisterProtobufType<SimpleEnumListMessage>();
-    qRegisterProtobufType<SimpleBytesMessage>();
-
-    qRegisterProtobufType<EmptyMessage>();
-    qRegisterProtobufType<Message_Uderscore_name>();
-    qRegisterProtobufType<MessageUderscorename>();
-    qRegisterProtobufType<MessageUnderscoreField>();
-    qRegisterProtobufType<PriorMessageUnderscoreField>();
-    qRegisterProtobufType<FollowingMessageUnderscoreField>();
-    qRegisterProtobufType<CombinedMessageUnderscoreField>();
+    QtProtobuf::qRegisterProtobufTypes();
+    qtprotobufnamespace::tests::qRegisterProtobufTypes();
+    qtprotobufnamespace1::externaltests::qRegisterProtobufTypes();
+    qtprotobufnamespace::tests::globalenums::qRegisterProtobufTypes();
 }
 
 TEST_F(SimpleTest, SimpleBoolMessageTest)

+ 3 - 27
tests/test_qml/main.cpp

@@ -26,39 +26,15 @@
 #include <QtQuickTest/quicktest.h>
 
 #include "simpletest.pb.h"
-
-//#include "simpleboolmessage.h"
-//#include "simplebytesmessage.h"
-//#include "simpledoublemessage.h"
-//#include "simplefloatmessage.h"
-//#include "simplefixedint32message.h"
-//#include "simplefixedint64message.h"
-//#include "simplesfixedint32message.h"
-//#include "simplesfixedint64message.h"
-//#include "simpleintmessage.h"
-//#include "simpleint64message.h"
-//#include "simplesintmessage.h"
-//#include "simplesint64message.h"
-//#include "simpleuintmessage.h"
-//#include "simpleuint64message.h"
-//#include "simplestringmessage.h"
+#include "qtprotobuf_global.pb.h"
 
 using namespace qtprotobufnamespace::tests;
 
 class TestSetup : public QObject {
 public:
     TestSetup() {
-        QtProtobuf::registerProtoTypes();
-        qRegisterProtobufType<SimpleBoolMessage>();
-        qRegisterProtobufType<SimpleBytesMessage>();
-        qRegisterProtobufType<SimpleDoubleMessage>();
-        qRegisterProtobufType<SimpleFloatMessage>();
-        qRegisterProtobufType<SimpleFixedInt32Message>();
-        qRegisterProtobufType<SimpleIntMessage>();
-        qRegisterProtobufType<SimpleSIntMessage>();
-        qRegisterProtobufType<SimpleUIntMessage>();
-        qRegisterProtobufType<SimpleStringMessage>();
-        qRegisterProtobufType<SimpleSFixedInt32Message>();
+        QtProtobuf::qRegisterProtobufTypes();
+        qtprotobufnamespace::tests::qRegisterProtobufTypes();
     }
     ~TestSetup() = default;
 };