Procházet zdrojové kódy

Implement example of Serialization plugin

- Add serialization interface
- Add plugin
- Add plugin test
Tatyana Borisova před 5 roky
rodič
revize
55fbbacc8d

+ 7 - 2
src/protobuf/CMakeLists.txt

@@ -40,7 +40,8 @@ file(GLOB HEADERS
     qprotobufjsonserializer.h
     qprotobufselfcheckiterator.h
     qprotobufmetaproperty.h
-    qprotobufmetaobject.h)
+    qprotobufmetaobject.h
+    qprotobufserializationplugininterface.h)
 
 file(GLOB PUBLIC_HEADERS
     qtprotobufglobal.h
@@ -54,11 +55,15 @@ file(GLOB PUBLIC_HEADERS
     qprotobufjsonserializer.h
     qprotobufselfcheckiterator.h
     qprotobufmetaproperty.h
-    qprotobufmetaobject.h)
+    qprotobufmetaobject.h
+    qprotobufserializationplugininterface.h)
 
 protobuf_generate_qt_headers(PUBLIC_HEADERS ${PUBLIC_HEADERS} COMPONENT ${TARGET})
 
 add_library(${TARGET} SHARED ${SOURCES})
+
+target_compile_definitions(QtProtobuf PUBLIC QT_PROTOBUF_PLUGIN_PATH=$<TARGET_FILE_DIR:serializationplugin>)
+
 target_compile_definitions(${TARGET} PRIVATE QT_BUILD_PROTOBUF_LIB PUBLIC QTPROTOBUF_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
     QTPROTOBUF_VERSION_MINOR=${PROJECT_VERSION_MINOR})
 

+ 50 - 0
src/protobuf/qprotobufserializationplugininterface.h

@@ -0,0 +1,50 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2019 Tatyana Borisova <tanusshhka@mail.ru>
+ *
+ * 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 //QProtobufSerializationPluginInterface
+
+#include <QObject>
+#include <QString>
+
+#include <unordered_map>
+#include <memory>
+
+#include "qtprotobufglobal.h"
+#include "qabstractprotobufserializer.h"
+
+namespace QtProtobuf {
+
+class Q_PROTOBUF_EXPORT QProtobufSerializationPluginInterface
+{
+public:
+    explicit QProtobufSerializationPluginInterface() {}
+    virtual ~QProtobufSerializationPluginInterface() {}
+
+    virtual QtProtobuf::QAbstractProtobufSerializer *serializer(const QString &serializer_name) = 0;
+};
+
+}
+#define SerializatorInterface_iid "com.qtprotobuf.QProtobufSerializationPluginInterface"
+Q_DECLARE_INTERFACE(QtProtobuf::QProtobufSerializationPluginInterface, SerializatorInterface_iid)

+ 189 - 10
src/protobuf/qprotobufserializerregistry.cpp

@@ -26,38 +26,217 @@
 #include "qprotobufserializerregistry_p.h"
 #include "qprotobufserializer.h"
 #include "qprotobufjsonserializer.h"
+#include "qprotobufserializationplugininterface.h"
 
+#include <QDir>
 #include <QString>
 #include <QHash>
+#include <QPluginLoader>
+#include <QJsonObject>
+#include <QJsonArray>
+
+namespace {
+const QLatin1String Serializationplugin("serializationplugin");
+const QLatin1String TypeNames("types");
+const QLatin1String MetaData("MetaData");
+const QLatin1String Version("version");
+const QLatin1String Rating("rating");
+const QLatin1String ProtoVersion("protobufVersion");
+const QLatin1String PluginName("name");
+const QLatin1String ProtobufSerializer("protobuf");
+const QLatin1String JsonSerializer("json");
+#ifdef _WIN32
+const QLatin1String libExtension(".dll");
+const QLatin1String libPrefix("");
+#else
+const QLatin1String libExtension(".so");
+const QLatin1String libPrefix("lib");
+#endif
+
+}
+
+#define STRINGIFY2(s) #s
+#define STRINGIFY(s) STRINGIFY2(s)
+static const char *QtProtobufPluginPath = STRINGIFY(QT_PROTOBUF_PLUGIN_PATH)"/";
 
 namespace QtProtobuf {
-class QProtobufSerializerRegistryPrivate {
+
+class QProtobufSerializerRegistryPrivateRecord final
+{
+public:
+    QProtobufSerializerRegistryPrivateRecord() : loader(nullptr) {}
+
+    void createDefaultImpl()
+    {
+        if (serializers.find(ProtobufSerializer) == serializers.end()) {
+            serializers[ProtobufSerializer] = std::shared_ptr<QAbstractProtobufSerializer>(new QProtobufSerializer);
+        }
+        if (serializers.find(JsonSerializer) == serializers.end()) {
+            serializers[JsonSerializer] = std::shared_ptr<QAbstractProtobufSerializer>(new QProtobufJsonSerializer);
+        }
+    }
+
+    void loadPluginMetadata(const QString &path, const QString &pluginName)
+    {
+        // Load default plugin
+        if (path.isEmpty() || pluginName.isEmpty()){
+            libPath = QtProtobufPluginPath + libPrefix + Serializationplugin + libExtension;
+        }
+        // Use custom plugin
+        else {
+            libPath = path + libPrefix + pluginName + libExtension;
+        }
+
+        loader = new QPluginLoader(libPath);
+        pluginData = loader->metaData();
+
+        QVariantMap fullJson = pluginData.toVariantMap();
+        if (!fullJson.isEmpty()) {
+            metaData = fullJson.value(MetaData).toMap();
+            pluginLoadedName = metaData.value(PluginName).toString();
+            typeArray = metaData.value(TypeNames).toList();
+        }
+    }
+
+    void loadPlugin()
+    {
+        QProtobufSerializationPluginInterface *loadedPlugin = qobject_cast<QProtobufSerializationPluginInterface*>(loadPluginImpl());
+        if (!pluginData.isEmpty() && loadedPlugin) {
+            for (int i = 0; i < typeArray.count(); i++) {
+                QString typeName = typeArray.at(i).toString();
+                serializers[typeName] = std::shared_ptr<QAbstractProtobufSerializer>(loadedPlugin->serializer(typeName));
+            }
+        }
+    }
+
+    QObject* loadPluginImpl()
+    {
+        if (loader == nullptr || !loader->load())
+        {
+            qProtoWarning() << "Can't load plugin from" << libPath << loader->errorString();
+            return nullptr;
+        }
+        return loader->instance();
+    }
+
+    std::unordered_map<QString, std::shared_ptr<QAbstractProtobufSerializer>> serializers;
+    QJsonObject pluginData;
+    QVariantMap metaData;
+    QString pluginLoadedName;
+    QPluginLoader *loader;
+    QString libPath;
+    QVariantList typeArray;
+};
+
+
+class QProtobufSerializerRegistryPrivate
+{
+
 public:
-    QProtobufSerializerRegistryPrivate() {
-        serializers["protobuf"] = std::shared_ptr<QAbstractProtobufSerializer>(new QProtobufSerializer);
-        serializers["json"] = std::shared_ptr<QAbstractProtobufSerializer>(new QProtobufJsonSerializer);
+    QProtobufSerializerRegistryPrivate()
+    {
+        // create default impl
+        std::shared_ptr<QProtobufSerializerRegistryPrivateRecord> plugin = std::shared_ptr<QProtobufSerializerRegistryPrivateRecord>(new QProtobufSerializerRegistryPrivateRecord());
+        plugin->createDefaultImpl();
+        m_plugins[DefaultImpl] = plugin;
     }
-    std::unordered_map<QString/*id*/,  std::shared_ptr<QAbstractProtobufSerializer>> serializers;
+
+    static const QString &loadPlugin(const QString &path, const QString &name)
+    {
+        std::shared_ptr<QProtobufSerializerRegistryPrivateRecord> plugin = std::shared_ptr<QProtobufSerializerRegistryPrivateRecord>(new QProtobufSerializerRegistryPrivateRecord());
+        plugin->loadPluginMetadata(path, name);
+
+        const QString &pluginName = plugin->pluginLoadedName;
+        if (m_plugins.find(pluginName) == m_plugins.end()) {
+            plugin->loadPlugin();
+            m_plugins[pluginName] = plugin;
+        }
+        return pluginName;
+    }
+
+
+    static std::unordered_map<QString/*pluginName*/, std::shared_ptr<QProtobufSerializerRegistryPrivateRecord>> m_plugins;
 };
+
+std::unordered_map<QString/*pluginName*/, std::shared_ptr<QProtobufSerializerRegistryPrivateRecord>> QProtobufSerializerRegistryPrivate::m_plugins;
+
 }
 
 using namespace QtProtobuf;
 
-QProtobufSerializerRegistry::QProtobufSerializerRegistry() : d(new QProtobufSerializerRegistryPrivate)
+QProtobufSerializerRegistry::QProtobufSerializerRegistry() :
+    dPtr(new QProtobufSerializerRegistryPrivate())
 {
-
 }
 
 QProtobufSerializerRegistry::~QProtobufSerializerRegistry() = default;
 
+const QString &QProtobufSerializerRegistry::loadPlugin(const QString &path, const QString &name)
+{
+    return dPtr->loadPlugin(path, name);
+}
 
-std::shared_ptr<QAbstractProtobufSerializer> QProtobufSerializerRegistry::getSerializer(const QString &id)
+std::shared_ptr<QAbstractProtobufSerializer> QProtobufSerializerRegistry::getSerializer(const QString &id, const QString &plugin)
 {
-    return d->serializers.at(id); //throws
+    return dPtr->m_plugins[plugin]->serializers.at(id); //throws
 }
 
-std::unique_ptr<QAbstractProtobufSerializer> QProtobufSerializerRegistry::acquireSerializer(const QString &/*id*/)
+std::unique_ptr<QAbstractProtobufSerializer> QProtobufSerializerRegistry::acquireSerializer(const QString &/*id*/, const QString &/*plugin*/)
 {
     Q_ASSERT_X(false, "QProtobufSerializerRegistry", "acquireSerializer is unimplemented");
     return std::unique_ptr<QAbstractProtobufSerializer>();
 }
+
+float QProtobufSerializerRegistry::pluginVersion(const QString &plugin)
+{
+    if (dPtr->m_plugins.find(plugin) == dPtr->m_plugins.end())
+        return 0.0;
+
+    std::shared_ptr<QProtobufSerializerRegistryPrivateRecord> implementation = dPtr->m_plugins[plugin];
+    if (implementation->metaData.isEmpty())
+        return 0.0;
+
+    return implementation->metaData.value(Version).toFloat();
+}
+
+QStringList QProtobufSerializerRegistry::pluginSerializers(const QString &plugin)
+{
+    QStringList strList;
+
+    if (dPtr->m_plugins.find(plugin) == dPtr->m_plugins.end())
+        return strList;
+
+    std::shared_ptr<QProtobufSerializerRegistryPrivateRecord> implementation = dPtr->m_plugins[plugin];
+
+    QVariantList typeArray = implementation->metaData.value(TypeNames).toList();
+    foreach(QVariant value, typeArray) {
+        if (!value.toString().isEmpty()) {
+            strList.append(value.toString());
+        }
+    }
+    return strList;
+}
+
+float QProtobufSerializerRegistry::pluginProtobufVersion(const QString &plugin)
+{
+    if (dPtr->m_plugins.find(plugin) == dPtr->m_plugins.end())
+        return 0.0;
+
+    std::shared_ptr<QProtobufSerializerRegistryPrivateRecord> implementation = dPtr->m_plugins[plugin];
+    if (implementation.get() && implementation->metaData.isEmpty())
+        return 0.0;
+
+    return implementation->metaData.value(ProtoVersion).toFloat();
+}
+
+int QProtobufSerializerRegistry::pluginRating(const QString &plugin)
+{
+    if (dPtr->m_plugins.find(plugin) == dPtr->m_plugins.end())
+        return 0;
+
+    std::shared_ptr<QProtobufSerializerRegistryPrivateRecord> implementation = dPtr->m_plugins[plugin];
+    if (implementation->metaData.isEmpty())
+        return 0;
+
+    return implementation->metaData.value(Rating).toInt();
+}

+ 12 - 4
src/protobuf/qprotobufserializerregistry_p.h

@@ -30,6 +30,7 @@
 
 #include <memory>
 #include <type_traits>
+#include <unordered_map>
 
 #include "qtprotobuflogging.h"
 #include "qprotobufselfcheckiterator.h"
@@ -40,6 +41,8 @@
 namespace QtProtobuf {
 
 class QProtobufSerializerRegistryPrivate;
+class QProtobufSerializerRegistryPrivateRecord;
+const QString DefaultImpl("Default");
 /*!
  * \ingroup QtProtobuf
  * \private
@@ -47,12 +50,17 @@ class QProtobufSerializerRegistryPrivate;
  *        Loads serializer plugins and constructs serializer based on identifier.
  *
  */
-
 class Q_PROTOBUF_EXPORT QProtobufSerializerRegistry final
 {
 public:
-    std::shared_ptr<QAbstractProtobufSerializer> getSerializer(const QString &id);
-    std::unique_ptr<QAbstractProtobufSerializer> acquireSerializer(const QString &id);
+    std::shared_ptr<QAbstractProtobufSerializer> getSerializer(const QString &id, const QString &plugin = DefaultImpl);
+    std::unique_ptr<QAbstractProtobufSerializer> acquireSerializer(const QString &id, const QString &plugin);
+    float pluginVersion(const QString &plugin);
+    QStringList pluginSerializers(const QString &plugin);
+    float pluginProtobufVersion(const QString &plugin);
+    int pluginRating(const QString &plugin);
+
+    const QString &loadPlugin(const QString &path = "", const QString &name = "");
 
     static QProtobufSerializerRegistry &instance() {
         static QProtobufSerializerRegistry _instance;
@@ -65,6 +73,6 @@ private:
 
     Q_DISABLE_COPY_MOVE(QProtobufSerializerRegistry)
 
-    std::unique_ptr<QProtobufSerializerRegistryPrivate> d;
+    std::unique_ptr<QProtobufSerializerRegistryPrivate> dPtr;
 };
 }

+ 0 - 1
src/protobuf/quick/CMakeLists.txt

@@ -1,4 +1,3 @@
-# TODO: keep quick plugin for future features, but it's useless for now
 set(TARGET protobufquickplugin)
 
 set(TARGET_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${TARGET})

+ 1 - 0
tests/CMakeLists.txt

@@ -2,6 +2,7 @@ add_subdirectory("test_protobuf")
 add_subdirectory("test_grpc")
 add_subdirectory("test_qml")
 add_subdirectory("test_protobuf_multifile")
+add_subdirectory("test_qprotobuf_serializer_plugin")
 if(NOT WIN32)#TODO: There are linking issues with windows build of well-known types...
 	add_subdirectory("test_wellknowntypes")
 endif()

+ 25 - 0
tests/test_qprotobuf_serializer_plugin/CMakeLists.txt

@@ -0,0 +1,25 @@
+set(TARGET qtprotobuf_plugin_test)
+
+include(${QTPROTOBUF_CMAKE_DIR}/QtProtobufCommon.cmake)
+
+find_package(Threads REQUIRED)
+find_package(Qt5 COMPONENTS Test REQUIRED)
+
+file(GLOB SOURCES
+    serializationplugintest.cpp)
+
+if(Qt5_POSITION_INDEPENDENT_CODE)
+    set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
+endif()
+
+set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+add_executable(${TARGET} ${SOURCES})
+target_link_libraries(${TARGET} gtest_main gtest ${QtProtobuf_GENERATED} ${QTPROTOBUF_COMMON_NAMESPACE}::QtProtobuf ${QTPROTOBUF_COMMON_NAMESPACE}::QtGrpc Qt5::Core Qt5::Test Qt5::Network ${CMAKE_THREAD_LIBS_INIT})
+add_target_windeployqt(TARGET ${TARGET}
+    QML_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+
+add_test(NAME ${TARGET} COMMAND ${TARGET})
+
+add_subdirectory("serialization")

+ 52 - 0
tests/test_qprotobuf_serializer_plugin/serialization/CMakeLists.txt

@@ -0,0 +1,52 @@
+set(TARGET serializationplugin)
+
+set(TARGET_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${TARGET})
+set(TARGET_LIB_DIR ${CMAKE_INSTALL_LIBDIR})
+set(TARGET_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
+set(TARGET_BIN_DIR ${CMAKE_INSTALL_BINDIR})
+
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_AUTORCC ON)
+
+find_package(Qt5 COMPONENTS Core REQUIRED)
+
+if(NOT DEFINED QT_QMAKE_EXECUTABLE)
+    find_program(QT_QMAKE_EXECUTABLE "qmake")
+    if(QT_QMAKE_EXECUTABLE STREQUAL QT_QMAKE_EXECUTABLE-NOTFOUND)
+        message(FATAL_ERROR "Could not find qmake executable")
+    endif()
+endif()
+
+execute_process(
+    COMMAND ${QT_QMAKE_EXECUTABLE} -query QT_INSTALL_QML
+    OUTPUT_VARIABLE TARGET_IMPORTS_DIR
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+
+set(TARGET_IMPORTS_DIR ${TARGET_IMPORTS_DIR}/QtProtobuf)
+
+file(GLOB SOURCES
+    qtserializationplugin.cpp
+    qprotobufjsonserializerimpl.cpp
+    qprotobufserializerimpl.cpp)
+
+file(GLOB HEADERS
+    qtserializationplugin.h
+    qtserialization_global.h)
+
+add_library(${TARGET} SHARED ${SOURCES})
+target_link_libraries(${TARGET} PRIVATE Qt5::Core Qt5::Qml ${QTPROTOBUF_COMMON_NAMESPACE}::QtProtobuf)
+set_target_properties(${TARGET} PROPERTIES
+    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/QtProtobuf"
+    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/QtProtobuf"
+    RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_BINARY_DIR}/QtProtobuf"
+    RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_BINARY_DIR}/QtProtobuf")
+target_compile_definitions(${TARGET} PRIVATE SERIALIZATION_LIB)
+
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/serializeinfo.json" "${CMAKE_CURRENT_BINARY_DIR}/QtProtobuf/serializeinfo.json" COPYONLY)
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/QtProtobuf/serializeinfo.json" DESTINATION "${TARGET_CMAKE_DIR}")
+
+install(TARGETS ${TARGET}
+    PUBLIC_HEADER DESTINATION "${TARGET_INCLUDE_DIR}"
+    RUNTIME DESTINATION "${TARGET_IMPORTS_DIR}"
+    LIBRARY DESTINATION "${TARGET_IMPORTS_DIR}")

+ 141 - 0
tests/test_qprotobuf_serializer_plugin/serialization/qprotobufjsonserializerimpl.cpp

@@ -0,0 +1,141 @@
+/*
+ * 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 "qprotobufjsonserializerimpl.h"
+#include "qprotobufmetaobject.h"
+#include "qprotobufmetaproperty.h"
+#include <QMetaProperty>
+
+QProtobufJsonSerializerImpl::QProtobufJsonSerializerImpl()
+{
+}
+
+QByteArray QProtobufJsonSerializerImpl::serializeMessage(const QObject *object,
+                                                         const QtProtobuf::QProtobufMetaObject &metaObject) const
+{
+    Q_UNUSED(object)
+    Q_UNUSED(metaObject)
+    return QByteArray();
+}
+
+void QProtobufJsonSerializerImpl::deserializeMessage(QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject,
+                                                     const QByteArray &data) const
+{
+    Q_UNUSED(object)
+    Q_UNUSED(data)
+    Q_UNUSED(metaObject)
+}
+
+QByteArray QProtobufJsonSerializerImpl::serializeObject(const QObject *object,
+                                                        const QtProtobuf::QProtobufMetaObject &metaObject,
+                                                        const QtProtobuf::QProtobufMetaProperty &/*metaProperty*/) const
+{
+    Q_UNUSED(object)
+    Q_UNUSED(metaObject)
+    return QByteArray();
+}
+
+void QProtobufJsonSerializerImpl::deserializeObject(QObject *object,
+                                                    const QtProtobuf::QProtobufMetaObject &metaObject,
+                                                    QtProtobuf::QProtobufSelfcheckIterator &it) const
+{
+    Q_UNUSED(object)
+    Q_UNUSED(it)
+    Q_UNUSED(metaObject)
+}
+
+QByteArray QProtobufJsonSerializerImpl::serializeListObject(const QObject *object,
+                                                            const QtProtobuf::QProtobufMetaObject &metaObject,
+                                                            const QtProtobuf::QProtobufMetaProperty &metaProperty) const
+{
+    Q_UNUSED(object)
+    Q_UNUSED(metaObject)
+    Q_UNUSED(metaProperty)
+    return QByteArray();
+}
+
+void QProtobufJsonSerializerImpl::deserializeListObject(QObject *object,
+                                                        const QtProtobuf::QProtobufMetaObject &metaObject,
+                                                        QtProtobuf::QProtobufSelfcheckIterator &it) const
+{
+    Q_UNUSED(object)
+    Q_UNUSED(it)
+    Q_UNUSED(metaObject)
+}
+
+QByteArray QProtobufJsonSerializerImpl::serializeMapPair(const QVariant &key, const QVariant &value,
+                                                         const QtProtobuf::QProtobufMetaProperty &metaProperty) const
+{
+    Q_UNUSED(key)
+    Q_UNUSED(value)
+    Q_UNUSED(metaProperty)
+    return QByteArray();
+}
+
+void QProtobufJsonSerializerImpl::deserializeMapPair(QVariant &key, QVariant &value,
+                                                     QtProtobuf::QProtobufSelfcheckIterator &it) const
+{
+    Q_UNUSED(key)
+    Q_UNUSED(value)
+    Q_UNUSED(it)
+}
+
+QByteArray QProtobufJsonSerializerImpl::serializeEnum(QtProtobuf::int64 value,
+                                                      const QMetaEnum &metaEnum,
+                                                      const QtProtobuf::QProtobufMetaProperty &metaProperty) const
+{
+    Q_UNUSED(value)
+    Q_UNUSED(metaEnum)
+    Q_UNUSED(metaProperty)
+    return QByteArray();
+}
+
+QByteArray QProtobufJsonSerializerImpl::serializeEnumList(const QList<QtProtobuf::int64> &value,
+                                                          const QMetaEnum &metaEnum,
+                                                          const QtProtobuf::QProtobufMetaProperty &metaProperty) const
+{
+    Q_UNUSED(value)
+    Q_UNUSED(metaEnum)
+    Q_UNUSED(metaProperty)
+    return QByteArray();
+}
+
+void QProtobufJsonSerializerImpl::deserializeEnum(QtProtobuf::int64 &value,
+                                                  const QMetaEnum &metaEnum,
+                                                  QtProtobuf::QProtobufSelfcheckIterator &it) const
+{
+    Q_UNUSED(value)
+    Q_UNUSED(metaEnum)
+    Q_UNUSED(it)
+}
+
+void QProtobufJsonSerializerImpl::deserializeEnumList(QList<QtProtobuf::int64> &value,
+                                                      const QMetaEnum &metaEnum,
+                                                      QtProtobuf::QProtobufSelfcheckIterator &it) const
+{
+    Q_UNUSED(value)
+    Q_UNUSED(metaEnum)
+    Q_UNUSED(it)
+}

+ 62 - 0
tests/test_qprotobuf_serializer_plugin/serialization/qprotobufjsonserializerimpl.h

@@ -0,0 +1,62 @@
+/*
+ * 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 //QProtobufJsonSerializerImpl
+
+#include "qabstractprotobufserializer.h"
+#include "qprotobufmetaobject.h"
+#include "qtprotobuftypes.h"
+
+#include <memory>
+
+/*!
+*  \ingroup QtProtobuf
+ * \brief The QProtobufJsonSerializerPlugin class
+ */
+class QProtobufJsonSerializerImpl : public QtProtobuf::QAbstractProtobufSerializer
+{
+public:
+    QProtobufJsonSerializerImpl();
+    ~QProtobufJsonSerializerImpl() = default;
+
+protected:
+    QByteArray serializeMessage(const QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject) const  override;
+    void deserializeMessage(QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject, const QByteArray &data) const override;
+
+    QByteArray serializeObject(const QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
+    void deserializeObject(QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
+
+    QByteArray serializeListObject(const QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
+    void deserializeListObject(QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
+
+    QByteArray serializeMapPair(const QVariant &key, const QVariant &value, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
+    void deserializeMapPair(QVariant &key, QVariant &value, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
+
+    QByteArray serializeEnum(QtProtobuf::int64 value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
+    QByteArray serializeEnumList(const QList<QtProtobuf::int64> &value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
+
+    void deserializeEnum(QtProtobuf::int64 &value, const QMetaEnum &metaEnum, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
+    void deserializeEnumList(QList<QtProtobuf::int64> &value, const QMetaEnum &metaEnum, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
+};

+ 139 - 0
tests/test_qprotobuf_serializer_plugin/serialization/qprotobufserializerimpl.cpp

@@ -0,0 +1,139 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>, Viktor Kopp <vifactor@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 "qprotobufserializerimpl.h"
+#include "qprotobufmetaproperty.h"
+#include "qprotobufmetaobject.h"
+
+QProtobufSerializerImpl::QProtobufSerializerImpl()
+{
+}
+
+QProtobufSerializerImpl::~QProtobufSerializerImpl()
+{
+}
+
+QByteArray QProtobufSerializerImpl::serializeMessage(const QObject *object,
+                                                     const QtProtobuf::QProtobufMetaObject &metaObject) const
+{
+    Q_UNUSED(object)
+    Q_UNUSED(metaObject)
+    return QByteArray();
+}
+
+void QProtobufSerializerImpl::deserializeMessage(QObject *object,
+                                                 const QtProtobuf::QProtobufMetaObject &metaObject,
+                                                 const QByteArray &data) const
+{
+    Q_UNUSED(object)
+    Q_UNUSED(data)
+    Q_UNUSED(metaObject)
+}
+
+QByteArray QProtobufSerializerImpl::serializeObject(const QObject *object,
+                                                    const QtProtobuf::QProtobufMetaObject &metaObject,
+                                                    const QtProtobuf::QProtobufMetaProperty &metaProperty) const
+{
+    Q_UNUSED(object)
+    Q_UNUSED(metaProperty)
+    Q_UNUSED(metaObject)
+    return QByteArray();
+}
+
+void QProtobufSerializerImpl::deserializeObject(QObject *object,
+                                                const QtProtobuf::QProtobufMetaObject &metaObject,
+                                                QtProtobuf::QProtobufSelfcheckIterator &it) const
+{
+    Q_UNUSED(object)
+    Q_UNUSED(it)
+    Q_UNUSED(metaObject)
+}
+
+QByteArray QProtobufSerializerImpl::serializeListObject(const QObject *object,
+                                                        const QtProtobuf::QProtobufMetaObject &metaObject,
+                                                        const QtProtobuf::QProtobufMetaProperty &metaProperty) const
+{
+    return serializeObject(object, metaObject, metaProperty);
+}
+
+void QProtobufSerializerImpl::deserializeListObject(QObject *object,
+                                                    const QtProtobuf::QProtobufMetaObject &metaObject,
+                                                    QtProtobuf::QProtobufSelfcheckIterator &it) const
+{
+    deserializeObject(object, metaObject, it);
+}
+
+QByteArray QProtobufSerializerImpl::serializeMapPair(const QVariant &key,
+                                                     const QVariant &value,
+                                                     const QtProtobuf::QProtobufMetaProperty &metaProperty) const
+{
+    Q_UNUSED(value)
+    Q_UNUSED(metaProperty)
+    Q_UNUSED(key)
+    return QByteArray();
+}
+
+void QProtobufSerializerImpl::deserializeMapPair(QVariant &key,
+                                                 QVariant &value,
+                                                 QtProtobuf::QProtobufSelfcheckIterator &it) const
+{
+    Q_UNUSED(value)
+    Q_UNUSED(it)
+    Q_UNUSED(key)
+}
+
+QByteArray QProtobufSerializerImpl::serializeEnum(QtProtobuf::int64 value,
+                                                  const QMetaEnum &/*metaEnum*/,
+                                                  const QtProtobuf::QProtobufMetaProperty &metaProperty) const
+{
+    Q_UNUSED(value)
+    Q_UNUSED(metaProperty)
+    return QByteArray();
+}
+
+QByteArray QProtobufSerializerImpl::serializeEnumList(const QList<QtProtobuf::int64> &value,
+                                                      const QMetaEnum &/*metaEnum*/,
+                                                      const QtProtobuf::QProtobufMetaProperty &metaProperty) const
+{
+    Q_UNUSED(value)
+    Q_UNUSED(metaProperty)
+    return QByteArray();
+}
+
+void QProtobufSerializerImpl::deserializeEnum(QtProtobuf::int64 &value,
+                                              const QMetaEnum &/*metaEnum*/,
+                                              QtProtobuf::QProtobufSelfcheckIterator &it) const
+{
+    Q_UNUSED(value)
+    Q_UNUSED(it)
+}
+
+void QProtobufSerializerImpl::deserializeEnumList(QList<QtProtobuf::int64> &value,
+                                                  const QMetaEnum &/*metaEnum*/,
+                                                  QtProtobuf::QProtobufSelfcheckIterator &it) const
+{
+    Q_UNUSED(value)
+    Q_UNUSED(it)
+}

+ 58 - 0
tests/test_qprotobuf_serializer_plugin/serialization/qprotobufserializerimpl.h

@@ -0,0 +1,58 @@
+/*
+ * 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 //QProtobufSerializerImpl
+
+#include "qabstractprotobufserializer.h"
+
+/*!
+ * \ingroup QtProtobuf
+ * \brief The QProtobufSerializer class
+ */
+class QProtobufSerializerImpl : public QtProtobuf::QAbstractProtobufSerializer
+{
+public:
+    QProtobufSerializerImpl();
+    ~QProtobufSerializerImpl();
+
+protected:
+    QByteArray serializeMessage(const QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject) const override;
+    void deserializeMessage(QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject, const QByteArray &data) const override;
+
+    QByteArray serializeObject(const QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
+    void deserializeObject(QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
+
+    QByteArray serializeListObject(const QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
+    void deserializeListObject(QObject *object, const QtProtobuf::QProtobufMetaObject &metaObject, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
+
+    QByteArray serializeMapPair(const QVariant &key, const QVariant &value, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
+    void deserializeMapPair(QVariant &key, QVariant &value, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
+
+    QByteArray serializeEnum(QtProtobuf::int64 value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
+    QByteArray serializeEnumList(const QList<QtProtobuf::int64> &value, const QMetaEnum &metaEnum, const QtProtobuf::QProtobufMetaProperty &metaProperty) const override;
+
+    void deserializeEnum(QtProtobuf::int64 &value, const QMetaEnum &metaEnum, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
+    void deserializeEnumList(QList<QtProtobuf::int64> &value, const QMetaEnum &metaEnum, QtProtobuf::QProtobufSelfcheckIterator &it) const override;
+};

+ 33 - 0
tests/test_qprotobuf_serializer_plugin/serialization/qtserialization_global.h

@@ -0,0 +1,33 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2019 Tatyana Borisova <tanusshhka@mail.ru>
+ *
+ * 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 <QtCore/QtGlobal>
+
+#ifdef SERIALIZATION_LIB
+    #define SERIALIZATIONSHARED_EXPORT Q_DECL_EXPORT
+#else
+    #define SERIALIZATIONSHARED_EXPORT Q_DECL_IMPORT
+#endif

+ 42 - 0
tests/test_qprotobuf_serializer_plugin/serialization/qtserializationplugin.cpp

@@ -0,0 +1,42 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2019 Tatyana Borisova <tanusshhka@mail.ru>
+ *
+ * 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 "qtserializationplugin.h"
+#include "qprotobufserializerimpl.h"
+#include "qprotobufjsonserializerimpl.h"
+
+QtSerializationPlugin::QtSerializationPlugin()
+{
+    m_serializers["protobuf"] = std::shared_ptr<QtProtobuf::QAbstractProtobufSerializer>(new QProtobufSerializerImpl());
+    m_serializers["json"] = std::shared_ptr<QtProtobuf::QAbstractProtobufSerializer>(new QProtobufJsonSerializerImpl());
+}
+
+QtProtobuf::QAbstractProtobufSerializer *QtSerializationPlugin::serializer(const QString &serializer_name)
+{
+    if (m_serializers.find(serializer_name) == m_serializers.end())
+        return nullptr;
+
+    return m_serializers[serializer_name].get();
+}

+ 51 - 0
tests/test_qprotobuf_serializer_plugin/serialization/qtserializationplugin.h

@@ -0,0 +1,51 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2019 Tatyana Borisova <tanusshhka@mail.ru>
+ *
+ * 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 <QObject>
+#include "qprotobufserializationplugininterface.h"
+#include "qtserialization_global.h"
+
+/*!
+ * \private
+ * \brief The QtSerializationPlugin class
+ */
+class SERIALIZATIONSHARED_EXPORT QtSerializationPlugin : public QObject, QtProtobuf::QProtobufSerializationPluginInterface
+{
+    Q_OBJECT
+    Q_PLUGIN_METADATA(IID SerializatorInterface_iid FILE "serializeinfo.json")
+    Q_INTERFACES(QtProtobuf::QProtobufSerializationPluginInterface)
+
+public:
+    QtSerializationPlugin();
+    ~QtSerializationPlugin() = default;
+
+     virtual QtProtobuf::QAbstractProtobufSerializer *serializer(const QString &serializer_name);
+
+protected:
+    std::unordered_map<QString/*id*/, std::shared_ptr<QtProtobuf::QAbstractProtobufSerializer>> m_serializers;
+
+};

+ 8 - 0
tests/test_qprotobuf_serializer_plugin/serialization/serializeinfo.json

@@ -0,0 +1,8 @@
+{
+    "name":"TestPlugin",
+    "author":"TatyanVladimirovich",
+    "version":1.0,
+    "protobufVersion":1.0,
+    "types":["protobuf", "json"],
+    "rating":0
+}

+ 79 - 0
tests/test_qprotobuf_serializer_plugin/serializationplugintest.cpp

@@ -0,0 +1,79 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2019 Tatyana Borisova <tanusshhka@mail.ru>
+ *
+ * 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 "serializationplugintest.h"
+#include "qprotobufserializerregistry_p.h"
+
+using namespace QtProtobuf::tests;
+using namespace QtProtobuf;
+
+namespace {
+const QLatin1String ProtobufSerializator("protobuf");
+const QLatin1String JsonSerializator("json");
+}
+
+QString SerializationPluginTest::loadedTestPlugin;
+void SerializationPluginTest::SetUpTestCase()
+{
+    //Register all types
+    QtProtobuf::qRegisterProtobufTypes();
+    loadedTestPlugin = QProtobufSerializerRegistry::instance().loadPlugin();
+}
+
+void SerializationPluginTest::SetUp()
+{
+    serializers[ProtobufSerializator] = QProtobufSerializerRegistry::instance().getSerializer(ProtobufSerializator, loadedTestPlugin);
+    serializers[JsonSerializator] = QProtobufSerializerRegistry::instance().getSerializer(JsonSerializator, loadedTestPlugin);
+}
+
+TEST_F(SerializationPluginTest, ProtobufLoadedSerializeTest)
+{
+    ASSERT_NE(serializers[ProtobufSerializator].get(), nullptr);
+}
+
+TEST_F(SerializationPluginTest, JsonLoadedSerializeTest)
+{
+    ASSERT_NE(serializers[JsonSerializator].get(), nullptr);
+}
+
+TEST_F(SerializationPluginTest, PluginLoadedSerializeTest)
+{
+    ASSERT_FLOAT_EQ(QProtobufSerializerRegistry::instance().pluginVersion(loadedTestPlugin), 1.0);
+}
+
+TEST_F(SerializationPluginTest, PortobufLoadedSerializeTest)
+{
+    ASSERT_FLOAT_EQ(QProtobufSerializerRegistry::instance().pluginProtobufVersion(loadedTestPlugin), 1.0);
+}
+
+TEST_F(SerializationPluginTest, RatingLoadedSerializeTest)
+{
+    ASSERT_EQ(QProtobufSerializerRegistry::instance().pluginRating(loadedTestPlugin), 0);
+}
+
+TEST_F(SerializationPluginTest, UnknownPluginLoadedSerializeTest)
+{
+    ASSERT_ANY_THROW(QProtobufSerializerRegistry::instance().getSerializer("SomeName", loadedTestPlugin));
+}

+ 46 - 0
tests/test_qprotobuf_serializer_plugin/serializationplugintest.h

@@ -0,0 +1,46 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2019 Tatyana Borisova <tanusshhka@mail.ru>
+ *
+ * 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 <gtest/gtest.h>
+#include <qprotobufserializer.h>
+
+namespace QtProtobuf {
+namespace tests {
+
+class SerializationPluginTest : public ::testing::Test
+{
+public:
+    SerializationPluginTest() = default;
+    void SetUp() override;
+    static void SetUpTestCase();
+protected:
+    std::unordered_map<QString, std::shared_ptr<QAbstractProtobufSerializer>> serializers;
+    static QString loadedTestPlugin;
+};
+
+}
+}