2022-10-05 17:11:30 +00:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
|
|
|
// Copyright (C) 2022 Alexey Edelev <semlanik@gmail.com>, Viktor Kopp <vifactor@gmail.com>
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
|
|
|
|
|
|
#include "syntax.qpb.h"
|
|
|
|
|
|
|
|
#include <QMetaProperty>
|
|
|
|
#include <QSignalSpy>
|
2022-10-05 17:31:33 +00:00
|
|
|
#include <QTest>
|
2022-10-05 17:11:30 +00:00
|
|
|
|
|
|
|
#include <qtprotobuftestscommon.h>
|
|
|
|
|
|
|
|
class QtProtobufSyntaxTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private slots:
|
|
|
|
void UnderscoresTest();
|
|
|
|
void UpperCaseTest();
|
|
|
|
void ReservedTest();
|
|
|
|
void ReservedUpperCaseTest();
|
|
|
|
void ReservedEnumTest();
|
|
|
|
void LowerCaseEnumTest();
|
|
|
|
};
|
|
|
|
|
|
|
|
using namespace qtprotobufnamespace::tests;
|
|
|
|
|
|
|
|
void QtProtobufSyntaxTest::UnderscoresTest()
|
|
|
|
{
|
|
|
|
//Sanity compilation checks
|
|
|
|
Message_Uderscore_name msg1;
|
|
|
|
MessageUderscorename msg2;
|
|
|
|
MessageUnderscoreField msg3;
|
|
|
|
PriorMessageUnderscoreField msg4;
|
|
|
|
FollowingMessageUnderscoreField msg5;
|
|
|
|
CombinedMessageUnderscoreField msg6;
|
|
|
|
|
|
|
|
qProtobufAssertMessagePropertyRegistered<MessageUnderscoreField, QtProtobuf::sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
|
|
|
|
qProtobufAssertMessagePropertyRegistered<PriorMessageUnderscoreField, QtProtobuf::sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
|
|
|
|
qProtobufAssertMessagePropertyRegistered<PriorMessageUnderscoreField, QtProtobuf::sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
|
|
|
|
qProtobufAssertMessagePropertyRegistered<FollowingMessageUnderscoreField , QtProtobuf::sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
|
|
|
|
qProtobufAssertMessagePropertyRegistered<CombinedMessageUnderscoreField , QtProtobuf::sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtProtobufSyntaxTest::UpperCaseTest()
|
|
|
|
{
|
|
|
|
qProtobufAssertMessagePropertyRegistered<MessageUpperCase, QtProtobuf::sint32>(1, "QtProtobuf::sint32", "testField");
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtProtobufSyntaxTest::ReservedTest()
|
|
|
|
{
|
|
|
|
qProtobufAssertMessagePropertyRegistered<MessageReserved, QtProtobuf::sint32>(1, "QtProtobuf::sint32", "import_proto");
|
|
|
|
qProtobufAssertMessagePropertyRegistered<MessageReserved, QtProtobuf::sint32>(2, "QtProtobuf::sint32", "property_proto");
|
|
|
|
qProtobufAssertMessagePropertyRegistered<MessageReserved, QtProtobuf::sint32>(3, "QtProtobuf::sint32", "id_proto");
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtProtobufSyntaxTest::ReservedUpperCaseTest()
|
|
|
|
{
|
|
|
|
qProtobufAssertMessagePropertyRegistered<MessageUpperCaseReserved, QtProtobuf::sint32>(1, "QtProtobuf::sint32", "import_proto");
|
|
|
|
qProtobufAssertMessagePropertyRegistered<MessageUpperCaseReserved, QtProtobuf::sint32>(2, "QtProtobuf::sint32", "property_proto");
|
|
|
|
qProtobufAssertMessagePropertyRegistered<MessageUpperCaseReserved, QtProtobuf::sint32>(3, "QtProtobuf::sint32", "id_proto");
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtProtobufSyntaxTest::ReservedEnumTest()
|
|
|
|
{
|
2023-08-05 15:10:53 +00:00
|
|
|
const auto &metaObject = MessageEnumReserved_QtProtobufNested::staticMetaObject;
|
|
|
|
QVERIFY(metaObject.enumeratorCount() > 0);
|
2022-10-05 17:11:30 +00:00
|
|
|
QMetaEnum simpleEnum;
|
2023-08-05 15:10:53 +00:00
|
|
|
for (int i = 0; i < metaObject.enumeratorCount(); i++) {
|
|
|
|
QMetaEnum tmp = metaObject.enumerator(i);
|
2022-10-05 17:11:30 +00:00
|
|
|
if (QString(tmp.name()) == QString("ReservedEnum")) {
|
|
|
|
simpleEnum = tmp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QVERIFY(simpleEnum.isValid());
|
|
|
|
QCOMPARE(simpleEnum.key(0), "Import");
|
|
|
|
QCOMPARE(simpleEnum.key(1), "Property");
|
|
|
|
QCOMPARE(simpleEnum.key(2), "Id");
|
|
|
|
|
|
|
|
QCOMPARE(simpleEnum.value(0), 0);
|
|
|
|
QCOMPARE(simpleEnum.value(1), 1);
|
|
|
|
QCOMPARE(simpleEnum.value(2), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtProtobufSyntaxTest::LowerCaseEnumTest()
|
|
|
|
{
|
2023-08-05 15:10:53 +00:00
|
|
|
const auto &metaObject = MessageEnumReserved_QtProtobufNested::staticMetaObject;
|
|
|
|
QVERIFY(metaObject.enumeratorCount() > 0);
|
2022-10-05 17:11:30 +00:00
|
|
|
QMetaEnum simpleEnum;
|
2023-08-05 15:10:53 +00:00
|
|
|
for (int i = 0; i < metaObject.enumeratorCount(); i++) {
|
|
|
|
QMetaEnum tmp = metaObject.enumerator(i);
|
2022-10-05 17:11:30 +00:00
|
|
|
if (QString(tmp.name()) == QString("LowerCaseEnum")) {
|
|
|
|
simpleEnum = tmp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QVERIFY(simpleEnum.isValid());
|
|
|
|
QCOMPARE(simpleEnum.key(0), "EnumValue0");
|
|
|
|
QCOMPARE(simpleEnum.key(1), "EnumValue1");
|
|
|
|
QCOMPARE(simpleEnum.key(2), "EnumValue2");
|
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_MAIN(QtProtobufSyntaxTest)
|
|
|
|
#include "tst_protobuf_syntax.moc"
|