12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #include <QtQuickTest>
- #include <QUrl>
- #include <QQmlEngine>
- #include <QQmlContext>
- #include <QQmlExtensionPlugin>
- #include <QGrpcHttp2Channel>
- #include <QGrpcInsecureCredentials>
- #include <QMetaObject>
- #include "testservice_grpc.qpb.h"
- using namespace qtprotobufnamespace::tests;
- using namespace QtProtobuf;
- class TestSetup : public QObject {
- Q_OBJECT
- public:
- static QUrl m_echoServerAddress;
- TestSetup() {
- QtProtobuf::qRegisterProtobufTypes();
- Q_PROTOBUF_IMPORT_QUICK_PLUGIN()
- Q_GRPC_IMPORT_QUICK_PLUGIN()
- qmlRegisterSingletonType<TestServiceClient>("qtprotobufnamespace.tests", 1, 0, "TestServiceClient", [](QQmlEngine *engine, QJSEngine *) -> QObject *{
- static TestServiceClient clientInstance;
- clientInstance.attachChannel(std::make_shared<QGrpcHttp2Channel>(m_echoServerAddress, QGrpcInsecureChannelCredentials() | QGrpcInsecureCallCredentials()));
- engine->setObjectOwnership(&clientInstance, QQmlEngine::CppOwnership);
- return &clientInstance;
- });
- }
- ~TestSetup() = default;
- public slots:
- void qmlEngineAvailable(QQmlEngine *engine)
- {
- engine->rootContext()->setContextProperty("qVersion", QT_VERSION);
- }
- };
|