/* * MIT License * * Copyright (c) 2022 Alexey Edelev , Viktor Kopp * * 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. */ #ifndef QT_PROTOBUF_BASIC_MULTI_TEST # include "externalpackageconsumer.qpb.h" # include "externalpackage.qpb.h" #endif #include #include #include #include class QtProtobufExternalPackageGenerationTest : public QObject { Q_OBJECT public: QtProtobufExternalPackageGenerationTest() { qRegisterProtobufTypes(); } private slots: void RepeatedExternalComplexMessageTest(); void ExternalEnumMessageTest(); void ExternalComplexMessageTest(); void NestedMessageTest(); }; using namespace qtprotobufnamespace::tests; void QtProtobufExternalPackageGenerationTest::RepeatedExternalComplexMessageTest() { const char *propertyName = "testExternalComplexData"; qProtobufAssertMessagePropertyRegistered( 1, "qtprotobufnamespace1::externaltests::ExternalComplexMessageRepeated", propertyName); qtprotobufnamespace1::externaltests::ExternalInt32Message complexMessage; complexMessage.setLocalList({1, 2, 3, 4, 5}); QSharedPointer externalMessage(new qtprotobufnamespace1::externaltests::ExternalComplexMessage); externalMessage->setTestFieldInt(complexMessage); qtprotobufnamespace1::externaltests::ExternalComplexMessageRepeated complexMessageList; complexMessageList << externalMessage; RepeatedExternalComplexMessage test; QVERIFY(test.setProperty(propertyName, QVariant::fromValue(complexMessageList))); QVERIFY(test.property(propertyName).value() == complexMessageList); QVERIFY(test.testExternalComplex() == complexMessageList); } void QtProtobufExternalPackageGenerationTest::ExternalEnumMessageTest() { using ExternalGlobalEnums = qtprotobufnamespace1::externaltests::ExternalTestEnumGadget; const char *propertyName = "externalEnum"; qProtobufAssertMessagePropertyRegistered(1, "qtprotobufnamespace1::externaltests::ExternalTestEnumGadget::ExternalTestEnum", propertyName); SimpleExternalEnumMessage test; QVERIFY(test.setProperty(propertyName, QVariant::fromValue(ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4))); QCOMPARE(test.property(propertyName).value(), ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4); QCOMPARE(test.externalEnum(), ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4); } void QtProtobufExternalPackageGenerationTest::ExternalComplexMessageTest() { const char *propertyName = "localList"; qProtobufAssertMessagePropertyRegistered( 1, "QtProtobuf::int32List", propertyName); qtprotobufnamespace1::externaltests::ExternalInt32Message test; QVERIFY(test.setProperty(propertyName, QVariant::fromValue({1, 2, 3, 4, 5}))); QVERIFY(test.property(propertyName).value() == QtProtobuf::int32List({1, 2, 3, 4, 5})); QVERIFY(test.localList() == QtProtobuf::int32List({1, 2, 3, 4, 5})); } void QtProtobufExternalPackageGenerationTest::NestedMessageTest() { qProtobufAssertMessagePropertyRegistered(1, "qtprotobufnamespace1::externaltests::NestedFieldMessage::NestedMessage*", "externalNested"); NestedExternal test{{15}}; QCOMPARE(test.externalNested().field(), 15); const char *propertyName = "externalNested"; QVERIFY(test.setProperty(propertyName, QVariant::fromValue(new qtprotobufnamespace1::externaltests::NestedFieldMessage::NestedMessage{55}))); QVERIFY(*(test.property(propertyName).value()) == qtprotobufnamespace1::externaltests::NestedFieldMessage::NestedMessage{55}); QVERIFY(test.externalNested() == qtprotobufnamespace1::externaltests::NestedFieldMessage::NestedMessage{55}); } QTEST_MAIN(QtProtobufExternalPackageGenerationTest) #include "externalpackage.moc"