simpletest.cpp.inc 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2019 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. #include <QVariantList>
  26. #include <QMetaProperty>
  27. #include <QSignalSpy>
  28. #include <gtest/gtest.h>
  29. #include "qtprotobuf_global.qpb.h"
  30. using namespace qtprotobufnamespace::tests;
  31. namespace QtProtobuf {
  32. namespace tests {
  33. class SimpleTest : public ::testing::Test
  34. {
  35. public:
  36. // see simpletest.proto for property names and their field indices
  37. SimpleTest()
  38. {
  39. }
  40. template<typename MessageType, typename PropertyType>
  41. static void assertMessagePropertyRegistered(int fieldIndex, const char *propertyTypeName, const char *propertyName)
  42. {
  43. // TODO: there should be(?) a mapping avaialble: PropertyType -> propertyTypeName
  44. const int propertyNumber = MessageType::propertyOrdering.at(fieldIndex);
  45. ASSERT_STREQ(MessageType::staticMetaObject.property(propertyNumber).typeName(), propertyTypeName);
  46. ASSERT_EQ(MessageType::staticMetaObject.property(propertyNumber).userType(), qMetaTypeId<PropertyType>());
  47. ASSERT_STREQ(MessageType::staticMetaObject.property(propertyNumber).name(), propertyName);
  48. }
  49. static void SetUpTestCase();
  50. };
  51. void SimpleTest::SetUpTestCase()
  52. {
  53. QtProtobuf::qRegisterProtobufTypes();
  54. qtprotobufnamespace::tests::qRegisterProtobufTypes();
  55. qtprotobufnamespace1::externaltests::qRegisterProtobufTypes();
  56. qtprotobufnamespace::tests::globalenums::qRegisterProtobufTypes();
  57. qtprotobufnamespace::tests::sequence::qRegisterProtobufTypes();
  58. }
  59. TEST_F(SimpleTest, SimpleBoolMessageTest)
  60. {
  61. const char *propertyName = "testFieldBool";
  62. assertMessagePropertyRegistered<SimpleBoolMessage, bool>(1, "bool", propertyName);
  63. SimpleBoolMessage test;
  64. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(true)));
  65. ASSERT_EQ(test.property(propertyName).value<bool>(), true);
  66. ASSERT_EQ(test.testFieldBool(), true);
  67. }
  68. TEST_F(SimpleTest, SimpleIntMessageTest)
  69. {
  70. const char *propertyName = "testFieldInt";
  71. assertMessagePropertyRegistered<SimpleIntMessage, int32>(1, "QtProtobuf::int32", propertyName);
  72. SimpleIntMessage test;
  73. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int32>(1)));
  74. ASSERT_EQ(test.property(propertyName).value<int32>(), 1);
  75. ASSERT_EQ(test.testFieldInt(), 1);
  76. }
  77. TEST_F(SimpleTest, SimpleSIntMessageTest)
  78. {
  79. const char *propertyName = "testFieldInt";
  80. assertMessagePropertyRegistered<SimpleSIntMessage, sint32>(1, "QtProtobuf::sint32", propertyName);
  81. SimpleSIntMessage test;
  82. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint32>(1)));
  83. ASSERT_EQ(test.property(propertyName).value<sint32>(), 1);
  84. ASSERT_EQ(test.testFieldInt(), 1);
  85. }
  86. TEST_F(SimpleTest, SimpleUIntMessageTest)
  87. {
  88. const char *propertyName = "testFieldInt";
  89. assertMessagePropertyRegistered<SimpleUIntMessage, uint32>(1, "QtProtobuf::uint32", propertyName);
  90. SimpleUIntMessage test;
  91. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<uint32>(1)));
  92. ASSERT_EQ(test.property(propertyName).value<uint32>(), 1);
  93. ASSERT_EQ(test.testFieldInt(), 1);
  94. }
  95. TEST_F(SimpleTest, SimpleInt64MessageTest)
  96. {
  97. const char *propertyName = "testFieldInt";
  98. assertMessagePropertyRegistered<SimpleInt64Message, int64>(1, "QtProtobuf::int64", propertyName);
  99. SimpleInt64Message test;
  100. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int64>(1)));
  101. ASSERT_EQ(test.property(propertyName).value<int64>(), 1);
  102. ASSERT_EQ(test.testFieldInt(), 1);
  103. }
  104. TEST_F(SimpleTest, SimpleSInt64MessageTest)
  105. {
  106. const char *propertyName = "testFieldInt";
  107. assertMessagePropertyRegistered<SimpleSInt64Message, sint64>(1, "QtProtobuf::sint64", propertyName);
  108. SimpleSInt64Message test;
  109. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint64>(1)));
  110. ASSERT_EQ(test.property(propertyName).value<sint64>(), 1);
  111. ASSERT_EQ(test.testFieldInt(), 1);
  112. }
  113. TEST_F(SimpleTest, SimpleUInt64MessageTest)
  114. {
  115. const char *propertyName = "testFieldInt";
  116. assertMessagePropertyRegistered<SimpleUInt64Message, uint64>(1, "QtProtobuf::uint64", propertyName);
  117. SimpleUInt64Message test;
  118. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<uint64>(1)));
  119. ASSERT_EQ(test.property(propertyName).value<uint64>(), 1);
  120. ASSERT_EQ(test.testFieldInt(), 1);
  121. }
  122. TEST_F(SimpleTest, SimpleFixedInt32MessageTest)
  123. {
  124. const char *propertyName = "testFieldFixedInt32";
  125. assertMessagePropertyRegistered<SimpleFixedInt32Message, fixed32>(1, "QtProtobuf::fixed32", propertyName);
  126. SimpleFixedInt32Message test;
  127. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<fixed32>(1)));
  128. ASSERT_EQ(test.property(propertyName).value<fixed32>(), 1);
  129. ASSERT_EQ(test.testFieldFixedInt32(), 1);
  130. }
  131. TEST_F(SimpleTest, SimpleFixedInt64MessageTest)
  132. {
  133. const char *propertyName = "testFieldFixedInt64";
  134. assertMessagePropertyRegistered<SimpleFixedInt64Message, fixed64>(1, "QtProtobuf::fixed64", propertyName);
  135. SimpleFixedInt64Message test;
  136. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<fixed64>(1)));
  137. ASSERT_EQ(test.property(propertyName).value<fixed64>(), 1);
  138. ASSERT_EQ(test.testFieldFixedInt64(), 1);
  139. }
  140. TEST_F(SimpleTest, SimpleSFixedInt32MessageTest)
  141. {
  142. const char *propertyName = "testFieldFixedInt32";
  143. assertMessagePropertyRegistered<SimpleSFixedInt32Message, sfixed32>(1, "QtProtobuf::sfixed32", propertyName);
  144. SimpleSFixedInt32Message test;
  145. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sfixed32>(1)));
  146. ASSERT_EQ(test.property(propertyName).value<sfixed32>(), 1);
  147. ASSERT_EQ(test.testFieldFixedInt32(), 1);
  148. }
  149. TEST_F(SimpleTest, SimpleSFixedInt64MessageTest)
  150. {
  151. const char *propertyName = "testFieldFixedInt64";
  152. assertMessagePropertyRegistered<SimpleSFixedInt64Message, sfixed64>(1, "QtProtobuf::sfixed64", propertyName);
  153. SimpleSFixedInt64Message test;
  154. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sfixed64>(1)));
  155. ASSERT_EQ(test.property(propertyName).value<sfixed64>(), 1);
  156. ASSERT_EQ(test.testFieldFixedInt64(), 1);
  157. }
  158. TEST_F(SimpleTest, SimpleStringMessageTest)
  159. {
  160. const char *propertyName = "testFieldString";
  161. SimpleStringMessage test;
  162. int propertyNumber = SimpleStringMessage::propertyOrdering.at(6); //See simpletest.proto
  163. ASSERT_EQ(SimpleStringMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::QString);
  164. ASSERT_STREQ(SimpleStringMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  165. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(QString("test1"))));
  166. ASSERT_STREQ(test.property(propertyName).toString().toStdString().c_str(), "test1");
  167. ASSERT_STREQ(test.testFieldString().toStdString().c_str(), "test1");
  168. }
  169. TEST_F(SimpleTest, SimpleFloatMessageTest)
  170. {
  171. const char *propertyName = "testFieldFloat";
  172. SimpleFloatMessage test;
  173. int propertyNumber = SimpleFloatMessage::propertyOrdering.at(7); //See simpletest.proto
  174. ASSERT_EQ(SimpleFloatMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::Float);
  175. ASSERT_STREQ(SimpleFloatMessage::staticMetaObject.property(propertyNumber).name(), "testFieldFloat");
  176. float assignedValue = 1.55f;
  177. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<float>(assignedValue)));
  178. ASSERT_FLOAT_EQ(test.property(propertyName).toFloat(), assignedValue);
  179. ASSERT_FLOAT_EQ(test.testFieldFloat(), assignedValue);
  180. }
  181. TEST_F(SimpleTest, SimpleDoubleMessageTest)
  182. {
  183. const char *propertyName = "testFieldDouble";
  184. SimpleDoubleMessage test;
  185. int propertyNumber = SimpleDoubleMessage::propertyOrdering.at(8); //See simpletest.proto
  186. ASSERT_EQ(SimpleDoubleMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::Double);
  187. ASSERT_STREQ(SimpleDoubleMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  188. double assignedValue = 0.55;
  189. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<double>(assignedValue)));
  190. ASSERT_DOUBLE_EQ(test.property(propertyName).toDouble(), assignedValue);
  191. ASSERT_DOUBLE_EQ(test.testFieldDouble(), assignedValue);
  192. }
  193. TEST_F(SimpleTest, SimpleLocalEnumTest)
  194. {
  195. ASSERT_GT(SimpleEnumMessage::staticMetaObject.enumeratorCount(), 0);
  196. QMetaEnum simpleEnum;
  197. for (int i = 0; i < SimpleEnumMessage::staticMetaObject.enumeratorCount(); i++) {
  198. QMetaEnum tmp = SimpleEnumMessage::staticMetaObject.enumerator(i);
  199. if (QString(tmp.name()) == QString("LocalEnum")) {
  200. simpleEnum = tmp;
  201. break;
  202. }
  203. }
  204. ASSERT_TRUE(simpleEnum.isValid());
  205. ASSERT_STREQ(simpleEnum.key(0), "LOCAL_ENUM_VALUE0");
  206. ASSERT_STREQ(simpleEnum.key(1), "LOCAL_ENUM_VALUE1");
  207. ASSERT_STREQ(simpleEnum.key(2), "LOCAL_ENUM_VALUE2");
  208. ASSERT_STREQ(simpleEnum.key(3), "LOCAL_ENUM_VALUE3");
  209. ASSERT_EQ(simpleEnum.value(0), 0);
  210. ASSERT_EQ(simpleEnum.value(1), 1);
  211. ASSERT_EQ(simpleEnum.value(2), 2);
  212. ASSERT_EQ(simpleEnum.value(3), 3);
  213. }
  214. TEST_F(SimpleTest, SimpleLocalEnumListTest)
  215. {
  216. ASSERT_GT(SimpleEnumListMessage::staticMetaObject.enumeratorCount(), 0);
  217. const char *propertyName = "localEnumList";
  218. assertMessagePropertyRegistered<SimpleEnumListMessage, SimpleEnumListMessage::LocalEnumRepeated>(1, "SimpleEnumListMessage::LocalEnumRepeated", propertyName);
  219. SimpleEnumListMessage::LocalEnumRepeated value({SimpleEnumListMessage::LOCAL_ENUM_VALUE2,
  220. SimpleEnumListMessage::LOCAL_ENUM_VALUE2,
  221. SimpleEnumListMessage::LOCAL_ENUM_VALUE1,
  222. SimpleEnumListMessage::LOCAL_ENUM_VALUE3});
  223. SimpleEnumListMessage test;
  224. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<SimpleEnumListMessage::LocalEnumRepeated>(value)));
  225. ASSERT_TRUE(test.property(propertyName).value<SimpleEnumListMessage::LocalEnumRepeated>() == value);
  226. ASSERT_TRUE(test.localEnumList() == value);
  227. }
  228. TEST_F(SimpleTest, SimpleExternalEnumMessageTest)
  229. {
  230. using ExternalGlobalEnums = qtprotobufnamespace1::externaltests::ExternalTestEnumGadget;
  231. const char *propertyName = "externalEnum";
  232. assertMessagePropertyRegistered<SimpleExternalEnumMessage, ExternalGlobalEnums::ExternalTestEnum>(1, "qtprotobufnamespace1::externaltests::ExternalTestEnumGadget::ExternalTestEnum", propertyName);
  233. SimpleExternalEnumMessage test;
  234. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<ExternalGlobalEnums::ExternalTestEnum>(ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4)));
  235. ASSERT_TRUE(test.property(propertyName).value<ExternalGlobalEnums::ExternalTestEnum>() == QVariant::fromValue<ExternalGlobalEnums::ExternalTestEnum>(ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4));
  236. ASSERT_TRUE(test.externalEnum() == QVariant::fromValue<ExternalGlobalEnums::ExternalTestEnum>(ExternalGlobalEnums::EXTERNAL_TEST_ENUM_VALUE4));
  237. }
  238. TEST_F(SimpleTest, SimpleEnumsTest)
  239. {
  240. EXPECT_GT(TestEnumGadget::staticMetaObject.enumeratorCount(), 0);
  241. QMetaEnum testEnum;
  242. for (int i = 0; i < TestEnumGadget::staticMetaObject.enumeratorCount(); i++) {
  243. QMetaEnum tmp = TestEnumGadget::staticMetaObject.enumerator(i);
  244. if (QString(tmp.name()) == QString("TestEnum")) {
  245. testEnum = tmp;
  246. break;
  247. }
  248. }
  249. ASSERT_TRUE(testEnum.isValid());
  250. ASSERT_STREQ(testEnum.key(0), "TEST_ENUM_VALUE0");
  251. ASSERT_STREQ(testEnum.key(1), "TEST_ENUM_VALUE1");
  252. ASSERT_STREQ(testEnum.key(2), "TEST_ENUM_VALUE2");
  253. ASSERT_STREQ(testEnum.key(3), "TEST_ENUM_VALUE3");
  254. ASSERT_STREQ(testEnum.key(4), "TEST_ENUM_VALUE4");
  255. ASSERT_EQ(testEnum.value(0), 0);
  256. ASSERT_EQ(testEnum.value(1), 1);
  257. ASSERT_EQ(testEnum.value(2), 2);
  258. ASSERT_EQ(testEnum.value(3), 4);
  259. ASSERT_EQ(testEnum.value(4), 3);
  260. for (int i = 0; i < TestEnumSecondInFileGadget::staticMetaObject.enumeratorCount(); i++) {
  261. QMetaEnum tmp = TestEnumSecondInFileGadget::staticMetaObject.enumerator(i);
  262. if (QString(tmp.name()) == QString("TestEnumSecondInFile")) {
  263. testEnum = tmp;
  264. break;
  265. }
  266. }
  267. ASSERT_TRUE(testEnum.isValid());
  268. ASSERT_STREQ(testEnum.key(0), "TEST_ENUM_SIF_VALUE0");
  269. ASSERT_STREQ(testEnum.key(1), "TEST_ENUM_SIF_VALUE1");
  270. ASSERT_STREQ(testEnum.key(2), "TEST_ENUM_SIF_VALUE2");
  271. ASSERT_EQ(testEnum.value(0), 0);
  272. ASSERT_EQ(testEnum.value(1), 1);
  273. ASSERT_EQ(testEnum.value(2), 2);
  274. }
  275. TEST_F(SimpleTest, SimpleFileEnumsTest)
  276. {
  277. const char *propertyName = "globalEnumList";
  278. assertMessagePropertyRegistered<SimpleFileEnumMessage, TestEnumGadget::TestEnumRepeated>(2, "qtprotobufnamespace::tests::TestEnumGadget::TestEnumRepeated", propertyName);
  279. TestEnumGadget::TestEnumRepeated value{TestEnumGadget::TEST_ENUM_VALUE1,
  280. TestEnumGadget::TEST_ENUM_VALUE3,
  281. TestEnumGadget::TEST_ENUM_VALUE4,
  282. TestEnumGadget::TEST_ENUM_VALUE2,
  283. TestEnumGadget::TEST_ENUM_VALUE1};
  284. SimpleFileEnumMessage test;
  285. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<TestEnumGadget::TestEnumRepeated>(value)));
  286. ASSERT_TRUE(test.property(propertyName).value<TestEnumGadget::TestEnumRepeated>() == value);
  287. ASSERT_TRUE(test.globalEnumList() == value);
  288. }
  289. TEST_F(SimpleTest, ComplexMessageTest)
  290. {
  291. ComplexMessage msg;
  292. }
  293. TEST_F(SimpleTest, SimpleBytesMessageTest)
  294. {
  295. const char *propertyName = "testFieldBytes";
  296. SimpleBytesMessage test;
  297. int propertyNumber = SimpleBytesMessage::propertyOrdering.at(1); //See simpletest.proto
  298. ASSERT_EQ(SimpleBytesMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::QByteArray);
  299. ASSERT_STREQ(SimpleBytesMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  300. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QByteArray>("\x01\x02\x03\x04\x05")));
  301. ASSERT_TRUE(test.property(propertyName).toByteArray() == QByteArray("\x01\x02\x03\x04\x05"));
  302. ASSERT_TRUE(test.testFieldBytes() == QByteArray("\x01\x02\x03\x04\x05"));
  303. }
  304. TEST_F(SimpleTest, SimpleExternalComplexMessageTest)
  305. {
  306. const char *propertyName = "localList";
  307. assertMessagePropertyRegistered<qtprotobufnamespace1::externaltests::SimpleExternalMessage, int32List>(
  308. 1, "QtProtobuf::int32List", propertyName);
  309. qtprotobufnamespace1::externaltests::SimpleExternalMessage test;
  310. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int32List>({1, 2, 3, 4, 5})));
  311. ASSERT_TRUE(test.property(propertyName).value<int32List>() == int32List({1, 2, 3, 4, 5}));
  312. ASSERT_TRUE(test.localList() == int32List({1, 2, 3, 4, 5}));
  313. }
  314. TEST_F(SimpleTest, RepeatedExternalComplexMessageTest)
  315. {
  316. const char *propertyName = "testExternalComplex";
  317. assertMessagePropertyRegistered<RepeatedExternalComplexMessage, qtprotobufnamespace1::externaltests::ExternalComplexMessageRepeated>(
  318. 1, "qtprotobufnamespace1::externaltests::ExternalComplexMessageRepeated", propertyName);
  319. qtprotobufnamespace1::externaltests::SimpleExternalMessage complexMessage;
  320. complexMessage.setLocalList({1, 2, 3, 4, 5});
  321. QSharedPointer<qtprotobufnamespace1::externaltests::ExternalComplexMessage> externalMessage(new qtprotobufnamespace1::externaltests::ExternalComplexMessage);
  322. externalMessage->setTestFieldInt(complexMessage);
  323. qtprotobufnamespace1::externaltests::ExternalComplexMessageRepeated complexMessageList;
  324. complexMessageList << externalMessage;
  325. RepeatedExternalComplexMessage test;
  326. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(complexMessageList)));
  327. ASSERT_TRUE(test.property(propertyName).value<qtprotobufnamespace1::externaltests::ExternalComplexMessageRepeated>() == complexMessageList);
  328. ASSERT_TRUE(test.testExternalComplex() == complexMessageList);
  329. }
  330. TEST_F(SimpleTest, RepeatedStringMessageTest)
  331. {
  332. const char *propertyName = "testRepeatedString";
  333. assertMessagePropertyRegistered<RepeatedStringMessage, QStringList>(1, "QStringList", propertyName);
  334. RepeatedStringMessage test;
  335. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QStringList>({"Text", "tryam"})));
  336. ASSERT_TRUE(test.property(propertyName).value<QStringList>() == QStringList({"Text", "tryam"}));
  337. ASSERT_TRUE(test.testRepeatedString() == QStringList({"Text", "tryam"}));
  338. }
  339. TEST_F(SimpleTest, RepeatedIntMessageTest)
  340. {
  341. const char *propertyName = "testRepeatedInt";
  342. assertMessagePropertyRegistered<RepeatedIntMessage, int32List>(1, "QtProtobuf::int32List", propertyName);
  343. RepeatedIntMessage test;
  344. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int32List>({1, 2, 3, 4, 5})));
  345. ASSERT_TRUE(test.property(propertyName).value<int32List>() == int32List({1, 2, 3, 4, 5}));
  346. ASSERT_TRUE(test.testRepeatedInt() == int32List({1, 2, 3, 4, 5}));
  347. test.testRepeatedInt().append(66);
  348. ASSERT_TRUE(test.testRepeatedInt() == int32List({1, 2, 3, 4, 5, 66}));
  349. test.testRepeatedInt().pop_back();
  350. ASSERT_TRUE(test.testRepeatedInt() == int32List({1, 2, 3, 4, 5}));
  351. }
  352. TEST_F(SimpleTest, RepeatedDoubleMessageTest)
  353. {
  354. const char *propertyName = "testRepeatedDouble";
  355. assertMessagePropertyRegistered<RepeatedDoubleMessage, DoubleList>(1, "QtProtobuf::DoubleList", propertyName);
  356. RepeatedDoubleMessage test;
  357. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QtProtobuf::DoubleList>({1.0, 2.3, 3, 4.7, 5.9})));
  358. ASSERT_TRUE(test.property(propertyName).value<QtProtobuf::DoubleList>() == QtProtobuf::DoubleList({1.0, 2.3, 3, 4.7, 5.9}));
  359. ASSERT_TRUE(test.testRepeatedDouble() == QtProtobuf::DoubleList({1.0, 2.3, 3, 4.7, 5.9}));
  360. test.testRepeatedDouble().append(6.6);
  361. ASSERT_TRUE(test.testRepeatedDouble() == QtProtobuf::DoubleList({1.0, 2.3, 3, 4.7, 5.9, 6.6}));
  362. test.testRepeatedDouble().pop_back();
  363. ASSERT_TRUE(test.testRepeatedDouble() == QtProtobuf::DoubleList({1.0, 2.3, 3, 4.7, 5.9}));
  364. }
  365. TEST_F(SimpleTest, RepeatedFloatMessageTest)
  366. {
  367. const char *propertyName = "testRepeatedFloat";
  368. assertMessagePropertyRegistered<RepeatedFloatMessage, FloatList>(1, "QtProtobuf::FloatList", propertyName);
  369. RepeatedFloatMessage test;
  370. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QtProtobuf::FloatList>({1.0f, 2.3f, 3, 4.7f, 5.9f})));
  371. ASSERT_TRUE(test.property(propertyName).value<QtProtobuf::FloatList>() == QtProtobuf::FloatList({1.0f, 2.3f, 3, 4.7f, 5.9f}));
  372. ASSERT_TRUE(test.testRepeatedFloat() == QtProtobuf::FloatList({1.0f, 2.3f, 3, 4.7f, 5.9f}));
  373. test.testRepeatedFloat().append(6.6f);
  374. ASSERT_TRUE(test.testRepeatedFloat() == QtProtobuf::FloatList({1.0f, 2.3f, 3, 4.7f, 5.9f, 6.6f}));
  375. test.testRepeatedFloat().pop_back();
  376. ASSERT_TRUE(test.testRepeatedFloat() == QtProtobuf::FloatList({1.0f, 2.3f, 3, 4.7f, 5.9f}));
  377. }
  378. TEST_F(SimpleTest, RepeatedBytesMessageTest)
  379. {
  380. const char *propertyName = "testRepeatedBytes";
  381. assertMessagePropertyRegistered<RepeatedBytesMessage, QByteArrayList>(1, "QByteArrayList", propertyName);
  382. QByteArrayList bList;
  383. bList << "\x01\x02\x03\x04\x05";
  384. bList << "\x01\x05\x03\x04\x03";
  385. RepeatedBytesMessage test;
  386. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QByteArrayList>(bList)));
  387. ASSERT_TRUE(test.property(propertyName).value<QByteArrayList>() == bList);
  388. ASSERT_TRUE(test.testRepeatedBytes() == bList);
  389. bList << "\x01\x05\x03\x03";
  390. test.testRepeatedBytes() << "\x01\x05\x03\x03";
  391. ASSERT_TRUE(test.testRepeatedBytes() == bList);
  392. bList.pop_back();
  393. test.testRepeatedBytes().pop_back();
  394. ASSERT_TRUE(test.testRepeatedBytes() == bList);
  395. }
  396. TEST_F(SimpleTest, RepeatedSIntMessageTest)
  397. {
  398. const char *propertyName = "testRepeatedInt";
  399. assertMessagePropertyRegistered<RepeatedSIntMessage, sint32List>(1, "QtProtobuf::sint32List", propertyName);
  400. RepeatedSIntMessage test;
  401. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint32List>({1, 2, 3, 4, 5})));
  402. ASSERT_TRUE(test.property(propertyName).value<sint32List>() == sint32List({1, 2, 3, 4, 5}));
  403. ASSERT_TRUE(test.testRepeatedInt() == sint32List({1, 2, 3, 4, 5}));
  404. test.testRepeatedInt() << 6;
  405. ASSERT_TRUE(test.testRepeatedInt() == sint32List({1, 2, 3, 4, 5, 6}));
  406. test.testRepeatedInt().pop_back();
  407. ASSERT_TRUE(test.testRepeatedInt() == sint32List({1, 2, 3, 4, 5}));
  408. }
  409. TEST_F(SimpleTest, RepeatedUIntMessageTest)
  410. {
  411. const char *propertyName = "testRepeatedInt";
  412. assertMessagePropertyRegistered<RepeatedUIntMessage, uint32List>(1, "QtProtobuf::uint32List", propertyName);
  413. RepeatedUIntMessage test;
  414. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<uint32List>({1, 2, 3, 4, 5})));
  415. ASSERT_TRUE(test.property(propertyName).value<uint32List>() == uint32List({1, 2, 3, 4, 5}));
  416. ASSERT_TRUE(test.testRepeatedInt() == uint32List({1, 2, 3, 4, 5}));
  417. test.testRepeatedInt().append(6);
  418. ASSERT_TRUE(test.testRepeatedInt() == uint32List({1, 2, 3, 4, 5,6}));
  419. test.testRepeatedInt().pop_back();
  420. ASSERT_TRUE(test.testRepeatedInt() == uint32List({1, 2, 3, 4, 5}));
  421. }
  422. TEST_F(SimpleTest, RepeatedInt64MessageTest)
  423. {
  424. const char *propertyName = "testRepeatedInt";
  425. assertMessagePropertyRegistered<RepeatedInt64Message, int64List>(1, "QtProtobuf::int64List", propertyName);
  426. RepeatedInt64Message test;
  427. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int64List>({1, 2, 3, 4, 5})));
  428. ASSERT_TRUE(test.property(propertyName).value<int64List>() == int64List({1, 2, 3, 4, 5}));
  429. ASSERT_TRUE(test.testRepeatedInt() == int64List({1, 2, 3, 4, 5}));
  430. test.testRepeatedInt().append(69);
  431. ASSERT_TRUE(test.testRepeatedInt() == int64List({1, 2, 3, 4, 5, 69}));
  432. test.testRepeatedInt().pop_back();
  433. ASSERT_TRUE(test.testRepeatedInt() == int64List({1, 2, 3, 4, 5}));
  434. }
  435. TEST_F(SimpleTest, RepeatedSInt64MessageTest)
  436. {
  437. const char *propertyName = "testRepeatedInt";
  438. assertMessagePropertyRegistered<RepeatedSInt64Message, sint64List>(1, "QtProtobuf::sint64List", propertyName);
  439. RepeatedSInt64Message test;
  440. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint64List>({1, 2, 3, 4, 5})));
  441. ASSERT_TRUE(test.property(propertyName).value<sint64List>() == sint64List({1, 2, 3, 4, 5}));
  442. ASSERT_TRUE(test.testRepeatedInt() == sint64List({1, 2, 3, 4, 5}));
  443. test.testRepeatedInt() << 96;
  444. ASSERT_TRUE(test.testRepeatedInt() == sint64List({1, 2, 3, 4, 5, 96}));
  445. test.testRepeatedInt().pop_back();
  446. ASSERT_TRUE(test.testRepeatedInt() == sint64List({1, 2, 3, 4, 5}));
  447. }
  448. TEST_F(SimpleTest, RepeatedUInt64MessageTest)
  449. {
  450. const char *propertyName = "testRepeatedInt";
  451. assertMessagePropertyRegistered<RepeatedUInt64Message, uint64List>(1, "QtProtobuf::uint64List", propertyName);
  452. RepeatedUInt64Message test;
  453. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<uint64List>({1, 2, 3, 4, 5})));
  454. ASSERT_TRUE(test.property(propertyName).value<uint64List>() == uint64List({1, 2, 3, 4, 5}));
  455. ASSERT_TRUE(test.testRepeatedInt() == uint64List({1, 2, 3, 4, 5}));
  456. test.testRepeatedInt().append(96);
  457. ASSERT_TRUE(test.testRepeatedInt() == uint64List({1, 2, 3, 4, 5, 96}));
  458. test.testRepeatedInt().pop_back();
  459. ASSERT_TRUE(test.testRepeatedInt() == uint64List({1, 2, 3, 4, 5}));
  460. }
  461. TEST_F(SimpleTest, RepeatedFixedIntMessageTest)
  462. {
  463. const char *propertyName = "testRepeatedInt";
  464. assertMessagePropertyRegistered<RepeatedFixedIntMessage, fixed32List>(1, "QtProtobuf::fixed32List", propertyName);
  465. RepeatedFixedIntMessage test;
  466. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<fixed32List>({1, 2, 3, 4, 5})));
  467. ASSERT_TRUE(test.property(propertyName).value<fixed32List>() == fixed32List({1, 2, 3, 4, 5}));
  468. ASSERT_TRUE(test.testRepeatedInt() == fixed32List({1, 2, 3, 4, 5}));
  469. test.testRepeatedInt() << 0;
  470. ASSERT_TRUE(test.testRepeatedInt() == fixed32List({1, 2, 3, 4, 5, 0}));
  471. test.testRepeatedInt().pop_back();
  472. ASSERT_TRUE(test.testRepeatedInt() == fixed32List({1, 2, 3, 4, 5}));
  473. }
  474. TEST_F(SimpleTest, RepeatedFixedInt64MessageTest)
  475. {
  476. const char *propertyName = "testRepeatedInt";
  477. assertMessagePropertyRegistered<RepeatedFixedInt64Message, fixed64List>(1, "QtProtobuf::fixed64List", propertyName);
  478. RepeatedFixedInt64Message test;
  479. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<fixed64List>({1, 2, 3, 4, 5})));
  480. ASSERT_TRUE(test.property(propertyName).value<fixed64List>() == fixed64List({1, 2, 3, 4, 5}));
  481. ASSERT_TRUE(test.testRepeatedInt() == fixed64List({1, 2, 3, 4, 5}));
  482. test.testRepeatedInt() << 0;
  483. ASSERT_TRUE(test.testRepeatedInt() == fixed64List({1, 2, 3, 4, 5, 0}));
  484. test.testRepeatedInt().pop_back();
  485. ASSERT_TRUE(test.testRepeatedInt() == fixed64List({1, 2, 3, 4, 5}));
  486. }
  487. TEST_F(SimpleTest, RepeatedSFixedIntMessageTest)
  488. {
  489. const char *propertyName = "testRepeatedInt";
  490. assertMessagePropertyRegistered<RepeatedSFixedIntMessage, sfixed32List>(1, "QtProtobuf::sfixed32List", propertyName);
  491. RepeatedSFixedIntMessage test;
  492. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sfixed32List>({1, 2, 3, 4, 5})));
  493. ASSERT_TRUE(test.property(propertyName).value<sfixed32List>() == sfixed32List({1, 2, 3, 4, 5}));
  494. ASSERT_TRUE(test.testRepeatedInt() == sfixed32List({1, 2, 3, 4, 5}));
  495. test.testRepeatedInt() << 0;
  496. ASSERT_TRUE(test.testRepeatedInt() == sfixed32List({1, 2, 3, 4, 5, 0}));
  497. test.testRepeatedInt().pop_back();
  498. ASSERT_TRUE(test.testRepeatedInt() == sfixed32List({1, 2, 3, 4, 5}));
  499. }
  500. TEST_F(SimpleTest, RepeatedSFixedInt64MessageTest)
  501. {
  502. const char *propertyName = "testRepeatedInt";
  503. assertMessagePropertyRegistered<RepeatedSFixedInt64Message, QtProtobuf::sfixed64List>(1, "QtProtobuf::sfixed64List", propertyName);
  504. RepeatedSFixedInt64Message test;
  505. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sfixed64List>({1, 2, 3, 4, 5})));
  506. ASSERT_TRUE(test.property(propertyName).value<sfixed64List>() == sfixed64List({1, 2, 3, 4, 5}));
  507. ASSERT_TRUE(test.testRepeatedInt() == sfixed64List({1, 2, 3, 4, 5}));
  508. test.testRepeatedInt() << 0;
  509. ASSERT_TRUE(test.testRepeatedInt() == sfixed64List({1, 2, 3, 4, 5, 0}));
  510. test.testRepeatedInt().pop_back();
  511. ASSERT_TRUE(test.testRepeatedInt() == sfixed64List({1, 2, 3, 4, 5}));
  512. }
  513. TEST_F(SimpleTest, StepChildEnumMessageTest)
  514. {
  515. const char *propertyName = "localStepChildEnum";
  516. assertMessagePropertyRegistered<StepChildEnumMessage, SimpleEnumMessage::LocalEnum>(1, "qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnum", propertyName);
  517. StepChildEnumMessage test;
  518. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<SimpleEnumMessage::LocalEnum>(SimpleEnumMessage::LocalEnum::LOCAL_ENUM_VALUE2)));
  519. ASSERT_TRUE(test.property(propertyName).value<SimpleEnumMessage::LocalEnum>() == SimpleEnumMessage::LocalEnum::LOCAL_ENUM_VALUE2);
  520. ASSERT_TRUE(test.localStepChildEnum() == SimpleEnumMessage::LocalEnum::LOCAL_ENUM_VALUE2);
  521. }
  522. TEST_F(SimpleTest, StepChildEnumListMessageTest)
  523. {
  524. const char *propertyName = "localStepChildList";
  525. assertMessagePropertyRegistered<StepChildEnumMessage, SimpleEnumMessage::LocalEnumRepeated>(2, "qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnumRepeated", propertyName);
  526. SimpleEnumMessage::LocalEnumRepeated value({SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  527. SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  528. SimpleEnumMessage::LOCAL_ENUM_VALUE1,
  529. SimpleEnumMessage::LOCAL_ENUM_VALUE3});
  530. StepChildEnumMessage test;
  531. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnumRepeated>(value)));
  532. ASSERT_TRUE(test.property(propertyName).value<SimpleEnumMessage::LocalEnumRepeated>() == value);
  533. ASSERT_TRUE(test.localStepChildList() == value);
  534. }
  535. TEST_F(SimpleTest, SimpleSInt32StringMapMessageTest)
  536. {
  537. const char *propertyName = "mapField";
  538. assertMessagePropertyRegistered<SimpleSInt32StringMapMessage, SimpleSInt32StringMapMessage::MapFieldEntry>(1, "SimpleSInt32StringMapMessage::MapFieldEntry", propertyName);
  539. ASSERT_TRUE(QMetaType::isRegistered(qMetaTypeId<SimpleSInt32StringMapMessage::MapFieldEntry>()));
  540. SimpleSInt32StringMapMessage::MapFieldEntry testMap = {{10, {"Some 10"}}, {0, {"Some 0"}}, {44, {"Some 44"}}};
  541. SimpleSInt32StringMapMessage test;
  542. test.setMapField(testMap);
  543. ASSERT_TRUE(test.property(propertyName).value<SimpleSInt32StringMapMessage::MapFieldEntry>() == testMap);
  544. ASSERT_TRUE(test.mapField() == testMap);
  545. ASSERT_STREQ(test.mapField()[10].toStdString().c_str(), "Some 10");
  546. ASSERT_STREQ(test.mapField()[0].toStdString().c_str(), "Some 0");
  547. ASSERT_STREQ(test.mapField()[44].toStdString().c_str(), "Some 44");
  548. test.mapField()[66] = "Some 66";
  549. ASSERT_STREQ(test.mapField()[66].toStdString().c_str(), "Some 66");
  550. test.mapField()[66] = "Some default";
  551. ASSERT_STREQ(test.mapField()[66].toStdString().c_str(), "Some default");
  552. }
  553. TEST_F(SimpleTest, SimpleStringStringMapMessageTest)
  554. {
  555. const char *propertyName = "mapField";
  556. assertMessagePropertyRegistered<SimpleStringStringMapMessage, SimpleStringStringMapMessage::MapFieldEntry>(13, "SimpleStringStringMapMessage::MapFieldEntry", propertyName);
  557. ASSERT_TRUE(QMetaType::isRegistered(qMetaTypeId<SimpleStringStringMapMessage::MapFieldEntry>()));
  558. SimpleStringStringMapMessage::MapFieldEntry testMap = {{"key 10", "Some 10"}, {"key 0", "Some 0"}, {"key 44", "Some 44"}};
  559. SimpleStringStringMapMessage test;
  560. test.setMapField(testMap);
  561. ASSERT_TRUE(test.property(propertyName).value<SimpleStringStringMapMessage::MapFieldEntry>() == testMap);
  562. ASSERT_TRUE(test.mapField() == testMap);
  563. ASSERT_STREQ(test.mapField()["key 10"].toStdString().c_str(), "Some 10");
  564. ASSERT_STREQ(test.mapField()["key 0"].toStdString().c_str(), "Some 0");
  565. ASSERT_STREQ(test.mapField()["key 44"].toStdString().c_str(), "Some 44");
  566. test.mapField()["key 66"] = "Some 66";
  567. ASSERT_STREQ(test.mapField()["key 66"].toStdString().c_str(), "Some 66");
  568. test.mapField()["key 66"] = "Some default";
  569. ASSERT_STREQ(test.mapField()["key 66"].toStdString().c_str(), "Some default");
  570. }
  571. TEST_F(SimpleTest, EmptyMessageTest)
  572. {
  573. ASSERT_EQ(EmptyMessage::propertyOrdering.size(), 0);
  574. ASSERT_EQ(EmptyMessage::staticMetaObject.propertyCount(), 1);
  575. }
  576. TEST_F(SimpleTest, NullPointerMessageTest)
  577. {
  578. ComplexMessage msg(0, {QString("not null")});
  579. msg.setTestComplexField_p(nullptr);
  580. ASSERT_TRUE(msg.testComplexField().testFieldString().isEmpty());
  581. }
  582. TEST_F(SimpleTest, AssignmentOperatorTest)
  583. {
  584. const char *propertyName = "testFieldInt";
  585. SimpleIntMessage test;
  586. SimpleIntMessage test2{35};
  587. QSignalSpy updateSpy(&test, &SimpleIntMessage::testFieldIntChanged);
  588. test.setProperty(propertyName, QVariant::fromValue<int32>(15));
  589. test.setTestFieldInt(25);
  590. test = test2;
  591. test = test;
  592. test = test2;
  593. ASSERT_EQ(test2.testFieldInt(), test.testFieldInt());
  594. ASSERT_EQ(3, updateSpy.count());
  595. }
  596. TEST_F(SimpleTest, MoveOperatorTest)
  597. {
  598. const char *propertyName = "testFieldInt";
  599. SimpleIntMessage test;
  600. SimpleIntMessage test2{35};
  601. QSignalSpy updateSpy(&test, &SimpleIntMessage::testFieldIntChanged);
  602. QSignalSpy movedUpdateSpy(&test2, &SimpleIntMessage::testFieldIntChanged);
  603. SimpleIntMessage test3(std::move(test2));
  604. test2.setTestFieldInt(35);
  605. test.setProperty(propertyName, QVariant::fromValue<int32>(15));
  606. test.setTestFieldInt(25);
  607. test = std::move(test2);
  608. ASSERT_EQ(35, test.testFieldInt());
  609. ASSERT_EQ(0, test2.testFieldInt());
  610. ASSERT_EQ(3, updateSpy.count());
  611. ASSERT_EQ(3, movedUpdateSpy.count());
  612. }
  613. TEST_F(SimpleTest, UnderscoresTest)
  614. {
  615. //Sanity compilation checks
  616. Message_Uderscore_name msg1;
  617. MessageUderscorename msg2;
  618. MessageUnderscoreField msg3;
  619. PriorMessageUnderscoreField msg4;
  620. FollowingMessageUnderscoreField msg5;
  621. CombinedMessageUnderscoreField msg6;
  622. assertMessagePropertyRegistered<MessageUnderscoreField, sint32>(1, "QtProtobuf::sint32", "underScore_Message_field");
  623. assertMessagePropertyRegistered<PriorMessageUnderscoreField, sint32>(1, "QtProtobuf::sint32", "_underScoreMessageField");
  624. assertMessagePropertyRegistered<PriorMessageUnderscoreField, sint32>(1, "QtProtobuf::sint32", "_underScoreMessageField");
  625. assertMessagePropertyRegistered<FollowingMessageUnderscoreField , sint32>(1, "QtProtobuf::sint32", "underScoreMessageField_");
  626. assertMessagePropertyRegistered<CombinedMessageUnderscoreField , sint32>(1, "QtProtobuf::sint32", "_underScoreMessage_Field_");
  627. }
  628. TEST_F(SimpleTest, SequenceTest)
  629. {
  630. assertMessagePropertyRegistered<sequence::TestMessageSequence, sequence::TestMessageSequence2*>(1, "TestMessageSequence2*", "testField");
  631. assertMessagePropertyRegistered<sequence::TestMessageSequence2, bool>(1, "bool", "testField");
  632. }
  633. TEST_F(SimpleTest, CyclingTest)
  634. {
  635. assertMessagePropertyRegistered<sequence::CyclingFirstDependency, sequence::CyclingSecondDependency*>(1, "CyclingSecondDependency*", "testField");
  636. assertMessagePropertyRegistered<sequence::CyclingSecondDependency, sequence::CyclingFirstDependency*>(1, "CyclingFirstDependency*", "testField");
  637. }
  638. TEST_F(SimpleTest, UpperCaseTest)
  639. {
  640. assertMessagePropertyRegistered<MessageUpperCase, sint32>(1, "QtProtobuf::sint32", "testField");
  641. }
  642. TEST_F(SimpleTest, ReservedTest)
  643. {
  644. assertMessagePropertyRegistered<MessageReserved, sint32>(1, "QtProtobuf::sint32", "importProto");
  645. assertMessagePropertyRegistered<MessageReserved, sint32>(2, "QtProtobuf::sint32", "propertyProto");
  646. assertMessagePropertyRegistered<MessageReserved, sint32>(3, "QtProtobuf::sint32", "idProto");
  647. }
  648. TEST_F(SimpleTest, ReservedUpperCaseTest)
  649. {
  650. assertMessagePropertyRegistered<MessageUpperCaseReserved, sint32>(1, "QtProtobuf::sint32", "importProto");
  651. assertMessagePropertyRegistered<MessageUpperCaseReserved, sint32>(2, "QtProtobuf::sint32", "propertyProto");
  652. assertMessagePropertyRegistered<MessageUpperCaseReserved, sint32>(3, "QtProtobuf::sint32", "idProto");
  653. }
  654. TEST_F(SimpleTest, ReservedEnumTest)
  655. {
  656. ASSERT_GT(MessageEnumReserved::staticMetaObject.enumeratorCount(), 0);
  657. QMetaEnum simpleEnum;
  658. for (int i = 0; i < MessageEnumReserved::staticMetaObject.enumeratorCount(); i++) {
  659. QMetaEnum tmp = MessageEnumReserved::staticMetaObject.enumerator(i);
  660. if (QString(tmp.name()) == QString("ReservedEnum")) {
  661. simpleEnum = tmp;
  662. break;
  663. }
  664. }
  665. ASSERT_TRUE(simpleEnum.isValid());
  666. ASSERT_STREQ(simpleEnum.key(0), "Import");
  667. ASSERT_STREQ(simpleEnum.key(1), "Property");
  668. ASSERT_STREQ(simpleEnum.key(2), "Id");
  669. ASSERT_EQ(simpleEnum.value(0), 0);
  670. ASSERT_EQ(simpleEnum.value(1), 1);
  671. ASSERT_EQ(simpleEnum.value(2), 2);
  672. }
  673. TEST_F(SimpleTest, LowerCaseEnumTest)
  674. {
  675. ASSERT_GT(MessageEnumReserved::staticMetaObject.enumeratorCount(), 0);
  676. QMetaEnum simpleEnum;
  677. for (int i = 0; i < MessageEnumReserved::staticMetaObject.enumeratorCount(); i++) {
  678. QMetaEnum tmp = MessageEnumReserved::staticMetaObject.enumerator(i);
  679. if (QString(tmp.name()) == QString("LowerCaseEnum")) {
  680. simpleEnum = tmp;
  681. break;
  682. }
  683. }
  684. ASSERT_TRUE(simpleEnum.isValid());
  685. ASSERT_STREQ(simpleEnum.key(0), "EnumValue0");
  686. ASSERT_STREQ(simpleEnum.key(1), "EnumValue1");
  687. ASSERT_STREQ(simpleEnum.key(2), "EnumValue2");
  688. }
  689. TEST_F(SimpleTest, MapRepeatedFieldSequenceTest)
  690. {
  691. assertMessagePropertyRegistered<sequence::RepeatedFieldSequence, sequence::RepeatedFieldSequence2Repeated>(1, "RepeatedFieldSequence2Repeated", "testField");
  692. assertMessagePropertyRegistered<sequence::MapFieldSequence, sequence::MapFieldSequence::TestFieldEntry>(1, "MapFieldSequence::TestFieldEntry", "testField");
  693. }
  694. } // tests
  695. } // qtprotobuf