syntaxtest.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 "syntax.qpb.h"
  27. #endif
  28. #include <QMetaProperty>
  29. #include <QSignalSpy>
  30. #include <QtTest/QtTest>
  31. #include <qtprotobuftestscommon.h>
  32. class QtProtobufSyntaxTest : public QObject
  33. {
  34. Q_OBJECT
  35. public:
  36. QtProtobufSyntaxTest()
  37. {
  38. qRegisterProtobufTypes();
  39. }
  40. private slots:
  41. void UnderscoresTest();
  42. void UpperCaseTest();
  43. void ReservedTest();
  44. void ReservedUpperCaseTest();
  45. void ReservedEnumTest();
  46. void LowerCaseEnumTest();
  47. };
  48. using namespace qtprotobufnamespace::tests;
  49. void QtProtobufSyntaxTest::UnderscoresTest()
  50. {
  51. //Sanity compilation checks
  52. Message_Uderscore_name msg1;
  53. MessageUderscorename msg2;
  54. MessageUnderscoreField msg3;
  55. PriorMessageUnderscoreField msg4;
  56. FollowingMessageUnderscoreField msg5;
  57. CombinedMessageUnderscoreField msg6;
  58. qProtobufAssertMessagePropertyRegistered<MessageUnderscoreField, QtProtobuf::sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
  59. qProtobufAssertMessagePropertyRegistered<PriorMessageUnderscoreField, QtProtobuf::sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
  60. qProtobufAssertMessagePropertyRegistered<PriorMessageUnderscoreField, QtProtobuf::sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
  61. qProtobufAssertMessagePropertyRegistered<FollowingMessageUnderscoreField , QtProtobuf::sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
  62. qProtobufAssertMessagePropertyRegistered<CombinedMessageUnderscoreField , QtProtobuf::sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
  63. }
  64. void QtProtobufSyntaxTest::UpperCaseTest()
  65. {
  66. qProtobufAssertMessagePropertyRegistered<MessageUpperCase, QtProtobuf::sint32>(1, "QtProtobuf::sint32", "testField");
  67. }
  68. void QtProtobufSyntaxTest::ReservedTest()
  69. {
  70. qProtobufAssertMessagePropertyRegistered<MessageReserved, QtProtobuf::sint32>(1, "QtProtobuf::sint32", "import_proto");
  71. qProtobufAssertMessagePropertyRegistered<MessageReserved, QtProtobuf::sint32>(2, "QtProtobuf::sint32", "property_proto");
  72. qProtobufAssertMessagePropertyRegistered<MessageReserved, QtProtobuf::sint32>(3, "QtProtobuf::sint32", "id_proto");
  73. }
  74. void QtProtobufSyntaxTest::ReservedUpperCaseTest()
  75. {
  76. qProtobufAssertMessagePropertyRegistered<MessageUpperCaseReserved, QtProtobuf::sint32>(1, "QtProtobuf::sint32", "import_proto");
  77. qProtobufAssertMessagePropertyRegistered<MessageUpperCaseReserved, QtProtobuf::sint32>(2, "QtProtobuf::sint32", "property_proto");
  78. qProtobufAssertMessagePropertyRegistered<MessageUpperCaseReserved, QtProtobuf::sint32>(3, "QtProtobuf::sint32", "id_proto");
  79. }
  80. void QtProtobufSyntaxTest::ReservedEnumTest()
  81. {
  82. QVERIFY(MessageEnumReserved::staticMetaObject.enumeratorCount() > 0);
  83. QMetaEnum simpleEnum;
  84. for (int i = 0; i < MessageEnumReserved::staticMetaObject.enumeratorCount(); i++) {
  85. QMetaEnum tmp = MessageEnumReserved::staticMetaObject.enumerator(i);
  86. if (QString(tmp.name()) == QString("ReservedEnum")) {
  87. simpleEnum = tmp;
  88. break;
  89. }
  90. }
  91. QVERIFY(simpleEnum.isValid());
  92. QCOMPARE(simpleEnum.key(0), "Import");
  93. QCOMPARE(simpleEnum.key(1), "Property");
  94. QCOMPARE(simpleEnum.key(2), "Id");
  95. QCOMPARE(simpleEnum.value(0), 0);
  96. QCOMPARE(simpleEnum.value(1), 1);
  97. QCOMPARE(simpleEnum.value(2), 2);
  98. }
  99. void QtProtobufSyntaxTest::LowerCaseEnumTest()
  100. {
  101. QVERIFY(MessageEnumReserved::staticMetaObject.enumeratorCount() > 0);
  102. QMetaEnum simpleEnum;
  103. for (int i = 0; i < MessageEnumReserved::staticMetaObject.enumeratorCount(); i++) {
  104. QMetaEnum tmp = MessageEnumReserved::staticMetaObject.enumerator(i);
  105. if (QString(tmp.name()) == QString("LowerCaseEnum")) {
  106. simpleEnum = tmp;
  107. break;
  108. }
  109. }
  110. QVERIFY(simpleEnum.isValid());
  111. QCOMPARE(simpleEnum.key(0), "EnumValue0");
  112. QCOMPARE(simpleEnum.key(1), "EnumValue1");
  113. QCOMPARE(simpleEnum.key(2), "EnumValue2");
  114. }
  115. QTEST_MAIN(QtProtobufSyntaxTest)
  116. #include "syntaxtest.moc"