simpletest.cpp.inc 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  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. const char *propertyName = "testComplexField";
  279. assertMessagePropertyRegistered<qtprotobufnamespace::tests::ComplexMessage, qtprotobufnamespace::tests::SimpleStringMessage*>(
  280. 2, "qtprotobufnamespace::tests::SimpleStringMessage*", propertyName);
  281. ComplexMessage test;
  282. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<qtprotobufnamespace::tests::SimpleStringMessage*>(new qtprotobufnamespace::tests::SimpleStringMessage{"test qwerty"})));
  283. ASSERT_TRUE(*(test.property(propertyName).value<qtprotobufnamespace::tests::SimpleStringMessage*>()) == qtprotobufnamespace::tests::SimpleStringMessage{"test qwerty"});
  284. ASSERT_TRUE(test.testComplexField() == qtprotobufnamespace::tests::SimpleStringMessage{"test qwerty"});
  285. }
  286. TEST_F(SimpleTest, SimpleBytesMessageTest)
  287. {
  288. const char *propertyName = "testFieldBytes";
  289. SimpleBytesMessage test;
  290. int propertyNumber = SimpleBytesMessage::propertyOrdering.at(1); //See simpletest.proto
  291. ASSERT_EQ(SimpleBytesMessage::staticMetaObject.property(propertyNumber).type(), QMetaType::QByteArray);
  292. ASSERT_STREQ(SimpleBytesMessage::staticMetaObject.property(propertyNumber).name(), propertyName);
  293. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QByteArray>("\x01\x02\x03\x04\x05")));
  294. ASSERT_TRUE(test.property(propertyName).toByteArray() == QByteArray("\x01\x02\x03\x04\x05"));
  295. ASSERT_TRUE(test.testFieldBytes() == QByteArray("\x01\x02\x03\x04\x05"));
  296. }
  297. TEST_F(SimpleTest, SimpleExternalComplexMessageTest)
  298. {
  299. const char *propertyName = "localList";
  300. assertMessagePropertyRegistered<qtprotobufnamespace1::externaltests::SimpleExternalMessage, int32List>(
  301. 1, "QtProtobuf::int32List", propertyName);
  302. qtprotobufnamespace1::externaltests::SimpleExternalMessage test;
  303. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int32List>({1, 2, 3, 4, 5})));
  304. ASSERT_TRUE(test.property(propertyName).value<int32List>() == int32List({1, 2, 3, 4, 5}));
  305. ASSERT_TRUE(test.localList() == int32List({1, 2, 3, 4, 5}));
  306. }
  307. TEST_F(SimpleTest, RepeatedExternalComplexMessageTest)
  308. {
  309. const char *propertyName = "testExternalComplex";
  310. assertMessagePropertyRegistered<RepeatedExternalComplexMessage, qtprotobufnamespace1::externaltests::ExternalComplexMessageRepeated>(
  311. 1, "qtprotobufnamespace1::externaltests::ExternalComplexMessageRepeated", propertyName);
  312. qtprotobufnamespace1::externaltests::SimpleExternalMessage complexMessage;
  313. complexMessage.setLocalList({1, 2, 3, 4, 5});
  314. QSharedPointer<qtprotobufnamespace1::externaltests::ExternalComplexMessage> externalMessage(new qtprotobufnamespace1::externaltests::ExternalComplexMessage);
  315. externalMessage->setTestFieldInt(complexMessage);
  316. qtprotobufnamespace1::externaltests::ExternalComplexMessageRepeated complexMessageList;
  317. complexMessageList << externalMessage;
  318. RepeatedExternalComplexMessage test;
  319. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue(complexMessageList)));
  320. ASSERT_TRUE(test.property(propertyName).value<qtprotobufnamespace1::externaltests::ExternalComplexMessageRepeated>() == complexMessageList);
  321. ASSERT_TRUE(test.testExternalComplex() == complexMessageList);
  322. }
  323. TEST_F(SimpleTest, RepeatedStringMessageTest)
  324. {
  325. const char *propertyName = "testRepeatedString";
  326. assertMessagePropertyRegistered<RepeatedStringMessage, QStringList>(1, "QStringList", propertyName);
  327. RepeatedStringMessage test;
  328. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QStringList>({"Text", "tryam"})));
  329. ASSERT_TRUE(test.property(propertyName).value<QStringList>() == QStringList({"Text", "tryam"}));
  330. ASSERT_TRUE(test.testRepeatedString() == QStringList({"Text", "tryam"}));
  331. }
  332. TEST_F(SimpleTest, RepeatedIntMessageTest)
  333. {
  334. const char *propertyName = "testRepeatedInt";
  335. assertMessagePropertyRegistered<RepeatedIntMessage, int32List>(1, "QtProtobuf::int32List", propertyName);
  336. RepeatedIntMessage test;
  337. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int32List>({1, 2, 3, 4, 5})));
  338. ASSERT_TRUE(test.property(propertyName).value<int32List>() == int32List({1, 2, 3, 4, 5}));
  339. ASSERT_TRUE(test.testRepeatedInt() == int32List({1, 2, 3, 4, 5}));
  340. test.testRepeatedInt().append(66);
  341. ASSERT_TRUE(test.testRepeatedInt() == int32List({1, 2, 3, 4, 5, 66}));
  342. test.testRepeatedInt().pop_back();
  343. ASSERT_TRUE(test.testRepeatedInt() == int32List({1, 2, 3, 4, 5}));
  344. }
  345. TEST_F(SimpleTest, RepeatedDoubleMessageTest)
  346. {
  347. const char *propertyName = "testRepeatedDouble";
  348. assertMessagePropertyRegistered<RepeatedDoubleMessage, DoubleList>(1, "QtProtobuf::DoubleList", propertyName);
  349. RepeatedDoubleMessage test;
  350. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QtProtobuf::DoubleList>({1.0, 2.3, 3, 4.7, 5.9})));
  351. ASSERT_TRUE(test.property(propertyName).value<QtProtobuf::DoubleList>() == QtProtobuf::DoubleList({1.0, 2.3, 3, 4.7, 5.9}));
  352. ASSERT_TRUE(test.testRepeatedDouble() == QtProtobuf::DoubleList({1.0, 2.3, 3, 4.7, 5.9}));
  353. test.testRepeatedDouble().append(6.6);
  354. ASSERT_TRUE(test.testRepeatedDouble() == QtProtobuf::DoubleList({1.0, 2.3, 3, 4.7, 5.9, 6.6}));
  355. test.testRepeatedDouble().pop_back();
  356. ASSERT_TRUE(test.testRepeatedDouble() == QtProtobuf::DoubleList({1.0, 2.3, 3, 4.7, 5.9}));
  357. }
  358. TEST_F(SimpleTest, RepeatedFloatMessageTest)
  359. {
  360. const char *propertyName = "testRepeatedFloat";
  361. assertMessagePropertyRegistered<RepeatedFloatMessage, FloatList>(1, "QtProtobuf::FloatList", propertyName);
  362. RepeatedFloatMessage test;
  363. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QtProtobuf::FloatList>({1.0f, 2.3f, 3, 4.7f, 5.9f})));
  364. ASSERT_TRUE(test.property(propertyName).value<QtProtobuf::FloatList>() == QtProtobuf::FloatList({1.0f, 2.3f, 3, 4.7f, 5.9f}));
  365. ASSERT_TRUE(test.testRepeatedFloat() == QtProtobuf::FloatList({1.0f, 2.3f, 3, 4.7f, 5.9f}));
  366. test.testRepeatedFloat().append(6.6f);
  367. ASSERT_TRUE(test.testRepeatedFloat() == QtProtobuf::FloatList({1.0f, 2.3f, 3, 4.7f, 5.9f, 6.6f}));
  368. test.testRepeatedFloat().pop_back();
  369. ASSERT_TRUE(test.testRepeatedFloat() == QtProtobuf::FloatList({1.0f, 2.3f, 3, 4.7f, 5.9f}));
  370. }
  371. TEST_F(SimpleTest, RepeatedBytesMessageTest)
  372. {
  373. const char *propertyName = "testRepeatedBytes";
  374. assertMessagePropertyRegistered<RepeatedBytesMessage, QByteArrayList>(1, "QByteArrayList", propertyName);
  375. QByteArrayList bList;
  376. bList << "\x01\x02\x03\x04\x05";
  377. bList << "\x01\x05\x03\x04\x03";
  378. RepeatedBytesMessage test;
  379. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<QByteArrayList>(bList)));
  380. ASSERT_TRUE(test.property(propertyName).value<QByteArrayList>() == bList);
  381. ASSERT_TRUE(test.testRepeatedBytes() == bList);
  382. bList << "\x01\x05\x03\x03";
  383. test.testRepeatedBytes() << "\x01\x05\x03\x03";
  384. ASSERT_TRUE(test.testRepeatedBytes() == bList);
  385. bList.pop_back();
  386. test.testRepeatedBytes().pop_back();
  387. ASSERT_TRUE(test.testRepeatedBytes() == bList);
  388. }
  389. TEST_F(SimpleTest, RepeatedSIntMessageTest)
  390. {
  391. const char *propertyName = "testRepeatedInt";
  392. assertMessagePropertyRegistered<RepeatedSIntMessage, sint32List>(1, "QtProtobuf::sint32List", propertyName);
  393. RepeatedSIntMessage test;
  394. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint32List>({1, 2, 3, 4, 5})));
  395. ASSERT_TRUE(test.property(propertyName).value<sint32List>() == sint32List({1, 2, 3, 4, 5}));
  396. ASSERT_TRUE(test.testRepeatedInt() == sint32List({1, 2, 3, 4, 5}));
  397. test.testRepeatedInt() << 6;
  398. ASSERT_TRUE(test.testRepeatedInt() == sint32List({1, 2, 3, 4, 5, 6}));
  399. test.testRepeatedInt().pop_back();
  400. ASSERT_TRUE(test.testRepeatedInt() == sint32List({1, 2, 3, 4, 5}));
  401. }
  402. TEST_F(SimpleTest, RepeatedUIntMessageTest)
  403. {
  404. const char *propertyName = "testRepeatedInt";
  405. assertMessagePropertyRegistered<RepeatedUIntMessage, uint32List>(1, "QtProtobuf::uint32List", propertyName);
  406. RepeatedUIntMessage test;
  407. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<uint32List>({1, 2, 3, 4, 5})));
  408. ASSERT_TRUE(test.property(propertyName).value<uint32List>() == uint32List({1, 2, 3, 4, 5}));
  409. ASSERT_TRUE(test.testRepeatedInt() == uint32List({1, 2, 3, 4, 5}));
  410. test.testRepeatedInt().append(6);
  411. ASSERT_TRUE(test.testRepeatedInt() == uint32List({1, 2, 3, 4, 5,6}));
  412. test.testRepeatedInt().pop_back();
  413. ASSERT_TRUE(test.testRepeatedInt() == uint32List({1, 2, 3, 4, 5}));
  414. }
  415. TEST_F(SimpleTest, RepeatedInt64MessageTest)
  416. {
  417. const char *propertyName = "testRepeatedInt";
  418. assertMessagePropertyRegistered<RepeatedInt64Message, int64List>(1, "QtProtobuf::int64List", propertyName);
  419. RepeatedInt64Message test;
  420. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<int64List>({1, 2, 3, 4, 5})));
  421. ASSERT_TRUE(test.property(propertyName).value<int64List>() == int64List({1, 2, 3, 4, 5}));
  422. ASSERT_TRUE(test.testRepeatedInt() == int64List({1, 2, 3, 4, 5}));
  423. test.testRepeatedInt().append(69);
  424. ASSERT_TRUE(test.testRepeatedInt() == int64List({1, 2, 3, 4, 5, 69}));
  425. test.testRepeatedInt().pop_back();
  426. ASSERT_TRUE(test.testRepeatedInt() == int64List({1, 2, 3, 4, 5}));
  427. }
  428. TEST_F(SimpleTest, RepeatedSInt64MessageTest)
  429. {
  430. const char *propertyName = "testRepeatedInt";
  431. assertMessagePropertyRegistered<RepeatedSInt64Message, sint64List>(1, "QtProtobuf::sint64List", propertyName);
  432. RepeatedSInt64Message test;
  433. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sint64List>({1, 2, 3, 4, 5})));
  434. ASSERT_TRUE(test.property(propertyName).value<sint64List>() == sint64List({1, 2, 3, 4, 5}));
  435. ASSERT_TRUE(test.testRepeatedInt() == sint64List({1, 2, 3, 4, 5}));
  436. test.testRepeatedInt() << 96;
  437. ASSERT_TRUE(test.testRepeatedInt() == sint64List({1, 2, 3, 4, 5, 96}));
  438. test.testRepeatedInt().pop_back();
  439. ASSERT_TRUE(test.testRepeatedInt() == sint64List({1, 2, 3, 4, 5}));
  440. }
  441. TEST_F(SimpleTest, RepeatedUInt64MessageTest)
  442. {
  443. const char *propertyName = "testRepeatedInt";
  444. assertMessagePropertyRegistered<RepeatedUInt64Message, uint64List>(1, "QtProtobuf::uint64List", propertyName);
  445. RepeatedUInt64Message test;
  446. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<uint64List>({1, 2, 3, 4, 5})));
  447. ASSERT_TRUE(test.property(propertyName).value<uint64List>() == uint64List({1, 2, 3, 4, 5}));
  448. ASSERT_TRUE(test.testRepeatedInt() == uint64List({1, 2, 3, 4, 5}));
  449. test.testRepeatedInt().append(96);
  450. ASSERT_TRUE(test.testRepeatedInt() == uint64List({1, 2, 3, 4, 5, 96}));
  451. test.testRepeatedInt().pop_back();
  452. ASSERT_TRUE(test.testRepeatedInt() == uint64List({1, 2, 3, 4, 5}));
  453. }
  454. TEST_F(SimpleTest, RepeatedFixedIntMessageTest)
  455. {
  456. const char *propertyName = "testRepeatedInt";
  457. assertMessagePropertyRegistered<RepeatedFixedIntMessage, fixed32List>(1, "QtProtobuf::fixed32List", propertyName);
  458. RepeatedFixedIntMessage test;
  459. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<fixed32List>({1, 2, 3, 4, 5})));
  460. ASSERT_TRUE(test.property(propertyName).value<fixed32List>() == fixed32List({1, 2, 3, 4, 5}));
  461. ASSERT_TRUE(test.testRepeatedInt() == fixed32List({1, 2, 3, 4, 5}));
  462. test.testRepeatedInt() << 0;
  463. ASSERT_TRUE(test.testRepeatedInt() == fixed32List({1, 2, 3, 4, 5, 0}));
  464. test.testRepeatedInt().pop_back();
  465. ASSERT_TRUE(test.testRepeatedInt() == fixed32List({1, 2, 3, 4, 5}));
  466. }
  467. TEST_F(SimpleTest, RepeatedFixedInt64MessageTest)
  468. {
  469. const char *propertyName = "testRepeatedInt";
  470. assertMessagePropertyRegistered<RepeatedFixedInt64Message, fixed64List>(1, "QtProtobuf::fixed64List", propertyName);
  471. RepeatedFixedInt64Message test;
  472. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<fixed64List>({1, 2, 3, 4, 5})));
  473. ASSERT_TRUE(test.property(propertyName).value<fixed64List>() == fixed64List({1, 2, 3, 4, 5}));
  474. ASSERT_TRUE(test.testRepeatedInt() == fixed64List({1, 2, 3, 4, 5}));
  475. test.testRepeatedInt() << 0;
  476. ASSERT_TRUE(test.testRepeatedInt() == fixed64List({1, 2, 3, 4, 5, 0}));
  477. test.testRepeatedInt().pop_back();
  478. ASSERT_TRUE(test.testRepeatedInt() == fixed64List({1, 2, 3, 4, 5}));
  479. }
  480. TEST_F(SimpleTest, RepeatedSFixedIntMessageTest)
  481. {
  482. const char *propertyName = "testRepeatedInt";
  483. assertMessagePropertyRegistered<RepeatedSFixedIntMessage, sfixed32List>(1, "QtProtobuf::sfixed32List", propertyName);
  484. RepeatedSFixedIntMessage test;
  485. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sfixed32List>({1, 2, 3, 4, 5})));
  486. ASSERT_TRUE(test.property(propertyName).value<sfixed32List>() == sfixed32List({1, 2, 3, 4, 5}));
  487. ASSERT_TRUE(test.testRepeatedInt() == sfixed32List({1, 2, 3, 4, 5}));
  488. test.testRepeatedInt() << 0;
  489. ASSERT_TRUE(test.testRepeatedInt() == sfixed32List({1, 2, 3, 4, 5, 0}));
  490. test.testRepeatedInt().pop_back();
  491. ASSERT_TRUE(test.testRepeatedInt() == sfixed32List({1, 2, 3, 4, 5}));
  492. }
  493. TEST_F(SimpleTest, RepeatedSFixedInt64MessageTest)
  494. {
  495. const char *propertyName = "testRepeatedInt";
  496. assertMessagePropertyRegistered<RepeatedSFixedInt64Message, QtProtobuf::sfixed64List>(1, "QtProtobuf::sfixed64List", propertyName);
  497. RepeatedSFixedInt64Message test;
  498. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<sfixed64List>({1, 2, 3, 4, 5})));
  499. ASSERT_TRUE(test.property(propertyName).value<sfixed64List>() == sfixed64List({1, 2, 3, 4, 5}));
  500. ASSERT_TRUE(test.testRepeatedInt() == sfixed64List({1, 2, 3, 4, 5}));
  501. test.testRepeatedInt() << 0;
  502. ASSERT_TRUE(test.testRepeatedInt() == sfixed64List({1, 2, 3, 4, 5, 0}));
  503. test.testRepeatedInt().pop_back();
  504. ASSERT_TRUE(test.testRepeatedInt() == sfixed64List({1, 2, 3, 4, 5}));
  505. }
  506. TEST_F(SimpleTest, StepChildEnumMessageTest)
  507. {
  508. const char *propertyName = "localStepChildEnum";
  509. assertMessagePropertyRegistered<StepChildEnumMessage, SimpleEnumMessage::LocalEnum>(1, "qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnum", propertyName);
  510. StepChildEnumMessage test;
  511. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<SimpleEnumMessage::LocalEnum>(SimpleEnumMessage::LocalEnum::LOCAL_ENUM_VALUE2)));
  512. ASSERT_TRUE(test.property(propertyName).value<SimpleEnumMessage::LocalEnum>() == SimpleEnumMessage::LocalEnum::LOCAL_ENUM_VALUE2);
  513. ASSERT_TRUE(test.localStepChildEnum() == SimpleEnumMessage::LocalEnum::LOCAL_ENUM_VALUE2);
  514. }
  515. TEST_F(SimpleTest, StepChildEnumListMessageTest)
  516. {
  517. const char *propertyName = "localStepChildList";
  518. assertMessagePropertyRegistered<StepChildEnumMessage, SimpleEnumMessage::LocalEnumRepeated>(2, "qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnumRepeated", propertyName);
  519. SimpleEnumMessage::LocalEnumRepeated value({SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  520. SimpleEnumMessage::LOCAL_ENUM_VALUE2,
  521. SimpleEnumMessage::LOCAL_ENUM_VALUE1,
  522. SimpleEnumMessage::LOCAL_ENUM_VALUE3});
  523. StepChildEnumMessage test;
  524. ASSERT_TRUE(test.setProperty(propertyName, QVariant::fromValue<qtprotobufnamespace::tests::SimpleEnumMessage::LocalEnumRepeated>(value)));
  525. ASSERT_TRUE(test.property(propertyName).value<SimpleEnumMessage::LocalEnumRepeated>() == value);
  526. ASSERT_TRUE(test.localStepChildList() == value);
  527. }
  528. TEST_F(SimpleTest, SimpleSInt32StringMapMessageTest)
  529. {
  530. const char *propertyName = "mapField";
  531. assertMessagePropertyRegistered<SimpleSInt32StringMapMessage, SimpleSInt32StringMapMessage::MapFieldEntry>(1, "qtprotobufnamespace::tests::SimpleSInt32StringMapMessage::MapFieldEntry", propertyName);
  532. ASSERT_TRUE(QMetaType::isRegistered(qMetaTypeId<SimpleSInt32StringMapMessage::MapFieldEntry>()));
  533. SimpleSInt32StringMapMessage::MapFieldEntry testMap = {{10, {"Some 10"}}, {0, {"Some 0"}}, {44, {"Some 44"}}};
  534. SimpleSInt32StringMapMessage test;
  535. test.setMapField(testMap);
  536. ASSERT_TRUE(test.property(propertyName).value<SimpleSInt32StringMapMessage::MapFieldEntry>() == testMap);
  537. ASSERT_TRUE(test.mapField() == testMap);
  538. ASSERT_STREQ(test.mapField()[10].toStdString().c_str(), "Some 10");
  539. ASSERT_STREQ(test.mapField()[0].toStdString().c_str(), "Some 0");
  540. ASSERT_STREQ(test.mapField()[44].toStdString().c_str(), "Some 44");
  541. test.mapField()[66] = "Some 66";
  542. ASSERT_STREQ(test.mapField()[66].toStdString().c_str(), "Some 66");
  543. test.mapField()[66] = "Some default";
  544. ASSERT_STREQ(test.mapField()[66].toStdString().c_str(), "Some default");
  545. }
  546. TEST_F(SimpleTest, SimpleStringStringMapMessageTest)
  547. {
  548. const char *propertyName = "mapField";
  549. assertMessagePropertyRegistered<SimpleStringStringMapMessage, SimpleStringStringMapMessage::MapFieldEntry>(13, "qtprotobufnamespace::tests::SimpleStringStringMapMessage::MapFieldEntry", propertyName);
  550. ASSERT_TRUE(QMetaType::isRegistered(qMetaTypeId<SimpleStringStringMapMessage::MapFieldEntry>()));
  551. SimpleStringStringMapMessage::MapFieldEntry testMap = {{"key 10", "Some 10"}, {"key 0", "Some 0"}, {"key 44", "Some 44"}};
  552. SimpleStringStringMapMessage test;
  553. test.setMapField(testMap);
  554. ASSERT_TRUE(test.property(propertyName).value<SimpleStringStringMapMessage::MapFieldEntry>() == testMap);
  555. ASSERT_TRUE(test.mapField() == testMap);
  556. ASSERT_STREQ(test.mapField()["key 10"].toStdString().c_str(), "Some 10");
  557. ASSERT_STREQ(test.mapField()["key 0"].toStdString().c_str(), "Some 0");
  558. ASSERT_STREQ(test.mapField()["key 44"].toStdString().c_str(), "Some 44");
  559. test.mapField()["key 66"] = "Some 66";
  560. ASSERT_STREQ(test.mapField()["key 66"].toStdString().c_str(), "Some 66");
  561. test.mapField()["key 66"] = "Some default";
  562. ASSERT_STREQ(test.mapField()["key 66"].toStdString().c_str(), "Some default");
  563. }
  564. TEST_F(SimpleTest, EmptyMessageTest)
  565. {
  566. ASSERT_EQ(EmptyMessage::propertyOrdering.size(), 0);
  567. ASSERT_EQ(EmptyMessage::staticMetaObject.propertyCount(), 1);
  568. }
  569. TEST_F(SimpleTest, NullPointerMessageTest)
  570. {
  571. ComplexMessage msg(0, {QString("not null")});
  572. msg.setTestComplexField_p(nullptr);
  573. ASSERT_TRUE(msg.testComplexField().testFieldString().isEmpty());
  574. }
  575. TEST_F(SimpleTest, AssignmentOperatorTest)
  576. {
  577. const char *propertyName = "testFieldInt";
  578. SimpleIntMessage test;
  579. SimpleIntMessage test2{35};
  580. QSignalSpy updateSpy(&test, &SimpleIntMessage::testFieldIntChanged);
  581. test.setProperty(propertyName, QVariant::fromValue<int32>(15));
  582. test.setTestFieldInt(25);
  583. test = test2;
  584. test = test;
  585. test = test2;
  586. ASSERT_EQ(test2.testFieldInt(), test.testFieldInt());
  587. ASSERT_EQ(3, updateSpy.count());
  588. }
  589. TEST_F(SimpleTest, MoveOperatorTest)
  590. {
  591. const char *propertyName = "testFieldInt";
  592. SimpleIntMessage test;
  593. SimpleIntMessage test2{35};
  594. QSignalSpy updateSpy(&test, &SimpleIntMessage::testFieldIntChanged);
  595. QSignalSpy movedUpdateSpy(&test2, &SimpleIntMessage::testFieldIntChanged);
  596. SimpleIntMessage test3(std::move(test2));
  597. test2.setTestFieldInt(35);
  598. test.setProperty(propertyName, QVariant::fromValue<int32>(15));
  599. test.setTestFieldInt(25);
  600. test = std::move(test2);
  601. ASSERT_EQ(35, test.testFieldInt());
  602. ASSERT_EQ(0, test2.testFieldInt());
  603. ASSERT_EQ(3, updateSpy.count());
  604. ASSERT_EQ(3, movedUpdateSpy.count());
  605. }
  606. TEST_F(SimpleTest, MoveOperatorRepeatedTest)
  607. {
  608. const char *propertyName = "testRepeatedInt";
  609. RepeatedIntMessage test;
  610. RepeatedIntMessage test2{{55,44,11,33}};
  611. QSignalSpy updateSpy(&test, &RepeatedIntMessage::testRepeatedIntChanged);
  612. QSignalSpy movedUpdateSpy(&test2, &RepeatedIntMessage::testRepeatedIntChanged);
  613. RepeatedIntMessage test3(std::move(test2));
  614. test2.setTestRepeatedInt({55,44,11,35});
  615. test.setProperty(propertyName, QVariant::fromValue<QtProtobuf::int32List>({55}));
  616. test.setTestRepeatedInt({44});
  617. test = std::move(test2);
  618. ASSERT_EQ(QtProtobuf::int32List({55,44,11,35}), test.testRepeatedInt());
  619. ASSERT_TRUE(test2.testRepeatedInt().isEmpty());
  620. ASSERT_EQ(3, updateSpy.count());
  621. ASSERT_EQ(3, movedUpdateSpy.count());
  622. }
  623. TEST_F(SimpleTest, UnderscoresTest)
  624. {
  625. //Sanity compilation checks
  626. Message_Uderscore_name msg1;
  627. MessageUderscorename msg2;
  628. MessageUnderscoreField msg3;
  629. PriorMessageUnderscoreField msg4;
  630. FollowingMessageUnderscoreField msg5;
  631. CombinedMessageUnderscoreField msg6;
  632. assertMessagePropertyRegistered<MessageUnderscoreField, sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
  633. assertMessagePropertyRegistered<PriorMessageUnderscoreField, sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
  634. assertMessagePropertyRegistered<PriorMessageUnderscoreField, sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
  635. assertMessagePropertyRegistered<FollowingMessageUnderscoreField , sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
  636. assertMessagePropertyRegistered<CombinedMessageUnderscoreField , sint32>(1, "QtProtobuf::sint32", "underScoreMessageField");
  637. }
  638. TEST_F(SimpleTest, SequenceTest)
  639. {
  640. assertMessagePropertyRegistered<sequence::TestMessageSequence, sequence::TestMessageSequence2*>(1, "qtprotobufnamespace::tests::sequence::TestMessageSequence2*", "testField");
  641. assertMessagePropertyRegistered<sequence::TestMessageSequence2, bool>(1, "bool", "testField");
  642. }
  643. TEST_F(SimpleTest, CyclingTest)
  644. {
  645. assertMessagePropertyRegistered<sequence::CyclingFirstDependency, sequence::CyclingSecondDependency*>(1, "qtprotobufnamespace::tests::sequence::CyclingSecondDependency*", "testField");
  646. assertMessagePropertyRegistered<sequence::CyclingSecondDependency, sequence::CyclingFirstDependency*>(1, "qtprotobufnamespace::tests::sequence::CyclingFirstDependency*", "testField");
  647. }
  648. TEST_F(SimpleTest, UpperCaseTest)
  649. {
  650. assertMessagePropertyRegistered<MessageUpperCase, sint32>(1, "QtProtobuf::sint32", "testField");
  651. }
  652. TEST_F(SimpleTest, ReservedTest)
  653. {
  654. assertMessagePropertyRegistered<MessageReserved, sint32>(1, "QtProtobuf::sint32", "import_proto");
  655. assertMessagePropertyRegistered<MessageReserved, sint32>(2, "QtProtobuf::sint32", "property_proto");
  656. assertMessagePropertyRegistered<MessageReserved, sint32>(3, "QtProtobuf::sint32", "id_proto");
  657. }
  658. TEST_F(SimpleTest, ReservedUpperCaseTest)
  659. {
  660. assertMessagePropertyRegistered<MessageUpperCaseReserved, sint32>(1, "QtProtobuf::sint32", "import_proto");
  661. assertMessagePropertyRegistered<MessageUpperCaseReserved, sint32>(2, "QtProtobuf::sint32", "property_proto");
  662. assertMessagePropertyRegistered<MessageUpperCaseReserved, sint32>(3, "QtProtobuf::sint32", "id_proto");
  663. }
  664. TEST_F(SimpleTest, ReservedEnumTest)
  665. {
  666. ASSERT_GT(MessageEnumReserved::staticMetaObject.enumeratorCount(), 0);
  667. QMetaEnum simpleEnum;
  668. for (int i = 0; i < MessageEnumReserved::staticMetaObject.enumeratorCount(); i++) {
  669. QMetaEnum tmp = MessageEnumReserved::staticMetaObject.enumerator(i);
  670. if (QString(tmp.name()) == QString("ReservedEnum")) {
  671. simpleEnum = tmp;
  672. break;
  673. }
  674. }
  675. ASSERT_TRUE(simpleEnum.isValid());
  676. ASSERT_STREQ(simpleEnum.key(0), "Import");
  677. ASSERT_STREQ(simpleEnum.key(1), "Property");
  678. ASSERT_STREQ(simpleEnum.key(2), "Id");
  679. ASSERT_EQ(simpleEnum.value(0), 0);
  680. ASSERT_EQ(simpleEnum.value(1), 1);
  681. ASSERT_EQ(simpleEnum.value(2), 2);
  682. }
  683. TEST_F(SimpleTest, LowerCaseEnumTest)
  684. {
  685. ASSERT_GT(MessageEnumReserved::staticMetaObject.enumeratorCount(), 0);
  686. QMetaEnum simpleEnum;
  687. for (int i = 0; i < MessageEnumReserved::staticMetaObject.enumeratorCount(); i++) {
  688. QMetaEnum tmp = MessageEnumReserved::staticMetaObject.enumerator(i);
  689. if (QString(tmp.name()) == QString("LowerCaseEnum")) {
  690. simpleEnum = tmp;
  691. break;
  692. }
  693. }
  694. ASSERT_TRUE(simpleEnum.isValid());
  695. ASSERT_STREQ(simpleEnum.key(0), "EnumValue0");
  696. ASSERT_STREQ(simpleEnum.key(1), "EnumValue1");
  697. ASSERT_STREQ(simpleEnum.key(2), "EnumValue2");
  698. }
  699. TEST_F(SimpleTest, MapRepeatedFieldSequenceTest)
  700. {
  701. assertMessagePropertyRegistered<sequence::RepeatedFieldSequence, sequence::RepeatedFieldSequence2Repeated>(1, "qtprotobufnamespace::tests::sequence::RepeatedFieldSequence2Repeated", "testField");
  702. assertMessagePropertyRegistered<sequence::MapFieldSequence, sequence::MapFieldSequence::TestFieldEntry>(1, "qtprotobufnamespace::tests::sequence::MapFieldSequence::TestFieldEntry", "testField");
  703. }
  704. } // tests
  705. } // qtprotobuf