simpletest.cpp.inc 37 KB

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