simpletest.cpp.inc 37 KB

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