externalpackage.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2022 Alexey Edelev <semlanik@gmail.com>, Viktor Kopp <vifactor@gmail.com>
  5. *
  6. * This file is part of QtProtobuf project https://git.semlanik.org/semlanik/qtprotobuf
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this
  9. * software and associated documentation files (the "Software"), to deal in the Software
  10. * without restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  12. * to permit persons to whom the Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all copies
  16. * or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef QT_PROTOBUF_BASIC_MULTI_TEST
  26. # include "externalpackageconsumer.qpb.h"
  27. # include "externalpackage.qpb.h"
  28. #endif
  29. #include <QMetaProperty>
  30. #include <QSignalSpy>
  31. #include <QtTest/QtTest>
  32. #include <qtprotobuftestscommon.h>
  33. class QtProtobufExternalPackageGenerationTest : public QObject
  34. {
  35. Q_OBJECT
  36. public:
  37. QtProtobufExternalPackageGenerationTest()
  38. {
  39. qRegisterProtobufTypes();
  40. }
  41. private slots:
  42. void RepeatedExternalComplexMessageTest();
  43. void ExternalEnumMessageTest();
  44. void ExternalComplexMessageTest();
  45. void NestedMessageTest();
  46. };
  47. using namespace qtprotobufnamespace::tests;
  48. void QtProtobufExternalPackageGenerationTest::RepeatedExternalComplexMessageTest()
  49. {
  50. const char *propertyName = "testExternalComplexData";
  51. qProtobufAssertMessagePropertyRegistered<RepeatedExternalComplexMessage, qtprotobufnamespace1::externaltests::ExternalComplexMessageRepeated>(
  52. 1, "qtprotobufnamespace1::externaltests::ExternalComplexMessageRepeated", propertyName);
  53. qtprotobufnamespace1::externaltests::ExternalInt32Message complexMessage;
  54. complexMessage.setLocalList({1, 2, 3, 4, 5});
  55. QSharedPointer<qtprotobufnamespace1::externaltests::ExternalComplexMessage> externalMessage(new qtprotobufnamespace1::externaltests::ExternalComplexMessage);
  56. externalMessage->setTestFieldInt(complexMessage);
  57. qtprotobufnamespace1::externaltests::ExternalComplexMessageRepeated complexMessageList;
  58. complexMessageList << externalMessage;
  59. RepeatedExternalComplexMessage test;
  60. QVERIFY(test.setProperty(propertyName, QVariant::fromValue(complexMessageList)));
  61. QVERIFY(test.property(propertyName).value<qtprotobufnamespace1::externaltests::ExternalComplexMessageRepeated>() == complexMessageList);
  62. QVERIFY(test.testExternalComplex() == complexMessageList);
  63. }
  64. void QtProtobufExternalPackageGenerationTest::ExternalEnumMessageTest()
  65. {
  66. using ExternalGlobalEnums = qtprotobufnamespace1::externaltests::ExternalTestEnumGadget;
  67. const char *propertyName = "externalEnum";
  68. qProtobufAssertMessagePropertyRegistered<SimpleExternalEnumMessage, ExternalGlobalEnums::ExternalTestEnum>(1, "qtprotobufnamespace1::externaltests::ExternalTestEnumGadget::ExternalTestEnum", propertyName);
  69. SimpleExternalEnumMessage test;
  70. QVERIFY(test.setProperty(propertyName, QVariant::fromValue<ExternalGlobalEnums::ExternalTestEnum>(ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4)));
  71. QCOMPARE(test.property(propertyName).value<ExternalGlobalEnums::ExternalTestEnum>(), ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4);
  72. QCOMPARE(test.externalEnum(), ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4);
  73. }
  74. void QtProtobufExternalPackageGenerationTest::ExternalComplexMessageTest()
  75. {
  76. const char *propertyName = "localList";
  77. qProtobufAssertMessagePropertyRegistered<qtprotobufnamespace1::externaltests::ExternalInt32Message, QtProtobuf::int32List>(
  78. 1, "QtProtobuf::int32List", propertyName);
  79. qtprotobufnamespace1::externaltests::ExternalInt32Message test;
  80. QVERIFY(test.setProperty(propertyName, QVariant::fromValue<QtProtobuf::int32List>({1, 2, 3, 4, 5})));
  81. QVERIFY(test.property(propertyName).value<QtProtobuf::int32List>() == QtProtobuf::int32List({1, 2, 3, 4, 5}));
  82. QVERIFY(test.localList() == QtProtobuf::int32List({1, 2, 3, 4, 5}));
  83. }
  84. void QtProtobufExternalPackageGenerationTest::NestedMessageTest()
  85. {
  86. qProtobufAssertMessagePropertyRegistered<NestedExternal, qtprotobufnamespace1::externaltests::NestedFieldMessage::NestedMessage*>(1, "qtprotobufnamespace1::externaltests::NestedFieldMessage::NestedMessage*", "externalNested");
  87. NestedExternal test{{15}};
  88. QCOMPARE(test.externalNested().field(), 15);
  89. const char *propertyName = "externalNested";
  90. QVERIFY(test.setProperty(propertyName, QVariant::fromValue<qtprotobufnamespace1::externaltests::NestedFieldMessage::NestedMessage*>(new qtprotobufnamespace1::externaltests::NestedFieldMessage::NestedMessage{55})));
  91. QVERIFY(*(test.property(propertyName).value<qtprotobufnamespace1::externaltests::NestedFieldMessage::NestedMessage*>()) == qtprotobufnamespace1::externaltests::NestedFieldMessage::NestedMessage{55});
  92. QVERIFY(test.externalNested() == qtprotobufnamespace1::externaltests::NestedFieldMessage::NestedMessage{55});
  93. }
  94. QTEST_MAIN(QtProtobufExternalPackageGenerationTest)
  95. #include "externalpackage.moc"