12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #include <QtQuickTest>
- #include <QUrl>
- #include <QQmlEngine>
- #include <QQmlContext>
- #include <QQmlExtensionPlugin>
- #include <QGrpcHttp2Channel>
- #include <QGrpcInsecureCredentials>
- #include <QMetaObject>
- #include <memory>
- #include "qabstractgrpcchannel.h"
- #include "testservice_grpc.qpb.h"
- using namespace qtprotobufnamespace::tests;
- using namespace QtProtobuf;
- static std::unique_ptr<TestServiceClient> clientInstance;
- class TestSetup : public QObject {
- Q_OBJECT
- public:
- TestSetup(std::shared_ptr<QAbstractGrpcChannel> channel) {
- clientInstance.reset(new TestServiceClient);
- QtProtobuf::qRegisterProtobufTypes();
- Q_PROTOBUF_IMPORT_QUICK_PLUGIN()
- Q_GRPC_IMPORT_QUICK_PLUGIN()
- clientInstance->attachChannel(channel);
- qmlRegisterSingletonType<TestServiceClient>("qtprotobufnamespace.tests", 1, 0, "TestServiceClient", [](QQmlEngine *engine, QJSEngine *) -> QObject *{
- engine->setObjectOwnership(clientInstance.get(), QQmlEngine::CppOwnership);
- return clientInstance.get();
- });
- }
- ~TestSetup() = default;
- public slots:
- void qmlEngineAvailable(QQmlEngine *engine)
- {
- QVersionNumber qtVersion = QVersionNumber::fromString(qVersion());
- engine->rootContext()->setContextProperty("qVersion", qVersion());
- engine->rootContext()->setContextProperty("qVersionMajor", qtVersion.majorVersion());
- engine->rootContext()->setContextProperty("qVersionMinor", qtVersion.minorVersion());
- }
- };
|