diff --git a/src/tools/qtgrpcgen/Qt6GrpcToolsMacros.cmake b/src/tools/qtgrpcgen/Qt6GrpcToolsMacros.cmake index d5ce0170..989526ae 100644 --- a/src/tools/qtgrpcgen/Qt6GrpcToolsMacros.cmake +++ b/src/tools/qtgrpcgen/Qt6GrpcToolsMacros.cmake @@ -154,7 +154,7 @@ function(qt6_add_grpc target type) _qt_internal_protoc_generate_cpp_exports(generated_export generated_export_options ${target} "${arg_EXPORT_MACRO}") if(generated_export) - list(APPEND cpp_sources "${generated_export}") # TODO: Unused, see QTBUG-121856 + list(APPEND generated_files "${generated_export}") endif() list(APPEND generation_options "${generated_export_options}") endif() diff --git a/src/tools/qtgrpcgen/qgrpcgenerator.cpp b/src/tools/qtgrpcgen/qgrpcgenerator.cpp index 52017a4e..ca8c892d 100644 --- a/src/tools/qtgrpcgen/qgrpcgenerator.cpp +++ b/src/tools/qtgrpcgen/qgrpcgenerator.cpp @@ -181,6 +181,11 @@ bool QGrpcGenerator::GenerateClientServices(const FileDescriptor *file, clientHeaderPrinter->Print("\n"); std::set internalIncludes = QGrpcGenerator::GetInternalIncludes(file); + if (!Options::instance().exportMacroFilename().empty()) { + std::string exportMacroFilename = Options::instance().exportMacroFilename(); + internalIncludes.insert(utils::removeFileSuffix(exportMacroFilename)); + } + for (const auto &include : internalIncludes) { clientHeaderPrinter->Print({ { "include", include } }, CommonTemplates::InternalIncludeTemplate()); @@ -243,5 +248,5 @@ bool QGrpcGenerator::GenerateAll(const std::vector &file std::string *error) const { Options::setFromString(parameter, qtprotoccommon::Options::QtGrpcGen); - return CodeGenerator::GenerateAll(files, parameter, generatorContext, error); + return GeneratorBase::GenerateAll(files, parameter, generatorContext, error); } diff --git a/src/tools/qtprotobufgen/qprotobufgenerator.cpp b/src/tools/qtprotobufgen/qprotobufgenerator.cpp index fbdbe253..7fac5949 100644 --- a/src/tools/qtprotobufgen/qprotobufgenerator.cpp +++ b/src/tools/qtprotobufgen/qprotobufgenerator.cpp @@ -118,32 +118,6 @@ void QProtobufGenerator::GenerateSources(const FileDescriptor *file, } -bool QProtobufGenerator::GenerateAll(const std::vector &files, - const std::string ¶meter, GeneratorContext *generatorContext, - std::string *error) const -{ - assert(!files.empty()); - assert(generatorContext != nullptr); - - Options::setFromString(parameter); - if (Options::instance().generateMacroExportFile()) { - std::string exportMacroName = Options::instance().exportMacro(); - std::string exportMacroFilename = Options::instance().exportMacroFilename(); - - assert(!exportMacroName.empty()); - assert(!exportMacroFilename.empty()); - - std::unique_ptr headerStream(generatorContext - ->Open(exportMacroFilename)); - std::shared_ptr headerPrinter(new Printer(headerStream.get(), '$')); - printDisclaimer(headerPrinter.get()); - headerPrinter->Print({ { "export_macro", Options::instance().exportMacro() } }, - CommonTemplates::ExportMacroTemplate()); - headerPrinter->PrintRaw("\n"); - } - return CodeGenerator::GenerateAll(files, parameter, generatorContext, error); -} - void QProtobufGenerator::GenerateHeader(const FileDescriptor *file, GeneratorContext *generatorContext) const { diff --git a/src/tools/qtprotobufgen/qprotobufgenerator.h b/src/tools/qtprotobufgen/qprotobufgenerator.h index aebcfcdf..cbf81a93 100644 --- a/src/tools/qtprotobufgen/qprotobufgenerator.h +++ b/src/tools/qtprotobufgen/qprotobufgenerator.h @@ -24,10 +24,6 @@ class QProtobufGenerator : public qtprotoccommon::GeneratorBase public: QProtobufGenerator(); ~QProtobufGenerator(); - bool GenerateAll(const std::vector &files, - const std::string ¶meter, - ::google::protobuf::compiler::GeneratorContext *generatorContext, - std::string *error) const override; bool Generate(const ::google::protobuf::FileDescriptor *file, const std::string ¶meter, ::google::protobuf::compiler::GeneratorContext *generatorContext, diff --git a/src/tools/qtprotoccommon/generatorbase.cpp b/src/tools/qtprotoccommon/generatorbase.cpp index 5c52adb2..554cdd2b 100644 --- a/src/tools/qtprotoccommon/generatorbase.cpp +++ b/src/tools/qtprotoccommon/generatorbase.cpp @@ -25,7 +25,25 @@ bool GeneratorBase::GenerateAll(const std::vector &files const std::string ¶meter, GeneratorContext *generatorContext, std::string *error) const { + assert(!files.empty()); + assert(generatorContext != nullptr); + Options::setFromString(parameter); + if (Options::instance().generateMacroExportFile()) { + std::string exportMacroName = Options::instance().exportMacro(); + std::string exportMacroFilename = Options::instance().exportMacroFilename(); + + assert(!exportMacroName.empty()); + assert(!exportMacroFilename.empty()); + + std::unique_ptr headerStream(generatorContext + ->Open(exportMacroFilename)); + std::shared_ptr headerPrinter(new Printer(headerStream.get(), '$')); + printDisclaimer(headerPrinter.get()); + headerPrinter->Print({ { "export_macro", exportMacroName } }, + CommonTemplates::ExportMacroTemplate()); + headerPrinter->PrintRaw("\n"); + } return CodeGenerator::GenerateAll(files, parameter, generatorContext, error); } diff --git a/tests/auto/grpcgen/CMakeLists.txt b/tests/auto/grpcgen/CMakeLists.txt index 7130cec0..6497afe6 100644 --- a/tests/auto/grpcgen/CMakeLists.txt +++ b/tests/auto/grpcgen/CMakeLists.txt @@ -35,6 +35,26 @@ qt_add_grpc(tst_qtgrpcgen CLIENT qt_autogen_tools_initial_setup(tst_qtgrpcgen) + +qt_add_grpc(tst_qtgrpcgen_client_grpc_only CLIENT + PROTO_FILES + ../shared/data/proto/testservice.proto + GENERATE_PACKAGE_SUBFOLDERS + OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_grpc_generated/separate/grpc" +) +qt_autogen_tools_initial_setup(tst_qtgrpcgen_client_grpc_only) + +qt_add_protobuf(tst_qtgrpcgen_protobuf_only + OUTPUT_DIRECTORY + "${CMAKE_CURRENT_BINARY_DIR}/qt_grpc_generated/separate/protobuf" + GENERATE_PACKAGE_SUBFOLDERS + PROTO_FILES + ../shared/data/proto/testservice.proto +) +qt_autogen_tools_initial_setup(tst_qtgrpcgen_protobuf_only) + +target_link_libraries(tst_qtgrpcgen_client_grpc_only PRIVATE tst_qtgrpcgen_protobuf_only) + if(TARGET Qt6::Qml) qt_internal_extend_target(tst_qtgrpcgen DEFINES diff --git a/tests/auto/grpcgen/data/expected_result/separate/grpc/qtgrpc/tests/testservice_client.grpc.qpb.cpp b/tests/auto/grpcgen/data/expected_result/separate/grpc/qtgrpc/tests/testservice_client.grpc.qpb.cpp new file mode 100644 index 00000000..551aa6c8 --- /dev/null +++ b/tests/auto/grpcgen/data/expected_result/separate/grpc/qtgrpc/tests/testservice_client.grpc.qpb.cpp @@ -0,0 +1,45 @@ +/* This file is autogenerated. DO NOT CHANGE. All changes will be lost */ + +#include "qtgrpc/tests/testservice_client.grpc.qpb.h" + +namespace qtgrpc::tests { +namespace TestService { +using namespace Qt::StringLiterals; + +Client::Client(QObject *parent) + : QAbstractGrpcClient("qtgrpc.tests.TestService"_L1, parent) +{ +} + + +std::shared_ptr Client::testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options) +{ + return call("testMethod"_L1, arg, options); +} + +void Client::testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QObject *context, const std::function)> &callback, const QGrpcCallOptions &options) +{ + std::shared_ptr reply = call("testMethod"_L1, arg, options); + QObject::connect(reply.get(), &QGrpcCallReply::finished, context, [reply, callback]() { + callback(reply); + }, Qt::SingleShotConnection); +} + +std::shared_ptr Client::streamTestMethodServerStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options) +{ + return startStream("testMethodServerStream"_L1, arg, options); +} + +std::shared_ptr Client::streamTestMethodClientStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options) +{ + return startStream("testMethodClientStream"_L1, arg, options); +} + +std::shared_ptr Client::streamTestMethodBiStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options) +{ + return startStream("testMethodBiStream"_L1, arg, options); +} + +} // namespace TestService +} // namespace qtgrpc::tests + diff --git a/tests/auto/grpcgen/data/expected_result/separate/grpc/qtgrpc/tests/testservice_client.grpc.qpb.h b/tests/auto/grpcgen/data/expected_result/separate/grpc/qtgrpc/tests/testservice_client.grpc.qpb.h new file mode 100644 index 00000000..3691a0da --- /dev/null +++ b/tests/auto/grpcgen/data/expected_result/separate/grpc/qtgrpc/tests/testservice_client.grpc.qpb.h @@ -0,0 +1,42 @@ +/* This file is autogenerated. DO NOT CHANGE. All changes will be lost */ + +#ifndef QPROTOBUF_TESTSERVICE_CLIENT_H +#define QPROTOBUF_TESTSERVICE_CLIENT_H + +#include +#include +#include + +#include +#include +#include + +#include + +#include "qtgrpc/tests/testservice.qpb.h" +#include "tst_qtgrpcgen_client_grpc_only_exports.qpb.h" + +namespace qtgrpc::tests { +namespace TestService { + +class QPB_TST_QTGRPCGEN_CLIENT_GRPC_ONLY_EXPORT Client : public QAbstractGrpcClient +{ + Q_OBJECT + +public: + explicit Client(QObject *parent = nullptr); + std::shared_ptr testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {}); + Q_INVOKABLE void testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QObject *context, const std::function)> &callback, const QGrpcCallOptions &options = {}); + + std::shared_ptr streamTestMethodServerStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {}); + + std::shared_ptr streamTestMethodClientStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {}); + + std::shared_ptr streamTestMethodBiStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {}); + + +}; +} // namespace TestService +} // namespace qtgrpc::tests + +#endif // QPROTOBUF_TESTSERVICE_CLIENT_H diff --git a/tests/auto/grpcgen/data/expected_result/separate/grpc/tst_qtgrpcgen_client_grpc_only_exports.qpb.h b/tests/auto/grpcgen/data/expected_result/separate/grpc/tst_qtgrpcgen_client_grpc_only_exports.qpb.h new file mode 100644 index 00000000..8bb19087 --- /dev/null +++ b/tests/auto/grpcgen/data/expected_result/separate/grpc/tst_qtgrpcgen_client_grpc_only_exports.qpb.h @@ -0,0 +1,12 @@ +/* This file is autogenerated. DO NOT CHANGE. All changes will be lost */ + +#if defined(QT_SHARED) || !defined(QT_STATIC) +# if defined(QT_BUILD_TST_QTGRPCGEN_CLIENT_GRPC_ONLY_LIB) +# define QPB_TST_QTGRPCGEN_CLIENT_GRPC_ONLY_EXPORT Q_DECL_EXPORT +# else +# define QPB_TST_QTGRPCGEN_CLIENT_GRPC_ONLY_EXPORT Q_DECL_IMPORT +# endif +#else +# define QPB_TST_QTGRPCGEN_CLIENT_GRPC_ONLY_EXPORT +#endif + diff --git a/tests/auto/grpcgen/data/expected_result/separate/protobuf/qtgrpc/tests/testservice.qpb.cpp b/tests/auto/grpcgen/data/expected_result/separate/protobuf/qtgrpc/tests/testservice.qpb.cpp new file mode 100644 index 00000000..0b913ffe --- /dev/null +++ b/tests/auto/grpcgen/data/expected_result/separate/protobuf/qtgrpc/tests/testservice.qpb.cpp @@ -0,0 +1,356 @@ +/* This file is autogenerated. DO NOT CHANGE. All changes will be lost */ + +#include "qtgrpc/tests/testservice.qpb.h" +#include +#include + +namespace qtgrpc::tests { + +class SimpleStringMessage_QtProtobufData : public QSharedData +{ +public: + SimpleStringMessage_QtProtobufData() + : QSharedData() + { + } + + SimpleStringMessage_QtProtobufData(const SimpleStringMessage_QtProtobufData &other) + : QSharedData(other), + m_testFieldString(other.m_testFieldString) + { + } + + QString m_testFieldString; +}; + +SimpleStringMessage::~SimpleStringMessage() = default; + +static constexpr struct { + QtProtobufPrivate::QProtobufPropertyOrdering::Data data; + const std::array qt_protobuf_SimpleStringMessage_uint_data; + const char qt_protobuf_SimpleStringMessage_char_data[50]; +} qt_protobuf_SimpleStringMessage_metadata { + // data + { + 0, /* = version */ + 1, /* = num fields */ + 2, /* = field number offset */ + 3, /* = property index offset */ + 4, /* = field flags offset */ + 32, /* = message full name length */ + }, + // uint_data + { + // JSON name offsets: + 33, /* = testFieldString */ + 49, /* = end-of-string-marker */ + // Field numbers: + 6, /* = testFieldString */ + // Property indices: + 0, /* = testFieldString */ + // Field flags: + QtProtobufPrivate::NoFlags, /* = testFieldString */ + }, + // char_data + /* metadata char_data: */ + "qtgrpc.tests.SimpleStringMessage\0" /* = full message name */ + /* field char_data: */ + "testFieldString\0" +}; + +const QtProtobufPrivate::QProtobufPropertyOrdering SimpleStringMessage::staticPropertyOrdering = { + &qt_protobuf_SimpleStringMessage_metadata.data +}; + +void SimpleStringMessage::registerTypes() +{ + qRegisterMetaType(); + qRegisterMetaType(); +} + +SimpleStringMessage::SimpleStringMessage() + : QProtobufMessage(&SimpleStringMessage::staticMetaObject, &SimpleStringMessage::staticPropertyOrdering), + dptr(new SimpleStringMessage_QtProtobufData) +{ +} + +SimpleStringMessage::SimpleStringMessage(const SimpleStringMessage &other) + : QProtobufMessage(other), + dptr(other.dptr) +{ +} +SimpleStringMessage &SimpleStringMessage::operator =(const SimpleStringMessage &other) +{ + QProtobufMessage::operator=(other); + dptr = other.dptr; + return *this; +} +SimpleStringMessage::SimpleStringMessage(SimpleStringMessage &&other) noexcept + : QProtobufMessage(std::move(other)), + dptr(std::move(other.dptr)) +{ +} +SimpleStringMessage &SimpleStringMessage::operator =(SimpleStringMessage &&other) noexcept +{ + QProtobufMessage::operator=(std::move(other)); + dptr.swap(other.dptr); + return *this; +} +bool SimpleStringMessage::operator ==(const SimpleStringMessage &other) const +{ + return QProtobufMessage::isEqual(*this, other) + && dptr->m_testFieldString == other.dptr->m_testFieldString; +} + +bool SimpleStringMessage::operator !=(const SimpleStringMessage &other) const +{ + return !this->operator ==(other); +} + +QString SimpleStringMessage::testFieldString() const +{ + return dptr->m_testFieldString; +} + +void SimpleStringMessage::setTestFieldString(const QString &testFieldString) +{ + if (dptr->m_testFieldString != testFieldString) { + dptr.detach(); + dptr->m_testFieldString = testFieldString; + } +} + + +class SimpleIntMessage_QtProtobufData : public QSharedData +{ +public: + SimpleIntMessage_QtProtobufData() + : QSharedData(), + m_testField(0) + { + } + + SimpleIntMessage_QtProtobufData(const SimpleIntMessage_QtProtobufData &other) + : QSharedData(other), + m_testField(other.m_testField) + { + } + + QtProtobuf::sint32 m_testField; +}; + +SimpleIntMessage::~SimpleIntMessage() = default; + +static constexpr struct { + QtProtobufPrivate::QProtobufPropertyOrdering::Data data; + const std::array qt_protobuf_SimpleIntMessage_uint_data; + const char qt_protobuf_SimpleIntMessage_char_data[41]; +} qt_protobuf_SimpleIntMessage_metadata { + // data + { + 0, /* = version */ + 1, /* = num fields */ + 2, /* = field number offset */ + 3, /* = property index offset */ + 4, /* = field flags offset */ + 29, /* = message full name length */ + }, + // uint_data + { + // JSON name offsets: + 30, /* = testField */ + 40, /* = end-of-string-marker */ + // Field numbers: + 1, /* = testField */ + // Property indices: + 0, /* = testField */ + // Field flags: + QtProtobufPrivate::NoFlags, /* = testField */ + }, + // char_data + /* metadata char_data: */ + "qtgrpc.tests.SimpleIntMessage\0" /* = full message name */ + /* field char_data: */ + "testField\0" +}; + +const QtProtobufPrivate::QProtobufPropertyOrdering SimpleIntMessage::staticPropertyOrdering = { + &qt_protobuf_SimpleIntMessage_metadata.data +}; + +void SimpleIntMessage::registerTypes() +{ + qRegisterMetaType(); + qRegisterMetaType(); +} + +SimpleIntMessage::SimpleIntMessage() + : QProtobufMessage(&SimpleIntMessage::staticMetaObject, &SimpleIntMessage::staticPropertyOrdering), + dptr(new SimpleIntMessage_QtProtobufData) +{ +} + +SimpleIntMessage::SimpleIntMessage(const SimpleIntMessage &other) + : QProtobufMessage(other), + dptr(other.dptr) +{ +} +SimpleIntMessage &SimpleIntMessage::operator =(const SimpleIntMessage &other) +{ + QProtobufMessage::operator=(other); + dptr = other.dptr; + return *this; +} +SimpleIntMessage::SimpleIntMessage(SimpleIntMessage &&other) noexcept + : QProtobufMessage(std::move(other)), + dptr(std::move(other.dptr)) +{ +} +SimpleIntMessage &SimpleIntMessage::operator =(SimpleIntMessage &&other) noexcept +{ + QProtobufMessage::operator=(std::move(other)); + dptr.swap(other.dptr); + return *this; +} +bool SimpleIntMessage::operator ==(const SimpleIntMessage &other) const +{ + return QProtobufMessage::isEqual(*this, other) + && dptr->m_testField == other.dptr->m_testField; +} + +bool SimpleIntMessage::operator !=(const SimpleIntMessage &other) const +{ + return !this->operator ==(other); +} + +QtProtobuf::sint32 SimpleIntMessage::testField() const +{ + return dptr->m_testField; +} + +void SimpleIntMessage::setTestField(const QtProtobuf::sint32 &testField) +{ + if (dptr->m_testField != testField) { + dptr.detach(); + dptr->m_testField = testField; + } +} + + +class BlobMessage_QtProtobufData : public QSharedData +{ +public: + BlobMessage_QtProtobufData() + : QSharedData() + { + } + + BlobMessage_QtProtobufData(const BlobMessage_QtProtobufData &other) + : QSharedData(other), + m_testBytes(other.m_testBytes) + { + } + + QByteArray m_testBytes; +}; + +BlobMessage::~BlobMessage() = default; + +static constexpr struct { + QtProtobufPrivate::QProtobufPropertyOrdering::Data data; + const std::array qt_protobuf_BlobMessage_uint_data; + const char qt_protobuf_BlobMessage_char_data[36]; +} qt_protobuf_BlobMessage_metadata { + // data + { + 0, /* = version */ + 1, /* = num fields */ + 2, /* = field number offset */ + 3, /* = property index offset */ + 4, /* = field flags offset */ + 24, /* = message full name length */ + }, + // uint_data + { + // JSON name offsets: + 25, /* = testBytes */ + 35, /* = end-of-string-marker */ + // Field numbers: + 1, /* = testBytes */ + // Property indices: + 0, /* = testBytes */ + // Field flags: + QtProtobufPrivate::NoFlags, /* = testBytes */ + }, + // char_data + /* metadata char_data: */ + "qtgrpc.tests.BlobMessage\0" /* = full message name */ + /* field char_data: */ + "testBytes\0" +}; + +const QtProtobufPrivate::QProtobufPropertyOrdering BlobMessage::staticPropertyOrdering = { + &qt_protobuf_BlobMessage_metadata.data +}; + +void BlobMessage::registerTypes() +{ + qRegisterMetaType(); + qRegisterMetaType(); +} + +BlobMessage::BlobMessage() + : QProtobufMessage(&BlobMessage::staticMetaObject, &BlobMessage::staticPropertyOrdering), + dptr(new BlobMessage_QtProtobufData) +{ +} + +BlobMessage::BlobMessage(const BlobMessage &other) + : QProtobufMessage(other), + dptr(other.dptr) +{ +} +BlobMessage &BlobMessage::operator =(const BlobMessage &other) +{ + QProtobufMessage::operator=(other); + dptr = other.dptr; + return *this; +} +BlobMessage::BlobMessage(BlobMessage &&other) noexcept + : QProtobufMessage(std::move(other)), + dptr(std::move(other.dptr)) +{ +} +BlobMessage &BlobMessage::operator =(BlobMessage &&other) noexcept +{ + QProtobufMessage::operator=(std::move(other)); + dptr.swap(other.dptr); + return *this; +} +bool BlobMessage::operator ==(const BlobMessage &other) const +{ + return QProtobufMessage::isEqual(*this, other) + && dptr->m_testBytes == other.dptr->m_testBytes; +} + +bool BlobMessage::operator !=(const BlobMessage &other) const +{ + return !this->operator ==(other); +} + +QByteArray BlobMessage::testBytes() const +{ + return dptr->m_testBytes; +} + +void BlobMessage::setTestBytes(const QByteArray &testBytes) +{ + if (dptr->m_testBytes != testBytes) { + dptr.detach(); + dptr->m_testBytes = testBytes; + } +} + +} // namespace qtgrpc::tests + +#include "moc_testservice.qpb.cpp" diff --git a/tests/auto/grpcgen/data/expected_result/separate/protobuf/qtgrpc/tests/testservice.qpb.h b/tests/auto/grpcgen/data/expected_result/separate/protobuf/qtgrpc/tests/testservice.qpb.h new file mode 100644 index 00000000..ddee11af --- /dev/null +++ b/tests/auto/grpcgen/data/expected_result/separate/protobuf/qtgrpc/tests/testservice.qpb.h @@ -0,0 +1,150 @@ +/* This file is autogenerated. DO NOT CHANGE. All changes will be lost */ + +#ifndef QPROTOBUF_TESTSERVICE_H +#define QPROTOBUF_TESTSERVICE_H + +#include +#include +#include + +#include +#include +#include "tst_qtgrpcgen_protobuf_only_exports.qpb.h" + +#include +#include +#include + +#include + + +namespace qtgrpc::tests { +class SimpleStringMessage; +using SimpleStringMessageRepeated = QList; +namespace SimpleStringMessage_QtProtobufNested { +enum class QtProtobufFieldEnum; +} // namespace SimpleStringMessage_QtProtobufNested + +class SimpleIntMessage; +using SimpleIntMessageRepeated = QList; +namespace SimpleIntMessage_QtProtobufNested { +enum class QtProtobufFieldEnum; +} // namespace SimpleIntMessage_QtProtobufNested + +class BlobMessage; +using BlobMessageRepeated = QList; +namespace BlobMessage_QtProtobufNested { +enum class QtProtobufFieldEnum; +} // namespace BlobMessage_QtProtobufNested + + +class SimpleStringMessage_QtProtobufData; +class QPB_TST_QTGRPCGEN_PROTOBUF_ONLY_EXPORT SimpleStringMessage : public QProtobufMessage +{ + Q_GADGET + Q_PROTOBUF_OBJECT + Q_PROPERTY(QString testFieldString READ testFieldString WRITE setTestFieldString SCRIPTABLE true) + +public: + using QtProtobufFieldEnum = SimpleStringMessage_QtProtobufNested::QtProtobufFieldEnum; + SimpleStringMessage(); + ~SimpleStringMessage(); + SimpleStringMessage(const SimpleStringMessage &other); + SimpleStringMessage &operator =(const SimpleStringMessage &other); + SimpleStringMessage(SimpleStringMessage &&other) noexcept; + SimpleStringMessage &operator =(SimpleStringMessage &&other) noexcept; + bool operator ==(const SimpleStringMessage &other) const; + bool operator !=(const SimpleStringMessage &other) const; + + QString testFieldString() const; + void setTestFieldString(const QString &testFieldString); + static void registerTypes(); + +private: + QExplicitlySharedDataPointer dptr; +}; +namespace SimpleStringMessage_QtProtobufNested { +Q_NAMESPACE_EXPORT(QPB_TST_QTGRPCGEN_PROTOBUF_ONLY_EXPORT) + +enum class QtProtobufFieldEnum { + TestFieldStringProtoFieldNumber = 6, +}; +Q_ENUM_NS(QtProtobufFieldEnum) + +} // namespace SimpleStringMessage_QtProtobufNested + +class SimpleIntMessage_QtProtobufData; +class QPB_TST_QTGRPCGEN_PROTOBUF_ONLY_EXPORT SimpleIntMessage : public QProtobufMessage +{ + Q_GADGET + Q_PROTOBUF_OBJECT + Q_PROPERTY(QtProtobuf::sint32 testField READ testField WRITE setTestField SCRIPTABLE true) + +public: + using QtProtobufFieldEnum = SimpleIntMessage_QtProtobufNested::QtProtobufFieldEnum; + SimpleIntMessage(); + ~SimpleIntMessage(); + SimpleIntMessage(const SimpleIntMessage &other); + SimpleIntMessage &operator =(const SimpleIntMessage &other); + SimpleIntMessage(SimpleIntMessage &&other) noexcept; + SimpleIntMessage &operator =(SimpleIntMessage &&other) noexcept; + bool operator ==(const SimpleIntMessage &other) const; + bool operator !=(const SimpleIntMessage &other) const; + + QtProtobuf::sint32 testField() const; + void setTestField(const QtProtobuf::sint32 &testField); + static void registerTypes(); + +private: + QExplicitlySharedDataPointer dptr; +}; +namespace SimpleIntMessage_QtProtobufNested { +Q_NAMESPACE_EXPORT(QPB_TST_QTGRPCGEN_PROTOBUF_ONLY_EXPORT) + +enum class QtProtobufFieldEnum { + TestFieldProtoFieldNumber = 1, +}; +Q_ENUM_NS(QtProtobufFieldEnum) + +} // namespace SimpleIntMessage_QtProtobufNested + +class BlobMessage_QtProtobufData; +class QPB_TST_QTGRPCGEN_PROTOBUF_ONLY_EXPORT BlobMessage : public QProtobufMessage +{ + Q_GADGET + Q_PROTOBUF_OBJECT + Q_PROPERTY(QByteArray testBytes READ testBytes WRITE setTestBytes SCRIPTABLE true) + +public: + using QtProtobufFieldEnum = BlobMessage_QtProtobufNested::QtProtobufFieldEnum; + BlobMessage(); + ~BlobMessage(); + BlobMessage(const BlobMessage &other); + BlobMessage &operator =(const BlobMessage &other); + BlobMessage(BlobMessage &&other) noexcept; + BlobMessage &operator =(BlobMessage &&other) noexcept; + bool operator ==(const BlobMessage &other) const; + bool operator !=(const BlobMessage &other) const; + + QByteArray testBytes() const; + void setTestBytes(const QByteArray &testBytes); + static void registerTypes(); + +private: + QExplicitlySharedDataPointer dptr; +}; +namespace BlobMessage_QtProtobufNested { +Q_NAMESPACE_EXPORT(QPB_TST_QTGRPCGEN_PROTOBUF_ONLY_EXPORT) + +enum class QtProtobufFieldEnum { + TestBytesProtoFieldNumber = 1, +}; +Q_ENUM_NS(QtProtobufFieldEnum) + +} // namespace BlobMessage_QtProtobufNested +} // namespace qtgrpc::tests + +Q_DECLARE_METATYPE(qtgrpc::tests::SimpleStringMessage) +Q_DECLARE_METATYPE(qtgrpc::tests::SimpleIntMessage) +Q_DECLARE_METATYPE(qtgrpc::tests::BlobMessage) +#endif // QPROTOBUF_TESTSERVICE_H diff --git a/tests/auto/grpcgen/data/expected_result/separate/protobuf/qtgrpc/tests/testservice_protobuftyperegistrations.cpp b/tests/auto/grpcgen/data/expected_result/separate/protobuf/qtgrpc/tests/testservice_protobuftyperegistrations.cpp new file mode 100644 index 00000000..ae816a94 --- /dev/null +++ b/tests/auto/grpcgen/data/expected_result/separate/protobuf/qtgrpc/tests/testservice_protobuftyperegistrations.cpp @@ -0,0 +1,10 @@ +#include +#include "qtgrpc/tests/testservice.qpb.h" + +namespace qtgrpc::tests { +static QtProtobuf::ProtoTypeRegistrar ProtoTypeRegistrarSimpleStringMessage(qRegisterProtobufType); +static QtProtobuf::ProtoTypeRegistrar ProtoTypeRegistrarSimpleIntMessage(qRegisterProtobufType); +static QtProtobuf::ProtoTypeRegistrar ProtoTypeRegistrarBlobMessage(qRegisterProtobufType); +static bool RegisterTestserviceProtobufTypes = [](){ qRegisterProtobufTypes(); return true; }(); +} // namespace qtgrpc::tests + diff --git a/tests/auto/grpcgen/data/expected_result/separate/protobuf/tst_qtgrpcgen_protobuf_only_exports.qpb.h b/tests/auto/grpcgen/data/expected_result/separate/protobuf/tst_qtgrpcgen_protobuf_only_exports.qpb.h new file mode 100644 index 00000000..73d80616 --- /dev/null +++ b/tests/auto/grpcgen/data/expected_result/separate/protobuf/tst_qtgrpcgen_protobuf_only_exports.qpb.h @@ -0,0 +1,12 @@ +/* This file is autogenerated. DO NOT CHANGE. All changes will be lost */ + +#if defined(QT_SHARED) || !defined(QT_STATIC) +# if defined(QT_BUILD_TST_QTGRPCGEN_PROTOBUF_ONLY_LIB) +# define QPB_TST_QTGRPCGEN_PROTOBUF_ONLY_EXPORT Q_DECL_EXPORT +# else +# define QPB_TST_QTGRPCGEN_PROTOBUF_ONLY_EXPORT Q_DECL_IMPORT +# endif +#else +# define QPB_TST_QTGRPCGEN_PROTOBUF_ONLY_EXPORT +#endif + diff --git a/tests/auto/grpcgen/tst_qtgrpcgen.cpp b/tests/auto/grpcgen/tst_qtgrpcgen.cpp index 93153bdf..963b561a 100644 --- a/tests/auto/grpcgen/tst_qtgrpcgen.cpp +++ b/tests/auto/grpcgen/tst_qtgrpcgen.cpp @@ -189,19 +189,37 @@ void tst_qtgrpcgen::cmakeGeneratedFile_data() QTest::addColumn("extension"); QTest::addColumn("cmakeGenerationFolder"); - const QLatin1StringView extensions[] = { cppProtobufGenExtension, - headerProtobufGenExtension, - cppExtension, - headerExtension }; + const QLatin1StringView protobufExtensions[] = { cppProtobufGenExtension, + headerProtobufGenExtension }; - for (const auto extension : extensions) { + const QLatin1StringView grpcExtensions[] = { cppExtension, headerExtension }; + + for (const auto extension : grpcExtensions) { QTest::addRow("testservice%s", extension.data()) << "testservice" << "/folder/qtgrpc/tests/" << QString(extension) << m_cmakeGenerated; + + QTest::addRow("separate/grpc/testservice%s", extension.data()) + << "testservice" + << "/separate/grpc/qtgrpc/tests/" << QString(extension) << m_cmakeGenerated; } + for (const auto extension : protobufExtensions) { + QTest::addRow("testservice%s", extension.data()) + << "testservice" + << "/folder/qtgrpc/tests/" << QString(extension) << m_cmakeGenerated; + + QTest::addRow("separate/protobuf/testservice%s", extension.data()) + << "testservice" + << "/separate/protobuf/qtgrpc/tests/" << QString(extension) << m_cmakeGenerated; + } + + QTest::addRow("tst_qtgrpcgen_client_grpc_only_exports.qpb.h") + << "tst_qtgrpcgen_client_grpc_only_exports.qpb.h" + << "/separate/grpc/" << QString() << m_cmakeGenerated; + #ifdef HAVE_QML const QLatin1StringView qmlExtensions[] = { cppExtension, headerExtension }; @@ -226,7 +244,7 @@ void tst_qtgrpcgen::cmakeGeneratedFile() QFile expectedResultFile(m_expectedResult + folder + fileName + extension); QFile generatedFile(cmakeGenerationFolder + folder + fileName + extension); - QVERIFY(expectedResultFile.exists()); + QVERIFY2(expectedResultFile.exists(), qPrintable(expectedResultFile.fileName())); QVERIFY(generatedFile.exists()); QVERIFY2(expectedResultFile.open(QIODevice::ReadOnly | QIODevice::Text), diff --git a/tests/auto/grpcquick/client/CMakeLists.txt b/tests/auto/grpcquick/client/CMakeLists.txt index 10d7418e..bd1a5ce2 100644 --- a/tests/auto/grpcquick/client/CMakeLists.txt +++ b/tests/auto/grpcquick/client/CMakeLists.txt @@ -25,6 +25,14 @@ qt_internal_add_test(tst_grpc_client_unarycall_qml Qt::Grpc ) +qt_add_grpc(tst_grpc_client_unarycall_qml_gen CLIENT + PROTO_FILES + ../../shared/data/proto/testservice.proto + QML + OUTPUT_DIRECTORY + "${CMAKE_CURRENT_BINARY_DIR}/qt_grpc_generated_qml" +) + qt_add_protobuf(tst_grpc_client_unarycall_qml_gen PROTO_FILES ../../shared/data/proto/testservice.proto @@ -34,14 +42,6 @@ qt_add_protobuf(tst_grpc_client_unarycall_qml_gen "${CMAKE_CURRENT_BINARY_DIR}/qt_grpc_generated_qml" ) -qt_add_grpc(tst_grpc_client_unarycall_qml_gen CLIENT - PROTO_FILES - ../../shared/data/proto/testservice.proto - QML - OUTPUT_DIRECTORY - "${CMAKE_CURRENT_BINARY_DIR}/qt_grpc_generated_qml" -) - qt_policy(SET QTP0001 NEW) qt_add_qml_module(tst_grpc_client_unarycall_qml